Merge branch 'master' into 14099-process-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 * as React from 'react';
6 import { compose } from 'redux';
7 import { reduxForm, InjectedFormProps, Field } from 'redux-form';
8 import { withDialog, WithDialogProps } from '~/store/dialog/with-dialog';
9 import { FormDialog } from '~/components/form-dialog/form-dialog';
10 import { DialogContentText } from '@material-ui/core';
11 import { TextField } from '~/components/text-field/text-field';
12 import { RENAME_FILE_DIALOG, RenameFileDialogData, renameFile } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
13
14 export const RenameFileDialog = compose(
15     withDialog(RENAME_FILE_DIALOG),
16     reduxForm({
17         form: RENAME_FILE_DIALOG,
18         onSubmit: (data: { name: string }, dispatch) => {
19             dispatch<any>(renameFile(data.name));
20         }
21     })
22 )((props: WithDialogProps<RenameFileDialogData> & InjectedFormProps<{ name: string }>) =>
23     <FormDialog
24         dialogTitle='Rename'
25         formFields={RenameDialogFormFields}
26         submitLabel='Ok'
27         {...props}
28     />);
29
30 const RenameDialogFormFields = (props: WithDialogProps<RenameFileDialogData>) => <>
31     <DialogContentText>
32         {`Please, enter a new name for ${props.data.name}`}
33     </DialogContentText>
34     <Field
35         name='name'
36         component={TextField}
37     />
38 </>;