From fac06c1b41f745569a1635b6641022020337ba7a Mon Sep 17 00:00:00 2001 From: pikiou Date: Wed, 1 Jun 2022 09:42:48 +0200 Subject: [PATCH] Add hosting Ask --- src/components/Asks/AskHosting.tsx | 27 ++++++++++--------- src/components/Asks/index.tsx | 3 +++ .../HostingForm/HostingForm.tsx | 2 +- src/server/gsheets/volunteers.ts | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/components/Asks/AskHosting.tsx b/src/components/Asks/AskHosting.tsx index 8c21f81..b04bf81 100644 --- a/src/components/Asks/AskHosting.tsx +++ b/src/components/Asks/AskHosting.tsx @@ -2,12 +2,12 @@ import { get } from "lodash" import { useCallback } from "react" import { fetchVolunteerAsksSet } from "../../store/volunteerAsksSet" import { useAskTools, addAsk, answerLaterOnProfile } from "./utils" -import ParticipationDetailsForm, { - fetchFor as fetchForParticipationDetailsForm, -} from "../VolunteerBoard/ParticipationDetailsForm/ParticipationDetailsForm" -import { useUserParticipationDetails } from "../VolunteerBoard/participationDetails.utils" +import HostingForm, { + fetchFor as fetchForHostingForm, +} from "../VolunteerBoard/HostingForm/HostingForm" +import { useUserHosting } from "../VolunteerBoard/hosting.utils" -export function AskParticipationDetails(asks: JSX.Element[], id: number): void { +export function AskHosting(asks: JSX.Element[], id: number): void { const { dispatch, jwtToken, volunteerAsks } = useAskTools() const onSubmit = useCallback((): void => { @@ -18,10 +18,13 @@ export function AskParticipationDetails(asks: JSX.Element[], id: number): void { ) }, [dispatch, id, jwtToken, volunteerAsks?.hiddenAsks]) - const [participationDetails] = useUserParticipationDetails() - const tshirtSize = get(participationDetails, "tshirtSize", "") - const food = get(participationDetails, "food", "") - const needToShow = !tshirtSize || !food + const [hosting] = useUserHosting() + const needsHosting = get(hosting, "needsHosting", false) + const canHostCount = get(hosting, "canHostCount", 0) + const distanceToFestival = get(hosting, "distanceToFestival", 0) + const hostingComment = get(hosting, "hostingComment", "") + const needToShow = + !needsHosting && canHostCount === 0 && distanceToFestival === 0 && hostingComment === "" addAsk( asks, @@ -29,11 +32,9 @@ export function AskParticipationDetails(asks: JSX.Element[], id: number): void { volunteerAsks, false, needToShow, - - {answerLaterOnProfile} - + {answerLaterOnProfile} ) } // Fetch server-side data here -export const fetchFor = [...fetchForParticipationDetailsForm] +export const fetchFor = [...fetchForHostingForm] diff --git a/src/components/Asks/index.tsx b/src/components/Asks/index.tsx index 14428e1..028a02c 100644 --- a/src/components/Asks/index.tsx +++ b/src/components/Asks/index.tsx @@ -5,6 +5,7 @@ import { useAskTools } from "./utils" import { AskWelcome } from "./AskWelcome" import { AskDiscord, fetchFor as fetchForDiscord } from "./AskDiscord" import { AskDayWishes, fetchFor as fetchForDayWishes } from "./AskDayWishes" +import { AskHosting, fetchFor as fetchForHosting } from "./AskHosting" import { AskTeamWishes, fetchFor as fetchForTeamWishes } from "./AskTeamWishes" import { AskParticipationDetails, @@ -22,6 +23,7 @@ const Asks = (): JSX.Element | null => { AskDayWishes(asks, 10) AskTeamWishes(asks, 11) AskParticipationDetails(asks, 12) + AskHosting(asks, 20) AskPushNotif(asks, 99) @@ -58,6 +60,7 @@ export default memo(Asks) export const fetchFor = [ ...fetchForDiscord, ...fetchForDayWishes, + ...fetchForHosting, ...fetchForTeamWishes, ...fetchForParticipationDetails, ] diff --git a/src/components/VolunteerBoard/HostingForm/HostingForm.tsx b/src/components/VolunteerBoard/HostingForm/HostingForm.tsx index 57647fd..0f79ee7 100644 --- a/src/components/VolunteerBoard/HostingForm/HostingForm.tsx +++ b/src/components/VolunteerBoard/HostingForm/HostingForm.tsx @@ -41,7 +41,7 @@ const HostingForm: FC = ({ children, afterSubmit }): JSX.Element => { return (
-
Mes jours de présence
+
Mon hébergement
diff --git a/src/server/gsheets/volunteers.ts b/src/server/gsheets/volunteers.ts index 3228fc2..1822a59 100644 --- a/src/server/gsheets/volunteers.ts +++ b/src/server/gsheets/volunteers.ts @@ -243,7 +243,7 @@ export const volunteerAsksSet = expressAccessor.set(async (list, body, id) => { } const newVolunteer = cloneDeep(volunteer) - if (notifChanges.teamWishes !== undefined) newVolunteer.hiddenAsks = notifChanges.hiddenAsks + if (notifChanges.hiddenAsks !== undefined) newVolunteer.hiddenAsks = notifChanges.hiddenAsks if (notifChanges.acceptsNotifs !== undefined) newVolunteer.acceptsNotifs = notifChanges.acceptsNotifs if (notifChanges.pushNotifSubscription !== undefined)