From 72a633ae4f0b30cd0cceaeedb45ea10bc6a6821e Mon Sep 17 00:00:00 2001 From: pikiou Date: Tue, 13 Sep 2022 02:53:30 +0200 Subject: [PATCH] Add Brunch and Retex forms ans asks --- .github/workflows/ci.yml | 2 +- src/components/Asks/AskBrunch.tsx | 39 ++ src/components/Asks/AskRetex.tsx | 59 +++ src/components/Asks/index.tsx | 44 ++- .../Form/IgnoreButton/IgnoreButton.tsx | 2 +- src/components/Navigation/MainMenu.tsx | 2 +- src/components/RegisterForm/index.tsx | 2 +- src/components/VolunteerBoard/Board.tsx | 76 ++-- .../VolunteerBoard/Brunch/Brunch.tsx | 42 ++ .../VolunteerBoard/Brunch/styles.module.scss | 36 ++ .../VolunteerBoard/BrunchForm/BrunchForm.tsx | 142 +++++++ .../BrunchForm/BrunchFormModal.tsx | 18 + .../BrunchForm/styles.module.scss | 109 +++++ .../DayWishesForm/DayWishesForm.tsx | 2 +- .../HostingForm/HostingForm.tsx | 2 +- .../VolunteerBoard/MealsForm/MealsForm.tsx | 2 +- .../MealsForm/styles.module.scss | 26 -- .../ParticipationDetailsForm.tsx | 2 +- .../PersonalInfoForm/PersonalInfoForm.tsx | 3 +- src/components/VolunteerBoard/Retex/Retex.tsx | 56 +++ .../VolunteerBoard/Retex/styles.module.scss | 36 ++ .../VolunteerBoard/RetexForm/RetexForm.tsx | 374 ++++++++++++++++++ .../RetexForm/RetexFormModal.tsx | 18 + .../RetexForm/styles.module.scss | 109 +++++ .../TeamWishesForm/TeamWishesForm.tsx | 2 +- src/components/VolunteerBoard/brunch.utils.ts | 25 ++ src/components/VolunteerBoard/retex.utils.ts | 55 +++ src/server/gsheets/localDb.ts | 2 + src/server/gsheets/retex.ts | 59 +++ src/server/index.ts | 2 + src/services/retex.ts | 56 +++ src/services/retexAccessors.ts | 6 + src/store/retexSet.ts | 53 +++ src/store/rootReducer.ts | 2 + src/store/ui.ts | 2 + 35 files changed, 1381 insertions(+), 86 deletions(-) create mode 100644 src/components/Asks/AskBrunch.tsx create mode 100644 src/components/Asks/AskRetex.tsx create mode 100644 src/components/VolunteerBoard/Brunch/Brunch.tsx create mode 100755 src/components/VolunteerBoard/Brunch/styles.module.scss create mode 100644 src/components/VolunteerBoard/BrunchForm/BrunchForm.tsx create mode 100644 src/components/VolunteerBoard/BrunchForm/BrunchFormModal.tsx create mode 100755 src/components/VolunteerBoard/BrunchForm/styles.module.scss create mode 100644 src/components/VolunteerBoard/Retex/Retex.tsx create mode 100755 src/components/VolunteerBoard/Retex/styles.module.scss create mode 100644 src/components/VolunteerBoard/RetexForm/RetexForm.tsx create mode 100644 src/components/VolunteerBoard/RetexForm/RetexFormModal.tsx create mode 100755 src/components/VolunteerBoard/RetexForm/styles.module.scss create mode 100644 src/components/VolunteerBoard/brunch.utils.ts create mode 100644 src/components/VolunteerBoard/retex.utils.ts create mode 100644 src/server/gsheets/retex.ts create mode 100644 src/services/retex.ts create mode 100644 src/services/retexAccessors.ts create mode 100644 src/store/retexSet.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9de998a..4cca398 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - node-version: [17.x] + node-version: [18.x] steps: - uses: actions/checkout@v2 diff --git a/src/components/Asks/AskBrunch.tsx b/src/components/Asks/AskBrunch.tsx new file mode 100644 index 0000000..b0ddcc4 --- /dev/null +++ b/src/components/Asks/AskBrunch.tsx @@ -0,0 +1,39 @@ +import { get } from "lodash" +import { useCallback } from "react" +import { fetchVolunteerAsksSet } from "../../store/volunteerAsksSet" +import { useAskTools, addAsk, answerLaterOnProfile } from "./utils" +import BrunchForm, { fetchFor as fetchForBrunchForm } from "../VolunteerBoard/BrunchForm/BrunchForm" +import { useBrunch } from "../VolunteerBoard/brunch.utils" + +export function AskBrunch(asks: JSX.Element[], id: number): void { + const { dispatch, jwtToken, volunteerAsks } = useAskTools() + + const onSubmit = useCallback((): void => { + dispatch( + fetchVolunteerAsksSet(jwtToken, 0, { + hiddenAsks: [...(volunteerAsks?.hiddenAsks || []), id], + }) + ) + }, [dispatch, id, jwtToken, volunteerAsks?.hiddenAsks]) + + const [retex] = useBrunch() + const question1Default = "-1" + const question1 = +get(retex, "question1", question1Default) + const needToShow = !!retex && question1 === -1 + + addAsk( + asks, + id, + volunteerAsks, + false, + needToShow, + <> + {answerLaterOnProfile} + Nous avons besoin d'une réponse avant le jeudi 15 soir minuit pour commander les repas ! + ^^ + + ) +} + +// Fetch server-side data here +export const fetchFor = [...fetchForBrunchForm] diff --git a/src/components/Asks/AskRetex.tsx b/src/components/Asks/AskRetex.tsx new file mode 100644 index 0000000..3592411 --- /dev/null +++ b/src/components/Asks/AskRetex.tsx @@ -0,0 +1,59 @@ +import { get } from "lodash" +import { useCallback } from "react" +import { fetchVolunteerAsksSet } from "../../store/volunteerAsksSet" +import { useAskTools, addAsk, answerLaterOnProfile } from "./utils" +import RetexForm, { fetchFor as fetchForRetexForm } from "../VolunteerBoard/RetexForm/RetexForm" +import { useRetex } from "../VolunteerBoard/retex.utils" + +export function AskRetex(asks: JSX.Element[], id: number): void { + const { dispatch, jwtToken, volunteerAsks } = useAskTools() + + const onSubmit = useCallback((): void => { + dispatch( + fetchVolunteerAsksSet(jwtToken, 0, { + hiddenAsks: [...(volunteerAsks?.hiddenAsks || []), id], + }) + ) + }, [dispatch, id, jwtToken, volunteerAsks?.hiddenAsks]) + + const [retex] = useRetex() + const question1Default = "-1" + const dayWishes = get(retex, "dayWishes", "") + const question1 = +get(retex, "question1", question1Default) + const question2 = get(retex, "question2", "") + const question3 = get(retex, "question3", "") + const question4 = get(retex, "question4", "") + const question5 = get(retex, "question5", "") + const question6 = get(retex, "question6", "") + const question7 = get(retex, "question7", "") + const question8 = get(retex, "question8", "") + const question9 = get(retex, "question9", "") + const wasHereBeforeAfter = dayWishes.match(/M|J|V|L/) + const needToShow = + !!retex && + (question1 === -1 || + !question2 || + !question3 || + !question4 || + (wasHereBeforeAfter && !question5) || + !question6 || + !question7 || + !question8 || + !question9) + + addAsk( + asks, + id, + volunteerAsks, + false, + needToShow, + <> + {answerLaterOnProfile} + Tes réponses sont modifiable sur la page Mon profil jusqu'au 23 + septembre. + + ) +} + +// Fetch server-side data here +export const fetchFor = [...fetchForRetexForm] diff --git a/src/components/Asks/index.tsx b/src/components/Asks/index.tsx index 79acb2d..8f1aa8d 100644 --- a/src/components/Asks/index.tsx +++ b/src/components/Asks/index.tsx @@ -3,16 +3,18 @@ import React, { memo } from "react" import styles from "./styles.module.scss" import { useAskTools } from "./utils" import { AskWelcome } from "./AskWelcome" +import { AskBrunch, fetchFor as fetchForBrunch } from "./AskBrunch" +import { AskRetex, fetchFor as fetchForRetex } from "./AskRetex" import { AskDiscord, fetchFor as fetchForDiscord } from "./AskDiscord" -import { AskDayWishes, fetchFor as fetchForDayWishes } from "./AskDayWishes" -import { AskHosting, fetchFor as fetchForHosting } from "./AskHosting" +// import { AskDayWishes, fetchFor as fetchForDayWishes } from "./AskDayWishes" +// import { AskHosting, fetchFor as fetchForHosting } from "./AskHosting" // import { AskMeals, fetchFor as fetchForMeals } from "./AskMeals" -import { AskPersonalInfo, fetchFor as fetchForPersonalInfo } from "./AskPersonalInfo" -import { AskTeamWishes, fetchFor as fetchForTeamWishes } from "./AskTeamWishes" -import { - AskParticipationDetails, - fetchFor as fetchForParticipationDetails, -} from "./AskParticipationDetails" +// import { AskPersonalInfo, fetchFor as fetchForPersonalInfo } from "./AskPersonalInfo" +// import { AskTeamWishes, fetchFor as fetchForTeamWishes } from "./AskTeamWishes" +// import { +// AskParticipationDetails, +// fetchFor as fetchForParticipationDetails, +// } from "./AskParticipationDetails" import { AskPushNotif } from "./AskPushNotif" const Asks = (): JSX.Element | null => { @@ -20,13 +22,15 @@ const Asks = (): JSX.Element | null => { const asks: JSX.Element[] = [] AskWelcome(asks, 1) - AskDiscord(asks, 3) + AskBrunch(asks, 2) + AskRetex(asks, 3) + AskDiscord(asks, 5) - AskDayWishes(asks, 10) - AskTeamWishes(asks, 11) - AskParticipationDetails(asks, 12) - AskPersonalInfo(asks, 15) - AskHosting(asks, 20) + // AskDayWishes(asks, 10) + // AskTeamWishes(asks, 11) + // AskParticipationDetails(asks, 12) + // AskPersonalInfo(asks, 15) + // AskHosting(asks, 20) // AskMeals(asks, 22) AskPushNotif(asks, 99) @@ -62,11 +66,13 @@ export default memo(Asks) // Fetch server-side data here export const fetchFor = [ + ...fetchForBrunch, + ...fetchForRetex, ...fetchForDiscord, - ...fetchForDayWishes, - ...fetchForHosting, + // ...fetchForDayWishes, + // ...fetchForHosting, // ...fetchForMeals, - ...fetchForTeamWishes, - ...fetchForParticipationDetails, - ...fetchForPersonalInfo, + // ...fetchForTeamWishes, + // ...fetchForParticipationDetails, + // ...fetchForPersonalInfo, ] diff --git a/src/components/Form/IgnoreButton/IgnoreButton.tsx b/src/components/Form/IgnoreButton/IgnoreButton.tsx index f42499a..687dac0 100644 --- a/src/components/Form/IgnoreButton/IgnoreButton.tsx +++ b/src/components/Form/IgnoreButton/IgnoreButton.tsx @@ -37,7 +37,7 @@ const FormButton: FC = ({ children, text, onClick }): JSX.Element => {
{children}
)} diff --git a/src/components/Navigation/MainMenu.tsx b/src/components/Navigation/MainMenu.tsx index dafb203..9affa03 100644 --- a/src/components/Navigation/MainMenu.tsx +++ b/src/components/Navigation/MainMenu.tsx @@ -52,7 +52,7 @@ const MainMenu: FC = (): JSX.Element => { - + {/* */} {
- {["WhatsApp", "Signal", "SMS", "Email", "Appel", "Aucun"].map((option) => ( + {["WhatsApp", "Signal", "SMS", "Email", "Aucun"].map((option) => (