Vœu de compagnon : être affecté avec 0 à N autres bénévoles
Nouveau vœu sur la fiche du bénévole — « je voudrais être affecté avec tel(s) bénévole(s) » — pris en compte à la fois pour le rendre visible et par le solveur. Backend : - `VolunteerCompanionWish` (`volunteer_id`, `companion_id`, à sens unique, `CHECK (volunteer_id <> companion_id)`) — migration 0010. - API : `wished_companion_ids` sur `VolunteerCreate`/`Update`/`Read`, mêmes règles que les autres vœux (ids inconnus → 422 `volunteer.unknown` ; se souhaiter soi-même → 422 `volunteer.cannot_wish_self`). - Solveur (`engine.py`) : bonus (+25 par correspondance) si un des compagnons souhaités du candidat est déjà affecté (décision déjà prise) au créneau — cumulable si plusieurs compagnons sont présents. Comme les autres termes de l'objectif, un bonus/malus, jamais une contrainte. - Seed de démo : ~20 % des bénévoles ont un vœu de compagnon (couple, amis). Frontend : - Fiche bénévole (`ConfigVolunteers.tsx`) : sélecteur de compagnons (ajout et édition), avec une bulle d'aide expliquant le sens unique et l'effet sur le solveur — c'est ce qui « fait apparaître » le lien entre bénévoles. - Panneau d'affectation : badge « avec N compagnon(s) souhaité(s) » sur un candidat, et bonus correspondant dans le classement par défaut (`candidateChanceScore`). - Mock (`runSolver`) : même bonus, pour que la démonstration se comporte pareil que le vrai solveur. CLAUDE.md à jour (modèle de domaine, section 4, journal). Vérifié : 194 tests backend (dont 13 nouveaux), ruff, alembic check ; typecheck/lint/build/smoke frontend ; solveur testé en direct sur le jeu de démo reseedé (0,25 s, 47 suggestions). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
b97b95c606
commit
6a4bcf8782
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
|
||||
import { ApiError } from '@/api';
|
||||
import {
|
||||
@@ -26,6 +26,7 @@ import type {
|
||||
ImportReport,
|
||||
PositionRead,
|
||||
VolunteerCreate,
|
||||
VolunteerRead,
|
||||
} from '@/api/schema';
|
||||
import { FieldLabel, HelpTip, TextInput } from '@/components/ui';
|
||||
import { ErrorNote, Loading } from '@/components/state';
|
||||
@@ -71,7 +72,21 @@ function positionOptions(positions: PositionRead[] | undefined): WishOption[] {
|
||||
.map((p) => ({ id: p.id, label: p.name, hint: p.location ?? undefined }));
|
||||
}
|
||||
|
||||
/** Sélecteur de vœux : liste déroulante + puces retirables. */
|
||||
/** Les autres bénévoles, pour le vœu de compagnon (jamais soi-même). */
|
||||
function volunteerOptions(
|
||||
volunteers: VolunteerRead[] | undefined,
|
||||
excludeId?: string,
|
||||
): WishOption[] {
|
||||
return [...(volunteers ?? [])]
|
||||
.filter((v) => v.id !== excludeId)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
a.last_name.localeCompare(b.last_name, 'fr') ||
|
||||
a.first_name.localeCompare(b.first_name, 'fr'),
|
||||
)
|
||||
.map((v) => ({ id: v.id, label: `${v.first_name} ${v.last_name}` }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Accès de connexion (lien magique) du bénévole. Ajouter un email sur sa
|
||||
* fiche ne crée aucun compte : sans ce geste explicite, `auth/magic-link` ne
|
||||
@@ -144,7 +159,7 @@ function WishPicker({
|
||||
emptyLabel,
|
||||
addLabel,
|
||||
}: {
|
||||
label: string;
|
||||
label: ReactNode;
|
||||
options: WishOption[];
|
||||
selected: string[];
|
||||
onChange: (ids: string[]) => void;
|
||||
@@ -214,6 +229,10 @@ export function ConfigVolunteers() {
|
||||
|
||||
const artistOpts = useMemo(() => artistOptions(artists.data), [artists.data]);
|
||||
const positionOpts = useMemo(() => positionOptions(positions.data), [positions.data]);
|
||||
const companionOpts = useMemo(
|
||||
() => volunteerOptions(volunteers.data, selectedId ?? undefined),
|
||||
[volunteers.data, selectedId],
|
||||
);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const needle = search.trim().toLowerCase();
|
||||
@@ -338,7 +357,10 @@ export function ConfigVolunteers() {
|
||||
</span>
|
||||
<span className="truncate font-mono text-[10px] opacity-70">
|
||||
{t('config.vol.wishesCount', {
|
||||
count: volunteer.artist_ids.length + volunteer.wished_position_ids.length,
|
||||
count:
|
||||
volunteer.artist_ids.length +
|
||||
volunteer.wished_position_ids.length +
|
||||
volunteer.wished_companion_ids.length,
|
||||
})}
|
||||
</span>
|
||||
</button>
|
||||
@@ -427,6 +449,19 @@ export function ConfigVolunteers() {
|
||||
emptyLabel={t('config.vol.noPositions')}
|
||||
addLabel={t('config.vol.pickPosition')}
|
||||
/>
|
||||
<WishPicker
|
||||
label={
|
||||
<>
|
||||
{t('config.vol.field.companions')}{' '}
|
||||
<HelpTip text={t('config.vol.companionsHint')} />
|
||||
</>
|
||||
}
|
||||
options={companionOpts}
|
||||
selected={selected.wished_companion_ids}
|
||||
onChange={(ids) => patch({ wished_companion_ids: ids })}
|
||||
emptyLabel={t('config.vol.noCompanions')}
|
||||
addLabel={t('config.vol.pickCompanion')}
|
||||
/>
|
||||
|
||||
<AvailabilityEditor volunteerId={selected.id} />
|
||||
|
||||
@@ -456,13 +491,16 @@ function AddVolunteerForm({ onClose }: { onClose: () => void }) {
|
||||
const createVolunteer = useCreateVolunteer();
|
||||
const artists = useArtists();
|
||||
const positions = usePositions();
|
||||
const volunteers = useVolunteers();
|
||||
const [form, setForm] = useState<VolunteerCreate>({ first_name: '', last_name: '' });
|
||||
const [artistIds, setArtistIds] = useState<string[]>([]);
|
||||
const [wishedPositionIds, setWishedPositionIds] = useState<string[]>([]);
|
||||
const [wishedCompanionIds, setWishedCompanionIds] = useState<string[]>([]);
|
||||
const [localError, setLocalError] = useState<string | null>(null);
|
||||
|
||||
const artistOpts = useMemo(() => artistOptions(artists.data), [artists.data]);
|
||||
const positionOpts = useMemo(() => positionOptions(positions.data), [positions.data]);
|
||||
const companionOpts = useMemo(() => volunteerOptions(volunteers.data), [volunteers.data]);
|
||||
|
||||
const set = <K extends keyof VolunteerCreate>(key: K, value: VolunteerCreate[K]) =>
|
||||
setForm((f) => ({ ...f, [key]: value }));
|
||||
@@ -482,6 +520,7 @@ function AddVolunteerForm({ onClose }: { onClose: () => void }) {
|
||||
comment: form.comment?.trim() || null,
|
||||
artist_ids: artistIds,
|
||||
wished_position_ids: wishedPositionIds,
|
||||
wished_companion_ids: wishedCompanionIds,
|
||||
});
|
||||
onClose();
|
||||
} catch (err) {
|
||||
@@ -558,6 +597,19 @@ function AddVolunteerForm({ onClose }: { onClose: () => void }) {
|
||||
emptyLabel={t('config.vol.noPositions')}
|
||||
addLabel={t('config.vol.pickPosition')}
|
||||
/>
|
||||
<WishPicker
|
||||
label={
|
||||
<>
|
||||
{t('config.vol.field.companions')}{' '}
|
||||
<HelpTip text={t('config.vol.companionsHint')} />
|
||||
</>
|
||||
}
|
||||
options={companionOpts}
|
||||
selected={wishedCompanionIds}
|
||||
onChange={setWishedCompanionIds}
|
||||
emptyLabel={t('config.vol.noCompanions')}
|
||||
addLabel={t('config.vol.pickCompanion')}
|
||||
/>
|
||||
|
||||
{localError ? (
|
||||
<div className="border-2 border-ink bg-orange p-[9px] font-display text-[11px] font-bold">
|
||||
|
||||
@@ -127,9 +127,14 @@ export function AssignmentPanel({
|
||||
const assigned = useMemo(() => shiftAssignments.data ?? [], [shiftAssignments.data]);
|
||||
|
||||
// Raisons du score, par bénévole : vœu de poste, conflit avec un artiste
|
||||
// qu'il veut voir sur ce créneau (indépendant de sa disponibilité déclarée).
|
||||
// qu'il veut voir sur ce créneau (indépendant de sa disponibilité déclarée),
|
||||
// compagnons souhaités déjà affectés à ce créneau.
|
||||
const detailsByVolunteer = useMemo(() => {
|
||||
const map = new Map<string, { wishesPosition: boolean; conflictsWishedArtist: boolean }>();
|
||||
const assignedIds = new Set(assigned.map((a) => a.volunteer_id));
|
||||
const map = new Map<
|
||||
string,
|
||||
{ wishesPosition: boolean; conflictsWishedArtist: boolean; companionMatches: number }
|
||||
>();
|
||||
for (const v of volunteers.data ?? []) {
|
||||
const conflictsWishedArtist = v.artist_ids.some((id) => {
|
||||
const artist = artistsById.get(id);
|
||||
@@ -138,14 +143,16 @@ export function AssignmentPanel({
|
||||
map.set(v.id, {
|
||||
wishesPosition: v.wished_position_ids.includes(positionId),
|
||||
conflictsWishedArtist,
|
||||
companionMatches: v.wished_companion_ids.filter((id) => assignedIds.has(id)).length,
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}, [volunteers.data, artistsById, shift, positionId]);
|
||||
}, [volunteers.data, artistsById, shift, positionId, assigned]);
|
||||
|
||||
// Score de chance de chaque candidat pour CE créneau : vœu de poste,
|
||||
// disponibilité (dont conflit avec un artiste qu'il veut voir), charge déjà
|
||||
// assignée — c'est ce qui classe la liste, pas juste « le moins chargé ».
|
||||
// disponibilité (dont conflit avec un artiste qu'il veut voir), compagnons
|
||||
// souhaités déjà présents, charge déjà assignée — c'est ce qui classe la
|
||||
// liste, pas juste « le moins chargé ».
|
||||
const scoreByVolunteer = useMemo(() => {
|
||||
const map = new Map<string, number>();
|
||||
for (const v of volunteers.data ?? []) {
|
||||
@@ -160,6 +167,7 @@ export function AssignmentPanel({
|
||||
shift.ends_at,
|
||||
),
|
||||
conflictsWishedArtist: details?.conflictsWishedArtist ?? false,
|
||||
companionMatches: details?.companionMatches ?? 0,
|
||||
assignedHours: hours.get(v.id) ?? 0,
|
||||
}),
|
||||
);
|
||||
@@ -280,6 +288,7 @@ export function AssignmentPanel({
|
||||
conflictsWishedArtist={
|
||||
detailsByVolunteer.get(volunteer.id)?.conflictsWishedArtist ?? false
|
||||
}
|
||||
companionMatches={detailsByVolunteer.get(volunteer.id)?.companionMatches ?? 0}
|
||||
suggested={suggestedIds.includes(volunteer.id)}
|
||||
resolvePosition={resolvePosition}
|
||||
/>
|
||||
@@ -303,6 +312,7 @@ function CandidateRow({
|
||||
coverage,
|
||||
wishesPosition,
|
||||
conflictsWishedArtist,
|
||||
companionMatches,
|
||||
suggested,
|
||||
resolvePosition,
|
||||
}: {
|
||||
@@ -313,6 +323,7 @@ function CandidateRow({
|
||||
coverage: Coverage;
|
||||
wishesPosition: boolean;
|
||||
conflictsWishedArtist: boolean;
|
||||
companionMatches: number;
|
||||
suggested: boolean;
|
||||
resolvePosition: (shiftId: string) => string | undefined;
|
||||
}) {
|
||||
@@ -379,9 +390,14 @@ function CandidateRow({
|
||||
{t('grille.panel.artistConflict')}
|
||||
</span>
|
||||
) : null}
|
||||
{companionMatches > 0 ? (
|
||||
<span className="inline-block border-[1.5px] border-ink bg-blue px-[6px] py-[3px] font-display text-[8.5px] font-extrabold uppercase tracking-wide">
|
||||
{t('grille.panel.withCompanion', { count: companionMatches })}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{blocking ? (
|
||||
{/* {blocking ? (
|
||||
<div className="flex items-stretch border-t-2 border-ink">
|
||||
<span className="flex w-[26px] flex-none items-center justify-center border-r-2 border-ink bg-hatch-orange font-display text-[12px] font-bold">
|
||||
⛔
|
||||
@@ -390,6 +406,14 @@ function CandidateRow({
|
||||
{t('grille.panel.blockingPrefix', { reason: violationText(blocking, resolvePosition) })}
|
||||
</span>
|
||||
</div>
|
||||
) : null} */}
|
||||
|
||||
{blocking ? (
|
||||
<div className="border-t-2 border-dashed border-ink bg-hatch-orange px-2 py-[6px]">
|
||||
<div className="font-display text-[8.5px] font-extrabold uppercase tracking-widest text-white">
|
||||
{t('grille.panel.blockingPrefix', { reason: violationText(blocking, resolvePosition) })}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{!isBlocked && warnings.length > 0 ? (
|
||||
|
||||
Reference in New Issue
Block a user