Fix team wish type from string to number

This commit is contained in:
pikiou 2022-02-10 17:47:14 +01:00
parent 6e22136737
commit ddd99ff4bb
7 changed files with 15 additions and 122 deletions

View File

@ -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(

View File

@ -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<Props> = (): 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<HTMLInputElement>) =>
setTeamWishes(e.target.value)
const onTeamWishesCommentChanged = (e: React.ChangeEvent<HTMLInputElement>) =>
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 <p>Loading...</p>
if (jwtToken) {
return (
<form>
<input
type="text"
id="teamWishes"
required
value={teamWishes}
onChange={onTeamWishesChanged}
/>
<br />
<input
type="text"
id="teamWishesComment"
required
value={teamWishesComment}
onChange={onTeamWishesCommentChanged}
/>
<button type="button" onClick={onSubmit}>
Envoyer
</button>
</form>
)
}
return <div>Besoin d&apos;être identifié</div>
}
// Fetch server-side data here
export const loadData = (): AppThunk[] => [fetchVolunteerTeamWishesSetIfNeed()]
export default memo(HomePage)

View File

@ -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: <Loading />,
})
export default (props: Props): JSX.Element => (
<ErrorBoundary>
<HomePage {...props} />
</ErrorBoundary>
)
export { loadData }

View File

@ -1 +0,0 @@
@import "../../theme/mixins";

View File

@ -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,

View File

@ -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,

View File

@ -29,7 +29,7 @@ export class Volunteer {
food = ""
teamWishes: string[] = []
teamWishes: number[] = []
teamWishesComment = ""