1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Field, InjectedFormProps, WrappedFieldProps } from "redux-form";
7 import { TextField } from "~/components/text-field/text-field";
8 import { NativeSelectField } from "~/components/select-field/select-field";
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";
24 type CssRules = 'root' | 'gridItem' | 'label' | 'title' | 'actions';
26 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
39 marginBottom: theme.spacing.unit * 3,
40 color: theme.palette.grey["600"]
44 justifyContent: 'flex-end'
48 export interface MyAccountPanelRootActionProps { }
50 export interface MyAccountPanelRootDataProps {
58 { key: 'Bio-informatician', value: 'Bio-informatician' },
59 { key: 'Data Scientist', value: 'Data Scientist' },
60 { key: 'Analyst', value: 'Analyst' },
61 { key: 'Researcher', value: 'Researcher' },
62 { key: 'Software Developer', value: 'Software Developer' },
63 { key: 'System Administrator', value: 'System Administrator' },
64 { key: 'Other', value: 'Other' }
67 type MyAccountPanelRootProps = InjectedFormProps<MyAccountPanelRootActionProps> & MyAccountPanelRootDataProps & WithStyles<CssRules>;
69 type LocalClusterProp = { localCluster: string };
70 const renderField: React.ComponentType<WrappedFieldProps & LocalClusterProp> = ({ input, localCluster }) => (
71 <span>{localCluster === input.value.substr(0, 5) ? "" : "federated"} user {input.value}</span>
74 export const MyAccountPanelRoot = withStyles(styles)(
75 ({ classes, isValid, handleSubmit, reset, isPristine, invalid, submitting, localCluster }: MyAccountPanelRootProps) => {
76 return <Card className={classes.root}>
78 <Typography variant="title" className={classes.title}>
79 Logged in as <Field name="uuid" component={renderField} localCluster={localCluster} />
81 <form onSubmit={handleSubmit}>
82 <Grid container spacing={24}>
83 <Grid item className={classes.gridItem} sm={6} xs={12}>
91 <Grid item className={classes.gridItem} sm={6} xs={12}>
99 <Grid item className={classes.gridItem} sm={6} xs={12}>
103 component={TextField}
107 <Grid item className={classes.gridItem} sm={6} xs={12}>
111 component={TextField}
115 <Grid item className={classes.gridItem} sm={6} xs={12}>
118 name="prefs.profile.organization"
119 component={TextField}
120 validate={MY_ACCOUNT_VALIDATION}
124 <Grid item className={classes.gridItem} sm={6} xs={12}>
126 label="E-mail at Organization"
127 name="prefs.profile.organization_email"
128 component={TextField}
129 validate={MY_ACCOUNT_VALIDATION}
133 <Grid item className={classes.gridItem} sm={6} xs={12}>
134 <InputLabel className={classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
136 id="prefs.profile.role"
137 name="prefs.profile.role"
138 component={NativeSelectField}
142 <Grid item className={classes.gridItem} sm={6} xs={12}>
145 name="prefs.profile.website_url"
146 component={TextField}
149 <Grid container direction="row" justify="flex-end" >
150 <Button color="primary" onClick={reset} disabled={isPristine}>Discard changes</Button>
155 disabled={isPristine || invalid || submitting}>