14720: Federated login chooser wip
[arvados.git] / src / views / login-panel / login-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { connect, DispatchProp } from 'react-redux';
7 import { Grid, Typography, Button } from '@material-ui/core';
8 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
9 import { login } from '~/store/auth/auth-action';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { RootState } from '~/store/store';
12 import { getProperty } from '~/store/properties/properties';
13 import { propertiesActions } from '~/store/properties/properties-actions';
14 import * as classNames from 'classnames';
15
16 type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
17
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19     root: {
20         position: 'relative',
21         backgroundColor: theme.palette.grey["200"],
22         '&::after': {
23             content: `''`,
24             position: 'absolute',
25             top: 0,
26             left: 0,
27             bottom: 0,
28             right: 0,
29             background: 'url("arvados-logo-big.png") no-repeat center center',
30             opacity: 0.2,
31         }
32     },
33     container: {
34         width: '560px',
35         zIndex: 10
36     },
37     title: {
38         marginBottom: theme.spacing.unit * 6,
39         color: theme.palette.grey["800"]
40     },
41     content: {
42         marginBottom: theme.spacing.unit * 3,
43         lineHeight: '1.2rem',
44         color: theme.palette.grey["800"]
45     },
46     'content__bolder': {
47         fontWeight: 'bolder'
48     },
49     button: {
50         boxShadow: 'none'
51     }
52 });
53
54 type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
55     remoteHosts: any,
56     homeCluster: string,
57     uuidPrefix: string
58 };
59
60 export const REMOTE_HOSTS_NAME = 'remoteHosts';
61 export const HOME_CLUSTER_NAME = 'homeCluster';
62 export const setRemoteHosts = (remoteHosts: any) =>
63     propertiesActions.SET_PROPERTY({ key: REMOTE_HOSTS_NAME, value: remoteHosts });
64
65 export const setHomeCluster = (homeCluster: string) =>
66     propertiesActions.SET_PROPERTY({ key: HOME_CLUSTER_NAME, value: homeCluster });
67
68 export const LoginPanel = withStyles(styles)(
69     connect((state: RootState) => ({
70         remoteHosts: state.properties.remoteHosts,
71         homeCluster: state.properties.homeCluster,
72         uuidPrefix: state.properties.uuidPrefix
73     }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix }: LoginPanelProps) =>
74         <Grid container direction="column" item xs alignItems="center" justify="center" className={classes.root}>
75             <Grid item className={classes.container}>
76                 <Typography variant='h6' align="center" className={classes.title}>
77                     Welcome to the Arvados Workbench
78                 </Typography>
79                 <Typography className={classes.content}>
80                     The "Log in" button below will show you a Google sign-in page.
81                     After you assure Google that you want to log in here with your Google account, you will be redirected back here to Arvados Workbench.
82                 </Typography>
83                 <Typography className={classes.content}>
84                     If you have never used Arvados Workbench before, logging in for the first time will automatically create a new account.
85                 </Typography>
86                 <Typography variant='body1' className={classNames(classes.content, classes.content__bolder)}>
87                     IMPORTANT: Please keep in mind to store exploratory data only but not any information used for clinical decision making.
88                 </Typography>
89                 <Typography className={classes.content}>
90                     Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google.
91                 </Typography>
92
93                 <Typography className={classes.content}>
94                     <form>
95                         <label>
96                             Choose your home cluster:
97                             <select value={homeCluster} onChange={(event) => dispatch(setHomeCluster(event.target.value))}>
98                                 {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
99                             </select>
100                         </label>
101                     </form>
102                 </Typography>
103                 <Typography component="div" align="right">
104                     <Button variant="contained" color="primary" className={classes.button} onClick={() => dispatch(login(uuidPrefix, remoteHosts[homeCluster]))}>
105                         Log in
106                     </Button>
107                 </Typography>
108             </Grid>
109         </Grid>
110     ));