From fc91dd02f3a1788b3ff87513164e18df181400d8 Mon Sep 17 00:00:00 2001 From: Teodora Zhelyazkova Date: Wed, 10 Jul 2024 13:40:11 +0300 Subject: [PATCH] feat: prefill campaign application organizer form values from current user (Epic #1842) (#1874) * feat: prefill campaign application organizer form values from current user * fix: remove useMemo * fix: change to useCurrentPerson hook --- .../CampaignApplicationForm.tsx | 30 +++++++++++-------- .../CampaignApplicationPage.tsx | 15 +++++++++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/components/client/campaign-application/CampaignApplicationForm.tsx b/src/components/client/campaign-application/CampaignApplicationForm.tsx index 7389f3a71..c1dbfbfd9 100644 --- a/src/components/client/campaign-application/CampaignApplicationForm.tsx +++ b/src/components/client/campaign-application/CampaignApplicationForm.tsx @@ -1,6 +1,6 @@ import { useCallback, useState } from 'react' - import { Grid, StepLabel } from '@mui/material' +import { Person } from 'gql/person' import { CampaignApplicationFormData, @@ -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', @@ -51,9 +40,24 @@ const steps: StepType[] = [ }, ] -export default function CampaignApplicationForm() { +type Props = { + person?: Person +} + +export default function CampaignApplicationForm({ person }: Props) { const [activeStep, setActiveStep] = useState(Steps.ORGANIZER) + const initialValues: CampaignApplicationFormData = { + organizer: { + name: `${person?.firstName} ${person?.lastName}` ?? '', + phone: person?.phone ?? '', + email: person?.email ?? '', + acceptTermsAndConditions: false, + transparencyTermsAccepted: false, + personalInformationProcessingAccepted: false, + }, + } + const handleSubmit = () => { stepsHandler({ activeStep, setActiveStep }) } diff --git a/src/components/client/campaign-application/CampaignApplicationPage.tsx b/src/components/client/campaign-application/CampaignApplicationPage.tsx index 6a70d1b95..6f8cfcefe 100644 --- a/src/components/client/campaign-application/CampaignApplicationPage.tsx +++ b/src/components/client/campaign-application/CampaignApplicationPage.tsx @@ -1,10 +1,23 @@ +import { CircularProgress, Grid } from '@mui/material' +import { useCurrentPerson } from 'common/util/useCurrentPerson' import Layout from '../layout/Layout' import CampaignApplicationForm from './CampaignApplicationForm' export default function CampaignApplicationPage() { + const { data: userData, isLoading } = useCurrentPerson() + const person = userData?.user || undefined + + if (isLoading) { + return ( + + + + ) + } + return ( - + ) }