Merge branch '17754-federated-acct-merge'. Closes #17754.
[arvados-workbench2.git] / src / views / inactive-panel / inactive-panel.tsx
index abfa1f8129aad55e8e7df7351056ea336fac70ec..8a7c7928933925e77462d7d8b5e4e8d0875bbbdd 100644 (file)
@@ -2,16 +2,16 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { connect, DispatchProp } from 'react-redux';
-import { Grid, Typography, Button, Select } from '@material-ui/core';
+import React from 'react';
+import { Dispatch } from 'redux';
+import { connect } from 'react-redux';
+import { Grid, Typography, Button } from '@material-ui/core';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
-import { login, authActions } from '~/store/auth/auth-action';
-import { ArvadosTheme } from '~/common/custom-theme';
-import { RootState } from '~/store/store';
-import * as classNames from 'classnames';
+import { ArvadosTheme } from 'common/custom-theme';
+import { navigateToLinkAccount } from 'store/navigation/navigation-action';
+import { RootState } from 'store/store';
 
-type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
+export type CssRules = 'root' | 'ontop' | 'title';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
@@ -28,51 +28,64 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
             opacity: 0.2,
         }
     },
-    container: {
-        width: '560px',
+    ontop: {
         zIndex: 10
     },
     title: {
         marginBottom: theme.spacing.unit * 6,
         color: theme.palette.grey["800"]
-    },
-    content: {
-        marginBottom: theme.spacing.unit * 3,
-        lineHeight: '1.2rem',
-        color: theme.palette.grey["800"]
-    },
-    'content__bolder': {
-        fontWeight: 'bolder'
-    },
-    button: {
-        boxShadow: 'none'
     }
 });
 
-type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
-    remoteHosts: { [key: string]: string },
-    homeCluster: string,
-    uuidPrefix: string
-};
+export interface InactivePanelActionProps {
+    startLinking: () => void;
+}
+
+const mapDispatchToProps = (dispatch: Dispatch): InactivePanelActionProps => ({
+    startLinking: () => {
+        dispatch<any>(navigateToLinkAccount);
+    }
+});
+
+const mapStateToProps = (state: RootState): InactivePanelStateProps => ({
+    inactivePageText: state.auth.config.clusterConfig.Workbench.InactivePageHTML,
+    isLoginClusterFederation: state.auth.config.clusterConfig.Login.LoginCluster !== '',
+});
+
+export interface InactivePanelStateProps {
+    inactivePageText: string;
+    isLoginClusterFederation: boolean;
+}
+
+type InactivePanelProps = WithStyles<CssRules> & InactivePanelActionProps & InactivePanelStateProps;
+
 
-export const InactivePanel = withStyles(styles)(
-    connect((state: RootState) => ({
-        remoteHosts: state.auth.remoteHosts,
-        homeCluster: state.auth.homeCluster,
-        uuidPrefix: state.auth.localCluster
-    }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix }: LoginPanelProps) =>
-        <Grid container justify="center" alignItems="center"
-            className={classes.root}
-            style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
-            <Grid item className={classes.container}>
-                <Typography variant='h6' align="center" className={classes.title}>
-                    Hi! You're logged in, but...
-               </Typography>
-                <Typography>
-                    Your account is inactive.
+export const InactivePanelRoot = ({ classes, startLinking, inactivePageText, isLoginClusterFederation }: InactivePanelProps) =>
+    <Grid container justify="center" alignItems="center" direction="column" spacing={24}
+        className={classes.root}
+        style={{ marginTop: 56, height: "100%" }}>
+        <Grid item>
+            <Typography>
+                <span dangerouslySetInnerHTML={{ __html: inactivePageText }} style={{ margin: "1em" }} />
+            </Typography>
+        </Grid>
+        { !isLoginClusterFederation
+        ? <><Grid item>
+            <Typography align="center">
+            If you would like to use this login to access another account click "Link Account".
+            </Typography>
+        </Grid>
+        <Grid item>
+            <Button className={classes.ontop} color="primary" variant="contained" onClick={() => startLinking()}>
+                Link Account
+            </Button>
+        </Grid></>
+        : <><Grid item>
+            <Typography align="center">
+                If you would like to use this login to access another account, please contact your administrator.
+            </Typography>
+        </Grid></> }
+    </Grid >;
 
-                   An administrator must activate your account before you can get any further.
-               </Typography>
-            </Grid>
-        </Grid >
-    ));
+export const InactivePanel = connect(mapStateToProps, mapDispatchToProps)(
+    withStyles(styles)(InactivePanelRoot));