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 { fetchVolunteerDayWishesSet, fetchVolunteerDayWishesSetIfNeed, } from "../../store/volunteerDayWishesSet" import { VolunteerDayWishes } from "../../services/volunteers" import { selectUserJwtToken } from "../../store/auth" import DayWishes from "../../components/VolunteerBoard/DayWishes/DayWishes" export type Props = RouteComponentProps let prevWishes: VolunteerDayWishes | undefined const HomePage: FC = (): JSX.Element => { const dispatch = useDispatch() const jwtToken = useSelector(selectUserJwtToken) const wishesForm = useSelector((state: AppState) => { const wishes = state.volunteerDayWishesSet?.entity if (wishes) { prevWishes = wishes return wishes } return prevWishes }, shallowEqual) const [dayWishes, setDayWishes] = useState(wishesForm?.dayWishes.join(",") || "") const [dayWishesComment, setDayWishesComment] = useState(wishesForm?.dayWishesComment || "") useEffect(() => { setDayWishes(wishesForm?.dayWishes.join(",") || "") setDayWishesComment(wishesForm?.dayWishesComment || "") }, [wishesForm]) const onDayWishesChanged = (e: React.ChangeEvent) => setDayWishes(e.target.value) const onDayWishesCommentChanged = (e: React.ChangeEvent) => setDayWishesComment(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( fetchVolunteerDayWishesSet(jwtToken, 0, { id: wishesForm.id, dayWishes: (dayWishes || "").split(","), dayWishesComment, }) ) }, [dispatch, jwtToken, wishesForm, dayWishes, dayWishesComment] ) if (jwtToken === undefined) return

Loading...

if (jwtToken) { return (

) } return
Besoin d'être identifié
} // Fetch server-side data here export const loadData = (): AppThunk[] => [fetchVolunteerDayWishesSetIfNeed()] export default memo(HomePage)