Skip to content

Commit

Permalink
chore: align validators result structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-yahia committed Dec 19, 2024
1 parent 0e602f4 commit bf7bfbc
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-12-05T11:39:04.447Z\n"
"PO-Revision-Date: 2024-12-05T11:39:04.447Z\n"
"POT-Creation-Date: 2024-12-19T09:18:35.465Z\n"
"PO-Revision-Date: 2024-12-19T09:18:35.466Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -211,8 +211,8 @@ msgstr "Active"
msgid "Completed"
msgstr "Completed"

msgid "Please add or cancel note before saving the event"
msgstr "Please add or cancel note before saving the event"
msgid "Please add or cancel the note before saving the event"
msgstr "Please add or cancel the note before saving the event"

msgid "Save and add another"
msgstr "Save and add another"
Expand Down Expand Up @@ -1210,8 +1210,8 @@ msgstr "Add coordinates"
msgid "Add area"
msgstr "Add area"

msgid "Please add or cancel the note before saving the event"
msgstr "Please add or cancel the note before saving the event"
msgid "Please selectoo {{categoryName}}"
msgstr "Please selectoo {{categoryName}}"

msgid "organisation unit could not be retrieved. Please try again later."
msgstr "organisation unit could not be retrieved. Please try again later."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const getEventDateValidatorContainers = () => {
const validatorContainers = [
{
validator: hasValue,
message: i18n.t('A value is required'),
errorMessage: i18n.t('A value is required'),
},
{
validator: preValidateDate,
message: i18n.t('Please provide a valid date'),
errorMessage: i18n.t('Please provide a valid date'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const validateCategories = (value?: ?string, props?: Object, fieldId?: string) =

return {
valid: hasValue(value),
message: i18n.t('Please select {{categoryName}}', { categoryName }),
errorMessage: i18n.t('Please select {{categoryName}}', { categoryName }),
};
};

export const getCategoryOptionsValidatorContainers = (props?: Object, fieldId?: string) => {
const validatorContainers = [
{
validator: (value?: ?string) => validateCategories(value, props, fieldId),
message: '',
errorMessage: '',
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const getEnrollmentDateValidatorContainer = () => {
const validatorContainers = [
{
validator: hasValue,
message:
errorMessage:
i18n.t('A value is required'),
},
{
validator: isValidEnrollmentDate,
message: i18n.t('Please provide a valid date'),
errorMessage: i18n.t('Please provide a valid date'),
},
{ validator: isValidNonFutureDate,
message: i18n.t('A date in the future is not allowed'),
errorMessage: i18n.t('A date in the future is not allowed'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export const getIncidentDateValidatorContainer = () => {
const validatorContainers = [
{
validator: hasValue,
message:
errorMessage:
i18n.t('A value is required'),
},
{
validator: isValidIncidentDate,
message: i18n.t('Please provide a valid date'),
errorMessage: i18n.t('Please provide a valid date'),
},
{ validator: isValidNonFutureDate,
message: i18n.t('A date in the future is not allowed'),
errorMessage: i18n.t('A date in the future is not allowed'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const getEventDateValidatorContainers = () => {
const validatorContainers = [
{
validator: hasValue,
message:
errorMessage:
i18n.t('A value is required'),
},
{
validator: preValidateDate,
message: i18n.t('Please provide a valid date'),
errorMessage: i18n.t('Please provide a valid date'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getNoteValidatorContainers = () => {
const validatorContainers = [
{
validator: validateNote,
message: i18n.t('Please add or cancel note before saving the event'),
errorMessage: i18n.t('Please add or cancel the note before saving the event'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ type Validator = (value: any,

export type ValidatorContainer = {
validator: Validator,
message: string,
errorMessage: string,
};

export function getValidationError(value: any, validatorContainers: ?Array<ValidatorContainer>, internalComponentError?: ?{error: ?string, errorCode: ?string}) {
if (!validatorContainers) {
return null;
}

let message;
let errorMessage;
const errorEncountered = validatorContainers.some((validatorContainer) => {
const validator = validatorContainer.validator;
const result = validator(value, internalComponentError);
Expand All @@ -24,10 +24,10 @@ export function getValidationError(value: any, validatorContainers: ?Array<Valid
return false;
}

message = (result && result.errorMessage) || (result && result.message) || validatorContainer.message;
errorMessage = (result && result.errorMessage) || validatorContainer.errorMessage;
return true;
});


return (errorEncountered ? (message || i18n.t('validation failed')) : null);
return (errorEncountered ? (errorMessage || i18n.t('validation failed')) : null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const validateCategories = (value?: ?string, props?: Object, fieldId?: string) =

return {
valid: hasValue(value),
message: i18n.t('Please select {{categoryName}}', { categoryName }),
errorMessage: i18n.t('Please select {{categoryName}}', { categoryName }),
};
};

export const getCategoryOptionsValidatorContainers = (props?: Object, fieldId?: string) => {
const validatorContainers = [
{
validator: (value?: ?string) => validateCategories(value, props, fieldId),
message: '',
errorMessage: '',
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const validateCategories = (value?: ?string, props?: Object, fieldId?: string) =

return {
valid: hasValue(value),
message: i18n.t('Please select {{categoryName}}', { categoryName }),
errorMessage: i18n.t('Please selectoo {{categoryName}}', { categoryName }),
};
};

export const getCategoryOptionsValidatorContainers = (props?: Object, fieldId?: string) => {
const validatorContainers = [
{
validator: (value?: ?string) => validateCategories(value, props, fieldId),
message: '',
errorMessage: '',
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const getEventDateValidatorContainers = () => {
const validatorContainers = [
{
validator: hasValue,
message:
errorMessage:
i18n.t('A value is required'),
},
{
validator: preValidateDate,
message: i18n.t('Please provide a valid date'),
errorMessage: i18n.t('Please provide a valid date'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getNoteValidatorContainers = () => {
const validatorContainers = [
{
validator: validateNote,
message: i18n.t('Please add or cancel the note before saving the event'),
errorMessage: i18n.t('Please add or cancel the note before saving the event'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ const validateCategories = (value?: ?string, props?: Object, fieldId?: string) =
?.find(category => category.id === fieldId)?.displayName;
return {
valid: hasValue(value),
message: i18n.t('Please select {{categoryName}}', { categoryName }),
errorMessage: i18n.t('Please select {{categoryName}}', { categoryName }),
};
};

export const getCategoryOptionsValidatorContainers = (props?: Object, fieldId?: string) => {
const validatorContainers = [
{
validator: (value?: ?string) => validateCategories(value, props, fieldId),
message: '',
errorMessage: '',
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const getEventDateValidatorContainers = () => {
const validatorContainers = [
{
validator: hasValue,
message: i18n.t('A value is required'),
errorMessage: i18n.t('A value is required'),
},
{
validator: preValidateDate,
message: i18n.t('Please provide a valid date'),
errorMessage: i18n.t('Please provide a valid date'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getNoteValidatorContainers = () => {
const validatorContainers = [
{
validator: validateNote,
message: i18n.t('Please add or cancel the note before saving the event'),
errorMessage: i18n.t('Please add or cancel the note before saving the event'),
},
];
return validatorContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getOrgUnitValidatorContainers = () => {
const validatorContainers = [
{
validator: validateOrgUnit,
message: i18n.t('Please provide an valid organisation unit'),
errorMessage: i18n.t('Please provide an valid organisation unit'),
},
];
return validatorContainers;
Expand Down

0 comments on commit bf7bfbc

Please sign in to comment.