diff --git a/src/components/TeamAssignment/TeamAssignment.tsx b/src/components/TeamAssignment/TeamAssignment.tsx index 9b71327..9cf4306 100644 --- a/src/components/TeamAssignment/TeamAssignment.tsx +++ b/src/components/TeamAssignment/TeamAssignment.tsx @@ -3,18 +3,17 @@ import ContentTitle from "../ui/Content/ContentTitle" import withUserConnected from "../../utils/withUserConnected" import { fetchTeamListIfNeed } from "../../store/teamList" import { fetchVolunteerListIfNeed } from "../../store/volunteerList" -import VolunteersWithTeamWishes from "./VolunteersWithTeamWishes" import TeamsWithCandidates from "./TeamsWithCandidates" +import withUserRole from "../../utils/withUserRole" +import ROLES from "../../utils/roles.constants" const TeamAssignment: FC = (): JSX.Element => ( <> - + - - ) -export default memo(withUserConnected(TeamAssignment)) +export default withUserRole(ROLES.ASSIGNER, memo(withUserConnected(TeamAssignment))) export const fetchFor = [fetchTeamListIfNeed, fetchVolunteerListIfNeed] diff --git a/src/components/TeamAssignment/TeamWithCandidates.tsx b/src/components/TeamAssignment/TeamWithCandidates.tsx index 5e3fe89..d62e887 100644 --- a/src/components/TeamAssignment/TeamWithCandidates.tsx +++ b/src/components/TeamAssignment/TeamWithCandidates.tsx @@ -28,7 +28,13 @@ const selectTeamsWithVolunteersCandidates = createSelector( return { id, name, - volunteers: volunteersSelection, + volunteersWithoutTeam: volunteersSelection.filter((volunteer) => !volunteer.team), + volunteersWithCurrentTeam: volunteersSelection.filter( + (volunteer) => volunteer.team === id + ), + volunteersWithOtherTeam: volunteersSelection.filter( + (volunteer) => volunteer.team && volunteer.team !== id + ), } }) ) @@ -49,57 +55,93 @@ const DaysDisplay: FC = ({ dayWishes }): JSX.Element => ( ) -type Props = { +type TeamWithCandidatesVolunteerProps = { + volunteer: any teamId: number } -const TeamWithCandidates: FC = ({ teamId }): JSX.Element | null => { - const teams = useSelector(selectTeamsWithVolunteersCandidates) - const currentTeam = teams.find((t) => t.id === teamId) +const TeamWithCandidatesVolunteer: FC = ({ + teamId, + volunteer, +}): JSX.Element => { + const { id, lastname, firstname, teamWishes, dayWishes, team } = volunteer const [, saveTeam] = useTeamAssign() const onTeamSelected = useCallback( - (volunteer, selectedTeamId) => { - saveTeam(volunteer, selectedTeamId) + (selectedVolunteer, selectedTeamId) => { + saveTeam(selectedVolunteer, selectedTeamId) }, [saveTeam] ) + return ( +
  • + + {firstname} {lastname} () + + {teamWishes.map((teamWish: any) => { + const active = teamWish.id === team + const current = teamWish.id === teamId + return ( + + ) + })} +
  • + ) +} + +type TeamWithCandidatesProps = { + teamId: number +} + +const TeamWithCandidates: FC = ({ teamId }): JSX.Element => { + const teams = useSelector(selectTeamsWithVolunteersCandidates) + const currentTeam = teams.find((t) => t.id === teamId) + if (!currentTeam) return
    return (
    Equipe {currentTeam.name}
    -
    Bénévoles intéressés ({currentTeam.volunteers.length}) :
    +
    Bénévoles intéressés :
      - {currentTeam.volunteers.map( - ({ id, lastname, firstname, teamWishes, dayWishes, team }) => ( -
    • - - {firstname} {lastname} () - - {teamWishes.map((teamWish) => { - const active = teamWish.id === team - const current = teamWish.id === teamId - return ( - - ) - })} -
    • - ) - )} + {currentTeam.volunteersWithoutTeam.map((volunteer) => ( + + ))} +
    +
      + {currentTeam.volunteersWithCurrentTeam.map((volunteer) => ( + + ))} +
    +
      + {currentTeam.volunteersWithOtherTeam.map((volunteer) => ( + + ))}
    ) diff --git a/src/components/TeamAssignment/TeamsWithCandidates.tsx b/src/components/TeamAssignment/TeamsWithCandidates.tsx index 483386a..bd52c66 100644 --- a/src/components/TeamAssignment/TeamsWithCandidates.tsx +++ b/src/components/TeamAssignment/TeamsWithCandidates.tsx @@ -3,8 +3,6 @@ import { useSelector } from "react-redux" import { selectTeamList } from "../../store/teamList" import TeamWithCandidates from "./TeamWithCandidates" import styles from "./styles.module.scss" -import withUserRole from "../../utils/withUserRole" -import ROLES from "../../utils/roles.constants" const TeamsWithCandidates: FC = (): JSX.Element => { const teams = useSelector(selectTeamList) @@ -27,4 +25,4 @@ const TeamsWithCandidates: FC = (): JSX.Element => { ) } -export default withUserRole(ROLES.ASSIGNER, memo(TeamsWithCandidates)) +export default memo(TeamsWithCandidates) diff --git a/src/components/TeamAssignment/VolunteersWithTeamWishes.tsx b/src/components/TeamAssignment/VolunteersWithTeamWishes.tsx index 3c201a5..d4707ce 100644 --- a/src/components/TeamAssignment/VolunteersWithTeamWishes.tsx +++ b/src/components/TeamAssignment/VolunteersWithTeamWishes.tsx @@ -4,6 +4,7 @@ import { createSelector } from "@reduxjs/toolkit" import { selectVolunteerListAlphaSorted } from "../../store/volunteerList" import { selectTeamList } from "../../store/teamList" import styles from "./styles.module.scss" +import ContentTitle from "../ui/Content/ContentTitle" const selectVolunteersWithTeamWishes = createSelector( selectVolunteerListAlphaSorted, @@ -23,24 +24,52 @@ const selectVolunteersWithTeamWishes = createSelector( })) ) +const selectVolunteersWithTeam = createSelector(selectVolunteersWithTeamWishes, (volunteers) => + volunteers.filter((volunteer) => volunteer.teamObject) +) + +const selectVolunteersWithoutTeam = createSelector(selectVolunteersWithTeamWishes, (volunteers) => + volunteers.filter((volunteer) => !volunteer.teamObject) +) + const VolunteersWithTeamWishes: FC = (): JSX.Element => { - const volunteers = useSelector(selectVolunteersWithTeamWishes) + const volunteersWithTeam = useSelector(selectVolunteersWithTeam) + const volunteersWithoutTeam = useSelector(selectVolunteersWithoutTeam) return ( -
    -
    Bénévoles ayant choisi des équipes ({volunteers.length}) :
    -
      - {volunteers.map(({ id, lastname, firstname, teamWishes, teamObject }) => ( -
    • - - {firstname} {lastname}{" "} - - {teamObject?.name} - {teamWishes.join(", ")} -
    • - ))} -
    -
    + <> + +
    +
    Bénévoles en attente d'équipe ({volunteersWithoutTeam.length}) :
    +
      + {volunteersWithoutTeam.map( + ({ id, lastname, firstname, teamWishes, teamObject }) => ( +
    • + + {firstname} {lastname}{" "} + + {teamObject?.name} + {teamWishes.join(", ")} +
    • + ) + )} +
    +
    Bénévoles dans une équipe ({volunteersWithTeam.length}) :
    +
      + {volunteersWithTeam.map( + ({ id, lastname, firstname, teamWishes, teamObject }) => ( +
    • + + {firstname} {lastname}{" "} + + {teamObject?.name} + {teamWishes.join(", ")} +
    • + ) + )} +
    +
    + ) } diff --git a/src/components/ui/Page/Page.tsx b/src/components/ui/Page/Page.tsx index b595180..2a1d97a 100644 --- a/src/components/ui/Page/Page.tsx +++ b/src/components/ui/Page/Page.tsx @@ -7,7 +7,9 @@ type Props = { const Page: FC = ({ children }): JSX.Element => (
    -
    {children}
    + {React.Children.map(children, (child) => ( +
    {child}
    + ))}
    ) diff --git a/src/pages/TeamAssignment/TeamAssignmentPage.tsx b/src/pages/TeamAssignment/TeamAssignmentPage.tsx index 21c25c5..5750f75 100644 --- a/src/pages/TeamAssignment/TeamAssignmentPage.tsx +++ b/src/pages/TeamAssignment/TeamAssignmentPage.tsx @@ -6,6 +6,7 @@ import { AppThunk } from "../../store" import { selectUserJwtToken } from "../../store/auth" import Page from "../../components/ui/Page/Page" import { TeamAssignment, fetchForTeamAssignment } from "../../components" +import VolunteersWithTeamWishes from "../../components/TeamAssignment/VolunteersWithTeamWishes" export type Props = RouteComponentProps @@ -15,9 +16,14 @@ const TeamAssignmentPage: FC = (): JSX.Element => { if (jwtToken === undefined) return

    Loading...

    if (jwtToken) { return ( - - - + <> + + + + + + + ) } return
    Besoin d'être identifié
    diff --git a/src/theme/mixins.scss b/src/theme/mixins.scss index d76d74c..2851832 100644 --- a/src/theme/mixins.scss +++ b/src/theme/mixins.scss @@ -16,6 +16,7 @@ display: flex; justify-content: center; align-content: center; + width: 100%; } @mixin page-wrapper-center { @@ -35,6 +36,10 @@ padding: 20px; width: $desktopWidth; } + + &::after { + flex-basis: 100%; + } } @mixin inner-content-wrapper() {