Skip to content

Commit

Permalink
fix: birth_date regex and validate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-kolesnikov committed Nov 20, 2023
1 parent 6d86fc6 commit 3888913
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const passwordNotValid =
'Пароль небезопасен. Проверьте написание. Он должен содержать цифры, символы, буквы. Длина не менее 8 знаков';
export const passwordNotMatch = 'Пароль не соотвествует. Проверьте написание';

export const birthdayError = 'Введите дату в формате ГОД-МЕСЯЦ-ДЕНЬ (YYYY-MM-DD)';
export const birthdayError = 'Введите дату в формате день.месяц.год (DD.MM.YYYY)';

export const URLS = {
SIGNUP: '/signup',
Expand Down Expand Up @@ -54,7 +54,7 @@ export const tests = {
},
birth_date: {
message: birthdayError,
regex: /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/,
regex: /^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$/,
},
password: {
message: passwordNotValid,
Expand Down
10 changes: 8 additions & 2 deletions src/pages/profile/profile-user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export default function ProfileUser() {
useFormAndValidation(initialValues);

const isChangeValue = useMemo(
() => Object.entries(values).some((entry) => initialValues[entry[0]] !== entry[1]),
() =>
Object.entries(values).some((entry) => {
if (initialValues[entry[0]] === null) {
return Boolean(initialValues[entry[0]]) !== Boolean(entry[1]);
}
return initialValues[entry[0]] !== entry[1];
}),
[initialValues, values]
);

Expand All @@ -47,7 +53,7 @@ export default function ProfileUser() {
first_name: `${values.first_name}`,
last_name: `${values.last_name}`,
// city: `${values.city}`,
birth_date: `${values.birth_date}`,
birth_date: values.birth_date === '' ? null : `${values.birth_date}`,
phone_number: `${values.phone_number}`,
})
.then((data) => {
Expand Down

0 comments on commit 3888913

Please sign in to comment.