From ee46373c5726f07b5cdc72bfa1fd30fb9da77013 Mon Sep 17 00:00:00 2001 From: "dimitar.nizamov" Date: Sun, 20 Nov 2022 12:06:09 +0100 Subject: [PATCH 1/6] 1133 - disable next button when not logged in --- .../one-time-donation/FormikStepper.tsx | 23 +++++++++++++++---- .../one-time-donation/LoginForm.tsx | 2 +- .../one-time-donation/RegisterDialog.tsx | 2 +- src/components/one-time-donation/Steps.tsx | 5 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/one-time-donation/FormikStepper.tsx b/src/components/one-time-donation/FormikStepper.tsx index e3f96f115..bb6518928 100644 --- a/src/components/one-time-donation/FormikStepper.tsx +++ b/src/components/one-time-donation/FormikStepper.tsx @@ -1,4 +1,4 @@ -import React, { PropsWithChildren, useContext, useEffect } from 'react' +import React, { PropsWithChildren, useCallback, useContext, useEffect } from 'react' import { styled } from '@mui/material/styles' import { useTranslation } from 'next-i18next' import { useRouter } from 'next/router' @@ -44,6 +44,10 @@ export function FormikStepper({ children, ...props }: GenericFormProps { + console.log('anon', isAnonymous) + console.log('logged', isLogged()) + console.log('loginStep', isLoginStep()) + if (isLoginStep() && !isLogged() && !isAnonymous) { + return true + } + return false + }, + [step], + ) return ( - {({ isSubmitting, handleSubmit, isValid }) => ( + {({ isSubmitting, handleSubmit, isValid, values: { isAnonymous } }) => (
Date: Sun, 20 Nov 2022 12:08:30 +0100 Subject: [PATCH 2/6] 1133 - fix anonymous submit value when mutating --- README.md | 2 ++ src/components/one-time-donation/Steps.tsx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c276d919d..c1afb993b 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,9 @@ Read more at [End-2-End Testing](https://github.com/podkrepi-bg/frontend/blob/ma ## Contributors ✨ + [![All Contributors](https://img.shields.io/badge/all_contributors-57-orange.svg?style=flat-square)](#contributors-) + Please check [contributors guide](https://github.com/podkrepi-bg/frontend/blob/master/CONTRIBUTING.md) for: diff --git a/src/components/one-time-donation/Steps.tsx b/src/components/one-time-donation/Steps.tsx index cdf98c218..32ba60b68 100644 --- a/src/components/one-time-donation/Steps.tsx +++ b/src/components/one-time-donation/Steps.tsx @@ -75,7 +75,7 @@ export default function DonationStepper({ onStepChange }: DonationStepperProps) firstName: values?.personsFirstName ? values.personsFirstName : 'Anonymous', lastName: values?.personsLastName ? values.personsLastName : 'Donor', personEmail: values?.personsEmail ? values.personsEmail : userEmail, - isAnonymous: values?.isAnonymous ? values.isAnonymous : true, + isAnonymous: values?.isAnonymous !== undefined ? values.isAnonymous : true, phone: values?.personsPhone ? values.personsPhone : null, successUrl: `${baseUrl}${routes.campaigns.oneTimeDonation(campaign.slug)}?success=true`, cancelUrl: `${baseUrl}${routes.campaigns.oneTimeDonation(campaign.slug)}?success=false`, From 39e347aee952ed37fc28740cea5ae8c18e3977bc Mon Sep 17 00:00:00 2001 From: "dimitar.nizamov" Date: Sun, 20 Nov 2022 12:18:03 +0100 Subject: [PATCH 3/6] 1133 - add option to be able to donate anonymous even if you are logged in --- src/components/one-time-donation/AnonymousForm.tsx | 10 ---------- src/components/one-time-donation/steps/SecondStep.tsx | 9 ++++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/one-time-donation/AnonymousForm.tsx b/src/components/one-time-donation/AnonymousForm.tsx index 3a0700f74..8066b2b38 100644 --- a/src/components/one-time-donation/AnonymousForm.tsx +++ b/src/components/one-time-donation/AnonymousForm.tsx @@ -21,16 +21,6 @@ export default function AnonymousForm() { {t('anonymous-menu.info-start')} - {isLogged() ? ( - - - - ) : ( - '' - )} diff --git a/src/components/one-time-donation/steps/SecondStep.tsx b/src/components/one-time-donation/steps/SecondStep.tsx index 1ca7a20a5..997b5e966 100644 --- a/src/components/one-time-donation/steps/SecondStep.tsx +++ b/src/components/one-time-donation/steps/SecondStep.tsx @@ -1,6 +1,8 @@ import { TabContext, TabList } from '@mui/lab' import TabPanel from '@mui/lab/TabPanel' import { Box, Tab, Typography, useMediaQuery } from '@mui/material' +import { useFormikContext } from 'formik' +import { OneTimeDonation } from 'gql/donations' import { useSession } from 'next-auth/react' import { useTranslation } from 'next-i18next' import React, { useState } from 'react' @@ -15,8 +17,13 @@ export default function SecondStep() { const { data: session } = useSession() const [value, setValue] = useState('1') - + const formik = useFormikContext() const handleChange = (event: React.SyntheticEvent, newValue: string) => { + if (Number(newValue) === 3) { + formik.setFieldValue('isAnonymous', true) + } else { + formik.setFieldValue('isAnonymous', false) + } setValue(newValue) } From 24c7fe01905be1000afcd76ed5024a2d0c4dbd92 Mon Sep 17 00:00:00 2001 From: "dimitar.nizamov" Date: Sun, 20 Nov 2022 12:28:17 +0100 Subject: [PATCH 4/6] 1133 - remove console.logs --- src/components/one-time-donation/AnonymousForm.tsx | 6 ------ src/components/one-time-donation/FormikStepper.tsx | 3 --- 2 files changed, 9 deletions(-) diff --git a/src/components/one-time-donation/AnonymousForm.tsx b/src/components/one-time-donation/AnonymousForm.tsx index 8066b2b38..df6a28e48 100644 --- a/src/components/one-time-donation/AnonymousForm.tsx +++ b/src/components/one-time-donation/AnonymousForm.tsx @@ -1,16 +1,10 @@ import * as React from 'react' import { useTranslation } from 'next-i18next' -import { useSession } from 'next-auth/react' import { Grid, Typography } from '@mui/material' import FormTextField from 'components/common/form/FormTextField' -import CheckboxField from 'components/common/form/CheckboxField' export default function AnonymousForm() { const { t } = useTranslation('one-time-donation') - const { data: session } = useSession() - function isLogged() { - return session && session.accessToken ? true : false - } return ( <> diff --git a/src/components/one-time-donation/FormikStepper.tsx b/src/components/one-time-donation/FormikStepper.tsx index bb6518928..3a270b8fa 100644 --- a/src/components/one-time-donation/FormikStepper.tsx +++ b/src/components/one-time-donation/FormikStepper.tsx @@ -62,9 +62,6 @@ export function FormikStepper({ children, ...props }: GenericFormProps { - console.log('anon', isAnonymous) - console.log('logged', isLogged()) - console.log('loginStep', isLoginStep()) if (isLoginStep() && !isLogged() && !isAnonymous) { return true } From aaaf2274b42053faac88506b58440dcbf77939a2 Mon Sep 17 00:00:00 2001 From: "dimitar.nizamov" Date: Sun, 20 Nov 2022 14:56:17 +0100 Subject: [PATCH 5/6] 1133 - add enum for auth step tabs --- src/components/one-time-donation/steps/SecondStep.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/one-time-donation/steps/SecondStep.tsx b/src/components/one-time-donation/steps/SecondStep.tsx index 997b5e966..895682647 100644 --- a/src/components/one-time-donation/steps/SecondStep.tsx +++ b/src/components/one-time-donation/steps/SecondStep.tsx @@ -11,6 +11,11 @@ import LoggedUserDialog from '../LoggedUserDialog' import LoginForm from '../LoginForm' import RegisterForm from '../RegisterDialog' +enum Tabs { + Login = 1, + Register = 2, + Anonymous = 3, +} export default function SecondStep() { const { t } = useTranslation('one-time-donation') const mobile = useMediaQuery('(max-width:575px)') @@ -18,13 +23,13 @@ export default function SecondStep() { const [value, setValue] = useState('1') const formik = useFormikContext() - const handleChange = (event: React.SyntheticEvent, newValue: string) => { - if (Number(newValue) === 3) { + const handleChange = (event: React.SyntheticEvent, newTab: string) => { + if (newTab === Tabs.Anonymous) { formik.setFieldValue('isAnonymous', true) } else { formik.setFieldValue('isAnonymous', false) } - setValue(newValue) + setValue(newTab) } return ( From 8298d69191e22a8997b3767def2cb2abbd0027fb Mon Sep 17 00:00:00 2001 From: "dimitar.nizamov" Date: Sun, 20 Nov 2022 15:03:32 +0100 Subject: [PATCH 6/6] 1133 - change Tabs to strings --- src/components/one-time-donation/steps/SecondStep.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/one-time-donation/steps/SecondStep.tsx b/src/components/one-time-donation/steps/SecondStep.tsx index 895682647..4806e39c1 100644 --- a/src/components/one-time-donation/steps/SecondStep.tsx +++ b/src/components/one-time-donation/steps/SecondStep.tsx @@ -12,9 +12,9 @@ import LoginForm from '../LoginForm' import RegisterForm from '../RegisterDialog' enum Tabs { - Login = 1, - Register = 2, - Anonymous = 3, + Login = '1', + Register = '2', + Anonymous = '3', } export default function SecondStep() { const { t } = useTranslation('one-time-donation')