1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect, DispatchProp } from 'react-redux';
7 import { Grid, Typography, Button, Select } from '@material-ui/core';
8 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
9 import { login, authActions } from '~/store/auth/auth-action';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { RootState } from '~/store/store';
13 type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
15 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
18 backgroundColor: theme.palette.grey["200"],
34 marginBottom: theme.spacing.unit * 6,
35 color: theme.palette.grey["800"]
38 marginBottom: theme.spacing.unit * 3,
40 color: theme.palette.grey["800"]
50 type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
51 remoteHosts: { [key: string]: string },
58 export const LoginPanel = withStyles(styles)(
59 connect((state: RootState) => ({
60 remoteHosts: state.auth.remoteHosts,
61 homeCluster: state.auth.homeCluster,
62 uuidPrefix: state.auth.localCluster,
63 loginCluster: state.auth.loginCluster,
64 welcomePage: state.auth.config.clusterConfig.Workbench.WelcomePageHTML
65 }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster, welcomePage }: LoginPanelProps) =>
66 <Grid container justify="center" alignItems="center"
67 className={classes.root}
68 style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
69 <Grid item className={classes.container}>
70 <Typography component="div">
71 <div dangerouslySetInnerHTML={{ __html: welcomePage }} style={{ margin: "1em" }} />
73 {Object.keys(remoteHosts).length > 1 && loginCluster === "" &&
75 <Typography component="div" align="right">
76 <label>Please select the cluster that hosts your user account:</label>
77 <Select native value={homeCluster} style={{ margin: "1em" }}
78 onChange={(event) => dispatch(authActions.SET_HOME_CLUSTER(event.target.value))}>
79 {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
83 <Typography component="div" align="right">
84 <Button variant="contained" color="primary" style={{ margin: "1em" }} className={classes.button}
85 onClick={() => dispatch(login(uuidPrefix, homeCluster, loginCluster, remoteHosts))}>
87 {uuidPrefix !== homeCluster && loginCluster !== homeCluster &&
88 <span> to {uuidPrefix} with user from {homeCluster}</span>}