importing by ~
[arvados.git] / src / views-components / project-copy-dialog / project-copy-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4 import { Dispatch, compose } from "redux";
5 import { withDialog } from "~/store/dialog/with-dialog";
6 import { dialogActions } from "~/store/dialog/dialog-actions";
7 import { ProjectCopy, CopyFormData } from "~/components/project-copy/project-copy";
8 import { reduxForm, startSubmit, stopSubmit, initialize } from 'redux-form';
9 import { resetPickerProjectTree } from "~/store/project-tree-picker/project-tree-picker-actions";
10
11 export const PROJECT_COPY_DIALOG = 'projectCopy';
12 export const openProjectCopyDialog = (data: { projectUuid: string, name: string }) =>
13     (dispatch: Dispatch) => {
14         dispatch<any>(resetPickerProjectTree());
15         const initialData: CopyFormData = { name: `Copy of: ${data.name}`, projectUuid: '', uuid: data.projectUuid };
16         dispatch<any>(initialize(PROJECT_COPY_DIALOG, initialData));
17         dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_COPY_DIALOG, data: {} }));
18     };
19
20 export const ProjectCopyDialog = compose(
21     withDialog(PROJECT_COPY_DIALOG),
22     reduxForm({
23         form: PROJECT_COPY_DIALOG,
24         onSubmit: (data, dispatch) => {
25             dispatch(startSubmit(PROJECT_COPY_DIALOG));
26             setTimeout(() => dispatch(stopSubmit(PROJECT_COPY_DIALOG, { name: 'Invalid path' })), 2000);
27         }
28     })
29 )(ProjectCopy);