Files
gruperly/apps/web/src/features/attendee-detail/AttendeeActionsMenu.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

160 lines
5.4 KiB
TypeScript

import { useEffect, useId, useRef, useState } from 'react'
import type { KeyboardEvent, RefObject } from 'react'
import { Ellipsis, MoveRight, Pause, Pencil, UserMinus } from 'lucide-react'
import { useToast } from '../../components/ui'
import { useAttendeeDetail } from './AttendeeDetailProvider'
const ITEM_CLASS =
'flex min-h-11 w-full items-center gap-2.5 rounded-lg px-3 text-left text-sm font-medium text-primary transition-colors hover:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent'
/** Accessible "⋯" menu for member-level actions. */
export function AttendeeActionsMenu({
triggerRef,
}: {
/** The screen passes it in so the confirmation dialog can give focus back
* when it closes. */
triggerRef: RefObject<HTMLButtonElement | null>
}) {
const { beginContactEdit, openRemoveDialog } = useAttendeeDetail()
const toast = useToast()
const [isOpen, setIsOpen] = useState(false)
const menuRef = useRef<HTMLDivElement>(null)
const itemRef = useRef<HTMLButtonElement>(null)
const menuId = useId()
useEffect(() => {
if (isOpen) itemRef.current?.focus()
}, [isOpen])
useEffect(() => {
if (!isOpen) return
const handlePointerDown = (event: PointerEvent) => {
const target = event.target as Node
if (menuRef.current?.contains(target) || triggerRef.current?.contains(target)) return
setIsOpen(false)
}
document.addEventListener('pointerdown', handlePointerDown)
return () => document.removeEventListener('pointerdown', handlePointerDown)
}, [isOpen, triggerRef])
const close = (restoreFocus = false) => {
setIsOpen(false)
if (restoreFocus) triggerRef.current?.focus()
}
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.key === 'Escape') {
event.stopPropagation()
close(true)
return
}
if (event.key === 'Tab') {
close()
return
}
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) return
event.preventDefault()
const items = Array.from(
menuRef.current?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? [],
)
if (items.length === 0) return
const current = items.indexOf(document.activeElement as HTMLElement)
const next =
event.key === 'Home'
? 0
: event.key === 'End'
? items.length - 1
: (current + (event.key === 'ArrowDown' ? 1 : -1) + items.length) % items.length
items[next]?.focus()
}
const showPendingChangeGroup = () => {
close()
// TODO(miembros): navegar al selector cuando se confirmen las reglas y exista el endpoint.
toast.info('Cambiar de grupo estará disponible cuando se confirme el flujo de traspaso.')
}
const showPendingPause = () => {
close()
// TODO(miembros): conectar la pausa cuando se defina su efecto sobre cupos y cobros.
toast.info('Pausar la membresía estará disponible cuando se confirme su lógica de negocio.')
}
return (
<div className="relative shrink-0">
<button
ref={triggerRef}
type="button"
onClick={() => setIsOpen((value) => !value)}
aria-haspopup="menu"
aria-expanded={isOpen}
aria-controls={isOpen ? menuId : undefined}
aria-label="Más acciones"
className="inline-flex size-11 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"
>
<Ellipsis className="size-5" aria-hidden="true" />
</button>
{isOpen ? (
<div
ref={menuRef}
id={menuId}
role="menu"
aria-label="Acciones del miembro"
onKeyDown={handleKeyDown}
className="absolute right-0 top-full z-40 mt-1 w-60 rounded-xl bg-primary-soft p-1.5 shadow-lg"
>
<button
ref={itemRef}
type="button"
role="menuitem"
className={ITEM_CLASS}
onClick={showPendingChangeGroup}
>
<MoveRight className="size-4 shrink-0 text-secondary" aria-hidden="true" />
Cambiar de grupo
</button>
<button
type="button"
role="menuitem"
className={ITEM_CLASS}
onClick={() => {
close()
beginContactEdit()
requestAnimationFrame(() => {
document.getElementById('attendee-contact')?.scrollIntoView({ behavior: 'smooth' })
})
}}
>
<Pencil className="size-4 shrink-0 text-secondary" aria-hidden="true" />
Editar contacto
</button>
<button
type="button"
role="menuitem"
className={ITEM_CLASS}
onClick={showPendingPause}
>
<Pause className="size-4 shrink-0 text-secondary" aria-hidden="true" />
Pausar membresía
</button>
<div className="my-1 border-t border-border/70" aria-hidden="true" />
<button
type="button"
role="menuitem"
className={`${ITEM_CLASS} text-danger-fg hover:bg-danger-soft`}
onClick={() => {
close()
openRemoveDialog()
}}
>
<UserMinus className="size-4 shrink-0" aria-hidden="true" />
Quitar del grupo
</button>
</div>
) : null}
</div>
)
}