Skip to content

Commit

Permalink
Terms and GDPR added in the registerForm (podkrepi-bg#1617)
Browse files Browse the repository at this point in the history
* Terms and GDPR added in the registerForm

* Format check added

* Some error messages added in the RegisterForm
  • Loading branch information
RalitsaIlieva authored and tongo-angelov committed Nov 14, 2023
1 parent 1e301f9 commit 1519778
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ Watch releases of this repository to be notified about future updates:
## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-73-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

Please check [contributors guide](https://github.com/podkrepi-bg/frontend/blob/master/CONTRIBUTING.md) for:
Expand Down
1 change: 1 addition & 0 deletions public/locales/bg/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"alerts": {
"welcome": "Добре дошли!",
"invalid-login": "Грешен потребител / парола.",
"register-error": "Моля, попълнете необходимата информация",
"duplicate-email": "Потребител с такъв имейл вече съществува",
"re-login": "Моля, влезте отново в профила си.",
"forgotten-password-error": "Потребителя не е намерен, моля опитайте отново!",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
2 changes: 2 additions & 0 deletions src/common/form/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
40 changes: 36 additions & 4 deletions src/components/client/one-time-donation/RegisterDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, CircularProgress, Grid, Typography } from '@mui/material'
import { Button, CircularProgress, FormHelperText, Grid, Typography } from '@mui/material'
import React, { useContext, useState } from 'react'
import { signIn } from 'next-auth/react'
import { useTranslation } from 'next-i18next'
Expand All @@ -12,6 +12,9 @@ import { useFormikContext } from 'formik'
import { OneTimeDonation } from 'gql/donations'
import { RegisterFormData } from 'components/client/auth/register/RegisterForm'
import { StepsContext } from './helpers/stepperContext'
import AcceptPrivacyPolicyField from 'components/common/form/AcceptPrivacyPolicyField'
import AcceptTermsField from 'components/common/form/AcceptTermsField'
import AcceptNewsLetterField from 'components/common/form/AcceptNewsletterField'

export default function RegisterForm() {
const { t } = useTranslation()
Expand All @@ -28,20 +31,30 @@ export default function RegisterForm() {
confirmPassword: formik.values.confirmPassword as string,
terms: formik.values.terms as boolean,
gdpr: formik.values.gdpr as boolean,
newsletter: formik.values.newsletter as boolean,
}
const onClick = async () => {
try {
setLoading(true)

// Register in Keycloak
await register(values)

if (values.terms && values.gdpr && values.password === values.confirmPassword) {
await register(values)
} else if (!values.terms) {
throw new Error('Terms not accepted')
} else if (!values.gdpr) {
throw new Error('GDPR not accepted')
} else {
throw new Error('Confirm password doesn`t match')
}

// Authenticate
const resp = await signIn<'credentials'>('credentials', {
email: values.email,
password: values.password,
redirect: false,
})

if (resp?.error) {
throw new Error(resp.error)
}
Expand All @@ -54,7 +67,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')
}
}

Expand Down Expand Up @@ -92,6 +105,25 @@ export default function RegisterForm() {
label="auth:account.confirm-password"
autoComplete="new-password"
/>
{formik.values.registerPassword !== formik.values.confirmPassword &&
formik.touched.confirmPassword && (
<FormHelperText sx={{ color: 'red' }}>
{t('validation:password-match')}
</FormHelperText>
)}
</Grid>
<Grid item xs={12}>
<AcceptTermsField name="terms" />
{!formik.values.terms && formik.touched.terms && (
<FormHelperText sx={{ color: 'red' }}>{t('validation:terms-of-use')}</FormHelperText>
)}
<AcceptPrivacyPolicyField name="gdpr" />
{!formik.values.gdpr && formik.touched.gdpr && (
<FormHelperText sx={{ color: 'red' }}>
{t('validation:terms-of-service')}
</FormHelperText>
)}
<AcceptNewsLetterField name="newsletter" />
</Grid>
<Grid item xs={12}>
<Button
Expand Down
4 changes: 4 additions & 0 deletions src/components/client/one-time-donation/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const initialValues: OneTimeDonation = {
registerLastName: '',
registerFirstName: '',
registerPassword: '',
confirmPassword: '',
isRecurring: false,
terms: false,
gdpr: false,
newsletter: false,
}
interface DonationStepperProps {
onStepChange: () => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const validateSecond: yup.SchemaOf<SecondStep> = yup.object().defined().s
registerFirstName: yup.string().notRequired(),
registerLastName: yup.string().notRequired(),
registerPassword: password.notRequired(),
confirmPassword: yup.string().notRequired(),
terms: yup.boolean().notRequired(),
gdpr: yup.boolean().notRequired(),
newsletter: yup.boolean().notRequired(),
})

export const validateThird: yup.SchemaOf<ThirdStep> = yup.object().defined().shape({
Expand Down
4 changes: 4 additions & 0 deletions src/gql/donations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export type OneTimeDonation = {
confirmPassword?: string
terms?: boolean
gdpr?: boolean
newsletter?: boolean
}

export type DonationStep = {
Expand All @@ -162,6 +163,9 @@ export type SecondStep = {
personsLastName?: string
personsPhone?: string
personsEmail?: string
terms?: boolean
gdpr?: boolean
newsletter?: boolean
}

export type ThirdStep = {
Expand Down

0 comments on commit 1519778

Please sign in to comment.