Skip to content

Commit

Permalink
Fill grant form with participant data (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
estyxx authored Nov 28, 2024
1 parent d4a3418 commit 5277de4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
61 changes: 36 additions & 25 deletions frontend/src/components/grant-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ export const GrantForm = ({
},
});

const { data: participantData } = useParticipantDataQuery({
variables: {
conference: conference,
},
});

const inputPlaceholderText = useTranslatedMessage("input.placeholder");
const { user, loading: loadingUser } = useCurrentUser({});
const [formState, formOptions] = useFormState<GrantFormFields>(
Expand Down Expand Up @@ -200,33 +206,37 @@ export const GrantForm = ({
formState.setField("notes", grant.notes);
formState.setField("travellingFrom", grant.travellingFrom);

if (grant.participant) {
formState.setField("participantBio", grant.participant.bio);
formState.setField("participantWebsite", grant.participant.website);
formState.setField(
"participantTwitterHandle",
grant.participant.twitterHandle,
);
formState.setField(
"participantInstagramHandle",
grant.participant.instagramHandle,
);
formState.setField(
"participantLinkedinUrl",
grant.participant.linkedinUrl,
);
formState.setField(
"participantFacebookUrl",
grant.participant.facebookUrl,
);
formState.setField(
"participantMastodonHandle",
grant.participant.mastodonHandle,
);
}
formState.setField("acceptedPrivacyPolicy", true);
}
}, [grant]);

if (participantData.me.participant) {
formState.setField("participantBio", participantData.me.participant.bio);
formState.setField(
"participantWebsite",
participantData.me.participant.website,
);
formState.setField(
"participantTwitterHandle",
participantData.me.participant.twitterHandle,
);
formState.setField(
"participantInstagramHandle",
participantData.me.participant.instagramHandle,
);
formState.setField(
"participantLinkedinUrl",
participantData.me.participant.linkedinUrl,
);
formState.setField(
"participantFacebookUrl",
participantData.me.participant.facebookUrl,
);
formState.setField(
"participantMastodonHandle",
participantData.me.participant.mastodonHandle,
);
}
}, []);

const handleOnSubmit = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
Expand Down Expand Up @@ -666,6 +676,7 @@ export const GrantForm = ({
<Spacer size="medium" />

<PublicProfileCard
me={participantData.me}
formOptions={formOptions}
photoRequired={false}
getParticipantValidationError={(field) =>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/grants/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export const getServerSideProps: GetServerSideProps = async ({
queryCurrentUser(client, {
conference: process.env.conferenceCode,
}),
queryParticipantData(client, {
conference: process.env.conferenceCode,
}),
]);
} catch (e) {
return {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/grants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export const getServerSideProps: GetServerSideProps = async ({
queryCurrentUser(client, {
conference: process.env.conferenceCode,
}),
queryParticipantData(client, {
conference: process.env.conferenceCode,
}),
]);

if (grant) {
Expand Down

0 comments on commit 5277de4

Please sign in to comment.