From 30cdbbe30affabfd187c05edd3f284bed3d00181 Mon Sep 17 00:00:00 2001 From: Dimitar Nizamov Date: Sun, 20 Nov 2022 15:14:35 +0100 Subject: [PATCH] [Bug] You can click Next if you are both not logged and not anonymous (#1134) * 1133 - disable next button when not logged in * 1133 - fix anonymous submit value when mutating * 1133 - add option to be able to donate anonymous even if you are logged in * 1133 - remove console.logs * 1133 - add enum for auth step tabs * 1133 - change Tabs to strings --- README.md | 2 ++ .../one-time-donation/AnonymousForm.tsx | 16 --------------- .../one-time-donation/FormikStepper.tsx | 20 +++++++++++++++---- .../one-time-donation/LoginForm.tsx | 2 +- .../one-time-donation/RegisterDialog.tsx | 2 +- src/components/one-time-donation/Steps.tsx | 5 ++--- .../one-time-donation/steps/SecondStep.tsx | 18 ++++++++++++++--- 7 files changed, 37 insertions(+), 28 deletions(-) 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/AnonymousForm.tsx b/src/components/one-time-donation/AnonymousForm.tsx index 3a0700f74..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 ( <> @@ -21,16 +15,6 @@ export default function AnonymousForm() { {t('anonymous-menu.info-start')} - {isLogged() ? ( - - - - ) : ( - '' - )} diff --git a/src/components/one-time-donation/FormikStepper.tsx b/src/components/one-time-donation/FormikStepper.tsx index e3f96f115..3a270b8fa 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 { + if (isLoginStep() && !isLogged() && !isAnonymous) { + return true + } + return false + }, + [step], + ) return ( - {({ isSubmitting, handleSubmit, isValid }) => ( + {({ isSubmitting, handleSubmit, isValid, values: { isAnonymous } }) => (
{ - setValue(newValue) + const formik = useFormikContext() + const handleChange = (event: React.SyntheticEvent, newTab: string) => { + if (newTab === Tabs.Anonymous) { + formik.setFieldValue('isAnonymous', true) + } else { + formik.setFieldValue('isAnonymous', false) + } + setValue(newTab) } return (