From ddd99ff4bbd9ff4e80b9e66f9ff6fedc44dba9d9 Mon Sep 17 00:00:00 2001 From: pikiou Date: Thu, 10 Feb 2022 17:47:14 +0100 Subject: [PATCH] Fix team wish type from string to number --- .../VolunteerBoard/teamWishes.utils.ts | 3 +- src/pages/TeamWishes/TeamWishes.tsx | 93 ------------------- src/pages/TeamWishes/index.tsx | 16 ---- src/pages/TeamWishes/styles.module.scss | 1 - src/routes/index.ts | 6 -- src/server/gsheets/accessors.ts | 16 +++- src/services/volunteers.ts | 2 +- 7 files changed, 15 insertions(+), 122 deletions(-) delete mode 100644 src/pages/TeamWishes/TeamWishes.tsx delete mode 100755 src/pages/TeamWishes/index.tsx delete mode 100755 src/pages/TeamWishes/styles.module.scss diff --git a/src/components/VolunteerBoard/teamWishes.utils.ts b/src/components/VolunteerBoard/teamWishes.utils.ts index 41fa2eb..f55811b 100644 --- a/src/components/VolunteerBoard/teamWishes.utils.ts +++ b/src/components/VolunteerBoard/teamWishes.utils.ts @@ -4,8 +4,9 @@ import useAction from "../../utils/useAction" import { selectUserJwtToken } from "../../store/auth" import { AppState } from "../../store" import { fetchVolunteerTeamWishesSet } from "../../store/volunteerTeamWishesSet" +import { VolunteerTeamWishes } from "../../services/volunteers" -export const useUserTeamWishes = (): [any, any] => { +export const useUserTeamWishes = (): [VolunteerTeamWishes | undefined, any] => { const save = useAction(fetchVolunteerTeamWishesSet) const jwtToken = useSelector(selectUserJwtToken) const userTeamWishes = useSelector( diff --git a/src/pages/TeamWishes/TeamWishes.tsx b/src/pages/TeamWishes/TeamWishes.tsx deleted file mode 100644 index a66a536..0000000 --- a/src/pages/TeamWishes/TeamWishes.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import { FC, memo, useCallback, useEffect, useState } from "react" -import { RouteComponentProps } from "react-router-dom" -import { useSelector, shallowEqual, useDispatch } from "react-redux" - -import { AppState, AppThunk } from "../../store" -import { - fetchVolunteerTeamWishesSet, - fetchVolunteerTeamWishesSetIfNeed, -} from "../../store/volunteerTeamWishesSet" -import { VolunteerTeamWishes } from "../../services/volunteers" -import { selectUserJwtToken } from "../../store/auth" - -export type Props = RouteComponentProps - -let prevWishes: VolunteerTeamWishes | undefined - -const HomePage: FC = (): JSX.Element => { - const dispatch = useDispatch() - const jwtToken = useSelector(selectUserJwtToken) - - const wishesForm = useSelector((state: AppState) => { - const wishes = state.volunteerTeamWishesSet?.entity - if (wishes) { - prevWishes = wishes - return wishes - } - return prevWishes - }, shallowEqual) - - const [teamWishes, setTeamWishes] = useState(wishesForm?.teamWishes.join(",") || "") - const [teamWishesComment, setTeamWishesComment] = useState(wishesForm?.teamWishesComment || "") - - useEffect(() => { - setTeamWishes(wishesForm?.teamWishes.join(",") || "") - setTeamWishesComment(wishesForm?.teamWishesComment || "") - }, [wishesForm]) - - const onTeamWishesChanged = (e: React.ChangeEvent) => - setTeamWishes(e.target.value) - const onTeamWishesCommentChanged = (e: React.ChangeEvent) => - setTeamWishesComment(e.target.value) - - const onSubmit = useCallback( - (event: React.SyntheticEvent): void => { - event.preventDefault() - if (!wishesForm) { - console.error("NO FORM WISHES RECEIVED") - return // Form should not even appear if this happens - } - dispatch( - fetchVolunteerTeamWishesSet(jwtToken, 0, { - id: wishesForm.id, - teamWishes: (teamWishes || "").split(","), - teamWishesComment, - }) - ) - }, - [dispatch, jwtToken, wishesForm, teamWishes, teamWishesComment] - ) - - if (jwtToken === undefined) return

Loading...

- - if (jwtToken) { - return ( -
- -
- - -
- ) - } - return
Besoin d'être identifié
-} - -// Fetch server-side data here -export const loadData = (): AppThunk[] => [fetchVolunteerTeamWishesSetIfNeed()] - -export default memo(HomePage) diff --git a/src/pages/TeamWishes/index.tsx b/src/pages/TeamWishes/index.tsx deleted file mode 100755 index 1edcaf7..0000000 --- a/src/pages/TeamWishes/index.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import loadable from "@loadable/component" - -import { Loading, ErrorBoundary } from "../../components" -import { Props, loadData } from "./TeamWishes" - -const HomePage = loadable(() => import("./TeamWishes"), { - fallback: , -}) - -export default (props: Props): JSX.Element => ( - - - -) - -export { loadData } diff --git a/src/pages/TeamWishes/styles.module.scss b/src/pages/TeamWishes/styles.module.scss deleted file mode 100755 index b5c6f69..0000000 --- a/src/pages/TeamWishes/styles.module.scss +++ /dev/null @@ -1 +0,0 @@ -@import "../../theme/mixins"; diff --git a/src/routes/index.ts b/src/routes/index.ts index b1b6d5d..ce92b77 100755 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -7,7 +7,6 @@ import AsyncPreRegisterPage, { loadData as loadPreRegisterPage } from "../pages/ import AsyncTeams, { loadData as loadTeamsData } from "../pages/Teams" import AsyncBoard, { loadData as loadBoardData } from "../pages/Board" import AsyncDayWishes, { loadData as loadDayWishesData } from "../pages/DayWishes" -import AsyncTeamWishes, { loadData as loadTeamWishesData } from "../pages/TeamWishes" import AsyncWish, { loadData as loadWishData } from "../pages/Wish" import AsyncVolunteerPage, { loadData as loadVolunteerPageData } from "../pages/VolunteerPage" import Login from "../pages/Login" @@ -52,11 +51,6 @@ export default [ component: AsyncDayWishes, loadData: loadDayWishesData, }, - { - path: "/teamWishes", - component: AsyncTeamWishes, - loadData: loadTeamWishesData, - }, { path: "/wish", component: AsyncWish, diff --git a/src/server/gsheets/accessors.ts b/src/server/gsheets/accessors.ts index 46d0894..362a171 100644 --- a/src/server/gsheets/accessors.ts +++ b/src/server/gsheets/accessors.ts @@ -509,7 +509,9 @@ export class Sheet< switch (arrayType) { case "string": if (!_.every(value, _.isString)) { - throw new Error(`Each date of ${value} is not a string`) + throw new Error( + `In ${prop}, each item of ${value} is not a string` + ) } stringifiedElement[prop as keyof Element] = formulaSafe( value.join(delimiter) @@ -518,14 +520,18 @@ export class Sheet< case "number": if (!_.every(value, _.isNumber)) { - throw new Error(`Each date of ${value} is not a number`) + throw new Error( + `In ${prop}, each item of ${value} is not a number` + ) } stringifiedElement[prop as keyof Element] = value.join(delimiter) break case "boolean": if (!_.every(value, _.isBoolean)) { - throw new Error(`Each date of ${value} is not a boolean`) + throw new Error( + `In ${prop}, each item of ${value} is not a boolean` + ) } stringifiedElement[prop as keyof Element] = _.map(value, (val) => val ? "X" : "" @@ -534,7 +540,9 @@ export class Sheet< case "date": if (!_.every(value, _.isDate)) { - throw new Error(`Each date of ${value} is not a date`) + throw new Error( + `In ${prop}, each item of ${value} is not a date` + ) } stringifiedElement[prop as keyof Element] = _.map( value, diff --git a/src/services/volunteers.ts b/src/services/volunteers.ts index 226d411..a60b949 100644 --- a/src/services/volunteers.ts +++ b/src/services/volunteers.ts @@ -29,7 +29,7 @@ export class Volunteer { food = "" - teamWishes: string[] = [] + teamWishes: number[] = [] teamWishesComment = ""