Files
gruperly/apps/web/src/features/groups/detail/PreRegistrationDetailModal.tsx

114 lines
4.4 KiB
TypeScript

import { Ban, Loader2, Mail, MessageCircle, Phone, UserCheck } from 'lucide-react'
import { Button, Modal } from '../../../components/ui'
import { formatPhoneDisplay } from '../../../lib/format'
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">{formatPhoneDisplay(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>
)
}