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, 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 { PeopleSelect, Person } from '~/views-components/sharing-dialog/people-select';
11 import { ADD_GROUP_MEMBERS_DIALOG, ADD_GROUP_MEMBERS_FORM, AddGroupMembersFormData, ADD_GROUP_MEMBERS_USERS_FIELD_NAME, addGroupMembers } from '~/store/group-details-panel/group-details-panel-actions';
12 import { minLength } from '~/validators/min-length';
14 export const AddGroupMembersDialog = compose(
15 withDialog(ADD_GROUP_MEMBERS_DIALOG),
16 reduxForm<AddGroupMembersFormData>({
17 form: ADD_GROUP_MEMBERS_FORM,
18 onSubmit: (data, dispatch) => {
19 dispatch(addGroupMembers(data));
23 (props: AddGroupMembersDialogProps) =>
25 dialogTitle='Add users'
26 formFields={UsersField}
32 type AddGroupMembersDialogProps = WithDialogProps<{}> & InjectedFormProps<AddGroupMembersFormData>;
34 const UsersField = () =>
36 name={ADD_GROUP_MEMBERS_USERS_FIELD_NAME}
37 component={UsersSelect}
38 validate={UsersFieldValidation} />;
40 const UsersFieldValidation = [minLength(1, () => 'Select at least one user')];
42 const UsersSelect = ({ fields }: WrappedFieldArrayProps<Person>) =>
46 label='Enter email adresses '
47 items={fields.getAll() || []}
48 onSelect={fields.push}
49 onDelete={fields.remove} />;