import { FC, memo, useCallback, useEffect, useRef } from "react" import { useSelector } from "react-redux" import get from "lodash/get" import set from "lodash/set" import classnames from "classnames" import styles from "./styles.module.scss" import { useUserTeamWishes } from "../teamWishes.utils" import { fetchTeamListIfNeed, selectSortedActiveTeams } from "../../../store/teamList" import useSelection from "../useSelection" import { fetchVolunteerTeamWishesSetIfNeed } from "../../../store/volunteerTeamWishesSet" import FormButton from "../../Form/FormButton/FormButton" type Props = { afterSubmit?: () => void | undefined } const TeamWishesForm: FC = ({ afterSubmit }): JSX.Element | null => { const teams = useSelector(selectSortedActiveTeams) const { selection, setSelection, toggleToSelection, isInSelection } = useSelection() const commentRef = useRef(null) const [userWishes, saveWishes] = useUserTeamWishes() useEffect(() => { if (!userWishes) return setSelection(...get(userWishes, "teamWishes", [])) set(commentRef, "current.value", get(userWishes, "teamWishesComment", "")) }, [userWishes, setSelection]) const onTeamClick = useCallback((id) => toggleToSelection(id), [toggleToSelection]) const onSubmit = useCallback(() => { const teamWishesComment = get(commentRef, "current.value", "") saveWishes({ teamWishes: selection, teamWishesComment }) if (afterSubmit) afterSubmit() }, [selection, saveWishes, afterSubmit]) return (
Mon choix d'équipe

Sélectionne la ou les équipes que tu aimerais rejoindre dans l'ordre de tes préférences.

Tu seras affecté à une équipe pour les jours de festival prochainement et nous tiendrons compte de tes préférences dans la mesure du possible.

Si tu es disponible pour aider en amont, même une autre équipe, n'hésite pas à le mettre en commentaire.

Pour plus d'informations sur les équipes,{" "} clique ici .

Mon choix :
    {selection.map((item) => { const team = teams.find((t: any) => t.id === item) if (!team) return null return
  1. {team.name}
  2. })}