Extract form dialog component
[arvados-workbench2.git] / src / views-components / dialog-create / dialog-collection-create-selected.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { InjectedFormProps, Field, WrappedFieldProps } from "redux-form";
7 import { WithDialogProps } from "~/store/dialog/with-dialog";
8 import { TextField } from "~/components/text-field/text-field";
9 import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION } from "~/validators/validators";
10 import { ProjectTreePicker } from "../project-tree-picker/project-tree-picker";
11 import { FormDialog } from '../../components/form-dialog/form-dialog';
12
13 export const DialogCollectionCreateWithSelected = (props: WithDialogProps<string> & InjectedFormProps<{ name: string }>) =>
14     <FormDialog
15         dialogTitle='Create a collection'
16         formFields={FormFields}
17         submitLabel='Create a collection'
18         {...props}
19     />;
20
21 const FormFields = () => <div style={{ display: 'flex' }}>
22     <div>
23         <Field
24             name='name'
25             component={TextField}
26             validate={COLLECTION_NAME_VALIDATION}
27             label="Collection Name" />
28         <Field
29             name='description'
30             component={TextField}
31             validate={COLLECTION_DESCRIPTION_VALIDATION}
32             label="Description - optional" />
33     </div>
34     <Field
35         name="projectUuid"
36         component={Picker}
37         validate={COLLECTION_PROJECT_VALIDATION} />
38 </div>;
39
40 const Picker = (props: WrappedFieldProps) =>
41     <div style={{ width: '400px', height: '144px', display: 'flex', flexDirection: 'column' }}>
42         <ProjectTreePicker onChange={projectUuid => props.input.onChange(projectUuid)} />
43     </div>;