Skip to content

Commit

Permalink
Merge pull request #1374 from culturecreates/bugfix/issue-1319
Browse files Browse the repository at this point in the history
Bugfix/issue 1319
  • Loading branch information
AbhishekPAnil authored Oct 1, 2024
2 parents 562c639 + f1eb722 commit 13bc153
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
75 changes: 54 additions & 21 deletions src/constants/formFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,40 @@ export const formNames = {
const rules = [
{
dataType: dataTypes.URI_STRING,
rule: {
type: 'url',
message: <Translation>{(t) => t('dashboard.events.addEditEvent.validations.url')}</Translation>,
},
rule: () => [
{
type: 'url',
message: <Translation>{(t) => t('dashboard.events.addEditEvent.validations.url')}</Translation>,
},
],
},
{
dataType: dataTypes.EMAIL,
rule: {
type: 'email',
message: <Translation>{(t) => t('login.validations.invalidEmail')}</Translation>,
},
rule: () => [
{
type: 'email',
message: <Translation>{(t) => t('login.validations.invalidEmail')}</Translation>,
},
],
},
{
dataType: dataTypes.IMAGE,
rule: ({ image, t }) => [
({ getFieldValue }) => ({
validator() {
if (
(getFieldValue('image') != undefined && getFieldValue('image')?.length > 0) ||
(image && !getFieldValue('image')) ||
(image && getFieldValue('image')?.length > 0)
) {
return Promise.resolve();
} else
return Promise.reject(
new Error(t('dashboard.events.addEditEvent.validations.otherInformation.emptyImage')),
);
},
}),
],
},
];

Expand Down Expand Up @@ -115,7 +138,9 @@ export const formFieldValue = [
name={Array.isArray(name) ? name[0] : name}
data={data}
entityId={entityId}
validations={validations}
validations={
validations && validations.trim() !== '' ? validations : t('common.validations.informationRequired')
}
dataCy={`input-text-area-${mappedField}-`}
placeholder={placeholder}
required={required}>
Expand Down Expand Up @@ -347,7 +372,6 @@ export const formFieldValue = [
locationPlace,
setLocationPlace,
t,
name,
placesSearch,
calendarContentLanguage,
allPlacesArtsdataList,
Expand All @@ -359,7 +383,7 @@ export const formFieldValue = [
fieldName,
}) => {
return (
<>
<div>
<Popover
data-cy={`popover-${mappedField ?? fieldName}`}
open={isPopoverOpen}
Expand Down Expand Up @@ -395,7 +419,7 @@ export const formFieldValue = [
}`}
onClick={() => {
setLocationPlace(place);
form.setFieldValue(name, place?.value);
form.setFieldValue(fieldName, place?.value);
setIsPopoverOpen(false);
}}
data-cy={`div-${mappedField ?? fieldName}-footlight-place-${index}`}>
Expand Down Expand Up @@ -429,7 +453,7 @@ export const formFieldValue = [
}`}
onClick={() => {
setLocationPlace(place);
form.setFieldValue(name, place?.value);
form.setFieldValue(fieldName, place?.value);
setIsPopoverOpen(false);
}}
data-cy={`div-${mappedField ?? fieldName}-footlight-place-${index}`}>
Expand Down Expand Up @@ -460,7 +484,7 @@ export const formFieldValue = [
className="event-popover-options"
onClick={() => {
setLocationPlace(place);
form.setFieldValue(name, place?.uri);
form.setFieldValue(fieldName, place?.uri);
setIsPopoverOpen(false);
}}
data-cy={`div-${mappedField ?? fieldName}-artsdata-place-${index}`}>
Expand Down Expand Up @@ -501,14 +525,14 @@ export const formFieldValue = [
closable
onClose={() => {
setLocationPlace();
form.setFieldValue(name, undefined);
form.setFieldValue(fieldName, undefined);
}}
edit={locationPlace?.source === sourceOptions.CMS && true}
onEdit={(e) => placeNavigationHandler(locationPlace?.value, locationPlace?.type, e)}
creatorId={locationPlace?.creatorId}
/>
)}
</>
</div>
);
},
},
Expand Down Expand Up @@ -557,6 +581,7 @@ export const renderFormFields = ({
mappedField,
t,
validations,
originalUrl,
fieldName,
}) => {
return (
Expand All @@ -565,7 +590,7 @@ export const renderFormFields = ({
<Form.Item
data-cy={`form-item-${mappedField ?? fieldName?.toLowerCase()}`}
label={label}
name={name}
name={name ?? fieldName?.toLowerCase()}
key={key}
initialValue={
Array.isArray(initialValue)
Expand All @@ -582,14 +607,18 @@ export const renderFormFields = ({
className={mappedField ?? fieldName?.toLowerCase()}
rules={rules
?.map((rule) => {
if (datatype === rule?.dataType) return rule.rule;
if (datatype === rule?.dataType) {
return rule.rule({ image: originalUrl, t, required, fieldName });
}
})
.concat([
{
required: required,
message: validations ?? t('common.validations.informationRequired'),
message:
validations && validations.trim() !== '' ? validations : t('common.validations.informationRequired'),
},
])
?.flat()
?.filter((rule) => rule !== undefined)}
help={
position === 'bottom' && userTips ? (
Expand Down Expand Up @@ -641,7 +670,7 @@ export const returnFormDataWithFields = ({
}) => {
return renderFormFields({
fieldName: field?.name,
name: [field?.mappedField],
name: field?.mappedField && [field?.mappedField],
mappedField: field?.mappedField,
type: field?.type,
datatype: field?.datatype,
Expand All @@ -657,7 +686,7 @@ export const returnFormDataWithFields = ({
type: field?.type,
isDynamicField: false,
calendarContentLanguage,
name: [field?.mappedField],
name: field?.mappedField && [field?.mappedField],
preview: true,
placeholder: bilingual({
data: field?.placeholder,
Expand Down Expand Up @@ -737,5 +766,9 @@ export const returnFormDataWithFields = ({
interfaceLanguage: user?.interfaceLanguage?.toLowerCase(),
locationPlace,
}),
originalUrl:
field?.mappedField === mappedFieldTypes.IMAGE
? entityData?.image?.find((image) => image?.isMain)?.original?.uri
: field?.mappedField === mappedFieldTypes.LOGO && entityData?.logo?.original?.uri,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function CreateNewOrganization() {
collection.push([field?.mappedField, contentLanguageKeyMap[language]]);
});
return collection;
} else return field?.mappedField;
} else return field?.mappedField ?? field?.name?.toLowerCase();
})
?.flat(),
);
Expand Down

0 comments on commit 13bc153

Please sign in to comment.