Replace mappings with compose fn
[arvados-workbench2.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, compose } 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
22 export const DialogCollectionCreateWithSelectedFile = compose(
23     withDialog(DIALOG_COLLECTION_CREATE_WITH_SELECTED),
24     reduxForm({
25         form: DIALOG_COLLECTION_CREATE_WITH_SELECTED,
26         onSubmit: (data, dispatch) => {
27             dispatch(startSubmit(DIALOG_COLLECTION_CREATE_WITH_SELECTED));
28             setTimeout(() => dispatch(stopSubmit(DIALOG_COLLECTION_CREATE_WITH_SELECTED, { name: 'Invalid name' })), 2000);
29         }
30     }))(DialogCollectionCreateWithSelected);