Add hosting Ask

This commit is contained in:
pikiou 2022-06-01 09:42:48 +02:00
parent 032e15d985
commit fac06c1b41
4 changed files with 19 additions and 15 deletions

View File

@ -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,
<ParticipationDetailsForm afterSubmit={onSubmit}>
{answerLaterOnProfile}
</ParticipationDetailsForm>
<HostingForm afterSubmit={onSubmit}>{answerLaterOnProfile}</HostingForm>
)
}
// Fetch server-side data here
export const fetchFor = [...fetchForParticipationDetailsForm]
export const fetchFor = [...fetchForHostingForm]

View File

@ -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,
]

View File

@ -41,7 +41,7 @@ const HostingForm: FC<Props> = ({ children, afterSubmit }): JSX.Element => {
return (
<div>
<div className={styles.title}>Mes jours de présence</div>
<div className={styles.title}>Mon hébergement</div>
<div className={classnames(styles.inputWrapper, styles.noBottomMargin)}>
<div className={styles.leftCol}>
<div className={styles.needsHostingTitle}>

View File

@ -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)