Skip to content

Commit

Permalink
feat: prefill campaign application organizer form values from current…
Browse files Browse the repository at this point in the history
… user
  • Loading branch information
teodorazhelyazkova committed Jul 3, 2024
1 parent 6b5d3e8 commit 9a5fa5a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useState } from 'react'

import { useCallback, useMemo, useState } from 'react'
import { Grid, StepLabel } from '@mui/material'
import { PersonResponse } from 'gql/person'

import {
CampaignApplicationFormData,
Expand All @@ -25,17 +25,6 @@ import {
StyledStepConnector,
} from './helpers/campaignApplication.styled'

const initialValues: CampaignApplicationFormData = {
organizer: {
name: '',
phone: '',
email: '',
acceptTermsAndConditions: false,
transparencyTermsAccepted: false,
personalInformationProcessingAccepted: false,
},
}

const steps: StepType[] = [
{
title: 'campaign-application:steps.organizer.title',
Expand All @@ -51,9 +40,27 @@ const steps: StepType[] = [
},
]

export default function CampaignApplicationForm() {
type Props = {
person: PersonResponse
}

export default function CampaignApplicationForm({ person }: Props) {
const [activeStep, setActiveStep] = useState<Steps>(Steps.ORGANIZER)

const initialValues: CampaignApplicationFormData = useMemo(
() => ({
organizer: {
name: `${person?.firstName} ${person?.lastName}` ?? '',
phone: person?.phone ?? '',
email: person?.email ?? '',
acceptTermsAndConditions: false,
transparencyTermsAccepted: false,
personalInformationProcessingAccepted: false,
},
}),
[person],
)

const handleSubmit = () => {
stepsHandler({ activeStep, setActiveStep })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { CircularProgress, Grid } from '@mui/material'
import { useSession } from 'next-auth/react'
import { useViewPersonByKeylockId } from 'common/hooks/person'
import Layout from '../layout/Layout'
import CampaignApplicationForm from './CampaignApplicationForm'

export default function CampaignApplicationPage() {
const { data: session } = useSession()
const { data: person, isLoading } = useViewPersonByKeylockId(session?.user?.sub as string)

if (isLoading) {
return (
<Grid container justifyContent="center" alignContent="center" sx={{ height: '100vh' }}>
<CircularProgress />
</Grid>
)
}

return (
<Layout maxWidth="md" sx={{ paddingInline: 5 }}>
<CampaignApplicationForm />
{person && <CampaignApplicationForm person={person} />}
</Layout>
)
}

0 comments on commit 9a5fa5a

Please sign in to comment.