From 196cab3b87931a1fc6e59f7733f48fc88522fcc3 Mon Sep 17 00:00:00 2001 From: jozef-drabik <104101610+jozef-drabik@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:35:05 +0100 Subject: [PATCH] 1119 - Confirm password in registration field is now required (#1214) * Confirm password - required * Extraction of functionality * prettier fix * Added confirmation password for RegisterDialog --- src/common/form/validation.ts | 7 +++++++ src/components/auth/register/RegisterForm.tsx | 10 ++++++---- src/components/one-time-donation/RegisterDialog.tsx | 8 ++++++++ src/gql/donations.d.ts | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/common/form/validation.ts b/src/common/form/validation.ts index 2bcd87ff0..2c999bdba 100644 --- a/src/common/form/validation.ts +++ b/src/common/form/validation.ts @@ -1,5 +1,6 @@ import { setLocale, string } from 'yup' import { TFunction } from 'next-i18next' +import * as yup from 'yup' export type TranslatableField = | (string | undefined) | { key: string; values?: Record } @@ -39,6 +40,7 @@ export const customValidators = { values: { max }, }), password: () => ({ key: 'validation:password' }), + confirmPassword: () => ({ key: 'validation:password-match' }), phone: () => ({ key: 'validation:phone' }), name: () => ({ key: 'validation:invalid' }), } @@ -76,3 +78,8 @@ export const password = string() .min(8, customValidators.passwordMin) .max(30, customValidators.passwordMax) .matches(passwordRegex, customValidators.password) + +export const confirmPassword = string().oneOf( + [yup.ref('password')], + customValidators.confirmPassword, +) diff --git a/src/components/auth/register/RegisterForm.tsx b/src/components/auth/register/RegisterForm.tsx index e1a311474..655eae812 100644 --- a/src/components/auth/register/RegisterForm.tsx +++ b/src/components/auth/register/RegisterForm.tsx @@ -6,7 +6,7 @@ import { signIn } from 'next-auth/react' import { useTranslation } from 'next-i18next' import { routes } from 'common/routes' -import { email, password, name } from 'common/form/validation' +import { email, password, name, confirmPassword } from 'common/form/validation' import { useRegister } from 'service/auth' import { AlertStore } from 'stores/AlertStore' import GenericForm from 'components/common/form/GenericForm' @@ -21,6 +21,7 @@ export type RegisterFormData = { lastName: string email: string password: string + confirmPassword: string terms: boolean gdpr: boolean } @@ -33,7 +34,7 @@ const validationSchema: yup.SchemaOf = yup lastName: name.required(), email: email.required(), password: password.required(), - 'confirm-password': yup.string().oneOf([yup.ref('password')], 'validation:password-match'), + confirmPassword: confirmPassword.required('validation:password-match'), terms: yup.bool().required().oneOf([true], 'validation:terms-of-use'), gdpr: yup.bool().required().oneOf([true], 'validation:terms-of-service'), }) @@ -43,6 +44,7 @@ const defaults: RegisterFormData = { lastName: '', email: '', password: '', + confirmPassword: '', terms: false, gdpr: false, } @@ -71,7 +73,7 @@ export default function RegisterForm({ initialValues = defaults }: RegisterFormP } if (resp?.ok) { AlertStore.show(t('auth:alerts.welcome'), 'success') - router.push(routes.profile.index) + await router.push(routes.profile.index) } } catch (error) { console.error(error) @@ -111,7 +113,7 @@ export default function RegisterForm({ initialValues = defaults }: RegisterFormP diff --git a/src/components/one-time-donation/RegisterDialog.tsx b/src/components/one-time-donation/RegisterDialog.tsx index ecc04868c..74a314a15 100644 --- a/src/components/one-time-donation/RegisterDialog.tsx +++ b/src/components/one-time-donation/RegisterDialog.tsx @@ -24,6 +24,7 @@ export default function RegisterForm() { lastName: formik.values.registerLastName as string, email: formik.values.registerEmail as string, password: formik.values.registerPassword as string, + confirmPassword: formik.values.confirmPassword as string, terms: formik.values.terms as boolean, gdpr: formik.values.gdpr as boolean, } @@ -89,6 +90,13 @@ export default function RegisterForm() { + + +