fix ParticipationDetailsForm

This commit is contained in:
memeriau 2022-01-30 21:33:22 +01:00
parent 444582c5cc
commit 67a8e84bd5
2 changed files with 10 additions and 5 deletions

View File

@ -2,7 +2,11 @@ import { FC, memo, useCallback, useEffect, useRef, useState } from "react"
import get from "lodash/get" import get from "lodash/get"
import set from "lodash/set" import set from "lodash/set"
import styles from "./styles.module.scss" import styles from "./styles.module.scss"
import { tShirtSizes, useUserParticipationDetails } from "../participationDetails.utils" import {
foodDefaultValue,
tShirtSizes,
useUserParticipationDetails,
} from "../participationDetails.utils"
const ParticipationDetailsForm: FC = (): JSX.Element | null => { const ParticipationDetailsForm: FC = (): JSX.Element | null => {
const sizeRef = useRef<HTMLSelectElement | null>(null) const sizeRef = useRef<HTMLSelectElement | null>(null)
@ -15,7 +19,7 @@ const ParticipationDetailsForm: FC = (): JSX.Element | null => {
const onSubmit = useCallback(() => { const onSubmit = useCallback(() => {
const age = get(ageRef, "current.value", "") const age = get(ageRef, "current.value", "")
const teeshirtSize = has2Shirts ? "" : get(sizeRef, "current.value", "") const teeshirtSize = has2Shirts ? "" : get(sizeRef, "current.value", "")
const food = get(dietRef, "current.value", "") const food = get(dietRef, "current.value", foodDefaultValue)
saveParticipationDetails({ age, teeshirtSize, food }) saveParticipationDetails({ age, teeshirtSize, food })
}, [has2Shirts, saveParticipationDetails]) }, [has2Shirts, saveParticipationDetails])
@ -27,7 +31,6 @@ const ParticipationDetailsForm: FC = (): JSX.Element | null => {
) )
useEffect(() => { useEffect(() => {
console.log("participationDetails", participationDetails)
const age = get(participationDetails, "age", "") const age = get(participationDetails, "age", "")
const teeshirtSize = get(participationDetails, "teeshirtSize", "") const teeshirtSize = get(participationDetails, "teeshirtSize", "")
const food = get(participationDetails, "food", "") const food = get(participationDetails, "food", "")
@ -47,7 +50,7 @@ const ParticipationDetailsForm: FC = (): JSX.Element | null => {
<input <input
type="radio" type="radio"
name="hasShirt" name="hasShirt"
onClick={() => onHas2ShirtsClick(true)} onChange={() => onHas2ShirtsClick(true)}
checked={has2Shirts} checked={has2Shirts}
/>{" "} />{" "}
Oui Oui
@ -56,7 +59,7 @@ const ParticipationDetailsForm: FC = (): JSX.Element | null => {
<input <input
type="radio" type="radio"
name="hasShirt" name="hasShirt"
onClick={() => onHas2ShirtsClick(false)} onChange={() => onHas2ShirtsClick(false)}
checked={!has2Shirts} checked={!has2Shirts}
/>{" "} />{" "}
Non Non

View File

@ -18,6 +18,8 @@ export const tShirtSizes = [
"Femme XL", "Femme XL",
] ]
export const foodDefaultValue = "Aucune"
export const useUserParticipationDetails = (): [any, any] => { export const useUserParticipationDetails = (): [any, any] => {
const save = useAction(fetchVolunteerParticipationDetailsSet) const save = useAction(fetchVolunteerParticipationDetailsSet)
const jwtToken = useSelector(selectUserJwtToken) const jwtToken = useSelector(selectUserJwtToken)