Merge branch 'origin/master' into 14478-log-in-into-clusters
[arvados-workbench2.git] / src / views / my-account-panel / my-account-panel-root.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 { Field, InjectedFormProps } from "redux-form";
7 import { TextField } from "~/components/text-field/text-field";
8 import { NativeSelectField } from "~/components/select-field/select-field";
9 import {
10     StyleRulesCallback,
11     WithStyles,
12     withStyles,
13     Card,
14     CardContent,
15     Button,
16     Typography,
17     Grid,
18     InputLabel
19 } from '@material-ui/core';
20 import { ArvadosTheme } from '~/common/custom-theme';
21 import { User } from "~/models/user";
22 import { MY_ACCOUNT_VALIDATION} from "~/validators/validators";
23
24 type CssRules = 'root' | 'gridItem' | 'label' | 'title' | 'actions';
25
26 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27     root: {
28         width: '100%',
29         overflow: 'auto'
30     },
31     gridItem: {
32         height: 45,
33         marginBottom: 20
34     },
35     label: {
36         fontSize: '0.675rem'
37     },
38     title: {
39         marginBottom: theme.spacing.unit * 3,
40         color: theme.palette.grey["600"]
41     },
42     actions: {
43         display: 'flex',
44         justifyContent: 'flex-end'
45     }
46 });
47
48 export interface MyAccountPanelRootActionProps {}
49
50 export interface MyAccountPanelRootDataProps {
51     isPristine: boolean;
52     isValid: boolean;
53     initialValues?: User;
54 }
55
56 const RoleTypes = [
57     {key: 'Bio-informatician', value: 'Bio-informatician'},
58     {key: 'Data Scientist', value: 'Data Scientist'},
59     {key: 'Analyst', value: 'Analyst'},
60     {key: 'Researcher', value: 'Researcher'},
61     {key: 'Software Developer', value: 'Software Developer'},
62     {key: 'System Administrator', value: 'System Administrator'},
63     {key: 'Other', value: 'Other'}
64 ];
65
66 type MyAccountPanelRootProps = InjectedFormProps<MyAccountPanelRootActionProps> & MyAccountPanelRootDataProps & WithStyles<CssRules>;
67
68 export const MyAccountPanelRoot = withStyles(styles)(
69     ({ classes, isValid, handleSubmit, reset, isPristine, invalid, submitting }: MyAccountPanelRootProps) => {
70         return <Card className={classes.root}>
71             <CardContent>
72                 <Typography variant="title" className={classes.title}>User profile</Typography>
73                 <form onSubmit={handleSubmit}>
74                     <Grid container direction="row" spacing={24}>
75                         <Grid item xs={6}>
76                             <Grid item className={classes.gridItem}>
77                                 <Field
78                                     label="E-mail"
79                                     name="email"
80                                     component={TextField}
81                                     disabled
82                                 />
83                             </Grid>
84                             <Grid item className={classes.gridItem}>
85                                 <Field
86                                     label="First name"
87                                     name="firstName"
88                                     component={TextField}
89                                     disabled
90                                 />
91                             </Grid>
92                             <Grid item className={classes.gridItem}>
93                                 <Field
94                                     label="Identity URL"
95                                     name="identityUrl"
96                                     component={TextField}
97                                     disabled
98                                 />
99                             </Grid>
100                             <Grid item className={classes.gridItem}>
101                                 <Field
102                                     label="Organization"
103                                     name="prefs.profile.organization"
104                                     component={TextField}
105                                     validate={MY_ACCOUNT_VALIDATION}
106                                     required
107                                 />
108                             </Grid>
109                             <Grid item className={classes.gridItem}>
110                                 <Field
111                                     label="Website"
112                                     name="prefs.profile.website_url"
113                                     component={TextField}
114                                 />
115                             </Grid>
116                             <Grid item className={classes.gridItem}>
117                                 <InputLabel className={classes.label} htmlFor="prefs.profile.role">Organization</InputLabel>
118                                 <Field
119                                     id="prefs.profile.role"
120                                     name="prefs.profile.role"
121                                     component={NativeSelectField}
122                                     items={RoleTypes}
123                                 />
124                             </Grid>
125                         </Grid>
126                         <Grid item xs={6}>
127                             <Grid item className={classes.gridItem} />
128                             <Grid item className={classes.gridItem}>
129                                 <Field
130                                     label="Last name"
131                                     name="lastName"
132                                     component={TextField}
133                                     disabled
134                                 />
135                             </Grid>
136                             <Grid item className={classes.gridItem} />
137                             <Grid item className={classes.gridItem}>
138                                 <Field
139                                     label="E-mail at Organization"
140                                     name="prefs.profile.organization_email"
141                                     component={TextField}
142                                     validate={MY_ACCOUNT_VALIDATION}
143                                     required
144                                 />
145                             </Grid>
146                         </Grid>
147                         <Grid item xs={12} className={classes.actions}>
148                             <Button color="primary" onClick={reset} disabled={isPristine}>Discard changes</Button>
149                             <Button
150                                 color="primary"
151                                 variant="contained"
152                                 type="submit"
153                                 disabled={isPristine || invalid || submitting}>
154                                     Save changes
155                             </Button>
156                         </Grid>
157                     </Grid>
158                 </form>
159             </CardContent>
160         </Card>;}
161 );