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 },
57 export const LoginPanel = withStyles(styles)(
58 connect((state: RootState) => ({
59 remoteHosts: state.auth.remoteHosts,
60 homeCluster: state.auth.homeCluster,
61 uuidPrefix: state.auth.localCluster,
62 welcomePage: state.config.clusterConfig.Workbench.WelcomePageHTML
63 }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, welcomePage }: LoginPanelProps) =>
64 <Grid container justify="center" alignItems="center"
65 className={classes.root}
66 style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
67 <Grid item className={classes.container}>
69 <div dangerouslySetInnerHTML={{ __html: welcomePage }} style={{ margin: "1em" }} />
71 {Object.keys(remoteHosts).length > 1 &&
72 <Typography component="div" align="right">
73 <label>Please select the cluster that hosts your user account:</label>
74 <Select native value={homeCluster} style={{ margin: "1em" }}
75 onChange={(event) => dispatch(authActions.SET_HOME_CLUSTER(event.target.value))}>
76 {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
80 <Typography component="div" align="right">
81 <Button variant="contained" color="primary" style={{ margin: "1em" }} className={classes.button}
82 onClick={() => dispatch(login(uuidPrefix, homeCluster, remoteHosts))}>
83 Log in to {uuidPrefix}
84 {uuidPrefix !== homeCluster &&
85 <span> with user from {homeCluster}</span>}