diff --git a/src/components/Modal/styles.module.scss b/src/components/Modal/styles.module.scss index 847b196..de18f9d 100755 --- a/src/components/Modal/styles.module.scss +++ b/src/components/Modal/styles.module.scss @@ -15,6 +15,7 @@ bottom: auto; right: auto; padding: 15px; + max-height: 80vh; outline: 0; background-color: $color-white; border-radius: 15px; diff --git a/src/components/VolunteerBoard/Board.tsx b/src/components/VolunteerBoard/Board.tsx index cb77bcf..944d269 100644 --- a/src/components/VolunteerBoard/Board.tsx +++ b/src/components/VolunteerBoard/Board.tsx @@ -3,6 +3,8 @@ import DayWishes from "./DayWishes/DayWishes" import DayWishesFormModal from "./DayWishesForm/DayWishesFormModal" import ParticipationDetails from "./ParticipationDetails/ParticipationDetails" import ParticipationDetailsFormModal from "./ParticipationDetailsForm/ParticipationDetailsFormModal" +import TeamWishes from "./TeamWishes/TeamWishes" +import TeamWishesFormModal from "./TeamWishesForm/TeamWishesFormModal" import withUserConnected from "../../utils/withUserConnected" const Board: FC = (): JSX.Element => ( @@ -11,6 +13,8 @@ const Board: FC = (): JSX.Element => ( + + ) diff --git a/src/components/VolunteerBoard/DayWishes/DayWishes.tsx b/src/components/VolunteerBoard/DayWishes/DayWishes.tsx index beac804..f001c1d 100644 --- a/src/components/VolunteerBoard/DayWishes/DayWishes.tsx +++ b/src/components/VolunteerBoard/DayWishes/DayWishes.tsx @@ -22,9 +22,7 @@ const DayWishes: FC = (): JSX.Element | null => { {comment && (
Mon commentaire : - - {get(userWishes, "dayWishesComment", "")} - + {comment}
)}
diff --git a/src/components/VolunteerBoard/ParticipationDetails/ParticipationDetails.tsx b/src/components/VolunteerBoard/ParticipationDetails/ParticipationDetails.tsx index d54ddb2..f9019bb 100644 --- a/src/components/VolunteerBoard/ParticipationDetails/ParticipationDetails.tsx +++ b/src/components/VolunteerBoard/ParticipationDetails/ParticipationDetails.tsx @@ -9,7 +9,7 @@ type Props = { afterSubmit?: () => void | undefined } -const ParticipationDetailsForm: FC = (): JSX.Element | null => { +const ParticipationDetails: FC = (): JSX.Element | null => { const [participationDetails] = useUserParticipationDetails() const age = get(participationDetails, "age", "") const tShirtSize = get(participationDetails, "teeshirtSize", "") @@ -44,4 +44,4 @@ const ParticipationDetailsForm: FC = (): JSX.Element | null => { ) } -export default memo(ParticipationDetailsForm) +export default memo(ParticipationDetails) diff --git a/src/components/VolunteerBoard/TeamWishes/TeamWishes.tsx b/src/components/VolunteerBoard/TeamWishes/TeamWishes.tsx new file mode 100644 index 0000000..b4c9956 --- /dev/null +++ b/src/components/VolunteerBoard/TeamWishes/TeamWishes.tsx @@ -0,0 +1,51 @@ +import { FC, memo, useCallback } from "react" +import { useSelector } from "react-redux" +import get from "lodash/get" +import styles from "./styles.module.scss" +import { displayModal, MODAL_IDS } from "../../../store/ui" +import useAction from "../../../utils/useAction" +import { useUserTeamWishes } from "../teamWishes.utils" +import { selectTeamList } from "../../../store/teamList" + +type Props = { + afterSubmit?: () => void | undefined +} + +const TeamWishes: FC = (): JSX.Element | null => { + const teams = useSelector(selectTeamList) + const [teamWishesData] = useUserTeamWishes() + const teamWishesString = get(teamWishesData, "teamWishes", []) + .map((id: number): string => + get( + teams.find((team) => team && team.id === id), + "name", + "" + ) + ) + .filter((name: string) => name) + .join(", ") + const comment = get(teamWishesData, "teamWishesComment", "") + const execDisplayModal = useAction(displayModal) + const onEdit = useCallback(() => execDisplayModal(MODAL_IDS.TEAMWISHES), [execDisplayModal]) + + return ( +
+
Mes choix d'équipes
+ {teamWishesString && {teamWishesString}} + {!teamWishesString && Non renseignés} + {comment && ( +
+ Mon commentaire : + {comment} +
+ )} +
+ +
+
+ ) +} + +export default memo(TeamWishes) diff --git a/src/components/VolunteerBoard/TeamWishes/styles.module.scss b/src/components/VolunteerBoard/TeamWishes/styles.module.scss new file mode 100755 index 0000000..979460e --- /dev/null +++ b/src/components/VolunteerBoard/TeamWishes/styles.module.scss @@ -0,0 +1,44 @@ +@import "../../../theme/variables"; +@import "../../../theme/mixins"; + +.root { + @include inner-content-wrapper(); + + position: relative; + padding-right: 130px; +} + +.title { + padding-bottom: 5px; + font-weight: bold; +} + +.line { + margin: 2px 0; +} + +.lineEmpty { + color: $color-red; + font-style: italic; +} + +.commentLine { + span { + display: inline-block; + } +} + +.commentLineTitle { + padding-right: 5px; +} + +.commentLineText { + font-style: italic; +} + +.editButton { + @include vertical-center(); + + position: absolute; + right: 20px; +} diff --git a/src/components/VolunteerBoard/TeamWishesForm/TeamWishesForm.tsx b/src/components/VolunteerBoard/TeamWishesForm/TeamWishesForm.tsx new file mode 100644 index 0000000..577ea80 --- /dev/null +++ b/src/components/VolunteerBoard/TeamWishesForm/TeamWishesForm.tsx @@ -0,0 +1,94 @@ +import { FC, memo, useCallback, useEffect, useRef, useState } 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 { selectTeamList } from "../../../store/teamList" +import useSelection from "../useSelection" + +type Props = { + afterSubmit?: () => void | undefined +} + +const TeamWishesForm: FC = ({ afterSubmit }): JSX.Element | null => { + const teams = useSelector(selectTeamList) + const { addToSelection, toggleToSelection, isInSelection } = useSelection() + const commentRef = useRef(null) + const [userWishes, saveWishes] = useUserTeamWishes() + const [extendedTeam, setExtendedTeam] = useState(null) + + useEffect(() => { + if (!userWishes) return + addToSelection(...get(userWishes, "teamWishes", [])) + set(commentRef, "current.value", get(userWishes, "teamWishesComment", "")) + }, [userWishes, addToSelection]) + + const onTeamClick = useCallback((id) => toggleToSelection(id), [toggleToSelection]) + + const onExtendClick = useCallback( + (id) => setExtendedTeam(extendedTeam === id ? null : id), + [extendedTeam, setExtendedTeam] + ) + + console.log("extendedTeam", extendedTeam) + + const onSubmit = useCallback(() => { + const teamWishesComment = get(commentRef, "current.value", "") + const teamWishes = teams + .map((team) => team && team.id) + .filter((id) => id && isInSelection(id)) + saveWishes({ teamWishes, teamWishesComment }) + if (afterSubmit) afterSubmit() + }, [teams, isInSelection, saveWishes, afterSubmit]) + + return ( +
+
Mes choix d'équipes
+
    + {teams.map((team: any) => ( +
  • + + +
    {team.description}
    +
  • + ))} +
+
+ +