diff --git a/src/components/VolunteerBoard/DayWishes/DayWishes.tsx b/src/components/VolunteerBoard/DayWishes/DayWishes.tsx index e0191a7..fe09fd4 100644 --- a/src/components/VolunteerBoard/DayWishes/DayWishes.tsx +++ b/src/components/VolunteerBoard/DayWishes/DayWishes.tsx @@ -1,76 +1,30 @@ -import { FC, memo, useCallback, useEffect, useRef, useState } from "react" -import classnames from "classnames" +import { FC, memo } from "react" import get from "lodash/get" -import set from "lodash/set" import styles from "./styles.module.scss" -import { - daysChoice, - daysChoiceSelectionDefaultState, - selectionChoices, - useUserDayWishes, -} from "./days.utils" +import { getDayLabel, useUserDayWishes } from "../days.utils" const DayWishes: FC = (): JSX.Element | null => { - const [selection, setSelection] = useState(daysChoiceSelectionDefaultState) - const commentRef = useRef(null) - const [userWishes, saveWishes] = useUserDayWishes() - - useEffect(() => { - if (!userWishes) return - console.log("userWishes", userWishes) - const newSelection = get(userWishes, "dayWishes", []).reduce( - (acc: selectionChoices, day: string) => ({ - ...acc, - [day]: true, - }), - daysChoice - ) - setSelection(newSelection) - set(commentRef, "current.value", get(userWishes, "dayWishesComment", "")) - }, [setSelection, commentRef, userWishes]) - - const onChoiceClick = useCallback( - (id) => { - setSelection({ - ...selection, - [id]: !selection[id], - }) - }, - [selection, setSelection] - ) - const onChoiceSubmit = useCallback(() => { - const comment = get(commentRef, "current.value", "") - const days = daysChoice.map(({ id }) => id).filter((id) => selection[id]) - saveWishes(days, comment) - }, [selection, commentRef, saveWishes]) + const [userWishes] = useUserDayWishes() + const dayWishesString = get(userWishes, "dayWishes", []).map(getDayLabel).join(", ") + const comment = get(userWishes, "dayWishesComment", "") return (
-
Jours de présence
- -
- -