X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/92dd5d32b573b5c90f3ce72dc207f6d0e7f21178..efedeb30d0641217f1fb27627c9ae4cba7aedd36:/src/views/my-account-panel/my-account-panel-root.tsx?ds=inline

diff --git a/src/views/my-account-panel/my-account-panel-root.tsx b/src/views/my-account-panel/my-account-panel-root.tsx
index c12f01aa..e84b3b64 100644
--- a/src/views/my-account-panel/my-account-panel-root.tsx
+++ b/src/views/my-account-panel/my-account-panel-root.tsx
@@ -3,11 +3,25 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { StyleRulesCallback, WithStyles, withStyles, Card, CardContent, TextField, Button, Typography, Grid, Table, TableHead, TableRow, TableCell, TableBody, Tooltip, IconButton } from '@material-ui/core';
+import { Field, InjectedFormProps, WrappedFieldProps } from "redux-form";
+import { TextField } from "~/components/text-field/text-field";
+import { NativeSelectField } from "~/components/select-field/select-field";
+import {
+    StyleRulesCallback,
+    WithStyles,
+    withStyles,
+    Card,
+    CardContent,
+    Button,
+    Typography,
+    Grid,
+    InputLabel
+} from '@material-ui/core';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { User } from "~/models/user";
+import { MY_ACCOUNT_VALIDATION } from "~/validators/validators";
 
-type CssRules = 'root' | 'gridItem' | 'title';
+type CssRules = 'root' | 'gridItem' | 'label' | 'title' | 'actions';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
@@ -15,105 +29,136 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         overflow: 'auto'
     },
     gridItem: {
-        minHeight: 45,
+        height: 45,
         marginBottom: 20
     },
+    label: {
+        fontSize: '0.675rem'
+    },
     title: {
         marginBottom: theme.spacing.unit * 3,
         color: theme.palette.grey["600"]
+    },
+    actions: {
+        display: 'flex',
+        justifyContent: 'flex-end'
     }
 });
 
-export interface MyAccountPanelRootActionProps {}
+export interface MyAccountPanelRootActionProps { }
 
 export interface MyAccountPanelRootDataProps {
-    user?: User;
+    isPristine: boolean;
+    isValid: boolean;
+    initialValues?: User;
+    localCluster: string;
 }
 
-type MyAccountPanelRootProps = MyAccountPanelRootActionProps & MyAccountPanelRootDataProps & WithStyles<CssRules>;
+const RoleTypes = [
+    { key: 'Bio-informatician', value: 'Bio-informatician' },
+    { key: 'Data Scientist', value: 'Data Scientist' },
+    { key: 'Analyst', value: 'Analyst' },
+    { key: 'Researcher', value: 'Researcher' },
+    { key: 'Software Developer', value: 'Software Developer' },
+    { key: 'System Administrator', value: 'System Administrator' },
+    { key: 'Other', value: 'Other' }
+];
+
+type MyAccountPanelRootProps = InjectedFormProps<MyAccountPanelRootActionProps> & MyAccountPanelRootDataProps & WithStyles<CssRules>;
+
+type LocalClusterProp = { localCluster: string };
+const renderField: React.ComponentType<WrappedFieldProps & LocalClusterProp> = ({ input, localCluster }) => (
+    <span>{localCluster === input.value.substr(0, 5) ? "" : "federated"} user {input.value}</span>
+);
 
 export const MyAccountPanelRoot = withStyles(styles)(
-    ({ classes, user }: MyAccountPanelRootProps) => {
-        console.log(user);
+    ({ classes, isValid, handleSubmit, reset, isPristine, invalid, submitting, localCluster }: MyAccountPanelRootProps) => {
         return <Card className={classes.root}>
             <CardContent>
-                <Typography variant="title" className={classes.title}>User profile</Typography>
-                <Grid container direction="row" spacing={24}>
-                    <Grid item xs={6}>
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="E-mail"
-                                name="email"
-                                fullWidth
-                                value={user!.email}
+                <Typography variant="title" className={classes.title}>
+                    Logged in as <Field name="uuid" component={renderField} localCluster={localCluster} />
+                </Typography>
+                <form onSubmit={handleSubmit}>
+                    <Grid container spacing={24}>
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="First name"
+                                name="firstName"
+                                component={TextField}
                                 disabled
                             />
                         </Grid>
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="First name"
-                                name="firstName"
-                                fullWidth
-                                value={user!.firstName}
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="Last name"
+                                name="lastName"
+                                component={TextField}
                                 disabled
                             />
                         </Grid>
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="Identity URL"
-                                name="identityUrl"
-                                fullWidth
-                                value={user!.identityUrl}
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="E-mail"
+                                name="email"
+                                component={TextField}
                                 disabled
                             />
                         </Grid>
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="Organization"
-                                name="organization"
-                                value={user!.prefs.profile!.organization}
-                                fullWidth
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="Username"
+                                name="username"
+                                component={TextField}
+                                disabled
                             />
                         </Grid>
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="Website"
-                                name="website"
-                                value={user!.prefs.profile!.website_url}
-                                fullWidth
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="Organization"
+                                name="prefs.profile.organization"
+                                component={TextField}
+                                validate={MY_ACCOUNT_VALIDATION}
+                                required
                             />
                         </Grid>
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="Role"
-                                name="role"
-                                value={user!.prefs.profile!.role}
-                                fullWidth
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="E-mail at Organization"
+                                name="prefs.profile.organization_email"
+                                component={TextField}
+                                validate={MY_ACCOUNT_VALIDATION}
+                                required
                             />
                         </Grid>
-                    </Grid>
-                    <Grid item xs={6}>
-                        <Grid item className={classes.gridItem} />
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="Last name"
-                                name="lastName"
-                                fullWidth
-                                value={user!.lastName}
-                                disabled
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <InputLabel className={classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
+                            <Field
+                                id="prefs.profile.role"
+                                name="prefs.profile.role"
+                                component={NativeSelectField}
+                                items={RoleTypes}
                             />
                         </Grid>
-                        <Grid item className={classes.gridItem} />
-                        <Grid item className={classes.gridItem}>
-                            <TextField
-                                label="E-mail at Organization"
-                                name="organizationEmail"
-                                value={user!.prefs.profile!.organization_email}
-                                fullWidth
+                        <Grid item className={classes.gridItem} sm={6} xs={12}>
+                            <Field
+                                label="Website"
+                                name="prefs.profile.website_url"
+                                component={TextField}
                             />
                         </Grid>
+                        <Grid container direction="row" justify="flex-end" >
+                            <Button color="primary" onClick={reset} disabled={isPristine}>Discard changes</Button>
+                            <Button
+                                color="primary"
+                                variant="contained"
+                                type="submit"
+                                disabled={isPristine || invalid || submitting}>
+                                Save changes
+                            </Button>
+                        </Grid>
                     </Grid>
-                </Grid>
-            </CardContent>
-        </Card>;}
-);
\ No newline at end of file
+                </form >
+            </CardContent >
+        </Card >;
+    }
+);
