Update node

This commit is contained in:
pikiou
2022-09-03 02:59:27 +02:00
parent b0862ab6d0
commit bd7dc7578e
30 changed files with 4490 additions and 12085 deletions

View File

@@ -7,7 +7,10 @@ import { selectTeamList } from "../../store/teamList"
import styles from "./styles.module.scss"
import { useTeamAssign } from "./teamAssign.utils"
import TeamMembers from "../TeamMembers/TeamMembers"
import { Volunteer } from "../../services/volunteers"
type NamedWishes = { id: number; name: string }
type VolunteerWithTeamWishesNames = Omit<Volunteer, "teamWishes"> & { teamWishes: NamedWishes[] }
const selectTeamsWithVolunteersCandidates = createSelector(
selectVolunteerListAlphaSorted,
selectTeamList,
@@ -15,16 +18,19 @@ const selectTeamsWithVolunteersCandidates = createSelector(
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 {
id: matchingTeam?.id,
name: matchingTeam?.name,
}
}),
}))
.map(
(volunteer) =>
({
...volunteer,
teamWishes: volunteer.teamWishes.map((wishId) => {
const matchingTeam = teams.find((team: any) => wishId === team?.id)
return {
id: matchingTeam?.id,
name: matchingTeam?.name,
}
}),
} as VolunteerWithTeamWishesNames)
)
return {
id,
name,
@@ -56,7 +62,7 @@ const DaysDisplay: FC<PropsDaysDisplay> = ({ dayWishes }): JSX.Element => (
)
type TeamWithCandidatesVolunteerProps = {
volunteer: any
volunteer: VolunteerWithTeamWishesNames
teamId: number
}
@@ -68,8 +74,8 @@ const TeamWithCandidatesVolunteer: FC<TeamWithCandidatesVolunteerProps> = ({
const [, saveTeam] = useTeamAssign()
const onTeamSelected = useCallback(
(selectedVolunteer, selectedTeamId) => {
saveTeam(selectedVolunteer, selectedTeamId)
(selectedVolunteerId: number, selectedTeamId: number) => {
saveTeam(selectedVolunteerId, selectedTeamId)
},
[saveTeam]
)
@@ -86,7 +92,7 @@ const TeamWithCandidatesVolunteer: FC<TeamWithCandidatesVolunteerProps> = ({
<button
key={teamWish.id}
type="button"
onClick={() => onTeamSelected({ id, team }, teamWish.id)}
onClick={() => onTeamSelected(id, teamWish.id)}
className={classnames(
styles.teamWishButton,
current && styles.teamCurrent,

View File

@@ -5,8 +5,11 @@ import { AppState } from "../../store"
import useAction from "../../utils/useAction"
import { fetchVolunteerTeamAssignSet } from "../../store/volunteerTeamAssignSet"
import { refreshVolunteerList } from "../../store/volunteerList"
import { VolunteerTeamAssign } from "../../services/volunteers"
export const useTeamAssign = (): [any, any] => {
type SetFunction = (id: VolunteerTeamAssign["id"], team: VolunteerTeamAssign["team"]) => void
export const useTeamAssign = (): [VolunteerTeamAssign | undefined, SetFunction] => {
const save = useAction(fetchVolunteerTeamAssignSet)
const refreshVolunteers = useAction(refreshVolunteerList)
const jwtToken = useSelector(selectUserJwtToken)
@@ -15,11 +18,11 @@ export const useTeamAssign = (): [any, any] => {
shallowEqual
)
const saveWishes = useCallback(
async (volunteer, teamId) => {
const saveWishes: SetFunction = useCallback(
async (id, team) => {
await save(jwtToken, 0, {
volunteer: volunteer.id,
team: volunteer.team === teamId ? 0 : teamId,
id,
team,
})
refreshVolunteers(jwtToken)
},