18123: Add group rename dialog
[arvados-workbench2.git] / src / views-components / dialog-forms / rename-group-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { compose, Dispatch } 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 { GroupResource } from 'models/group';
13 import { RENAME_GROUP_DIALOG, RENAME_GROUP_NAME_FIELD_NAME, RenameGroupFormData, renameGroup } from 'store/groups-panel/groups-panel-actions';
14 // import { WarningCollection } from 'components/warning-collection/warning-collection';
15 import { RENAME_FILE_VALIDATION } from 'validators/validators';
16
17 export const RenameGroupDialog = compose(
18     withDialog(RENAME_GROUP_DIALOG),
19     reduxForm<RenameGroupFormData>({
20         form: RENAME_GROUP_DIALOG,
21         // touchOnChange: true,
22         onSubmit: (data: RenameGroupFormData, dispatch: Dispatch) => {
23             console.log(data);
24             // dispatch<any>(renameGroup(data));
25         }
26     })
27 )((props: RenameGroupDialogProps) =>
28     <FormDialog
29         dialogTitle='Rename'
30         formFields={RenameGroupFormFields}
31         submitLabel='Ok'
32         {...props}
33     />);
34
35 interface RenameGroupDataProps {
36     data: GroupResource;
37 }
38
39 type RenameGroupDialogProps = RenameGroupDataProps & WithDialogProps<{}> & InjectedFormProps<RenameGroupFormData>;
40
41 const RenameGroupFormFields = (props: RenameGroupDialogProps) => {
42     // console.log(props);
43     return <>
44         <DialogContentText>
45             {`Please enter a new name for ${props.data.name}`}
46         </DialogContentText>
47         <Field
48             name={RENAME_GROUP_NAME_FIELD_NAME}
49             component={TextField as any}
50             autoFocus={true}
51             validate={RENAME_FILE_VALIDATION}
52         />
53         {/* <WarningCollection text="Renaming a file will change the collection's content address." /> */}
54     </>;
55 }