Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] You can click Next if you are both not logged and not anonymous #1134

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ Read more at [End-2-End Testing](https://github.com/podkrepi-bg/frontend/blob/ma
## Contributors ✨

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

[![All Contributors](https://img.shields.io/badge/all_contributors-57-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
10 changes: 0 additions & 10 deletions src/components/one-time-donation/AnonymousForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ export default function AnonymousForm() {
<Grid item xs={12} color="#343434" sx={{ opacity: 0.9 }}>
<Typography>{t('anonymous-menu.info-start')}</Typography>
</Grid>
{isLogged() ? (
<Grid item xs={12}>
<CheckboxField
name="isAnonymous"
label={t('anonymous-menu.want-anonymous-donation').toString()}
/>
</Grid>
) : (
''
)}
<Grid item xs={12} md={12}>
<FormTextField name="personsEmail" type="text" label="Email" fullWidth />
</Grid>
Expand Down
23 changes: 19 additions & 4 deletions src/components/one-time-donation/FormikStepper.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -44,6 +44,10 @@ export function FormikStepper({ children, ...props }: GenericFormProps<OneTimeDo
const currentChild = childrenArray[step]
const { data: session } = useSession()

function isLoginStep() {
return step === childrenArray.length - 3
}

function isLastStep() {
return step === childrenArray.length - 2
}
Expand All @@ -56,7 +60,18 @@ export function FormikStepper({ children, ...props }: GenericFormProps<OneTimeDo
return true
}
const { t } = useTranslation('one-time-donation')

const hideNextButton = useCallback(
(isAnonymous: boolean) => {
console.log('anon', isAnonymous)
console.log('logged', isLogged())
console.log('loginStep', isLoginStep())
if (isLoginStep() && !isLogged() && !isAnonymous) {
return true
}
return false
},
[step],
)
return (
<Formik
{...props}
Expand All @@ -72,7 +87,7 @@ export function FormikStepper({ children, ...props }: GenericFormProps<OneTimeDo
}}
validateOnMount
validateOnBlur>
{({ isSubmitting, handleSubmit, isValid }) => (
{({ isSubmitting, handleSubmit, isValid, values: { isAnonymous } }) => (
<Form
onSubmit={handleSubmit}
style={{
Expand Down Expand Up @@ -112,7 +127,7 @@ export function FormikStepper({ children, ...props }: GenericFormProps<OneTimeDo
</Grid>
<Grid item xs={12} md={6}>
<LoadingButton
disabled={!isValid}
disabled={!isValid || isSubmitting || hideNextButton(isAnonymous)}
fullWidth
type="submit"
variant="contained"
Expand Down
2 changes: 1 addition & 1 deletion src/components/one-time-donation/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function LoginForm() {
}
if (resp?.ok) {
setLoading(false)
formik.values.isAnonymous = false
formik.setFieldValue('isAnonymous', false)
setStep(2)
AlertStore.show(t('auth:alerts.welcome'), 'success')
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/one-time-donation/RegisterDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function RegisterForm() {
if (resp?.ok) {
setLoading(false)
AlertStore.show(t('auth:alerts.welcome'), 'success')
formik.values.isAnonymous = false
formik.setFieldValue('isAnonymous', false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the strange behaviour before was coming from either here!

setStep(2)
}
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/one-time-donation/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useCurrentPerson } from 'common/util/useCurrentPerson'

const initialValues: OneTimeDonation = {
message: '',
isAnonymous: true,
isAnonymous: false,
amount: '',
amountWithFees: 0,
cardIncludeFees: false,
Expand Down Expand Up @@ -64,7 +64,6 @@ export default function DonationStepper({ onStepChange }: DonationStepperProps)
return session && session.accessToken ? true : false
}

initialValues.isAnonymous = !isLogged()
const userEmail = session?.user?.email

const donate = React.useCallback(
Expand All @@ -76,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 ?? !isLogged(),
isAnonymous: values?.isAnonymous !== undefined ? values.isAnonymous : true,
Comment on lines -79 to +78
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or here

phone: values?.personsPhone ? values.personsPhone : null,
successUrl: `${baseUrl}${routes.campaigns.oneTimeDonation(campaign.slug)}?success=true`,
cancelUrl: `${baseUrl}${routes.campaigns.oneTimeDonation(campaign.slug)}?success=false`,
Expand Down
9 changes: 8 additions & 1 deletion src/components/one-time-donation/steps/SecondStep.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,8 +17,13 @@ export default function SecondStep() {
const { data: session } = useSession()

const [value, setValue] = useState('1')

const formik = useFormikContext<OneTimeDonation>()
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
if (Number(newValue) === 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimitur2204 It's not really clear to me what the constant 3 stands for.

If we're using that as a number of step let's name it in some kind of enum or similar so it brings more context.

Similar to:

if (Number(step) === Steps.Anonymous) {
  // ...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see we can also use names instead of numbers for the tabs.

Ex. logged, newProfile, anonymous 💭

formik.setFieldValue('isAnonymous', true)
} else {
formik.setFieldValue('isAnonymous', false)
}
setValue(newValue)
}

Expand Down