21720:
[arvados.git] / services / workbench2 / src / views / inactive-panel / inactive-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { Dispatch } from 'redux';
7 import { connect } from 'react-redux';
8 import { Grid, Typography, Button } from '@mui/material';
9 import { CustomStyleRulesCallback } from 'common/custom-theme';
10 import { WithStyles } from '@mui/styles';
11 import withStyles from '@mui/styles/withStyles';
12 import { ArvadosTheme } from 'common/custom-theme';
13 import { navigateToLinkAccount } from 'store/navigation/navigation-action';
14 import { RootState } from 'store/store';
15 import { sanitizeHTML } from 'common/html-sanitize';
16
17 export type CssRules = 'root' | 'ontop' | 'title';
18
19 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20     root: {
21         position: 'relative',
22         backgroundColor: theme.palette.grey["200"],
23         background: 'url("arvados-logo-big.png") no-repeat center center',
24         backgroundBlendMode: 'soft-light',
25     },
26     ontop: {
27         zIndex: 10
28     },
29     title: {
30         marginBottom: theme.spacing(6),
31         color: theme.palette.grey["800"]
32     }
33 });
34
35 export interface InactivePanelActionProps {
36     startLinking: () => void;
37 }
38
39 const mapDispatchToProps = (dispatch: Dispatch): InactivePanelActionProps => ({
40     startLinking: () => {
41         dispatch<any>(navigateToLinkAccount);
42     }
43 });
44
45 const mapStateToProps = (state: RootState): InactivePanelStateProps => ({
46     inactivePageText: state.auth.config.clusterConfig.Workbench.InactivePageHTML,
47     isLoginClusterFederation: state.auth.config.clusterConfig.Login.LoginCluster !== '',
48 });
49
50 export interface InactivePanelStateProps {
51     inactivePageText: string;
52     isLoginClusterFederation: boolean;
53 }
54
55 type InactivePanelProps = WithStyles<CssRules> & InactivePanelActionProps & InactivePanelStateProps;
56
57 export const InactivePanelRoot = ({ classes, startLinking, inactivePageText, isLoginClusterFederation }: InactivePanelProps) =>
58     <Grid container justifyContent="center" alignItems="center" direction="column" spacing={3}
59         className={classes.root}
60         style={{ marginTop: 56, height: "100%" }}>
61         <Grid item>
62             <Typography>
63                 <span dangerouslySetInnerHTML={{ __html: sanitizeHTML(inactivePageText) }} style={{ margin: "1em" }} />
64             </Typography>
65         </Grid>
66         { !isLoginClusterFederation
67         ? <><Grid item>
68             <Typography align="center">
69             If you would like to use this login to access another account click "Link Account".
70             </Typography>
71         </Grid>
72         <Grid item>
73             <Button className={classes.ontop} color="primary" variant="contained" onClick={() => startLinking()}>
74                 Link Account
75             </Button>
76         </Grid></>
77         : <><Grid item>
78             <Typography align="center">
79                 If you would like to use this login to access another account, please contact your administrator.
80             </Typography>
81         </Grid></> }
82     </Grid >;
83
84 export const InactivePanel = connect(mapStateToProps, mapDispatchToProps)(
85     withStyles(styles)(InactivePanelRoot));