Files
gruperly/apps/web/src/features/attendee-detail/AttendeeContactSection.tsx
Jose Selesan faf949fc9b 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.
2026-10-01 18:41:55 -03:00

136 lines
3.7 KiB
TypeScript

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'
export function AttendeeContactSection() {
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 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
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>
)
}