diff --git a/src/components/TeamAssignment/TeamAssignment.tsx b/src/components/TeamAssignment/TeamAssignment.tsx index 4a9bff2..9b71327 100644 --- a/src/components/TeamAssignment/TeamAssignment.tsx +++ b/src/components/TeamAssignment/TeamAssignment.tsx @@ -4,10 +4,13 @@ import withUserConnected from "../../utils/withUserConnected" import { fetchTeamListIfNeed } from "../../store/teamList" import { fetchVolunteerListIfNeed } from "../../store/volunteerList" import VolunteersWithTeamWishes from "./VolunteersWithTeamWishes" +import TeamsWithCandidates from "./TeamsWithCandidates" const TeamAssignment: FC = (): JSX.Element => ( <> - + + + ) diff --git a/src/components/TeamAssignment/TeamWithCandidates.tsx b/src/components/TeamAssignment/TeamWithCandidates.tsx new file mode 100644 index 0000000..48fe8a6 --- /dev/null +++ b/src/components/TeamAssignment/TeamWithCandidates.tsx @@ -0,0 +1,57 @@ +import { FC, memo } from "react" +import { useSelector } from "react-redux" +import { createSelector } from "@reduxjs/toolkit" +import { selectVolunteerList } from "../../store/volunteerList" +import { selectTeamList } from "../../store/teamList" + +const selectTeamsWithVolunteersCandidates = createSelector( + selectVolunteerList, + selectTeamList, + (volunteers, teams) => + teams.map(({ id, name }: any) => { + const volunteersSelection = volunteers + .filter((volunteer) => volunteer.teamWishes.includes(id)) + .map((volunteer) => ({ + ...volunteer, + teamWishes: volunteer.teamWishes.map((wishId) => { + const matchingTeam = teams.find((team: any) => wishId === team?.id) + return matchingTeam?.name + }), + })) + return { + id, + name, + volunteers: volunteersSelection, + } + }) +) + +type Props = { + teamId: number +} + +const TeamWithCandidates: FC = ({ teamId }): JSX.Element | null => { + const teams = useSelector(selectTeamsWithVolunteersCandidates) + const team = teams.find((t) => t.id === teamId) + if (!team) return null + + return ( +
+
+ Equipe {team.name} ({team.volunteers.length}) : +
+
    + {team.volunteers.map(({ id, lastname, firstname, teamWishes }) => ( +
  • + + {firstname} {lastname} + {" "} + : {teamWishes.join(", ")} +
  • + ))} +
+
+ ) +} + +export default memo(TeamWithCandidates) diff --git a/src/components/TeamAssignment/TeamsWithCandidates.tsx b/src/components/TeamAssignment/TeamsWithCandidates.tsx new file mode 100644 index 0000000..bd52c66 --- /dev/null +++ b/src/components/TeamAssignment/TeamsWithCandidates.tsx @@ -0,0 +1,28 @@ +import { FC, memo, useState } from "react" +import { useSelector } from "react-redux" +import { selectTeamList } from "../../store/teamList" +import TeamWithCandidates from "./TeamWithCandidates" +import styles from "./styles.module.scss" + +const TeamsWithCandidates: FC = (): JSX.Element => { + const teams = useSelector(selectTeamList) + const [currentTeam, setCurrentTeam] = useState(0) + + return ( +
+
Cliquez sur l'équipe à gérer :
+
    + {teams.map((team: any) => ( +
  • + +
  • + ))} +
+ {!!currentTeam && } +
+ ) +} + +export default memo(TeamsWithCandidates) diff --git a/src/components/TeamAssignment/styles.module.scss b/src/components/TeamAssignment/styles.module.scss index 2fd66b4..fbbedaa 100755 --- a/src/components/TeamAssignment/styles.module.scss +++ b/src/components/TeamAssignment/styles.module.scss @@ -5,3 +5,19 @@ padding-bottom: 10px; font-weight: bold; } + +.teamList { + margin: 0 0 20px; + padding: 0; +} + +.teamListItem { + display: inline-block; + margin: 2px; + text-align: center; + background-color: #ccc; + + button { + padding: 4px 10px; + } +}