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:
79
apps/web/src/features/attendee-detail/detail.ts
Normal file
79
apps/web/src/features/attendee-detail/detail.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import type { AttendeePaymentSummary } from '@gruperly/shared'
|
||||
import { UpdateAttendeeSchema } from '@gruperly/shared'
|
||||
|
||||
export function contactEmailError(email: string): string | null {
|
||||
const result = UpdateAttendeeSchema.safeParse({ email })
|
||||
if (result.success) return null
|
||||
return result.error.issues[0]?.message ?? 'Ingresá un email válido'
|
||||
}
|
||||
|
||||
export type PaymentPresentation = {
|
||||
periodLabel: string
|
||||
statusLabel: string
|
||||
chipLabel: string
|
||||
isDue: boolean
|
||||
}
|
||||
|
||||
export function paymentPresentation(
|
||||
payment: AttendeePaymentSummary | null,
|
||||
today = new Date(),
|
||||
): PaymentPresentation {
|
||||
const periodLabel = capitalize(formatMonthAndYear(today))
|
||||
if (!payment) {
|
||||
return { periodLabel, statusLabel: 'Sin cobro registrado', chipLabel: 'Al día', isDue: false }
|
||||
}
|
||||
|
||||
const isDue = payment.status === 'PENDING' || payment.status === 'OVERDUE'
|
||||
return {
|
||||
periodLabel,
|
||||
statusLabel: paymentStatusLabel(payment.status),
|
||||
chipLabel: isDue ? `Debe ${formatMonth(new Date(payment.dueDate))}` : 'Al día',
|
||||
isDue,
|
||||
}
|
||||
}
|
||||
|
||||
export function formatNotesUpdatedAt(updatedAt: string, today = new Date()): string {
|
||||
const date = new Date(updatedAt)
|
||||
if (sameCalendarDate(date, today)) return 'Editado hoy'
|
||||
return `Editado ${date.toLocaleDateString('es-MX', {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
})}`
|
||||
}
|
||||
|
||||
function paymentStatusLabel(status: AttendeePaymentSummary['status']): string {
|
||||
switch (status) {
|
||||
case 'PAID':
|
||||
return 'Pagado'
|
||||
case 'OVERDUE':
|
||||
return 'Vencido'
|
||||
case 'CANCELLED':
|
||||
return 'Cancelado'
|
||||
default:
|
||||
return 'Pendiente'
|
||||
}
|
||||
}
|
||||
|
||||
function formatMonth(date: Date): string {
|
||||
return date.toLocaleDateString('es-MX', { month: 'long' })
|
||||
}
|
||||
|
||||
function formatMonthAndYear(date: Date): string {
|
||||
const parts = new Intl.DateTimeFormat('es-MX', { month: 'long', year: 'numeric' }).formatToParts(date)
|
||||
const month = parts.find((part) => part.type === 'month')?.value ?? ''
|
||||
const year = parts.find((part) => part.type === 'year')?.value ?? ''
|
||||
return `${month} ${year}`.trim()
|
||||
}
|
||||
|
||||
function capitalize(value: string): string {
|
||||
return `${value.charAt(0).toUpperCase()}${value.slice(1)}`
|
||||
}
|
||||
|
||||
function sameCalendarDate(left: Date, right: Date): boolean {
|
||||
return (
|
||||
left.getFullYear() === right.getFullYear() &&
|
||||
left.getMonth() === right.getMonth() &&
|
||||
left.getDate() === right.getDate()
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user