Skip to content

Commit

Permalink
OneTimeDonationPage: Render DonationStepper only on client (#1543)
Browse files Browse the repository at this point in the history
* OneTimeDonationPage: Render DonationStepper only on client
sessionStorage is not available on SSR

* SecondStep: Go to anonymous tab if isAnonymous is true
Now that the flow is saved inside sessionstorage, we need this for consistency reasons
  • Loading branch information
sashko9807 authored Aug 3, 2023
1 parent 3c94fdf commit b1e1c46
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/components/client/one-time-donation/AnonymousForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { useTranslation } from 'next-i18next'
import { Grid, Typography } from '@mui/material'
import EmailField from 'components/common/form/EmailField'
import { useSession } from 'next-auth/react'
import { useFormikContext } from 'formik'
import { OneTimeDonation } from 'gql/donations'

export default function AnonymousForm() {
const { t } = useTranslation('one-time-donation')
const { data: session } = useSession()
const formik = useFormikContext<OneTimeDonation>()
const isLogged = session?.accessToken ? true : false
return (
<>
Expand All @@ -23,7 +26,13 @@ export default function AnonymousForm() {
name="personsEmail"
label="Email"
fullWidth
value={isLogged ? session?.user?.email : null}
value={
isLogged
? session?.user?.email
: formik.values.personsEmail
? formik.values.personsEmail
: ''
}
disabled={isLogged ? true : false}
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { beneficiaryCampaignPictureUrl } from 'common/util/campaignImageUrls'
import Layout from 'components/client/layout/Layout'
import { useViewCampaign } from 'common/hooks/campaigns'
import CenteredSpinner from 'components/common/CenteredSpinner'
import DonationStepper from '../Steps'
import dynamic from 'next/dynamic'

import {
BeneficiaryAvatar,
Expand All @@ -24,6 +24,8 @@ const scrollWindow = () => {
window.scrollTo({ top: 200, behavior: 'smooth' })
}

const DonationStepper = dynamic(() => import('../Steps'), { ssr: false })

export default function OneTimeDonation({ slug }: { slug: string }) {
const { data, isLoading } = useViewCampaign(slug)
// const paymentIntentMutation = useCreatePaymentIntent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default function SecondStep() {
const mobile = useMediaQuery('(max-width:575px)')
const { data: session } = useSession()

const [value, setValue] = useState('1')
const formik = useFormikContext<OneTimeDonation>()
const [value, setValue] = useState(formik.values.isAnonymous ? '3' : '1')
const handleChange = (event: React.SyntheticEvent, newTab: string) => {
if (newTab === Tabs.Anonymous) {
formik.setFieldValue('isAnonymous', true)
Expand Down

0 comments on commit b1e1c46

Please sign in to comment.