Files
gruperly/apps/web/src/features/attendee-detail/AbsenceLinkSection.tsx
Jose Selesan 454f20ed25 feat(api): add timezone support for group fetching and increase page size
feat(attendance): refactor attendance summary logic and update tests

feat(analytics): extend GroupRiskSummary schema with absence and attendance counts

feat(groups): enhance group schema with attendee and waitlist counts

chore(skills): add frontend design skill with guidelines and license

feat(attendee-detail): implement AttendeePhoneLine component for phone display

feat(groups): create AttendanceBadge and CapacityIndicator components for group cards

feat(groups): add card utility functions for attendance alerts and capacity summaries

test(groups): implement tests for attendance alert and capacity summary logic
2026-09-30 17:39:13 -03:00

78 lines
2.8 KiB
TypeScript

import { useId, useState } from 'react'
import { Check, Copy, MessageCircle } from 'lucide-react'
import { cn } from '../../lib/utils'
import { useAttendeeDetail } from './AttendeeDetailProvider'
import { ACTION_BUTTON_CLASS, PRIMARY_ACTION_CLASS } from './actionButton'
import { Section } from './Section'
import { useCopyToClipboard } from './useCopyToClipboard'
export function AbsenceLinkSection() {
const { attendee } = useAttendeeDetail()
const { copied, copy } = useCopyToClipboard()
const [isOpen, setIsOpen] = useState(false)
const panelId = useId()
const token = attendee?.notifyToken
const url = token ? `${window.location.origin}/report-absence/${token}` : null
if (!attendee || !url) return null
const phoneDigits = attendee.phone?.replace(/\D/g, '') ?? ''
const shareUrl = phoneDigits
? `https://wa.me/${phoneDigits}?text=${encodeURIComponent(
`Hola ${attendee.fullName.split(' ')[0]}, desde este link podés avisar tus ausencias en ${url}`,
)}`
: null
return (
<Section
title="Link de ausencias"
toggle={{ isOpen, panelId, onToggle: () => setIsOpen((value) => !value) }}
>
{/* El panel queda en el DOM pero oculto: `aria-controls` siempre resuelve y
el texto de "Link copiado" no se pierde al plegar y desplegar. */}
<div id={panelId} hidden={!isOpen}>
<p className="text-sm text-foreground">
Mandales este link para que avisen cuando no puedan venir.
</p>
{/* Apiladas y a ancho completo: al 50% los rótulos ("Enviar por WhatsApp")
se partían en dos líneas y quedaban por debajo del mínimo táctil.
Copiar queda arriba, pegado a su confirmación, y la acción principal
se distingue por el relleno de acento. */}
<div className="mt-2.5 flex flex-col gap-2">
<button
type="button"
onClick={() => copy(url)}
className={cn(ACTION_BUTTON_CLASS, 'w-full')}
>
<Copy className="size-4" aria-hidden="true" />
Copiar link
</button>
{shareUrl ? (
<a
href={shareUrl}
target="_blank"
rel="noopener noreferrer"
aria-label={`Enviar el link por WhatsApp a ${attendee.fullName}`}
className={PRIMARY_ACTION_CLASS}
>
<MessageCircle className="size-4" aria-hidden="true" />
Enviar por WhatsApp
</a>
) : null}
</div>
<p
aria-live="polite"
className="flex min-h-5 items-center gap-1.5 pt-2 text-xs font-medium text-success"
>
{copied ? (
<>
<Check className="size-3.5" aria-hidden="true" />
Link copiado
</>
) : null}
</p>
</div>
</Section>
)
}