1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { compose } from "redux";
7 import { reduxForm, InjectedFormProps, Field, WrappedFieldArrayProps, FieldArray } from 'redux-form';
8 import { withDialog, WithDialogProps } from "~/store/dialog/with-dialog";
9 import { FormDialog } from '~/components/form-dialog/form-dialog';
10 import { CREATE_GROUP_DIALOG, CREATE_GROUP_FORM, createGroup, CreateGroupFormData, CREATE_GROUP_NAME_FIELD_NAME, CREATE_GROUP_USERS_FIELD_NAME } from '~/store/groups-panel/groups-panel-actions';
11 import { TextField } from '~/components/text-field/text-field';
12 import { maxLength } from '~/validators/max-length';
13 import { require } from '~/validators/require';
14 import { PeopleSelect, Person } from '~/views-components/sharing-dialog/people-select';
16 export const CreateGroupDialog = compose(
17 withDialog(CREATE_GROUP_DIALOG),
18 reduxForm<CreateGroupFormData>({
19 form: CREATE_GROUP_FORM,
20 onSubmit: (data, dispatch) => {
21 dispatch(createGroup(data));
25 (props: CreateGroupDialogComponentProps) =>
27 dialogTitle='Create a group'
28 formFields={CreateGroupFormFields}
34 type CreateGroupDialogComponentProps = WithDialogProps<{}> & InjectedFormProps<CreateGroupFormData>;
36 const CreateGroupFormFields = () =>
42 const GroupNameField = () =>
44 name={CREATE_GROUP_NAME_FIELD_NAME}
46 validate={GROUP_NAME_VALIDATION}
50 const GROUP_NAME_VALIDATION = [require, maxLength(255)];
52 const UsersField = () =>
54 name={CREATE_GROUP_USERS_FIELD_NAME}
55 component={UsersSelect} />;
57 const UsersSelect = ({ fields }: WrappedFieldArrayProps<Person>) =>
60 label='Enter email adresses '
61 items={fields.getAll() || []}
62 onSelect={fields.push}
63 onDelete={fields.remove} />;