Skip to content

Commit

Permalink
III-5817 - Use Yup validation instead of custom validation
Browse files Browse the repository at this point in the history
  • Loading branch information
brampauwelyn committed Oct 11, 2023
1 parent 810f8ba commit 9250c60
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
"required": "Name ist erforderlich."
},
"age_range": {
"required": "Altersklasse erforderlich."
"required": "Altersklasse erforderlich.",
"matches": "Das angegebene Alter ist ungültig"
}
},
"name": {
Expand All @@ -269,7 +270,6 @@
"from": "Von",
"till": "Bis",
"age": "Jahre",
"error_not_valid": "Das angegebene Alter ist ungültig",
"error_max_lower_than_min": "Das Höchstalter kann nicht unter dem Mindestalter liegen.",
"error_no_min_age": "Bitte geben Sie ein Mindestalter ein"
}
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
"required": "Nom est requis."
},
"age_range": {
"required": "Group d'âge est requis"
"required": "Group d'âge est requis",
"matches": "L'âge spécifié n'est pas valide"
}
},
"name": {
Expand All @@ -269,7 +270,6 @@
"from": "De",
"till": "à",
"age": "ans",
"error_not_valid": "L'âge spécifié n'est pas valide",
"error_max_lower_than_min": "L'âge maximum ne peut être inférieur à l'âge minimum.",
"error_no_min_age": "Veuillez entrer un âge minimum"
}
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
"required": "Naam is verplicht."
},
"age_range": {
"required": "Leeftijdsgroep is verplicht."
"required": "Leeftijdsgroep is verplicht.",
"matches": "De opgegeven leeftijd is niet geldig"
}
},
"name": {
Expand All @@ -269,7 +270,6 @@
"from": "Van",
"till": "Tot",
"age": "jaar",
"error_not_valid": "De opgegeven leeftijd is niet geldig",
"error_max_lower_than_min": "De maximumleeftijd kan niet lager zijn dan de minimumleeftijd.",
"error_no_min_age": "Gelieve een minimum leeftijd in te vullen"
}
Expand Down
12 changes: 1 addition & 11 deletions src/pages/steps/AgeRangeStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ const AgeRangeStep = ({
};

const handleSubmitCustomAgeRange = (field: Field) => {
const numberRegex = new RegExp(/^\d+$/);

if (
!numberRegex.test(customMinAgeRange) ||
!numberRegex.test(customMaxAgeRange)
) {
setCustomAgeRangeError(t('create.name_and_age.age.error_not_valid'));
return;
}

if (parseInt(customMinAgeRange) > parseInt(customMaxAgeRange)) {
setCustomAgeRangeError(
t('create.name_and_age.age.error_max_lower_than_min'),
Expand Down Expand Up @@ -274,7 +264,7 @@ const AgeRangeStep = ({
{errors.nameAndAgeRange?.typicalAgeRange && (
<Text color="red">
{t(
'create.name_and_age.validation_messages.age_range.required',
`create.name_and_age.validation_messages.age_range.${errors.nameAndAgeRange?.typicalAgeRange.type}`,
)}
</Text>
)}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/steps/NameAndAgeRangeStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
StepsConfiguration,
} from './Steps';

const numberHyphenNumberRegex = /^\d+-\d+$/;

const useEditNameAndAgeRange = ({
scope,
onSuccess,
Expand Down Expand Up @@ -81,7 +83,7 @@ const nameAndAgeRangeStepConfiguration: StepsConfiguration<'nameAndAgeRange'> =
title: ({ t }) => t('create.name_and_age.title'),
validation: yup.object().shape({
name: yup.object().shape({}).required(),
typicalAgeRange: yup.string().required(),
typicalAgeRange: yup.string().matches(numberHyphenNumberRegex).required(),
}),
shouldShowStep: ({ watch, formState }) => {
const location = watch('location');
Expand Down

0 comments on commit 9250c60

Please sign in to comment.