From a2600817cf2ce81c5da32e9d6a722fc7d746cfdb Mon Sep 17 00:00:00 2001 From: Ralitsa Ilieva Date: Tue, 10 Oct 2023 12:44:48 +0200 Subject: [PATCH 1/3] Terms and GDPR added in the registerForm --- public/locales/bg/auth.json | 1 + public/locales/en/auth.json | 1 + src/common/form/validation.ts | 2 ++ .../client/one-time-donation/FormikStepper.tsx | 6 +++--- .../one-time-donation/RegisterDialog.tsx | 18 ++++++++++++++++-- .../client/one-time-donation/Steps.tsx | 4 ++++ .../helpers/validation-schema.ts | 9 ++++++++- src/gql/donations.d.ts | 4 ++++ 8 files changed, 39 insertions(+), 6 deletions(-) diff --git a/public/locales/bg/auth.json b/public/locales/bg/auth.json index de309d026..fd2880268 100644 --- a/public/locales/bg/auth.json +++ b/public/locales/bg/auth.json @@ -2,6 +2,7 @@ "alerts": { "welcome": "Добре дошли!", "invalid-login": "Грешен потребител / парола.", + "register-error": "Моля, попълнете необходимата информация", "duplicate-email": "Потребител с такъв имейл вече съществува", "re-login": "Моля, влезте отново в профила си.", "forgotten-password-error": "Потребителя не е намерен, моля опитайте отново!", diff --git a/public/locales/en/auth.json b/public/locales/en/auth.json index 88246118b..d03645475 100644 --- a/public/locales/en/auth.json +++ b/public/locales/en/auth.json @@ -2,6 +2,7 @@ "alerts": { "welcome": "Welcome!", "invalid-login": "Wrong username / password.", + "register-error": "Please, fill in the necessary information", "re-login": "Please login into your account.", "forgotten-password-error": "User not found, please try again!", "forgotten-password-success": "Please check your email!", diff --git a/src/common/form/validation.ts b/src/common/form/validation.ts index 40c4ec54f..9216d491c 100644 --- a/src/common/form/validation.ts +++ b/src/common/form/validation.ts @@ -44,6 +44,8 @@ export const customValidators = { phone: () => ({ key: 'validation:phone' }), name: () => ({ key: 'validation:invalid' }), paymentRef: () => ({ key: 'validation:payment-reference' }), + terms: () => ({ key: 'validation:terms-of-use' }), + gdpr: () => ({key: 'validation:terms-of-service'}), } setLocale({ diff --git a/src/components/client/one-time-donation/FormikStepper.tsx b/src/components/client/one-time-donation/FormikStepper.tsx index 968758d1a..767b1c2d4 100644 --- a/src/components/client/one-time-donation/FormikStepper.tsx +++ b/src/components/client/one-time-donation/FormikStepper.tsx @@ -8,7 +8,7 @@ import { Box, Button, Grid, Step, StepLabel, Stepper, useMediaQuery } from '@mui import { StepsContext } from './helpers/stepperContext' import { OneTimeDonation } from 'gql/donations' import { useSession } from 'next-auth/react' - + const PREFIX = 'FormikStepper' const classes = { @@ -90,7 +90,7 @@ export function FormikStepper({ children, ...props }: GenericFormProps - {({ isSubmitting, handleSubmit, isValid, values }) => ( + {({ isSubmitting, handleSubmit, values }) => (
{ try { setLoading(true) - // Register in Keycloak + + if(values.terms && values.gdpr) { await register(values) + } else { + throw new Error("Terms or GDPR not accepted") + } // Authenticate const resp = await signIn<'credentials'>('credentials', { @@ -42,6 +50,7 @@ export default function RegisterForm() { password: values.password, redirect: false, }) + if (resp?.error) { throw new Error(resp.error) } @@ -54,7 +63,7 @@ export default function RegisterForm() { } catch (error) { console.error(error) setLoading(false) - AlertStore.show(t('auth:alerts.invalid-login'), 'error') + AlertStore.show(t('auth:alerts.register-error'), 'error') } } @@ -93,6 +102,11 @@ export default function RegisterForm() { autoComplete="new-password" /> + + + + +