From a5ce24473767588054b48c5355a317989b4b68fa Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Tue, 11 Dec 2018 09:57:34 +0100 Subject: [PATCH] Create CreateGroupDialog's form Feature #14505 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../groups-panel/groups-panel-actions.ts | 20 +++++++- .../dialog-forms/create-group-dialog.tsx | 46 +++++++++++++++---- .../sharing-dialog/people-select.tsx | 6 ++- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/store/groups-panel/groups-panel-actions.ts b/src/store/groups-panel/groups-panel-actions.ts index 28a1c07e..b5465d0d 100644 --- a/src/store/groups-panel/groups-panel-actions.ts +++ b/src/store/groups-panel/groups-panel-actions.ts @@ -2,16 +2,34 @@ // // SPDX-License-Identifier: AGPL-3.0 +import { Dispatch } from 'redux'; +import { reset } from 'redux-form'; import { bindDataExplorerActions } from "~/store/data-explorer/data-explorer-action"; import { dialogActions } from '~/store/dialog/dialog-actions'; +import { Person } from '~/views-components/sharing-dialog/people-select'; export const GROUPS_PANEL_ID = "groupsPanel"; export const CREATE_GROUP_DIALOG = "createGroupDialog"; export const CREATE_GROUP_FORM = "createGroupForm"; +export const CREATE_GROUP_NAME_FIELD_NAME = 'name'; +export const CREATE_GROUP_USERS_FIELD_NAME = 'users'; export const GroupsPanelActions = bindDataExplorerActions(GROUPS_PANEL_ID); export const loadGroupsPanel = () => GroupsPanelActions.REQUEST_ITEMS(); export const openCreateGroupDialog = () => - dialogActions.OPEN_DIALOG({ id: CREATE_GROUP_DIALOG, data: {} }); + (dispatch: Dispatch) => { + dispatch(dialogActions.OPEN_DIALOG({ id: CREATE_GROUP_DIALOG, data: {} })); + dispatch(reset(CREATE_GROUP_FORM)); + }; + +export interface CreateGroupFormData { + [CREATE_GROUP_NAME_FIELD_NAME]: string; + [CREATE_GROUP_USERS_FIELD_NAME]: Person[]; +} + +export const createGroup = (data: CreateGroupFormData) => + (dispatch: Dispatch) => { + console.log(data); + }; diff --git a/src/views-components/dialog-forms/create-group-dialog.tsx b/src/views-components/dialog-forms/create-group-dialog.tsx index 10d60c3a..554ad790 100644 --- a/src/views-components/dialog-forms/create-group-dialog.tsx +++ b/src/views-components/dialog-forms/create-group-dialog.tsx @@ -4,16 +4,22 @@ import * as React from 'react'; import { compose } from "redux"; -import { reduxForm, InjectedFormProps } from 'redux-form'; +import { reduxForm, InjectedFormProps, Field, WrappedFieldArrayProps, FieldArray } from 'redux-form'; import { withDialog, WithDialogProps } from "~/store/dialog/with-dialog"; import { FormDialog } from '~/components/form-dialog/form-dialog'; -import { CREATE_GROUP_DIALOG, CREATE_GROUP_FORM } from '~/store/groups-panel/groups-panel-actions'; +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'; +import { TextField } from '~/components/text-field/text-field'; +import { maxLength } from '~/validators/max-length'; +import { require } from '~/validators/require'; +import { PeopleSelect, Person } from '~/views-components/sharing-dialog/people-select'; export const CreateGroupDialog = compose( withDialog(CREATE_GROUP_DIALOG), - reduxForm<{}>({ + reduxForm({ form: CREATE_GROUP_FORM, - onSubmit: (data, dispatch) => { return; } + onSubmit: (data, dispatch) => { + dispatch(createGroup(data)); + } }) )( (props: CreateGroupDialogComponentProps) => @@ -25,8 +31,32 @@ export const CreateGroupDialog = compose( /> ); -type CreateGroupDialogComponentProps = WithDialogProps<{}> & InjectedFormProps<{}>; +type CreateGroupDialogComponentProps = WithDialogProps<{}> & InjectedFormProps; -const CreateGroupFormFields = (props: CreateGroupDialogComponentProps) => - CreateGroupFormFields -; +const CreateGroupFormFields = () => + <> + + + ; + +const GroupNameField = () => + ; + +const GROUP_NAME_VALIDATION = [require, maxLength(255)]; + +const UsersField = () => + ; + +const UsersSelect = ({ fields }: WrappedFieldArrayProps) => + ; diff --git a/src/views-components/sharing-dialog/people-select.tsx b/src/views-components/sharing-dialog/people-select.tsx index 2aada00e..bee59c22 100644 --- a/src/views-components/sharing-dialog/people-select.tsx +++ b/src/views-components/sharing-dialog/people-select.tsx @@ -20,6 +20,7 @@ export interface Person { export interface PeopleSelectProps { items: Person[]; + label?: string; onBlur?: (event: React.FocusEvent) => void; onFocus?: (event: React.FocusEvent) => void; @@ -43,9 +44,12 @@ export const PeopleSelect = connect()( }; render() { + + const { label = 'Invite people' } = this.props; + return (