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,88 +1,98 @@
import { useRef } from 'react'
import { Link, useNavigate } from '@tanstack/react-router'
import { ArrowLeft, Loader2 } from 'lucide-react'
import { Button } from '../../components/ui'
import { LargeTitle } from '../../components/layout/LargeTitle'
import { Avatar, Badge, Button } from '../../components/ui'
import { AbsenceLinkSection } from './AbsenceLinkSection'
import { AttendeeActionsMenu } from './AttendeeActionsMenu'
import { AttendeeAttendanceSection } from './AttendeeAttendanceSection'
import { AttendeeContactActions } from './AttendeeContactActions'
import { AttendeeContactSection } from './AttendeeContactSection'
import { AttendeePhoneLine } from './AttendeePhoneLine'
import { AttendeeNotesSection } from './AttendeeNotesSection'
import { AttendeePaymentsSection } from './AttendeePaymentsSection'
import { useAttendeeDetail } from './AttendeeDetailProvider'
import { ConfirmRemoveAttendeeDialog } from './ConfirmRemoveAttendeeDialog'
import { formatMemberSince } from './attendance'
import { paymentPresentation } from './detail'
export function AttendeeDetailView() {
const { groupId, groupName, attendee, attendeePending, attendeeFailed } = useAttendeeDetail()
const navigate = useNavigate()
const menuTriggerRef = useRef<HTMLButtonElement>(null)
if (attendeePending) {
return (
<div className="flex items-center justify-center py-20">
<Loader2 className="size-8 animate-spin text-accent" />
</div>
)
}
if (attendeeFailed || !attendee) {
return (
<div className="animate-fade-in rounded-2xl bg-danger-soft p-6">
{/* The title carries the red (at 18px it already counts as large text and
reaches 3:1) and the body uses `text-primary`: on `danger-soft` the red
does not pass the 4.5:1 a `text-sm` needs. */}
<h1 className="text-lg font-bold text-danger">Miembro no encontrado</h1>
<p className="mt-2 text-sm text-primary">
No se pudo cargar la información de este miembro.
</p>
<Button
variant="ghost"
className="mt-4 px-0 text-accent-fg hover:bg-transparent hover:text-primary"
onClick={() => void navigate({ to: '/groups/$groupId', params: { groupId } })}
>
Volver al grupo
</Button>
</div>
)
}
const payment = attendee ? paymentPresentation(attendee.payment) : null
return (
<section className="animate-fade-in">
<div className="flex items-center justify-between gap-2">
<Link
to="/groups/$groupId"
params={{ groupId }}
className="flex min-h-11 min-w-0 items-center gap-1.5 rounded-lg py-2 text-sm text-foreground transition-colors hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
>
<ArrowLeft className="size-4 shrink-0" aria-hidden="true" />
<span className="truncate">{groupName ?? 'Grupo'}</span>
</Link>
<section className="mx-auto w-full max-w-md animate-fade-in lg:max-w-2xl">
<LargeTitle
title={attendee?.fullName ?? 'Miembro'}
barContext={groupName ?? 'Grupo'}
leading={
<Link
to="/groups/$groupId"
params={{ groupId }}
aria-label="Volver al grupo"
className="relative z-10 inline-flex size-11 shrink-0 items-center justify-center rounded-xl text-primary transition-colors hover:bg-primary-soft active:scale-[0.96] motion-reduce:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
>
<ArrowLeft className="size-5" aria-hidden="true" />
</Link>
}
barTrailing={<AttendeeActionsMenu triggerRef={menuTriggerRef} />}
titleLeading={
attendee ? (
<Avatar
name={attendee.fullName}
className="size-14 rounded-full bg-accent-soft text-base text-accent-fg ring-1 ring-border"
/>
) : null
}
>
{attendee && payment ? (
<div className="mt-3 flex flex-wrap items-center gap-2 text-sm text-secondary">
<Badge variant={payment.isDue ? 'warning' : 'success'} className="text-[11px]">
{payment.chipLabel}
</Badge>
<span>Desde {formatMemberSince(attendee.createdAt)}</span>
</div>
) : null}
</LargeTitle>
<AttendeeActionsMenu triggerRef={menuTriggerRef} />
</div>
{attendeePending ? (
<div className="flex items-center justify-center py-20">
<Loader2 className="size-8 animate-spin text-accent" />
</div>
) : null}
<div className="mt-1">
<h1 className="text-balance text-2xl font-bold leading-tight tracking-tight text-primary">
{attendee.fullName}
</h1>
<p className="mt-1 whitespace-nowrap text-sm text-foreground">
Miembro desde {formatMemberSince(attendee.createdAt)}
</p>
<AttendeePhoneLine />
</div>
{attendeeFailed || (!attendeePending && !attendee) ? (
<div className="mt-6 rounded-2xl bg-danger-soft p-6">
<h2 className="text-lg font-bold text-danger-fg">Miembro no encontrado</h2>
<p className="mt-2 text-sm text-primary">
No se pudo cargar la información de este miembro.
</p>
<Button
variant="ghost"
className="mt-4 px-0 text-accent-fg hover:bg-transparent hover:text-primary"
onClick={() => void navigate({ to: '/groups/$groupId', params: { groupId } })}
>
Volver al grupo
</Button>
</div>
) : null}
<div className="mt-3">
<AttendeeContactActions />
</div>
{attendee ? (
<>
<div className="mt-5">
<AttendeeContactActions />
</div>
{/* Ordered by how often they are used. Adding Pagos means inserting one
more block above Asistencia; each section brings its own spacing, so
the layout does not need to change. */}
<div className="mt-5">
<AttendeeAttendanceSection />
<AttendeeContactSection />
<AbsenceLinkSection />
</div>
<div className="mt-6">
<AttendeeContactSection />
<AttendeePaymentsSection />
<AttendeeAttendanceSection />
<AttendeeNotesSection />
<AbsenceLinkSection />
</div>
</>
) : null}
<ConfirmRemoveAttendeeDialog returnFocusRef={menuTriggerRef} />
</section>