init-setup-shell-acc-dialog
[arvados-workbench2.git] / src / views-components / dialog-forms / setup-shell-account-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4 import * as React from 'react';
5 import { compose } from "redux";
6 import { reduxForm, InjectedFormProps, Field } from 'redux-form';
7 import { withDialog, WithDialogProps } from "~/store/dialog/with-dialog";
8 import { FormDialog } from '~/components/form-dialog/form-dialog';
9 import { TextField } from '~/components/text-field/text-field';
10 import { VirtualMachinesResource } from '~/models/virtual-machines';
11 import { USER_LENGTH_VALIDATION } from '~/validators/validators';
12 import { InputLabel } from '@material-ui/core';
13 import { NativeSelectField } from '~/components/select-field/select-field';
14 import { SETUP_SHELL_ACCOUNT_DIALOG, createUser } from '~/store/users/users-actions';
15
16 interface SetupShellAccountFormDialogData {
17     email: string;
18     virtualMachineName: string;
19     groupVirtualMachine: string;
20 }
21
22 export const SetupShellAccountDialog = compose(
23     withDialog(SETUP_SHELL_ACCOUNT_DIALOG),
24     reduxForm<SetupShellAccountFormDialogData>({
25         form: SETUP_SHELL_ACCOUNT_DIALOG,
26         onSubmit: (data, dispatch) => {
27             dispatch(createUser(data));
28         }
29     })
30 )(
31     (props: SetupShellAccountDialogComponentProps) =>
32         <FormDialog
33             dialogTitle='Setup shell account'
34             formFields={SetupShellAccountFormFields}
35             submitLabel='Submit'
36             {...props}
37         />
38 );
39
40 const UserEmailField = ({ data }: any) =>
41     <Field
42         name='email'
43         component={TextField}
44         disabled
45         label={data.email} />;
46
47 const UserGroupsVirtualMachineField = () =>
48     <Field
49         name='groups'
50         component={TextField}
51         validate={USER_LENGTH_VALIDATION}
52         label="Groups for virtual machine (comma separated list)" />;
53
54 type SetupShellAccountDialogComponentProps = WithDialogProps<{}> & InjectedFormProps<SetupShellAccountFormDialogData>;
55
56 const SetupShellAccountFormFields = (props: SetupShellAccountDialogComponentProps) =>
57     <>
58         <UserEmailField data={props.data}/>
59         <UserGroupsVirtualMachineField />
60     </>;
61
62
63