feat(attendee-detail): enhance attendee detail view with payment and notes sections

- Added payment presentation logic to display payment status and due dates.
- Introduced AttendeeNotesSection and AttendeePaymentsSection components for managing notes and payments.
- Implemented forms for editing contact information and notes with validation.
- Updated API to support attendee updates and added corresponding tests.
- Improved attendance summary logic to reflect all visible sessions.
- Enhanced UI with loading states and error handling for better user experience.
This commit is contained in:
Jose Selesan
2026-10-01 18:41:55 -03:00
parent 6d120f4b1f
commit faf949fc9b
31 changed files with 1129 additions and 225 deletions

View File

@@ -1,43 +1,135 @@
import { Mail } from 'lucide-react'
import { useAttendeeDetail } from './AttendeeDetailProvider'
import { useEffect, useState } from 'react'
import { Mail, Phone } from 'lucide-react'
import { formatPhoneDisplay } from '../../lib/format'
import { cn } from '../../lib/utils'
import { AttendeeContactForm } from './AttendeeContactForm'
import { contactEmailError } from './detail'
import { Section } from './Section'
import { useAttendeeDetail } from './AttendeeDetailProvider'
/* Inner `px-3`: the hover band bleeds all the way to the section edge
(it separates from the text, not the other way around) and the notes below
add the same so the email and they land in the same column. */
const ROW_CLASS =
'flex w-full min-h-11 items-center justify-between gap-3 rounded-lg px-3 py-2.5 transition-colors hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent'
/** The attendee's email and notes. The phone does not go here: it is already in
* the subtitle, behind the WhatsApp and Llamar buttons, and repeating it filled
* the screen with a value that was already in view.
*
* With no data the section is not drawn: there are no "Sin email"/"Sin notas"
* rows. It shows up on its own as soon as the attendee has one of them (today
* the email can arrive when approving a pre-registration; the notes, once
* editing exists). */
export function AttendeeContactSection() {
const { attendee } = useAttendeeDetail()
const {
attendee,
isEditingContact,
beginContactEdit,
endContactEdit,
saveAttendee,
isUpdatingAttendee,
} = useAttendeeDetail()
const [phone, setPhone] = useState('')
const [email, setEmail] = useState('')
const [error, setError] = useState<string | null>(null)
useEffect(() => {
if (!isEditingContact || !attendee) return
setPhone(attendee.phone ?? '')
setEmail(attendee.email ?? '')
setError(null)
}, [attendee, isEditingContact])
if (!attendee) return null
const { email, notes } = attendee
if (!email && !notes) return null
const cancel = () => {
setError(null)
endContactEdit()
}
const save = async () => {
const emailError = contactEmailError(email)
if (emailError) {
setError(emailError)
return
}
try {
await saveAttendee({ phone, email })
endContactEdit()
} catch {
setError('No pudimos guardar los cambios. Revisá tu conexión e intentá de nuevo.')
}
}
return (
<Section title="Contacto">
<div className="divide-y divide-border/60">
{email ? (
<a href={`mailto:${email}`} className={ROW_CLASS}>
<span className="truncate text-sm text-primary">{email}</span>
<Mail className="size-4 shrink-0 text-foreground" aria-hidden="true" />
</a>
) : null}
{notes ? (
<p className="whitespace-pre-line px-3 py-2 text-sm leading-relaxed text-primary">{notes}</p>
) : null}
</div>
<Section
id="attendee-contact"
title="Contacto"
trailing={
!isEditingContact ? (
<button
type="button"
onClick={beginContactEdit}
className="min-h-11 rounded-lg px-2 text-sm font-medium text-accent-fg transition-colors hover:bg-primary-soft hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
>
Editar
</button>
) : null
}
>
{isEditingContact ? (
<AttendeeContactForm
phone={phone}
email={email}
error={error}
isSaving={isUpdatingAttendee}
onPhoneChange={(value) => {
setPhone(value)
setError(null)
}}
onEmailChange={(value) => {
setEmail(value)
setError(null)
}}
onCancel={cancel}
onSave={() => void save()}
/>
) : (
<div className="divide-y divide-border/60">
<ContactRow
icon={Phone}
label="Teléfono"
value={formatPhoneDisplay(attendee.phone) ?? 'Agregar teléfono'}
href={attendee.phone ? `tel:${attendee.phone.replace(/\D/g, '')}` : undefined}
placeholder={!attendee.phone}
/>
<ContactRow
icon={Mail}
label="Email"
value={attendee.email ?? 'Agregar email'}
href={attendee.email ? `mailto:${attendee.email}` : undefined}
placeholder={!attendee.email}
/>
</div>
)}
</Section>
)
}
type ContactRowProps = {
icon: typeof Phone
label: string
value: string
href?: string
placeholder: boolean
}
function ContactRow({ icon: Icon, label, value, href, placeholder }: ContactRowProps) {
const content = (
<>
<Icon className="size-4 shrink-0 text-secondary" aria-hidden="true" />
<span className="min-w-0">
<span className="block text-xs font-medium text-secondary">{label}</span>
<span className={cn('block truncate text-sm text-primary', placeholder && 'text-secondary')}>
{value}
</span>
</span>
</>
)
const className = 'flex min-h-14 items-center gap-3 rounded-lg px-3 py-2'
return href ? (
<a href={href} className={cn(className, 'transition-colors hover:bg-primary-soft')}>
{content}
</a>
) : (
<div className={className}>{content}</div>
)
}