feat: pasar de la lista de espera a otro grupo del profesor

- `POST /groups/:gid/waitlist/:entryId/promote` acepta `targetGroupId`
  opcional (por defecto, el grupo en el que se anotó). El destino tiene que
  ser del mismo profesor; cupo y teléfono duplicado se validan ahí.
- Detalle de la lista de espera: selector "Asignar a" con los grupos llenos
  deshabilitados.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-11-02 15:39:55 -03:00
parent d397e9663c
commit fc12ec3ae0
7 changed files with 181 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import type {
UpdateGroupAutomations,
AttendeeListItem,
GroupDto,
GroupListItem,
GroupPreRegistrationDto,
GroupWaitlistEntryDto,
GroupRiskLevel,
@@ -17,6 +18,7 @@ import {
approveGroupPreRegistration,
getGroup,
getGroupAttendees,
getGroups,
getGroupPreRegistrations,
getGroupsRiskOverview,
getGroupWaitlist,
@@ -75,7 +77,10 @@ type GroupDetailContextValue = {
isSubmittingApproval: boolean
isSubmittingRejection: boolean
isRegeneratingInvite: boolean
promoteEntry: (entry: GroupWaitlistEntryDto) => void
/** Grupos del profe: destino posible al pasar a alguien de la lista de espera. */
groups: GroupListItem[]
/** `targetGroupId` es este grupo por defecto, u otro grupo del profe. */
promoteEntry: (entry: GroupWaitlistEntryDto, targetGroupId: string) => void
removeEntry: (entry: GroupWaitlistEntryDto) => void
approvePreRegistration: (entry: GroupPreRegistrationDto) => void
rejectPreRegistration: (entry: GroupPreRegistrationDto) => void
@@ -157,6 +162,8 @@ export function GroupDetailProvider({
enabled: Boolean(groupId),
})
const groupsQuery = useQuery({ queryKey: ['groups'], queryFn: getGroups })
const group = groupQuery.data
const attendees = useMemo(() => attendeesQuery.data?.data ?? [], [attendeesQuery.data])
const attendeesTotal = attendeesQuery.data?.pagination?.total ?? attendees.length
@@ -208,10 +215,19 @@ export function GroupDetailProvider({
})
const promoteWaitlistMutation = useMutation({
mutationFn: (entryId: string) => promoteGroupWaitlistEntry(groupId, entryId),
onSuccess: (result) => {
toast.success(`${result.attendee.fullName} pasó de la lista de espera al grupo.`)
mutationFn: ({ entryId, targetGroupId }: { entryId: string; targetGroupId: string }) =>
promoteGroupWaitlistEntry(groupId, entryId, targetGroupId),
onSuccess: (result, { targetGroupId }) => {
if (targetGroupId === groupId) {
toast.success(`${result.attendee.fullName} pasó de la lista de espera al grupo.`)
} else {
const targetName = groupsQuery.data?.data.find((g) => g.id === targetGroupId)?.name ?? 'otro grupo'
toast.success(`${result.attendee.fullName} pasó a ${targetName}.`)
void queryClient.invalidateQueries({ queryKey: ['group-attendees', targetGroupId] })
void queryClient.invalidateQueries({ queryKey: ['group', targetGroupId] })
}
invalidateGroupQueries()
void queryClient.invalidateQueries({ queryKey: ['groups'] })
},
onError: (err: Error) => {
if (err instanceof ApiError && err.problem?.code === 'group_capacity_reached') {
@@ -377,9 +393,10 @@ export function GroupDetailProvider({
isSubmittingApproval: approvePreRegistrationMutation.isPending,
isSubmittingRejection: rejectPreRegistrationMutation.isPending,
isRegeneratingInvite: regenerateTokenMutation.isPending,
promoteEntry: (entry) => {
groups: groupsQuery.data?.data ?? [],
promoteEntry: (entry, targetGroupId) => {
setSelectedWaitlistEntry(null)
promoteWaitlistMutation.mutate(entry.id)
promoteWaitlistMutation.mutate({ entryId: entry.id, targetGroupId })
},
removeEntry: (entry) => {
setSelectedWaitlistEntry(null)

View File

@@ -1,11 +1,19 @@
import type { GroupListItem } from '@gruperly/shared'
import { useEffect, useState } from 'react'
import { Loader2, Mail, MessageCircle, Phone, StickyNote, Trash2, UserCheck } from 'lucide-react'
import { Button, Modal } from '../../../components/ui'
import { formatPhoneDisplay } from '../../../lib/format'
import { DetailRow } from './DetailRow'
import { useGroupDetail } from './GroupDetailProvider'
function isFull(group: GroupListItem): boolean {
return group.capacity != null && group.attendeesCount >= group.capacity
}
export function WaitlistEntryDetailModal() {
const {
groupId,
groups,
selectedWaitlistEntry,
setSelectedWaitlistEntry,
hasFreeCapacity,
@@ -15,6 +23,16 @@ export function WaitlistEntryDetailModal() {
isSubmittingWaitlistRemoval,
} = useGroupDetail()
// Por defecto pasa al grupo en el que se anotó; el profe puede elegir otro.
const [targetGroupId, setTargetGroupId] = useState(groupId)
useEffect(() => {
setTargetGroupId(groupId)
}, [groupId, selectedWaitlistEntry])
const isCurrentGroup = targetGroupId === groupId
const targetGroup = groups.find((group) => group.id === targetGroupId)
const targetHasFreeCapacity = isCurrentGroup ? hasFreeCapacity : !targetGroup || !isFull(targetGroup)
return (
<Modal
isOpen={selectedWaitlistEntry !== null}
@@ -81,18 +99,42 @@ export function WaitlistEntryDetailModal() {
</DetailRow>
</div>
{!hasFreeCapacity ? (
{groups.length > 1 ? (
<label className="block">
<span className="mb-1.5 block text-sm font-medium text-primary">Asignar a</span>
<select
value={targetGroupId}
onChange={(event) => setTargetGroupId(event.target.value)}
className="h-10 w-full rounded-xl border border-border bg-surface px-3 text-base text-primary sm:text-sm focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
>
{groups.map((group) => {
const isOwnGroup = group.id === groupId
// El grupo actual queda elegible siempre: su cupo lo explica el aviso de abajo.
const full = !isOwnGroup && isFull(group)
return (
<option key={group.id} value={group.id} disabled={full}>
{group.name}
{isOwnGroup ? ' (en el que se anotó)' : full ? ' (sin cupo)' : ''}
</option>
)
})}
</select>
</label>
) : null}
{!targetHasFreeCapacity ? (
<p className="rounded-xl border border-border bg-primary-soft/30 px-4 py-3 text-xs text-foreground/70">
El grupo alcanzó su cupo de miembros. Quita un miembro o aumenta el cupo para poder pasar a esta
persona al grupo.
{isCurrentGroup
? 'El grupo alcanzó su cupo de miembros. Quita un miembro o aumenta el cupo para poder pasar a esta persona al grupo.'
: 'Ese grupo alcanzó su cupo de miembros. Elige otro grupo o libera un lugar primero.'}
</p>
) : null}
<div className="grid grid-cols-1 gap-2.5 border-t border-border pt-2">
<Button
variant="primary"
onClick={() => promoteEntry(selectedWaitlistEntry)}
disabled={isSubmittingPromotion || !hasFreeCapacity}
onClick={() => promoteEntry(selectedWaitlistEntry, targetGroupId)}
disabled={isSubmittingPromotion || !targetHasFreeCapacity}
className="gap-2"
>
{isSubmittingPromotion ? (
@@ -100,7 +142,9 @@ export function WaitlistEntryDetailModal() {
) : (
<UserCheck className="size-4" />
)}
<span>Pasar al grupo</span>
<span className="truncate">
{isCurrentGroup || !targetGroup ? 'Pasar al grupo' : `Pasar a ${targetGroup.name}`}
</span>
</Button>
<Button
variant="ghost"

View File

@@ -319,9 +319,12 @@ export const updateGroupAttendee = (
export const getGroupWaitlist = (groupId: string, page = 1, pageSize = 100) =>
apiFetch<GroupWaitlistList>(`/api/v1/groups/${groupId}/waitlist?page=${page}&pageSize=${pageSize}`)
export const promoteGroupWaitlistEntry = (groupId: string, entryId: string) =>
// Sin `targetGroupId` la persona pasa al grupo en el que se anotó. El body va
// siempre: `apiFetch` manda Content-Type JSON y un body vacío no se parsea.
export const promoteGroupWaitlistEntry = (groupId: string, entryId: string, targetGroupId?: string) =>
apiFetch<PromoteGroupWaitlistEntryResult>(`/api/v1/groups/${groupId}/waitlist/${entryId}/promote`, {
method: 'POST',
body: JSON.stringify({ targetGroupId }),
})
export const removeGroupWaitlistEntry = (groupId: string, entryId: string) =>