Skip to content

Commit

Permalink
Merge pull request #590 from culturecreates/feature/issue-471
Browse files Browse the repository at this point in the history
Feature/issue 471
  • Loading branch information
AbhishekPAnil authored Sep 19, 2023
2 parents 2642af7 + abc5963 commit f6d34d9
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 395 deletions.
118 changes: 61 additions & 57 deletions src/components/BilingualTextEditor/BilingualTextEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function BilingualTextEditor(props) {
const { t } = useTranslation();
const reactQuillRefFr = useRef(null);
const reactQuillRefEn = useRef(null);
const [descriptionMinimumWordCount] = useState(props?.descriptionMinimumWordCount ?? 0);
const [descriptionMinimumWordCount] = useState(props?.descriptionMinimumWordCount ?? null);

return (
<ContentLanguageInput calendarContentLanguage={calendarContentLanguage}>
Expand Down Expand Up @@ -49,34 +49,36 @@ function BilingualTextEditor(props) {
},
})
: [],
() => ({
validator() {
if (
reactQuillRefFr?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
) {
return Promise.resolve();
} else if (
reactQuillRefEn?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
)
return Promise.resolve();
else
return Promise.reject(
new Error(
calendarContentLanguage === contentLanguage.ENGLISH ||
calendarContentLanguage === contentLanguage.FRENCH
? t('dashboard.organization.createNew.validations.unilingualDescriptionShort')
: calendarContentLanguage === contentLanguage.BILINGUAL &&
t('dashboard.organization.createNew.validations.frenchShort'),
),
);
},
}),
descriptionMinimumWordCount
? () => ({
validator() {
if (
reactQuillRefFr?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
) {
return Promise.resolve();
} else if (
reactQuillRefEn?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
)
return Promise.resolve();
else
return Promise.reject(
new Error(
calendarContentLanguage === contentLanguage.ENGLISH ||
calendarContentLanguage === contentLanguage.FRENCH
? t('dashboard.organization.createNew.validations.unilingualDescriptionShort')
: calendarContentLanguage === contentLanguage.BILINGUAL &&
t('dashboard.organization.createNew.validations.frenchShort'),
),
);
},
})
: [],
]}
/>

Expand Down Expand Up @@ -115,34 +117,36 @@ function BilingualTextEditor(props) {
})
: [],

() => ({
validator() {
if (
reactQuillRefEn?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
) {
return Promise.resolve();
} else if (
reactQuillRefFr?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
)
return Promise.resolve();
else
return Promise.reject(
new Error(
calendarContentLanguage === contentLanguage.ENGLISH ||
calendarContentLanguage === contentLanguage.FRENCH
? t('dashboard.organization.createNew.validations.unilingualDescriptionShort')
: calendarContentLanguage === contentLanguage.BILINGUAL &&
t('dashboard.organization.createNew.validations.englishShort'),
),
);
},
}),
descriptionMinimumWordCount
? () => ({
validator() {
if (
reactQuillRefEn?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
) {
return Promise.resolve();
} else if (
reactQuillRefFr?.current?.unprivilegedEditor
?.getText()
.split(' ')
?.filter((n) => n != '')?.length > descriptionMinimumWordCount
)
return Promise.resolve();
else
return Promise.reject(
new Error(
calendarContentLanguage === contentLanguage.ENGLISH ||
calendarContentLanguage === contentLanguage.FRENCH
? t('dashboard.organization.createNew.validations.unilingualDescriptionShort')
: calendarContentLanguage === contentLanguage.BILINGUAL &&
t('dashboard.organization.createNew.validations.englishShort'),
),
);
},
})
: [],
]}
/>
</BilingualInput>
Expand Down
37 changes: 32 additions & 5 deletions src/constants/formFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const dataTypes = {
IDENTITY_STRING: 'IdentityString',
URI_STRING: 'URIString',
IMAGE: 'Image',
EMAIL: 'Email',
};

export const mappedFieldTypes = {
Expand All @@ -64,6 +65,13 @@ const rules = [
message: <Translation>{(t) => t('dashboard.events.addEditEvent.validations.url')}</Translation>,
},
},
{
dataType: dataTypes.EMAIL,
rule: {
type: 'email',
message: <Translation>{(t) => t('login.validations.invalidEmail')}</Translation>,
},
},
];

export const formFieldValue = [
Expand Down Expand Up @@ -137,6 +145,17 @@ export const formFieldValue = [
placeholder={t('dashboard.events.addEditEvent.otherInformation.contact.placeHolderWebsite')}
/>
);
else if (datatype === dataTypes.EMAIL)
return (
<StyledInput
placeholder={contentLanguageBilingual({
en: placeholder?.en,
fr: placeholder?.fr,
interfaceLanguage: user?.interfaceLanguage?.toLowerCase(),
calendarContentLanguage: calendarContentLanguage,
})}
/>
);
else
return (
<TextArea
Expand Down Expand Up @@ -173,7 +192,7 @@ export const formFieldValue = [
},
{
type: formTypes.MULTISELECT,
element: ({ taxonomyData, user, type, isDynamicField, calendarContentLanguage, placeholder }) => {
element: ({ taxonomyData, user, taxonomyAlias, isDynamicField, calendarContentLanguage, placeholder }) => {
return (
<TreeSelectOption
allowClear
Expand All @@ -186,7 +205,7 @@ export const formFieldValue = [
calendarContentLanguage: calendarContentLanguage,
})}
clearIcon={<CloseCircleOutlined style={{ color: '#1b3de6', fontSize: '14px' }} />}
treeData={treeTaxonomyOptions(taxonomyData, user, type, isDynamicField, calendarContentLanguage)}
treeData={treeTaxonomyOptions(taxonomyData, user, taxonomyAlias, isDynamicField, calendarContentLanguage)}
tagRender={(props) => {
const { label, closable, onClose } = props;
return (
Expand Down Expand Up @@ -332,7 +351,7 @@ export const formFieldValue = [
placeholder,
required,
// validations,
descriptionMinimumWordCount = 10,
descriptionMinimumWordCount,
}) => {
if (datatype === dataTypes.MULTI_LINGUAL)
return (
Expand Down Expand Up @@ -361,18 +380,21 @@ export const renderFormFields = ({
position,
hidden,
label,
style,
mappedField,
}) => {
return (
<>
{position === 'top' && datatype !== dataTypes.IMAGE && <p className="add-event-date-heading">{userTips}</p>}

<Form.Item
label={label}
name={name}
key={key}
initialValue={initialValue}
required={required}
hidden={hidden}
style={style}
className={mappedField}
rules={rules?.map((rule) => {
if (datatype === rule?.dataType) return rule.rule;
})}
Expand Down Expand Up @@ -404,17 +426,19 @@ export const returnFormDataWithFields = ({
setIsPopoverOpen,
isPopoverOpen,
form,
style,
}) => {
return renderFormFields({
name: [field?.mappedField],
mappedField: field?.mappedField,
type: field?.type,
datatype: field?.datatype,
required: field?.isRequiredField,
element: formField?.element({
datatype: field?.datatype,
taxonomyData: allTaxonomyData,
user: user,
type: field?.mappedField,
type: field?.type,
isDynamicField: false,
calendarContentLanguage,
name: [field?.mappedField],
Expand Down Expand Up @@ -458,6 +482,7 @@ export const returnFormDataWithFields = ({
setIsPopoverOpen,
isPopoverOpen,
form,
taxonomyAlias: field?.taxonomyAlias,
}),
key: index,
initialValue: formInitialValueHandler(field?.type, field?.mappedField, field?.datatype, entityData),
Expand All @@ -476,5 +501,7 @@ export const returnFormDataWithFields = ({
position: field?.userTips?.position,
hidden: field?.isAdminOnlyField ? (adminCheckHandler() ? false : true) : false,
form,
style,
taxonomyAlias: field?.taxonomyAlias,
});
};
3 changes: 2 additions & 1 deletion src/locales/en/translationEn.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@
},
"addOrganization": {
"newOrganization": "New Organization",
"editOrganization": "Edit Organization"
"editOrganization": "Edit Organization",
"addMoreDetails": "Add more details to your organization"
},
"notification": {
"addSuccess": "Success! Your organization has been created.",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/fr/transalationFr.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@
},
"addOrganization": {
"newOrganization": "Nouvelle organisation",
"editOrganization": "Modifier l’organisation"
"editOrganization": "Modifier l’organisation",
"addMoreDetails": "Ajouter des détails à votre organisation"
},
"notification": {
"addSuccess": "Succès ! Votre organisation a été créé.",
Expand Down
Loading

0 comments on commit f6d34d9

Please sign in to comment.