21720: replaced theme.spacing.unit * x with theme.spacing(x) everywhere
[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, WithStyles, withStyles } from '@material-ui/core';
15 import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
16 import { GroupClass } from 'models/group';
17
18 type CssRules = 'propertiesForm' | 'description';
19
20 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
21     propertiesForm: {
22         marginTop: theme.spacing(2),
23         marginBottom: theme.spacing(2),
24     },
25     description: {
26         marginTop: theme.spacing(2),
27         marginBottom: theme.spacing(2),
28     },
29 });
30
31 type DialogProjectProps = WithDialogProps<{sourcePanel: GroupClass}> & InjectedFormProps<ProjectCreateFormDialogData>;
32
33 export const DialogProjectCreate = (props: DialogProjectProps) => {
34     let title = 'New Project';
35     let fields = ProjectAddFields;
36     const sourcePanel = props.data.sourcePanel || '';
37
38     if (sourcePanel === GroupClass.ROLE) {
39         title = 'New Group';
40         fields = GroupAddFields;
41     }
42
43     return <FormDialog
44         dialogTitle={title}
45         formFields={fields as any}
46         submitLabel='Create'
47         {...props}
48     />;
49 };
50
51 const CreateProjectPropertiesList = resourcePropertiesList(PROJECT_CREATE_FORM_NAME);
52
53 const ProjectAddFields = withStyles(styles)(
54     ({ classes }: WithStyles<CssRules>) => <span>
55         <ResourceParentField />
56         <ProjectNameField />
57         <div className={classes.description}>
58             <ProjectDescriptionField />
59         </div>
60         <div className={classes.propertiesForm}>
61             <FormLabel>Properties</FormLabel>
62             <FormGroup>
63                 <CreateProjectPropertiesForm />
64                 <CreateProjectPropertiesList />
65             </FormGroup>
66         </div>
67     </span>);
68
69 const GroupAddFields = withStyles(styles)(
70     ({ classes }: WithStyles<CssRules>) => <span>
71         <ProjectNameField />
72         <UsersField />
73         <div className={classes.description}>
74             <ProjectDescriptionField />
75         </div>
76         <div className={classes.propertiesForm}>
77             <FormLabel>Properties</FormLabel>
78             <FormGroup>
79                 <CreateProjectPropertiesForm />
80                 <CreateProjectPropertiesList />
81             </FormGroup>
82         </div>
83     </span>);