refs #13989 Merge branch 'origin/13989-webdav-service'
[arvados-workbench2.git] / src / views-components / rename-file-dialog / rename-file-dialog.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 { RenameDialog } from "~/components/rename-dialog/rename-dialog";
10
11 export const RENAME_FILE_DIALOG = 'renameFileDialog';
12
13 export const openRenameFileDialog = (originalName: string) =>
14     (dispatch: Dispatch) => {
15         dispatch(reset(RENAME_FILE_DIALOG));
16         dispatch(dialogActions.OPEN_DIALOG({ id: RENAME_FILE_DIALOG, data: originalName }));
17     };
18
19 export const [RenameFileDialog] = [RenameDialog]
20     .map(withDialog(RENAME_FILE_DIALOG))
21     .map(reduxForm({
22         form: RENAME_FILE_DIALOG,
23         onSubmit: (data, dispatch) => {
24             dispatch(startSubmit(RENAME_FILE_DIALOG));
25             // TODO: call collection file renaming action here
26             setTimeout(() => dispatch(stopSubmit(RENAME_FILE_DIALOG, { name: 'Invalid name' })), 2000);
27         }
28     }));