mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-05 11:00:56 +00:00
fix: personalId birthdate validation
This commit is contained in:
parent
e3b01ab53a
commit
6780762bf7
2 changed files with 33 additions and 5 deletions
|
|
@ -14,7 +14,7 @@ export const isPersonalIdNumberValid = (personalIdNumber: string): boolean => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isPersonalIdNumberWithBirthdateValid = (
|
export const isPersonalIdMatchingBirthdate = (
|
||||||
personalIdNumber: string,
|
personalIdNumber: string,
|
||||||
birthdate: string
|
birthdate: string
|
||||||
): boolean => {
|
): boolean => {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
import PersonalIdConfirmCheckBox from '$lib/components/checkbox/PersonalIdConfirmCheckBox.svelte';
|
import PersonalIdConfirmCheckBox from '$lib/components/checkbox/PersonalIdConfirmCheckBox.svelte';
|
||||||
import {
|
import {
|
||||||
parseBirthdateSexFromPersonalId,
|
parseBirthdateSexFromPersonalId,
|
||||||
isPersonalIdNumberWithBirthdateValid
|
isPersonalIdMatchingBirthdate
|
||||||
} from '$lib/utils/personalIdFormat';
|
} from '$lib/utils/personalIdFormat';
|
||||||
import PersonalIdErrorModal from '$lib/components/modal/PersonalIdErrorModal.svelte';
|
import PersonalIdErrorModal from '$lib/components/modal/PersonalIdErrorModal.svelte';
|
||||||
import LinkErrorModal from '$lib/components/modal/LinkErrorModal.svelte';
|
import LinkErrorModal from '$lib/components/modal/LinkErrorModal.svelte';
|
||||||
|
|
@ -127,7 +127,20 @@
|
||||||
birthdate: yup
|
birthdate: yup
|
||||||
.string()
|
.string()
|
||||||
.required()
|
.required()
|
||||||
.matches(/^([0-3]?[0-9])\.(0?[1-9]|1[0-2])\.[0-9]{4}$/),
|
.matches(/^([0-3]?[0-9])\.(0?[1-9]|1[0-2])\.[0-9]{4}$/)
|
||||||
|
.test((_val) => {
|
||||||
|
if ($form.candidate.citizenship !== 'Česká republika') return true;
|
||||||
|
if (!_val) return false;
|
||||||
|
if (isPersonalIdMatchingBirthdate(
|
||||||
|
$form.candidate.personalIdNumber,
|
||||||
|
_val
|
||||||
|
)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
pushErrorText("Datum narození a rodné číslo se neshodují.")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}),
|
||||||
birthSurname: yup.string(),
|
birthSurname: yup.string(),
|
||||||
sex: yup.string(),
|
sex: yup.string(),
|
||||||
address: yup.string(),
|
address: yup.string(),
|
||||||
|
|
@ -397,7 +410,22 @@
|
||||||
return '+' + telephone.match(/[0-9]{1,3}/g)!.join(' ');
|
return '+' + telephone.match(/[0-9]{1,3}/g)!.join(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
$: if ($form.candidate.citizenship === 'Česká republika') {
|
let lastCitizenshipSelected = $form.candidate.citizenship;
|
||||||
|
$: if ($form.candidate.citizenship !== lastCitizenshipSelected) {
|
||||||
|
lastCitizenshipSelected = $form.candidate.citizenship;
|
||||||
|
$form.candidate.birthdate = '';
|
||||||
|
$form.candidate.sex = '';
|
||||||
|
|
||||||
|
if ($form.candidate.citizenship === 'Česká republika') {
|
||||||
|
let [birthdate, sex] = parseBirthdateSexFromPersonalId(data.whoami.personalIdNumber);
|
||||||
|
$form.candidate.birthdate = birthdate;
|
||||||
|
$form.candidate.sex = sex;
|
||||||
|
pushSuccessText(
|
||||||
|
`Datum narození a pohlaví bylo vyplněno automaticky podle Vašeho rodného čísla (${data.whoami.personalIdNumber}).`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* $: if ($form.candidate.citizenship === 'Česká republika') {
|
||||||
if ($form.candidate.birthdate === '' && $form.candidate.sex === '') {
|
if ($form.candidate.birthdate === '' && $form.candidate.sex === '') {
|
||||||
let [birthdate, sex] = parseBirthdateSexFromPersonalId(data.whoami.personalIdNumber);
|
let [birthdate, sex] = parseBirthdateSexFromPersonalId(data.whoami.personalIdNumber);
|
||||||
$form.candidate.birthdate = birthdate;
|
$form.candidate.birthdate = birthdate;
|
||||||
|
|
@ -409,7 +437,7 @@
|
||||||
} else {
|
} else {
|
||||||
$form.candidate.birthdate = '';
|
$form.candidate.birthdate = '';
|
||||||
$form.candidate.sex = '';
|
$form.candidate.sex = '';
|
||||||
}
|
} */
|
||||||
|
|
||||||
if (details !== undefined) {
|
if (details !== undefined) {
|
||||||
details.candidate.birthdate = details.candidate.birthdate.split('-').reverse().join('.');
|
details.candidate.birthdate = details.candidate.birthdate.split('-').reverse().join('.');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue