diff --git a/src/constants/placeFormRequiredFieldNames.js b/src/constants/placeFormRequiredFieldNames.js new file mode 100644 index 000000000..af33626d0 --- /dev/null +++ b/src/constants/placeFormRequiredFieldNames.js @@ -0,0 +1,7 @@ +export const placeFormRequiredFieldNames = { + PLACE_TYPE: 'PLACE_TYPE', + NAME: 'NAME', + NAME_EN: 'NAME_EN', + NAME_FR: 'NAME_FR', + STREET_ADDRESS: 'STREET_ADDRESS', +}; diff --git a/src/locales/en/translationEn.json b/src/locales/en/translationEn.json index b1872decd..00dd421ad 100644 --- a/src/locales/en/translationEn.json +++ b/src/locales/en/translationEn.json @@ -636,7 +636,10 @@ "saveError": "This place needs more information before it can be saved." }, "validations": { - "nameRequired": "Name is required." + "nameRequired": "Name is required.", + "placeTypeRequired": "A minimum of one type is requred.", + "streetAddressRequired": "Street address is required.", + "postalCodeRequired": "Postal code is required." } } } @@ -730,7 +733,7 @@ "userTypes": "User types", "clear": "Clear", "userName": "Username", - "addUser":"Utilisateur", + "addUser": "Utilisateur", "firstName": "First name", "lastName": "Last name", "active": "Active", @@ -740,7 +743,7 @@ "editor": "Editor", "contributor": "Contributor", "guest": "Guest", - "superAdmin":"Super Admin", + "superAdmin": "Super Admin", "invitedBy": "Invited By", "tooltip": { "editUser": "Edit user", diff --git a/src/locales/fr/transalationFr.json b/src/locales/fr/transalationFr.json index 78a39ff45..5e5af0a76 100644 --- a/src/locales/fr/transalationFr.json +++ b/src/locales/fr/transalationFr.json @@ -633,7 +633,10 @@ "saveError": "Cet lieu a besoin de plus d'informations avant d'être enregistré." }, "validations": { - "nameRequired": "Le nom est requis." + "nameRequired": "Le nom est requis.", + "placeTypeRequired": "Un minimum d'un type est requis.", + "streetAddressRequired": "L'adresse postale est requise.", + "postalCodeRequired": "Le code postal est requis." } } } @@ -723,7 +726,7 @@ "sort": "Trier par", "status": "Statut", "userTypes": "Type", - "addUser":"Utilisateur", + "addUser": "Utilisateur", "clear": "Réinitialiser", "userName": "Nom d’utilisateur", "firstName": "Prénom", diff --git a/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx b/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx index 2828cf86a..102d4f88f 100644 --- a/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx +++ b/src/pages/Dashboard/CreateNewOrganization/CreateNewOrganization.jsx @@ -505,224 +505,237 @@ function CreateNewOrganization() {
- + - - -
- -
+ + + + +
+ +
+ + +
+ + onSaveHandler()} + disabled={ + addOrganizationLoading || imageUploadLoading || updateOrganizationLoading ? true : false + } + /> + +
+ +
+ -
- - onSaveHandler()} - disabled={ - addOrganizationLoading || imageUploadLoading || updateOrganizationLoading ? true : false - } - /> - +
+

+ {organizationId + ? t('dashboard.organization.createNew.addOrganization.editOrganization') + : t('dashboard.organization.createNew.addOrganization.newOrganization')} +

- - -
-

- {organizationId - ? t('dashboard.organization.createNew.addOrganization.editOrganization') - : t('dashboard.organization.createNew.addOrganization.newOrganization')} -

-
- - - {fields?.map((section, index) => { - if (section?.length > 0) - return ( - - <> - {artsDataLinkChecker(organizationData?.sameAs) && section[0]?.category === formCategory.PRIMARY && ( - - -

- {t('dashboard.organization.createNew.addOrganization.dataSource')} -

- - - - - -
- - {t('dashboard.organization.createNew.addOrganization.question.firstPart')} - - { - navigate( - `${PathName.Dashboard}/${calendarId}${PathName.Organizations}${PathName.Search}`, - ); - }}> - {t('dashboard.organization.createNew.addOrganization.question.secondPart')} - - - {t('dashboard.organization.createNew.addOrganization.question.thirdPart')} - -
- - -
-
-
- -
- )} - {section?.map((field) => { - return formFieldValue?.map((formField, index) => { - if (formField?.type === field.type) { - return returnFormDataWithFields({ - field, - formField, - allTaxonomyData, - user, - calendarContentLanguage, - entityData: organizationData ? organizationData : artsData ? artsData : newEntityData, - index, - t, - adminCheckHandler, - currentCalendarData, - imageCropOpen, - setImageCropOpen, - placesSearch, - allPlacesList, - locationPlace, - setLocationPlace, - setIsPopoverOpen, - isPopoverOpen, - form, - style: { - display: !field?.isPreset - ? !addedFields?.includes(field?.mappedField) - ? 'none' - : '' - : '', - }, - }); - } - }); - })} - {section[0]?.category === formCategory.PRIMARY && - allTaxonomyData?.data?.map((taxonomy, index) => { - if (taxonomy?.isDynamicField) { - let initialValues; - organizationData?.dynamicFields?.forEach((dynamicField) => { - if (taxonomy?.id === dynamicField?.taxonomyId) initialValues = dynamicField?.conceptIds; - }); - return ( - - } - clearIcon={} - treeData={treeDynamicTaxonomyOptions(taxonomy?.concept, user, calendarContentLanguage)} - tagRender={(props) => { - const { label, closable, onClose } = props; - return ( - - }> - {label} - - ); - }} + {fields?.map((section, index) => { + if (section?.length > 0) + return ( + + <> + {(artsDataLinkChecker(organizationData?.sameAs) || artsDataLinkChecker(artsData?.sameAs)) && + section[0]?.category === formCategory.PRIMARY && ( + + +

+ {t('dashboard.organization.createNew.addOrganization.dataSource')} +

+ + + -
- ); - } + + +
+ + {t('dashboard.organization.createNew.addOrganization.question.firstPart')} + + { + navigate( + `${PathName.Dashboard}/${calendarId}${PathName.Organizations}${PathName.Search}`, + ); + }}> + {t('dashboard.organization.createNew.addOrganization.question.secondPart')} + + + {t('dashboard.organization.createNew.addOrganization.question.thirdPart')} + +
+ + +
+
+
+ + + )} + {section?.map((field) => { + return formFieldValue?.map((formField, index) => { + if (formField?.type === field.type) { + return returnFormDataWithFields({ + field, + formField, + allTaxonomyData, + user, + calendarContentLanguage, + entityData: organizationData ? organizationData : artsData ? artsData : newEntityData, + index, + t, + adminCheckHandler, + currentCalendarData, + imageCropOpen, + setImageCropOpen, + placesSearch, + allPlacesList, + locationPlace, + setLocationPlace, + setIsPopoverOpen, + isPopoverOpen, + form, + style: { + display: !field?.isPreset + ? !addedFields?.includes(field?.mappedField) + ? 'none' + : '' + : '', + }, + }); + } + }); })} - - <> - {section?.filter((field) => !field?.isPreset)?.length > 0 && ( - - {section - ?.filter((field) => !field?.isPreset) - ?.map((field) => addedFields?.includes(field?.mappedField)) - ?.includes(false) ? ( - section?.map((field) => { - if (!addedFields?.includes(field?.mappedField) && !field?.isPreset) - return ( - } - disabled={false} - label={contentLanguageBilingual({ - en: field?.label?.en, - fr: field?.label?.fr, - interfaceLanguage: user?.interfaceLanguage?.toLowerCase(), - calendarContentLanguage: calendarContentLanguage, - })} - promptText={contentLanguageBilingual({ - en: field?.helperText?.en, - fr: field?.helperText?.fr, - interfaceLanguage: user?.interfaceLanguage?.toLowerCase(), - calendarContentLanguage: calendarContentLanguage, - })} - secondaryIcon={} - onClick={() => addFieldsHandler(field?.mappedField)} + {section[0]?.category === formCategory.PRIMARY && + allTaxonomyData?.data?.map((taxonomy, index) => { + if (taxonomy?.isDynamicField) { + let initialValues; + organizationData?.dynamicFields?.forEach((dynamicField) => { + if (taxonomy?.id === dynamicField?.taxonomyId) initialValues = dynamicField?.conceptIds; + }); + return ( + + } + clearIcon={} + treeData={treeDynamicTaxonomyOptions( + taxonomy?.concept, + user, + calendarContentLanguage, + )} + tagRender={(props) => { + const { label, closable, onClose } = props; + return ( + + }> + {label} + + ); + }} /> - ); - }) - ) : ( - - )} - - )} - -
- ); - })} + + ); + } + })} + + <> + {section?.filter((field) => !field?.isPreset)?.length > 0 && ( + + {section + ?.filter((field) => !field?.isPreset) + ?.map((field) => addedFields?.includes(field?.mappedField)) + ?.includes(false) ? ( + section?.map((field) => { + if (!addedFields?.includes(field?.mappedField) && !field?.isPreset) + return ( + } + disabled={false} + label={contentLanguageBilingual({ + en: field?.label?.en, + fr: field?.label?.fr, + interfaceLanguage: user?.interfaceLanguage?.toLowerCase(), + calendarContentLanguage: calendarContentLanguage, + })} + promptText={contentLanguageBilingual({ + en: field?.helperText?.en, + fr: field?.helperText?.fr, + interfaceLanguage: user?.interfaceLanguage?.toLowerCase(), + calendarContentLanguage: calendarContentLanguage, + })} + secondaryIcon={} + onClick={() => addFieldsHandler(field?.mappedField)} + /> + ); + }) + ) : ( + + )} + + )} + + + ); + })} +
diff --git a/src/pages/Dashboard/CreateNewPerson/CreateNewPerson.jsx b/src/pages/Dashboard/CreateNewPerson/CreateNewPerson.jsx index ebea656ce..7d91b3699 100644 --- a/src/pages/Dashboard/CreateNewPerson/CreateNewPerson.jsx +++ b/src/pages/Dashboard/CreateNewPerson/CreateNewPerson.jsx @@ -306,168 +306,181 @@ function CreateNewPerson() { return fields && !personLoading && !taxonomyLoading && !artsDataLoading ? (
-
- + + - - -
- -
+ + + + +
+ +
+ + +
+ + onSaveHandler()} + disabled={addPersonLoading || imageUploadLoading || updatePersonLoading ? true : false} + /> + +
+ +
+ -
- - onSaveHandler()} - disabled={addPersonLoading || imageUploadLoading || updatePersonLoading ? true : false} - /> - +
+

+ {personId + ? t('dashboard.people.createNew.addPerson.editPerson') + : t('dashboard.people.createNew.addPerson.newPerson')} +

- - -
-

- {personId - ? t('dashboard.people.createNew.addPerson.editPerson') - : t('dashboard.people.createNew.addPerson.newPerson')} -

-
- - - {fields?.map((section, index) => { - if (section?.length > 0) - return ( - - <> - {artsDataLinkChecker(personData?.sameAs) && section[0]?.category === formCategory.PRIMARY && ( - - -

{t('dashboard.people.createNew.addPerson.dataSource')}

- - - - - -
- - {t('dashboard.people.createNew.addPerson.question.firstPart')} - - { - navigate(`${PathName.Dashboard}/${calendarId}${PathName.People}${PathName.Search}`); - }}> - {t('dashboard.people.createNew.addPerson.question.secondPart')} - - - {t('dashboard.people.createNew.addPerson.question.thirdPart')} - -
- - -
-
-
- -
- )} - {section?.map((field) => { - return formFieldValue?.map((formField, index) => { - if (formField?.type === field.type) { - return returnFormDataWithFields({ - field, - formField, - allTaxonomyData, - user, - calendarContentLanguage, - entityData: personData ? personData : artsData ? artsData : newEntityData, - index, - t, - adminCheckHandler, - currentCalendarData, - imageCropOpen, - setImageCropOpen, - form, - }); - } - }); - })} - {section[0]?.category === formCategory.PRIMARY && - allTaxonomyData?.data?.map((taxonomy, index) => { - if (taxonomy?.isDynamicField) { - let initialValues; - personData?.dynamicFields?.forEach((dynamicField) => { - if (taxonomy?.id === dynamicField?.taxonomyId) initialValues = dynamicField?.conceptIds; - }); - return ( - - } - clearIcon={} - treeData={treeDynamicTaxonomyOptions(taxonomy?.concept, user, calendarContentLanguage)} - tagRender={(props) => { - const { label, closable, onClose } = props; - return ( - - }> - {label} - - ); - }} + {fields?.map((section, index) => { + if (section?.length > 0) + return ( + + <> + {(artsDataLinkChecker(personData?.sameAs) || artsDataLinkChecker(artsData?.sameAs)) && + section[0]?.category === formCategory.PRIMARY && ( + + +

{t('dashboard.people.createNew.addPerson.dataSource')}

+ + + -
- ); - } + + +
+ + {t('dashboard.people.createNew.addPerson.question.firstPart')} + + { + navigate(`${PathName.Dashboard}/${calendarId}${PathName.People}${PathName.Search}`); + }}> + {t('dashboard.people.createNew.addPerson.question.secondPart')} + + + {t('dashboard.people.createNew.addPerson.question.thirdPart')} + +
+ + +
+
+
+ + + )} + {section?.map((field) => { + return formFieldValue?.map((formField, index) => { + if (formField?.type === field.type) { + return returnFormDataWithFields({ + field, + formField, + allTaxonomyData, + user, + calendarContentLanguage, + entityData: personData ? personData : artsData ? artsData : newEntityData, + index, + t, + adminCheckHandler, + currentCalendarData, + imageCropOpen, + setImageCropOpen, + form, + }); + } + }); })} - - <> -
- ); - })} + {section[0]?.category === formCategory.PRIMARY && + allTaxonomyData?.data?.map((taxonomy, index) => { + if (taxonomy?.isDynamicField) { + let initialValues; + personData?.dynamicFields?.forEach((dynamicField) => { + if (taxonomy?.id === dynamicField?.taxonomyId) initialValues = dynamicField?.conceptIds; + }); + return ( + + } + clearIcon={} + treeData={treeDynamicTaxonomyOptions( + taxonomy?.concept, + user, + calendarContentLanguage, + )} + tagRender={(props) => { + const { label, closable, onClose } = props; + return ( + + }> + {label} + + ); + }} + /> + + ); + } + })} + + <> + + ); + })} +
diff --git a/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx b/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx index 6d3f193cd..c004c18e6 100644 --- a/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx +++ b/src/pages/Dashboard/CreateNewPlace/CreateNewPlace.jsx @@ -64,6 +64,7 @@ import { useAddImageMutation } from '../../../services/image'; import { usePrompt } from '../../../hooks/usePrompt'; import { useAddPostalAddressMutation, useUpdatePostalAddressMutation } from '../../../services/postalAddress'; import PlacesAutocomplete, { geocodeByAddress, getLatLng } from 'react-places-autocomplete'; +import { placeFormRequiredFieldNames } from '../../../constants/placeFormRequiredFieldNames'; const { TextArea } = Input; @@ -111,7 +112,9 @@ function CreateNewPlace() { const placeId = searchParams.get('id'); const artsDataId = location?.state?.data?.id ?? null; const calendarContentLanguage = currentCalendarData?.contentLanguage; - + let requiredFields = currentCalendarData?.formSchema?.filter((form) => form?.formName === 'Place'); + requiredFields = requiredFields && requiredFields?.length > 0 && requiredFields[0]; + let requiredFieldNames = requiredFields ? requiredFields?.requiredfields?.map((field) => field?.fieldName) : []; const { currentData: placeData, isLoading: isPlaceLoading } = useGetPlaceQuery( { placeId: placeId, calendarId, sessionId: timestampRef }, { skip: placeId ? false : true }, @@ -294,6 +297,7 @@ function CreateNewPlace() { formFieldNames.TYPE, formFieldNames.STREET_ADDRESS_ENGLISH, formFieldNames.STREET_ADDRESS_FRENCH, + formFieldNames.POSTAL_CODE, ]), ]) .then(() => { @@ -672,7 +676,7 @@ function CreateNewPlace() { return !isPlaceLoading && !artsDataLoading && !taxonomyLoading ? (
-
+ @@ -715,7 +719,7 @@ function CreateNewPlace() { <> - {artsDataLinkChecker(placeData?.sameAs) && ( + {(artsDataLinkChecker(placeData?.sameAs) || artsDataLinkChecker(artsData?.sameAs)) && (

@@ -724,16 +728,16 @@ function CreateNewPlace() { { return type?.entityId; })} - required={true}> + rules={[ + { + required: requiredFieldNames?.includes(placeFormRequiredFieldNames?.PLACE_TYPE), + message: t('dashboard.places.createNew.addPlace.validations.placeTypeRequired'), + }, + ]}> @@ -1254,7 +1265,9 @@ function CreateNewPlace() { if (value || getFieldValue(formFieldNames.STREET_ADDRESS_FRENCH)) { return Promise.resolve(); } else - return Promise.reject(new Error(t('dashboard.events.addEditEvent.validations.title'))); + return Promise.reject( + new Error(t('dashboard.places.createNew.addPlace.validations.streetAddressRequired')), + ); }, }), ]}> @@ -1330,8 +1343,8 @@ function CreateNewPlace() { label={t('dashboard.places.createNew.addPlace.address.postalCode.postalCode')} rules={[ { - type: 'url', - message: t('dashboard.events.addEditEvent.validations.url'), + required: true, + message: t('dashboard.places.createNew.addPlace.validations.postalCodeRequired'), }, ]}> @@ -1346,19 +1359,7 @@ function CreateNewPlace() { name={formFieldNames.PROVINCE_FRENCH} key={contentLanguage.FRENCH} initialValue={placeData?.address?.addressRegion?.fr ?? artsData?.address?.addressRegion?.fr} - dependencies={[formFieldNames.PROVINCE_ENGLISH]} - rules={[ - ({ getFieldValue }) => ({ - validator(_, value) { - if (value || getFieldValue(formFieldNames.PROVINCE_ENGLISH)) { - return Promise.resolve(); - } else - return Promise.reject( - new Error(t('dashboard.events.addEditEvent.validations.title')), - ); - }, - }), - ]}> + dependencies={[formFieldNames.PROVINCE_ENGLISH]}>