From d8310cc9f34b243b82539bc56bd3a2638954db5e Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 14:39:06 +0300 Subject: [PATCH 1/2] add "required" info to common image label --- .../ProjectCreationForm.tsx | 8 +++++-- .../ProjectCreationForm/configuration.ts | 21 +++++++++++++------ .../commonCreation/hooks/useCommonForm.ts | 6 +++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx index 79c91d8e78..ebca1317b8 100644 --- a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx +++ b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx @@ -178,8 +178,12 @@ const ProjectCreationForm: FC = (props) => { ref={formRef} initialValues={initialValues} onSubmit={isEditing ? handleProjectUpdate : handleProjectCreate} - items={getConfiguration(true, roles, { - existingNames: existingProjectsNames, + items={getConfiguration({ + isProject: true, + roles, + shouldBeUnique: { + existingNames: existingProjectsNames, + }, })} submitButtonText={isEditing ? "Save changes" : "Create Space"} disabled={isLoading} diff --git a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts index 118bedcf33..d18f9938db 100644 --- a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts +++ b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts @@ -9,11 +9,20 @@ import { } from "../../constants"; import styles from "./ProjectCreationForm.module.scss"; -export const getConfiguration = ( - isProject = true, - roles?: Roles, - shouldBeUnique?: { existingNames: string[] }, -): CreationFormItem[] => { +interface Options { + isProject: boolean; + roles?: Roles; + shouldBeUnique?: { existingNames: string[] }; + isImageRequired?: boolean; +} + +export const getConfiguration = (options: Options): CreationFormItem[] => { + const { + isProject = true, + roles, + shouldBeUnique, + isImageRequired = false, + } = options; const type = isProject ? "Space" : "Common"; const items: CreationFormItem[] = [ @@ -22,7 +31,7 @@ export const getConfiguration = ( className: styles.projectImages, props: { name: "projectImages", - label: `${type} picture`, + label: `${type} picture${isImageRequired ? " (required)" : ""}`, maxImagesAmount: 1, }, }, diff --git a/src/pages/commonCreation/hooks/useCommonForm.ts b/src/pages/commonCreation/hooks/useCommonForm.ts index 18ed453a27..c614e73d1f 100644 --- a/src/pages/commonCreation/hooks/useCommonForm.ts +++ b/src/pages/commonCreation/hooks/useCommonForm.ts @@ -76,6 +76,10 @@ export const useCommonForm = ( return { initialValues, onSubmit, - formItems: getConfiguration(false, roles), + formItems: getConfiguration({ + isProject: false, + roles, + isImageRequired: true, + }), }; }; From 98d1a1432a04cd8cfcc3837a7b4b6df6c192a77d Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 17 Oct 2023 14:47:06 +0300 Subject: [PATCH 2/2] add validation message to the common picture form item --- .../components/ProjectCreationForm/configuration.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts index d18f9938db..85064ac204 100644 --- a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts +++ b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/configuration.ts @@ -34,6 +34,14 @@ export const getConfiguration = (options: Options): CreationFormItem[] => { label: `${type} picture${isImageRequired ? " (required)" : ""}`, maxImagesAmount: 1, }, + validation: isImageRequired + ? { + min: { + value: 1, + message: `${type} picture is required`, + }, + } + : undefined, }, { type: CreationFormItemType.TextField,