1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { InjectedFormProps, Field, WrappedFieldProps } from 'redux-form';
7 import { WithDialogProps } from '~/store/dialog/with-dialog';
8 import { FormDialog } from '~/components/form-dialog/form-dialog';
9 import { ProjectTreePicker } from '~/views-components/project-tree-picker/project-tree-picker';
10 import { Typography } from "@material-ui/core";
11 import { COPY_NAME_VALIDATION, MAKE_A_COPY_VALIDATION } from '~/validators/validators';
12 import { TextField } from "~/components/text-field/text-field";
13 import { ProjectCopyFormDialogData } from "~/store/project-copy-dialog/project-copy-dialog";
15 export const ProjectCopyFormDialog = (props: WithDialogProps<string> & InjectedFormProps<ProjectCopyFormDialogData>) =>
17 dialogTitle='Make a copy'
18 formFields={ProjectCopyFields}
23 const ProjectCopyFields = () => <div>
24 <ProjectCopyNameField />
25 <ProjectCopyDialogFields />
28 const ProjectCopyNameField = () =>
32 validate={COPY_NAME_VALIDATION}
33 label="Enter a new name for the copy" />;
35 const ProjectCopyDialogFields = () =>
38 component={ProjectPicker}
39 validate={MAKE_A_COPY_VALIDATION} />;
41 const ProjectPicker = (props: WrappedFieldProps) =>
42 <div style={{ height: '200px', display: 'flex', flexDirection: 'column' }}>
43 <ProjectTreePicker onChange={handleChange(props)} />
44 {props.meta.dirty && props.meta.error &&
45 <Typography variant='caption' color='error'>
50 const handleChange = (props: WrappedFieldProps) => (value: string) =>
51 props.input.value === value
52 ? props.input.onChange('')
53 : props.input.onChange(value);