Merge branch 'master' into 13894-default-view-component
[arvados.git] / src / views-components / create-collection-dialog-with-selected / create-collection-dialog-with-selected.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { reduxForm, reset, startSubmit, stopSubmit } from "redux-form";
7 import { withDialog } from "../../store/dialog/with-dialog";
8 import { dialogActions } from "../../store/dialog/dialog-actions";
9 import { DialogCollectionCreateWithSelected } from "../dialog-create/dialog-collection-create-selected";
10 import { loadProjectTreePickerProjects } from "../project-tree-picker/project-tree-picker";
11
12 export const DIALOG_COLLECTION_CREATE_WITH_SELECTED = 'dialogCollectionCreateWithSelected';
13
14 export const createCollectionWithSelected = () =>
15     (dispatch: Dispatch) => {
16         dispatch(reset(DIALOG_COLLECTION_CREATE_WITH_SELECTED));
17         dispatch<any>(loadProjectTreePickerProjects(''));
18         dispatch(dialogActions.OPEN_DIALOG({ id: DIALOG_COLLECTION_CREATE_WITH_SELECTED, data: {} }));
19     };
20
21 export const [DialogCollectionCreateWithSelectedFile] = [DialogCollectionCreateWithSelected]
22     .map(withDialog(DIALOG_COLLECTION_CREATE_WITH_SELECTED))
23     .map(reduxForm({
24         form: DIALOG_COLLECTION_CREATE_WITH_SELECTED,
25         onSubmit: (data, dispatch) => {
26             dispatch(startSubmit(DIALOG_COLLECTION_CREATE_WITH_SELECTED));
27             setTimeout(() => dispatch(stopSubmit(DIALOG_COLLECTION_CREATE_WITH_SELECTED, { name: 'Invalid name' })), 2000);
28         }
29     }));