From 2bfd8d2a7bf108ad60062a08b47ce43af6280ed6 Mon Sep 17 00:00:00 2001 From: memeriau Date: Sat, 29 Jan 2022 16:49:34 +0100 Subject: [PATCH] add component to display day wishes --- .../VolunteerBoard/DayWishes/DayWishes.tsx | 84 +++++-------------- .../DayWishes/styles.module.scss | 66 +++++---------- .../DayWishesForm/DayWishesForm.tsx | 78 +++++++++++++++++ .../DayWishesForm/styles.module.scss | 60 +++++++++++++ .../{DayWishes => }/days.utils.ts | 13 ++- src/pages/Board/Board.tsx | 36 ++++++++ src/pages/Board/index.tsx | 16 ++++ src/pages/Board/styles.module.scss | 9 ++ src/pages/DayWishes/DayWishes.tsx | 2 +- src/routes/index.ts | 6 ++ src/theme/mixins.scss | 11 +++ src/theme/variables.scss | 1 + 12 files changed, 269 insertions(+), 113 deletions(-) create mode 100644 src/components/VolunteerBoard/DayWishesForm/DayWishesForm.tsx create mode 100755 src/components/VolunteerBoard/DayWishesForm/styles.module.scss rename src/components/VolunteerBoard/{DayWishes => }/days.utils.ts (74%) create mode 100644 src/pages/Board/Board.tsx create mode 100755 src/pages/Board/index.tsx create mode 100755 src/pages/Board/styles.module.scss 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
-
    - {daysChoice.map(({ id, label }) => ( -
  • - -
  • - ))} -
-
- -