mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 00:54:21 +02:00
Fix team wish type from string to number
This commit is contained in:
parent
6e22136737
commit
ddd99ff4bb
@ -4,8 +4,9 @@ import useAction from "../../utils/useAction"
|
|||||||
import { selectUserJwtToken } from "../../store/auth"
|
import { selectUserJwtToken } from "../../store/auth"
|
||||||
import { AppState } from "../../store"
|
import { AppState } from "../../store"
|
||||||
import { fetchVolunteerTeamWishesSet } from "../../store/volunteerTeamWishesSet"
|
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 save = useAction(fetchVolunteerTeamWishesSet)
|
||||||
const jwtToken = useSelector(selectUserJwtToken)
|
const jwtToken = useSelector(selectUserJwtToken)
|
||||||
const userTeamWishes = useSelector(
|
const userTeamWishes = useSelector(
|
||||||
|
@ -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'être identifié</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch server-side data here
|
|
||||||
export const loadData = (): AppThunk[] => [fetchVolunteerTeamWishesSetIfNeed()]
|
|
||||||
|
|
||||||
export default memo(HomePage)
|
|
@ -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 }
|
|
@ -1 +0,0 @@
|
|||||||
@import "../../theme/mixins";
|
|
@ -7,7 +7,6 @@ import AsyncPreRegisterPage, { loadData as loadPreRegisterPage } from "../pages/
|
|||||||
import AsyncTeams, { loadData as loadTeamsData } from "../pages/Teams"
|
import AsyncTeams, { loadData as loadTeamsData } from "../pages/Teams"
|
||||||
import AsyncBoard, { loadData as loadBoardData } from "../pages/Board"
|
import AsyncBoard, { loadData as loadBoardData } from "../pages/Board"
|
||||||
import AsyncDayWishes, { loadData as loadDayWishesData } from "../pages/DayWishes"
|
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 AsyncWish, { loadData as loadWishData } from "../pages/Wish"
|
||||||
import AsyncVolunteerPage, { loadData as loadVolunteerPageData } from "../pages/VolunteerPage"
|
import AsyncVolunteerPage, { loadData as loadVolunteerPageData } from "../pages/VolunteerPage"
|
||||||
import Login from "../pages/Login"
|
import Login from "../pages/Login"
|
||||||
@ -52,11 +51,6 @@ export default [
|
|||||||
component: AsyncDayWishes,
|
component: AsyncDayWishes,
|
||||||
loadData: loadDayWishesData,
|
loadData: loadDayWishesData,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/teamWishes",
|
|
||||||
component: AsyncTeamWishes,
|
|
||||||
loadData: loadTeamWishesData,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/wish",
|
path: "/wish",
|
||||||
component: AsyncWish,
|
component: AsyncWish,
|
||||||
|
@ -509,7 +509,9 @@ export class Sheet<
|
|||||||
switch (arrayType) {
|
switch (arrayType) {
|
||||||
case "string":
|
case "string":
|
||||||
if (!_.every(value, _.isString)) {
|
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(
|
stringifiedElement[prop as keyof Element] = formulaSafe(
|
||||||
value.join(delimiter)
|
value.join(delimiter)
|
||||||
@ -518,14 +520,18 @@ export class Sheet<
|
|||||||
|
|
||||||
case "number":
|
case "number":
|
||||||
if (!_.every(value, _.isNumber)) {
|
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)
|
stringifiedElement[prop as keyof Element] = value.join(delimiter)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "boolean":
|
case "boolean":
|
||||||
if (!_.every(value, _.isBoolean)) {
|
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) =>
|
stringifiedElement[prop as keyof Element] = _.map(value, (val) =>
|
||||||
val ? "X" : ""
|
val ? "X" : ""
|
||||||
@ -534,7 +540,9 @@ export class Sheet<
|
|||||||
|
|
||||||
case "date":
|
case "date":
|
||||||
if (!_.every(value, _.isDate)) {
|
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(
|
stringifiedElement[prop as keyof Element] = _.map(
|
||||||
value,
|
value,
|
||||||
|
@ -29,7 +29,7 @@ export class Volunteer {
|
|||||||
|
|
||||||
food = ""
|
food = ""
|
||||||
|
|
||||||
teamWishes: string[] = []
|
teamWishes: number[] = []
|
||||||
|
|
||||||
teamWishesComment = ""
|
teamWishesComment = ""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user