21720: ran codemods, updated spacing, minor layout fixes
[arvados.git] / services / workbench2 / src / views-components / dialog-create / dialog-project-create.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { InjectedFormProps } from 'redux-form';
7 import { WithDialogProps } from 'store/dialog/with-dialog';
8 import { ProjectCreateFormDialogData, PROJECT_CREATE_FORM_NAME } from 'store/projects/project-create-actions';
9 import { FormDialog } from 'components/form-dialog/form-dialog';
10 import { ProjectNameField, ProjectDescriptionField, UsersField } from 'views-components/form-fields/project-form-fields';
11 import { CreateProjectPropertiesForm } from 'views-components/project-properties/create-project-properties-form';
12 import { ResourceParentField } from '../form-fields/resource-form-fields';
13 import { CustomStyleRulesCallback } from 'common/custom-theme';
14 import { FormGroup, FormLabel } from '@mui/material';
15 import { WithStyles } from '@mui/styles';
16 import withStyles from '@mui/styles/withStyles';
17 import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
18 import { GroupClass } from 'models/group';
19
20 type CssRules = 'propertiesForm' | 'description';
21
22 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
23     propertiesForm: {
24         marginTop: theme.spacing(2),
25         marginBottom: theme.spacing(2),
26     },
27     description: {
28         marginTop: theme.spacing(2),
29         marginBottom: theme.spacing(2),
30     },
31 });
32
33 type DialogProjectProps = WithDialogProps<{sourcePanel: GroupClass}> & InjectedFormProps<ProjectCreateFormDialogData>;
34
35 export const DialogProjectCreate = (props: DialogProjectProps) => {
36     let title = 'New Project';
37     let fields = ProjectAddFields;
38     const sourcePanel = props.data.sourcePanel || '';
39
40     if (sourcePanel === GroupClass.ROLE) {
41         title = 'New Group';
42         fields = GroupAddFields;
43     }
44
45     return <FormDialog
46         dialogTitle={title}
47         formFields={fields as any}
48         submitLabel='Create'
49         {...props}
50     />;
51 };
52
53 const CreateProjectPropertiesList = resourcePropertiesList(PROJECT_CREATE_FORM_NAME);
54
55 const ProjectAddFields = withStyles(styles)(
56     ({ classes }: WithStyles<CssRules>) => <span>
57         <ResourceParentField />
58         <ProjectNameField />
59         <div className={classes.description}>
60             <ProjectDescriptionField />
61         </div>
62         <div className={classes.propertiesForm}>
63             <FormLabel>Properties</FormLabel>
64             <FormGroup>
65                 <CreateProjectPropertiesForm />
66                 <CreateProjectPropertiesList />
67             </FormGroup>
68         </div>
69     </span>);
70
71 const GroupAddFields = withStyles(styles)(
72     ({ classes }: WithStyles<CssRules>) => <span>
73         <ProjectNameField />
74         <UsersField />
75         <div className={classes.description}>
76             <ProjectDescriptionField />
77         </div>
78         <div className={classes.propertiesForm}>
79             <FormLabel>Properties</FormLabel>
80             <FormGroup>
81                 <CreateProjectPropertiesForm />
82                 <CreateProjectPropertiesList />
83             </FormGroup>
84         </div>
85     </span>);