feat: implement group pre-registration feature with approval and rejection workflows

- Add API endpoints for managing group pre-registrations, including approval and rejection.
- Create database migration for `group_pre_registrations` table and associated enum for status.
- Implement use cases for listing, approving, and rejecting pre-registrations.
- Add frontend components for displaying pre-registration details and managing approvals/rejections.
- Update shared schemas to include pre-registration data structures and validation.
- Remove obsolete `WaitlistNoticeCard` component and replace with `PreRegistrationNoticeCard`.
This commit is contained in:
Jose Selesan
2026-09-29 15:25:24 -03:00
parent 0f02331dfc
commit 45a1f50231
32 changed files with 1335 additions and 165 deletions

View File

@@ -4,23 +4,27 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import type {
AttendeeDto,
GroupDto,
GroupPreRegistrationDto,
GroupWaitlistEntryDto,
GroupRiskLevel,
} from '@gruperly/shared'
import { useToast } from '../../../components/ui'
import {
ApiError,
approveGroupPreRegistration,
getGroup,
getGroupAttendees,
getGroupPreRegistrations,
getGroupsRiskOverview,
getGroupWaitlist,
getInviteToken,
promoteGroupWaitlistEntry,
rejectGroupPreRegistration,
removeGroupWaitlistEntry,
} from '../../../lib/api'
import { useRemoveAttendee } from './useRemoveAttendee'
export type ListSection = 'members' | 'waitlist'
export type ListSection = 'members' | 'preregistrations' | 'waitlist'
type GroupDetailContextValue = {
groupId: string
@@ -34,6 +38,9 @@ type GroupDetailContextValue = {
waitlistTotal: number
waitlistPending: boolean
firstWaitlistEntry: GroupWaitlistEntryDto | null
preRegistrations: GroupPreRegistrationDto[]
preRegistrationsTotal: number
preRegistrationsPending: boolean
hasFreeCapacity: boolean
inviteUrl: string | undefined
invitePending: boolean
@@ -51,12 +58,18 @@ type GroupDetailContextValue = {
confirmRemoveAttendee: (promoteFromWaitlist: boolean) => void
selectedWaitlistEntry: GroupWaitlistEntryDto | null
setSelectedWaitlistEntry: (entry: GroupWaitlistEntryDto | null) => void
selectedPreRegistration: GroupPreRegistrationDto | null
setSelectedPreRegistration: (entry: GroupPreRegistrationDto | null) => void
isSubmittingRemoval: boolean
isSubmittingPromotion: boolean
isSubmittingWaitlistRemoval: boolean
isSubmittingApproval: boolean
isSubmittingRejection: boolean
isRegeneratingInvite: boolean
promoteEntry: (entry: GroupWaitlistEntryDto) => void
removeEntry: (entry: GroupWaitlistEntryDto) => void
approvePreRegistration: (entry: GroupPreRegistrationDto) => void
rejectPreRegistration: (entry: GroupPreRegistrationDto) => void
regenerateInvite: () => void
copyInviteLink: () => Promise<void>
copyWhatsappMessage: () => Promise<void>
@@ -73,6 +86,7 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
const [listSection, setListSection] = useState<ListSection>('members')
const [attendeeToRemove, setAttendeeToRemove] = useState<AttendeeDto | null>(null)
const [selectedWaitlistEntry, setSelectedWaitlistEntry] = useState<GroupWaitlistEntryDto | null>(null)
const [selectedPreRegistration, setSelectedPreRegistration] = useState<GroupPreRegistrationDto | null>(null)
const [searchFilter, setSearchFilter] = useState('')
const groupQuery = useQuery({
@@ -105,17 +119,30 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
enabled: Boolean(groupId),
})
const preRegistrationsQuery = useQuery({
queryKey: ['group-preregistrations', groupId],
queryFn: () => getGroupPreRegistrations(groupId, 1, 100),
enabled: Boolean(groupId),
})
const group = groupQuery.data
const attendees = useMemo(() => attendeesQuery.data?.data ?? [], [attendeesQuery.data])
const attendeesTotal = attendeesQuery.data?.pagination?.total ?? attendees.length
const waitlistEntries = useMemo(() => waitlistQuery.data?.data ?? [], [waitlistQuery.data])
const waitlistTotal = waitlistQuery.data?.pagination?.total ?? waitlistEntries.length
const preRegistrations = useMemo(
() => preRegistrationsQuery.data?.data ?? [],
[preRegistrationsQuery.data],
)
const preRegistrationsTotal =
preRegistrationsQuery.data?.pagination?.total ?? preRegistrations.length
const firstWaitlistEntry = waitlistEntries[0] ?? null
const hasFreeCapacity = group?.capacity == null || attendeesTotal < group.capacity
const invalidateGroupQueries = () => {
void queryClient.invalidateQueries({ queryKey: ['group-attendees', groupId] })
void queryClient.invalidateQueries({ queryKey: ['group-waitlist', groupId] })
void queryClient.invalidateQueries({ queryKey: ['group-preregistrations', groupId] })
void queryClient.invalidateQueries({ queryKey: ['group', groupId] })
}
@@ -161,10 +188,56 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
},
})
const approvePreRegistrationMutation = useMutation({
mutationFn: (entry: GroupPreRegistrationDto) =>
approveGroupPreRegistration(groupId, entry.id),
onSuccess: (result, entry) => {
setSelectedPreRegistration(null)
toast.success(
result.outcome === 'added'
? `${entry.fullName} ahora es miembro del grupo.`
: `${entry.fullName} fue agregado a la lista de espera: el grupo está completo.`,
)
invalidateGroupQueries()
},
onError: (err: Error) => {
if (err instanceof ApiError) {
if (err.problem?.code === 'attendee_already_registered') {
toast.error('Ya hay un miembro con ese teléfono en el grupo. Puedes rechazar la pre-inscripción.')
return
}
if (err.problem?.code === 'pre_registration_already_reviewed') {
toast.error('Esta pre-inscripción ya fue revisada.')
invalidateGroupQueries()
return
}
}
toast.error(err.message || 'No se pudo aprobar la pre-inscripción.')
},
})
const rejectPreRegistrationMutation = useMutation({
mutationFn: (entry: GroupPreRegistrationDto) =>
rejectGroupPreRegistration(groupId, entry.id),
onSuccess: (_result, entry) => {
setSelectedPreRegistration(null)
toast.success(`La pre-inscripción de ${entry.fullName} fue rechazada.`)
invalidateGroupQueries()
},
onError: (err: Error) => {
if (err instanceof ApiError && err.problem?.code === 'pre_registration_already_reviewed') {
toast.error('Esta pre-inscripción ya fue revisada.')
invalidateGroupQueries()
return
}
toast.error(err.message || 'No se pudo rechazar la pre-inscripción.')
},
})
const inviteUrl = inviteTokenQuery.data?.inviteUrl
const whatsappMessage =
group && inviteUrl
? `¡Hola! 👋 Te invito a unirte al grupo *${group.name}*.\n\nCompleta tus datos de inscripción en el siguiente enlace:\n${inviteUrl}`
? `¡Hola! 👋 Te invito a unirte al grupo *${group.name}*.\n\nCompleta tu pre-inscripción en el siguiente enlace. El profesor revisará tu solicitud:\n${inviteUrl}`
: ''
const whatsappShareUrl = whatsappMessage
? `https://wa.me/?text=${encodeURIComponent(whatsappMessage)}`
@@ -215,6 +288,9 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
waitlistTotal,
waitlistPending: waitlistQuery.isPending,
firstWaitlistEntry,
preRegistrations,
preRegistrationsTotal,
preRegistrationsPending: preRegistrationsQuery.isPending,
hasFreeCapacity,
inviteUrl,
invitePending: inviteTokenQuery.isPending,
@@ -235,9 +311,13 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
},
selectedWaitlistEntry,
setSelectedWaitlistEntry,
selectedPreRegistration,
setSelectedPreRegistration,
isSubmittingRemoval: removeAttendeeMutation.isRemovingAttendee,
isSubmittingPromotion: promoteWaitlistMutation.isPending,
isSubmittingWaitlistRemoval: removeWaitlistEntryMutation.isPending,
isSubmittingApproval: approvePreRegistrationMutation.isPending,
isSubmittingRejection: rejectPreRegistrationMutation.isPending,
isRegeneratingInvite: regenerateTokenMutation.isPending,
promoteEntry: (entry) => {
setSelectedWaitlistEntry(null)
@@ -247,6 +327,12 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
setSelectedWaitlistEntry(null)
removeWaitlistEntryMutation.mutate(entry)
},
approvePreRegistration: (entry) => {
approvePreRegistrationMutation.mutate(entry)
},
rejectPreRegistration: (entry) => {
rejectPreRegistrationMutation.mutate(entry)
},
regenerateInvite: () => regenerateTokenMutation.mutate(),
copyInviteLink,
copyWhatsappMessage,

View File

@@ -5,6 +5,7 @@ import { GroupHeader } from './GroupHeader'
import { GroupInfoCard } from './GroupInfoCard'
import { InviteLinkModal } from './InviteLinkModal'
import { MembersWaitlistSection } from './MembersWaitlistSection'
import { PreRegistrationDetailModal } from './PreRegistrationDetailModal'
import { RemoveAttendeeModal } from './RemoveAttendeeModal'
import { useGroupDetail } from './GroupDetailProvider'
import { WaitlistEntryDetailModal } from './WaitlistEntryDetailModal'
@@ -60,6 +61,7 @@ export function GroupDetailView() {
onConfirm={confirmRemoveAttendee}
/>
<WaitlistEntryDetailModal />
<PreRegistrationDetailModal />
</section>
)
}

View File

@@ -74,7 +74,7 @@ export function InviteLinkModal() {
{`¡Hola! 👋 Te invito a unirte al grupo `}
<strong>{group?.name}</strong>.
{'\n\n'}
Completa tus datos de inscripción en el siguiente enlace:
Completa tu pre-inscripción en el siguiente enlace. El profesor revisará tu solicitud:
{'\n'}
<span className="break-all text-accent underline">{inviteUrl}</span>
</div>

View File

@@ -1,15 +1,20 @@
import { useNavigate } from '@tanstack/react-router'
import { Clock, Loader2, Plus, Search, Share2, Users } from 'lucide-react'
import { Clock, Loader2, Plus, Search, Share2, UserCheck, Users } from 'lucide-react'
import { Button, Input } from '../../../components/ui'
import { cn } from '../../../lib/utils'
import { useGroupDetail } from './GroupDetailProvider'
import { MembersTable } from './MembersTable'
import { PreRegistrationsTable } from './PreRegistrationsTable'
import { WaitlistTable } from './WaitlistTable'
const TAB_CLASS =
'flex min-h-10 flex-1 items-center justify-center gap-1.5 rounded-md px-2 text-xs font-semibold transition-[color,background-color,box-shadow] duration-150'
export function MembersWaitlistSection() {
const {
groupId, attendees, attendeesTotal, attendeesPending,
waitlistEntries, waitlistTotal, waitlistPending,
preRegistrations, preRegistrationsTotal, preRegistrationsPending,
listSection, setListSection, searchFilter, setSearchFilter, openInviteModal,
} = useGroupDetail()
const navigate = useNavigate()
@@ -21,6 +26,14 @@ export function MembersWaitlistSection() {
(a.phone && a.phone.includes(query)) ||
(a.email && a.email.toLowerCase().includes(query)),
)
const filteredPreRegistrations = preRegistrations.filter(
(p) =>
p.fullName.toLowerCase().includes(query) ||
p.phone.includes(query) ||
(p.email && p.email.toLowerCase().includes(query)),
)
const showSearch = listSection === 'members' || listSection === 'preregistrations'
return (
// Radios concéntricos: `rounded-2xl` (16px) con `p-2` (8px) deja a las
@@ -32,7 +45,7 @@ export function MembersWaitlistSection() {
<div
role="tablist"
aria-label="Listado del grupo"
className="flex w-full items-center gap-1 rounded-lg bg-surface p-0.5 shadow-xs sm:w-[26rem]"
className="flex w-full items-center gap-1 rounded-lg bg-surface p-0.5 shadow-xs sm:w-[36rem]"
>
<button
type="button"
@@ -40,7 +53,7 @@ export function MembersWaitlistSection() {
aria-selected={listSection === 'members'}
onClick={() => setListSection('members')}
className={cn(
'flex min-h-10 flex-1 items-center justify-center gap-1.5 rounded-md px-2 text-xs font-semibold transition-[color,background-color,box-shadow] duration-150',
TAB_CLASS,
listSection === 'members'
? 'bg-accent text-on-accent shadow-xs'
: 'text-foreground/80 hover:bg-primary-soft hover:text-primary',
@@ -51,13 +64,30 @@ export function MembersWaitlistSection() {
Miembros ({attendeesTotal})
</span>
</button>
<button
type="button"
role="tab"
aria-selected={listSection === 'preregistrations'}
onClick={() => setListSection('preregistrations')}
className={cn(
TAB_CLASS,
listSection === 'preregistrations'
? 'bg-accent text-on-accent shadow-xs'
: 'text-foreground/80 hover:bg-primary-soft hover:text-primary',
)}
>
<UserCheck className="size-4 shrink-0" />
<span className="whitespace-nowrap">
Pre-inscripciones ({preRegistrationsTotal})
</span>
</button>
<button
type="button"
role="tab"
aria-selected={listSection === 'waitlist'}
onClick={() => setListSection('waitlist')}
className={cn(
'flex min-h-10 flex-1 items-center justify-center gap-1.5 rounded-md px-2 text-xs font-semibold transition-[color,background-color,box-shadow] duration-150',
TAB_CLASS,
listSection === 'waitlist'
? 'bg-accent text-on-accent shadow-xs'
: 'text-foreground/80 hover:bg-primary-soft hover:text-primary',
@@ -68,14 +98,14 @@ export function MembersWaitlistSection() {
</button>
</div>
{listSection === 'members' ? (
{showSearch ? (
<div className="relative w-full sm:w-64">
<Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-foreground/70" />
<Input
placeholder="Buscar por nombre o teléfono..."
value={searchFilter}
onChange={(e) => setSearchFilter(e.target.value)}
aria-label="Buscar miembros"
aria-label="Buscar en el listado"
className="h-10 rounded-lg border-transparent pl-9 shadow-xs placeholder:text-foreground/80"
/>
</div>
@@ -85,7 +115,9 @@ export function MembersWaitlistSection() {
<p className="text-xs leading-relaxed text-foreground/80">
{listSection === 'members'
? 'Listado de todos los miembros incorporados al grupo.'
: 'Personas que esperan un cupo libre en el grupo. Al pasar a alguien al grupo, se crea automáticamente su registro como miembro.'}
: listSection === 'preregistrations'
? 'Personas que se inscribieron a través del enlace compartido. Al aprobar, entran al grupo; si el grupo está lleno, pasan a la lista de espera.'
: 'Personas que esperan un cupo libre en el grupo. Al pasar a alguien al grupo, se crea automáticamente su registro como miembro.'}
</p>
</div>
@@ -135,7 +167,48 @@ export function MembersWaitlistSection() {
{filteredAttendees.length > 0 ? <MembersTable attendees={filteredAttendees} /> : null}
</>
) : (
) : null}
{listSection === 'preregistrations' ? (
<div className="space-y-4">
{preRegistrationsPending ? (
<div className="flex items-center justify-center py-12">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
) : null}
{!preRegistrationsPending && preRegistrations.length === 0 ? (
<div className="rounded-lg bg-primary-soft/50 px-4 py-10 text-center">
<UserCheck className="mx-auto mb-2 size-10 text-foreground/40" />
<p className="text-sm font-semibold text-primary">
No hay pre-inscripciones pendientes
</p>
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
Cuando alguien se inscriba a través del enlace compartido, aparecerá aquí para que
revises y apruebes su lugar.
</p>
<div className="mt-4 flex justify-center">
<Button variant="outline" onClick={openInviteModal} className="w-full sm:w-auto">
<Share2 className="size-4" />
Compartir Enlace
</Button>
</div>
</div>
) : null}
{preRegistrations.length > 0 && filteredPreRegistrations.length === 0 ? (
<div className="py-8 text-center text-sm text-foreground/80">
No se encontraron pre-inscripciones que coincidan con la búsqueda.
</div>
) : null}
{filteredPreRegistrations.length > 0 ? (
<PreRegistrationsTable entries={filteredPreRegistrations} />
) : null}
</div>
) : null}
{listSection === 'waitlist' ? (
<div className="space-y-4">
{waitlistPending ? (
<div className="flex items-center justify-center py-12">
@@ -156,7 +229,7 @@ export function MembersWaitlistSection() {
{waitlistEntries.length > 0 ? <WaitlistTable entries={waitlistEntries} /> : null}
</div>
)}
) : null}
</div>
</div>
)

View File

@@ -0,0 +1,112 @@
import { Ban, Loader2, Mail, MessageCircle, Phone, UserCheck } from 'lucide-react'
import { Button, Modal } from '../../../components/ui'
import { DetailRow } from './DetailRow'
import { useGroupDetail } from './GroupDetailProvider'
export function PreRegistrationDetailModal() {
const {
selectedPreRegistration,
setSelectedPreRegistration,
hasFreeCapacity,
approvePreRegistration,
rejectPreRegistration,
isSubmittingApproval,
isSubmittingRejection,
} = useGroupDetail()
return (
<Modal
isOpen={selectedPreRegistration !== null}
onClose={() => setSelectedPreRegistration(null)}
title="Detalle de la pre-inscripción"
maxWidth="sm"
>
{selectedPreRegistration ? (
<div className="space-y-5">
<div className="flex items-center gap-3">
<div className="flex size-12 items-center justify-center rounded-full bg-accent/10 text-lg font-bold text-accent">
{selectedPreRegistration.fullName.charAt(0).toUpperCase()}
</div>
<div className="min-w-0">
<p className="truncate text-lg font-semibold text-primary">
{selectedPreRegistration.fullName}
</p>
<p className="text-xs text-foreground/50">
Solicitado el{' '}
{new Date(selectedPreRegistration.createdAt).toLocaleDateString('es-ES', {
day: 'numeric',
month: 'long',
year: 'numeric',
})}
</p>
</div>
</div>
<div className="space-y-1 divide-y divide-border rounded-xl border border-border bg-primary-soft/30">
<DetailRow icon={<Phone className="size-4 text-accent" />} label="Teléfono">
<div className="flex items-center gap-2">
<span className="text-primary">{selectedPreRegistration.phone}</span>
<a
href={`https://wa.me/${selectedPreRegistration.phone.replace(/\D/g, '')}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 text-xs font-medium text-success transition-colors hover:text-success/80"
>
<MessageCircle className="size-3.5" />
<span>WhatsApp</span>
</a>
</div>
</DetailRow>
{selectedPreRegistration.email ? (
<DetailRow icon={<Mail className="size-4 text-accent" />} label="Email">
<a
href={`mailto:${selectedPreRegistration.email}`}
className="text-primary transition-colors hover:text-accent"
>
{selectedPreRegistration.email}
</a>
</DetailRow>
) : null}
</div>
{!hasFreeCapacity ? (
<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. Si aprobás, esta persona quedará en la lista de
espera hasta que se libere un lugar.
</p>
) : null}
<div className="grid grid-cols-1 gap-2.5 border-t border-border pt-2">
<Button
variant="primary"
onClick={() => approvePreRegistration(selectedPreRegistration)}
disabled={isSubmittingApproval || isSubmittingRejection}
className="gap-2"
>
{isSubmittingApproval ? (
<Loader2 className="size-4 animate-spin" />
) : (
<UserCheck className="size-4" />
)}
<span>Aprobar</span>
</Button>
<Button
variant="ghost"
onClick={() => rejectPreRegistration(selectedPreRegistration)}
disabled={isSubmittingApproval || isSubmittingRejection}
className="gap-2 border border-danger/20 text-danger hover:bg-danger/10 hover:text-danger"
>
{isSubmittingRejection ? (
<Loader2 className="size-4 animate-spin" />
) : (
<Ban className="size-4" />
)}
Rechazar
</Button>
</div>
</div>
) : null}
</Modal>
)
}

View File

@@ -0,0 +1,63 @@
import type { GroupPreRegistrationDto } from '@gruperly/shared'
import { ChevronRight } from 'lucide-react'
import { useGroupDetail } from './GroupDetailProvider'
export function PreRegistrationsTable({ entries }: { entries: GroupPreRegistrationDto[] }) {
const { setSelectedPreRegistration } = useGroupDetail()
return (
<table className="w-full table-fixed text-left text-sm">
<thead>
<tr className="border-b border-border/70 text-xs font-semibold text-foreground/80">
<th scope="col" className="w-[46%] px-3 pb-2">Nombre</th>
<th scope="col" className="px-3 pb-2">Teléfono</th>
<th scope="col" className="px-3 pb-2">Solicitado</th>
<th scope="col" className="w-9 px-1 pb-2">
<span className="sr-only">Detalle</span>
</th>
</tr>
</thead>
<tbody>
{entries.map((entry) => (
<tr
key={entry.id}
className="group cursor-pointer border-b border-border/70 transition-colors last:border-b-0 hover:bg-primary-soft/60"
onClick={() => setSelectedPreRegistration(entry)}
>
<td className="px-3 py-2.5">
<div className="flex min-w-0 items-center gap-2.5">
<div className="flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/10 text-xs font-semibold text-accent">
{entry.fullName.charAt(0).toUpperCase()}
</div>
<div className="min-w-0">
<p className="truncate font-medium text-primary" title={entry.fullName}>
{entry.fullName}
</p>
{entry.email ? (
<p className="truncate text-xs text-foreground/70" title={entry.email}>
{entry.email}
</p>
) : null}
</div>
</div>
</td>
<td className="min-w-0 px-3 py-2.5 text-foreground/80">
<span className="block truncate tabular-nums" title={entry.phone}>
{entry.phone}
</span>
</td>
<td className="min-w-0 px-3 py-2.5 text-xs text-foreground/70">
{new Date(entry.createdAt).toLocaleDateString('es-ES', {
day: 'numeric',
month: 'short',
})}
</td>
<td className="w-9 px-1 py-2.5 text-foreground/50">
<ChevronRight className="ml-auto size-4 transition-colors group-hover:text-accent" />
</td>
</tr>
))}
</tbody>
</table>
)
}

View File

@@ -43,6 +43,11 @@ export function GroupInviteSummary() {
</div>
) : null}
</div>
<p className="mt-3 text-xs leading-relaxed text-foreground/60">
Al completar el formulario envías una solicitud de pre-inscripción. El profesor revisará tus
datos y te confirmará el lugar.
</p>
</div>
)
}

View File

@@ -104,7 +104,7 @@ export function JoinForm() {
className="w-full gap-2 py-2.5 text-sm font-semibold"
>
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : null}
<span>Completar Inscripción</span>
<span>Enviar Solicitud</span>
</Button>
</div>
</form>

View File

@@ -4,11 +4,6 @@ import { useMutation, useQuery } from '@tanstack/react-query'
import type { GroupInviteInfoDto } from '@gruperly/shared'
import { ApiError, getInviteInfo, joinViaInvite } from '../../lib/api'
type RegisteredAttendee = {
fullName: string
phone: string | null
}
type JoinGroupContextValue = {
token: string
group: GroupInviteInfoDto | undefined
@@ -23,8 +18,7 @@ type JoinGroupContextValue = {
email: string
setEmail: (value: string) => void
errorMessage: string | null
registeredAttendee: RegisteredAttendee | null
waitlistMessage: string | null
preRegistrationMessage: string | null
submit: () => void
isSubmitting: boolean
}
@@ -37,8 +31,7 @@ export function JoinGroupProvider({ token, children }: { token: string; children
const [phone, setPhone] = useState('')
const [email, setEmail] = useState('')
const [errorMessage, setErrorMessage] = useState<string | null>(null)
const [registeredAttendee, setRegisteredAttendee] = useState<RegisteredAttendee | null>(null)
const [waitlistMessage, setWaitlistMessage] = useState<string | null>(null)
const [preRegistrationMessage, setPreRegistrationMessage] = useState<string | null>(null)
const inviteQuery = useQuery({
queryKey: ['public-invite', token],
@@ -57,16 +50,7 @@ export function JoinGroupProvider({ token, children }: { token: string; children
}),
onSuccess: (data) => {
setErrorMessage(null)
if (data.status === 'waitlisted') {
setRegisteredAttendee(null)
setWaitlistMessage(data.message)
return
}
setWaitlistMessage(null)
setRegisteredAttendee({
fullName: data.attendee?.fullName ?? `${firstName.trim()} ${lastName.trim()}`.trim(),
phone: data.attendee?.phone ?? null,
})
setPreRegistrationMessage(data.message)
},
onError: (error: unknown) => {
if (error instanceof ApiError) {
@@ -76,6 +60,16 @@ export function JoinGroupProvider({ token, children }: { token: string; children
)
return
}
if (error.problem?.code === 'pre_registration_already_pending') {
setErrorMessage(
'Ya enviaste una solicitud de inscripción para este grupo y está pendiente de revisión. Pronto recibirás novedades.',
)
return
}
if (error.problem?.code === 'pre_registration_already_approved') {
setErrorMessage('Tu inscripción para este grupo ya fue aprobada.')
return
}
setErrorMessage(error.message || 'Error al procesar la inscripción.')
return
}
@@ -110,8 +104,7 @@ export function JoinGroupProvider({ token, children }: { token: string; children
email,
setEmail,
errorMessage,
registeredAttendee,
waitlistMessage,
preRegistrationMessage,
submit,
isSubmitting: joinMutation.isPending,
}
@@ -125,4 +118,4 @@ export function useJoinGroup() {
throw new Error('useJoinGroup debe usarse dentro de <JoinGroupProvider>')
}
return context
}
}

View File

@@ -3,12 +3,11 @@ import { PublicFooter, PublicHeader } from '../../components/layout'
import { GroupInviteSummary } from './GroupInviteSummary'
import { InvalidInviteCard } from './InvalidInviteCard'
import { JoinForm } from './JoinForm'
import { JoinSuccessCard } from './JoinSuccessCard'
import { useJoinGroup } from './JoinGroupProvider'
import { WaitlistNoticeCard } from './WaitlistNoticeCard'
import { PreRegistrationNoticeCard } from './PreRegistrationNoticeCard'
export function JoinGroupView() {
const { group, invitePending, inviteFailed, registeredAttendee, waitlistMessage } = useJoinGroup()
const { group, invitePending, inviteFailed, preRegistrationMessage } = useJoinGroup()
return (
<div className="flex min-h-screen flex-col justify-between bg-background text-primary selection:bg-accent selection:text-white">
@@ -25,10 +24,9 @@ export function JoinGroupView() {
{inviteFailed || (!group && !invitePending) ? <InvalidInviteCard /> : null}
{registeredAttendee ? <JoinSuccessCard /> : null}
{waitlistMessage ? <WaitlistNoticeCard /> : null}
{preRegistrationMessage ? <PreRegistrationNoticeCard /> : null}
{!registeredAttendee && !waitlistMessage && group ? (
{!preRegistrationMessage && group ? (
<div className="space-y-6 rounded-2xl border border-border bg-surface p-6 shadow-xl sm:p-8">
<GroupInviteSummary />
<JoinForm />
@@ -40,4 +38,4 @@ export function JoinGroupView() {
<PublicFooter />
</div>
)
}
}

View File

@@ -1,49 +0,0 @@
import { CheckCircle2 } from 'lucide-react'
import { Badge } from '../../components/ui'
import { useJoinGroup } from './JoinGroupProvider'
export function JoinSuccessCard() {
const { group, registeredAttendee } = useJoinGroup()
if (!group || !registeredAttendee) return null
return (
<div className="animate-step-enter space-y-5 rounded-2xl border border-success/30 bg-surface p-6 text-center shadow-xl sm:p-8">
<div className="mx-auto flex size-16 items-center justify-center rounded-full bg-success-soft text-success">
<CheckCircle2 className="size-10" />
</div>
<div>
<Badge variant="success" className="mb-2">
Registro Confirmado
</Badge>
<h1 className="text-2xl font-bold text-primary">¡Inscripción Exitosa!</h1>
<p className="mt-2 text-sm leading-relaxed text-foreground/70">
Tus datos han sido registrados con éxito en el grupo{' '}
<strong className="font-semibold text-primary">{group.name}</strong>.
</p>
</div>
<div className="space-y-2 rounded-xl border border-border bg-primary-soft/50 p-4 text-left text-xs">
<div className="flex justify-between">
<span className="text-foreground/60">Profesor:</span>
<span className="font-semibold text-primary">{group.teacherName}</span>
</div>
<div className="flex justify-between">
<span className="text-foreground/60">Alumno:</span>
<span className="font-semibold text-primary">{registeredAttendee.fullName}</span>
</div>
{registeredAttendee.phone ? (
<div className="flex justify-between">
<span className="text-foreground/60">Teléfono registrado:</span>
<span className="font-semibold text-primary">{registeredAttendee.phone}</span>
</div>
) : null}
</div>
<p className="text-xs text-foreground/60">
El profesor se pondrá en contacto contigo a la brevedad por WhatsApp para darte la bienvenida y
coordinar los detalles de la clase.
</p>
</div>
)
}

View File

@@ -2,9 +2,9 @@ import { Clock } from 'lucide-react'
import { Badge } from '../../components/ui'
import { useJoinGroup } from './JoinGroupProvider'
export function WaitlistNoticeCard() {
const { group, waitlistMessage } = useJoinGroup()
if (!group || !waitlistMessage) return null
export function PreRegistrationNoticeCard() {
const { group, preRegistrationMessage } = useJoinGroup()
if (!group || !preRegistrationMessage) return null
return (
<div className="animate-step-enter space-y-5 rounded-2xl border border-accent/30 bg-surface p-6 text-center shadow-xl sm:p-8">
@@ -14,16 +14,17 @@ export function WaitlistNoticeCard() {
<div>
<Badge variant="neutral" className="mb-2">
Lista de Espera
Pre-inscripción
</Badge>
<h1 className="text-2xl font-bold text-primary">Cupo completo</h1>
<p className="mt-2 text-sm leading-relaxed text-foreground/70">{waitlistMessage}</p>
<h1 className="text-2xl font-bold text-primary">Solicitud enviada</h1>
<p className="mt-2 text-sm leading-relaxed text-foreground/70">{preRegistrationMessage}</p>
</div>
<p className="text-xs text-foreground/60">
El profesor se pondrá en contacto contigo cuando haya un lugar disponible en{' '}
<strong className="font-semibold text-primary">{group.name}</strong>.
El profesor revisará tu solicitud para el grupo{' '}
<strong className="font-semibold text-primary">{group.name}</strong> y se pondrá en contacto
contigo por WhatsApp para confirmarte el lugar.
</p>
</div>
)
}
}

View File

@@ -1,5 +1,6 @@
import type {
AbsenceDetails,
ApproveGroupPreRegistrationResult,
AttendeeDto,
AttendeeHistory,
AttendeeList,
@@ -20,6 +21,7 @@ import type {
GroupDto,
GroupInviteInfoDto,
GroupList,
GroupPreRegistrationList,
GroupRiskSummary,
GroupsRiskOverview,
GroupWaitlistEntryDto,
@@ -36,6 +38,7 @@ import type {
ProblemDetails,
PromoteGroupWaitlistEntryResult,
PublicNotifyAbsence,
RejectGroupPreRegistrationResult,
RemoveAttendeeResult,
RemoveGroupWaitlistEntryResult,
SessionStudents,
@@ -180,6 +183,23 @@ export const removeGroupWaitlistEntry = (groupId: string, entryId: string) =>
method: 'DELETE',
})
export const getGroupPreRegistrations = (groupId: string, page = 1, pageSize = 100) =>
apiFetch<GroupPreRegistrationList>(
`/api/v1/groups/${groupId}/preregistrations?page=${page}&pageSize=${pageSize}`,
)
export const approveGroupPreRegistration = (groupId: string, entryId: string) =>
apiFetch<ApproveGroupPreRegistrationResult>(
`/api/v1/groups/${groupId}/preregistrations/${entryId}/approve`,
{ method: 'POST' },
)
export const rejectGroupPreRegistration = (groupId: string, entryId: string) =>
apiFetch<RejectGroupPreRegistrationResult>(
`/api/v1/groups/${groupId}/preregistrations/${entryId}/reject`,
{ method: 'POST' },
)
export const removeGroupAttendee = (
groupId: string,
attendeeId: string,