merge master
[arvados.git] / src / views-components / file-remove-dialog / file-remove-dialog.ts
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 { connect } from "react-redux";
7 import { ConfirmationDialog } from "~/components/confirmation-dialog/confirmation-dialog";
8 import { withDialog } from "~/store/dialog/with-dialog";
9 import { dialogActions } from "~/store/dialog/dialog-actions";
10 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
11
12 const FILE_REMOVE_DIALOG = 'fileRemoveDialog';
13
14 const mapDispatchToProps = (dispatch: Dispatch) => ({
15     onConfirm: () => {
16         // TODO: dispatch action that removes single file
17         dispatch(dialogActions.CLOSE_DIALOG({ id: FILE_REMOVE_DIALOG }));
18         dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing file...', hideDuration: 2000 }));
19         setTimeout(() => {
20             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File removed.', hideDuration: 2000 }));
21         }, 1000);
22     }
23 });
24
25 export const openFileRemoveDialog = (fileId: string) =>
26     dialogActions.OPEN_DIALOG({
27         id: FILE_REMOVE_DIALOG,
28         data: {
29             title: 'Removing file',
30             text: 'Are you sure you want to remove this file?',
31             confirmButtonLabel: 'Remove',
32             fileId
33         }
34     });
35
36 export const [FileRemoveDialog] = [ConfirmationDialog]
37     .map(withDialog(FILE_REMOVE_DIALOG))
38     .map(connect(undefined, mapDispatchToProps));