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
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { useId, useState } from 'react'
|
||||
import { Check, ChevronDown, Copy, MessageCircle } from 'lucide-react'
|
||||
import { Check, Copy, MessageCircle } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { useAttendeeDetail } from './AttendeeDetailProvider'
|
||||
import { ACTION_BUTTON_CLASS } from './actionButton'
|
||||
import { SECTION_TITLE_CLASS, Section } from './Section'
|
||||
import { ACTION_BUTTON_CLASS, PRIMARY_ACTION_CLASS } from './actionButton'
|
||||
import { Section } from './Section'
|
||||
import { useCopyToClipboard } from './useCopyToClipboard'
|
||||
|
||||
export function AbsenceLinkSection() {
|
||||
@@ -25,66 +25,52 @@ export function AbsenceLinkSection() {
|
||||
|
||||
return (
|
||||
<Section
|
||||
title={
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsOpen((value) => !value)}
|
||||
aria-expanded={isOpen}
|
||||
aria-controls={panelId}
|
||||
className={cn(
|
||||
SECTION_TITLE_CLASS,
|
||||
'flex min-h-11 w-full items-center gap-1.5 text-left',
|
||||
)}
|
||||
>
|
||||
Link de ausencias
|
||||
<ChevronDown
|
||||
className={cn('size-4 transition-transform', isOpen && 'rotate-180')}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
}
|
||||
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}>
|
||||
<div className="pt-1">
|
||||
<p className="text-sm text-foreground">
|
||||
Mandales este link para que avisen cuando no puedan venir.
|
||||
</p>
|
||||
<div className="mt-2.5 flex flex-col gap-2 sm:flex-row">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => copy(url)}
|
||||
className={cn(ACTION_BUTTON_CLASS, 'flex-1')}
|
||||
>
|
||||
<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={cn(ACTION_BUTTON_CLASS, 'flex-1')}
|
||||
>
|
||||
<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"
|
||||
<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')}
|
||||
>
|
||||
{copied ? (
|
||||
<>
|
||||
<Check className="size-3.5" aria-hidden="true" />
|
||||
Link copiado
|
||||
</>
|
||||
) : null}
|
||||
</p>
|
||||
<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>
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { cn } from '../../lib/utils'
|
||||
import {
|
||||
attendanceStatusClass,
|
||||
attendanceStatusLabel,
|
||||
attendanceSummaryLabel,
|
||||
attendanceSummary,
|
||||
formatSessionShortDate,
|
||||
HISTORY_LIMIT,
|
||||
HISTORY_PREVIEW,
|
||||
@@ -67,14 +67,15 @@ export function AttendeeAttendanceSection() {
|
||||
const visible = visibleSessions(sessions, showAll)
|
||||
const hasMore = sessions.length > HISTORY_PREVIEW
|
||||
const isCapped = sessions.length >= HISTORY_LIMIT
|
||||
const summary = attendanceSummary(visible)
|
||||
|
||||
return (
|
||||
<Section title="Asistencia" trailing={attendanceSummaryLabel(visible)}>
|
||||
<Section title="Asistencia" trailing={summary.label}>
|
||||
<ul className="divide-y divide-border/60">
|
||||
{visible.map((session) => {
|
||||
const Icon = iconFor(session.status)
|
||||
return (
|
||||
<li key={session.classSessionId} className="flex items-center justify-between gap-3 py-2.5">
|
||||
<li key={session.classSessionId} className="flex items-center justify-between gap-3 py-2">
|
||||
<span className="truncate text-sm text-primary">
|
||||
{formatSessionShortDate(session.startsAt)}
|
||||
</span>
|
||||
@@ -92,6 +93,12 @@ export function AttendeeAttendanceSection() {
|
||||
})}
|
||||
</ul>
|
||||
|
||||
{/* Las clases sin registro no son ausencias: se avisa aparte y en voz baja
|
||||
para que el "1 de 1" de arriba no se lea como un fallo. */}
|
||||
{summary.unmarkedLabel ? (
|
||||
<p className="pt-2 text-right text-xs text-foreground">{summary.unmarkedLabel}</p>
|
||||
) : null}
|
||||
|
||||
{showAll && isCapped ? (
|
||||
<p className="pt-2 text-xs text-foreground">
|
||||
El historial guarda las últimas {HISTORY_LIMIT} clases.
|
||||
@@ -104,7 +111,7 @@ export function AttendeeAttendanceSection() {
|
||||
variant="ghost"
|
||||
onClick={() => setShowAll((value) => !value)}
|
||||
aria-expanded={showAll}
|
||||
className="h-11 gap-1 px-2 text-sm text-accent hover:text-accent-strong"
|
||||
className="h-11 gap-1 px-2 text-sm text-accent-fg hover:text-primary"
|
||||
>
|
||||
{showAll ? 'Ver menos' : `Ver todas (${sessions.length})`}
|
||||
<ChevronDown className={cn('size-4 transition-transform', showAll && 'rotate-180')} />
|
||||
|
||||
@@ -16,6 +16,9 @@ export function AttendeeContactActions() {
|
||||
|
||||
return (
|
||||
<div className="flex gap-2.5">
|
||||
{/* Los íconos van con `accent-fg` y no con `accent`: el azul de `accent` es
|
||||
el mismo en los dos temas y sobre `primary-soft` oscuro queda en 2.2:1.
|
||||
`accent-fg` da 6.2:1 en claro y 7.1:1 en oscuro. */}
|
||||
<a
|
||||
href={`https://wa.me/${digits}`}
|
||||
target="_blank"
|
||||
@@ -23,7 +26,7 @@ export function AttendeeContactActions() {
|
||||
aria-label={`Abrir WhatsApp con ${label}`}
|
||||
className={cn(ACTION_BUTTON_CLASS, 'flex-1')}
|
||||
>
|
||||
<MessageCircle className="size-4 text-accent" aria-hidden="true" />
|
||||
<MessageCircle className="size-4 text-accent-fg" aria-hidden="true" />
|
||||
WhatsApp
|
||||
</a>
|
||||
<a
|
||||
@@ -31,7 +34,7 @@ export function AttendeeContactActions() {
|
||||
aria-label={`Llamar a ${label}`}
|
||||
className={cn(ACTION_BUTTON_CLASS, 'flex-1')}
|
||||
>
|
||||
<Phone className="size-4 text-accent" aria-hidden="true" />
|
||||
<Phone className="size-4 text-accent-fg" aria-hidden="true" />
|
||||
Llamar
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -1,64 +1,37 @@
|
||||
import { Check, Copy, Mail } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { formatPhoneDisplay } from '../../lib/format'
|
||||
import { Mail } from 'lucide-react'
|
||||
import { useAttendeeDetail } from './AttendeeDetailProvider'
|
||||
import { Section } from './Section'
|
||||
import { useCopyToClipboard } from './useCopyToClipboard'
|
||||
|
||||
const ROW_CLASS =
|
||||
'flex w-full min-h-11 items-center justify-between gap-3 rounded-lg py-2.5 transition-colors hover:bg-primary-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
||||
|
||||
/** Email y notas del miembro. El teléfono no va acá: ya está en el subtítulo y
|
||||
* detrás de los botones de WhatsApp y Llamar, y repetirlo llenaba la pantalla
|
||||
* de un dato que ya estaba a la vista.
|
||||
*
|
||||
* Sin datos no se dibuja la sección: no hay filas con "Sin email"/"Sin notas".
|
||||
* Aparece sola en cuanto el miembro tenga alguno (hoy el email puede llegar al
|
||||
* aprobar una preinscripción; las notas, cuando exista la edición). */
|
||||
export function AttendeeContactSection() {
|
||||
const { attendee } = useAttendeeDetail()
|
||||
const { copied, copy } = useCopyToClipboard()
|
||||
|
||||
if (!attendee) return null
|
||||
|
||||
const phone = attendee.phone
|
||||
const phoneLabel = formatPhoneDisplay(phone)
|
||||
const { email, notes } = attendee
|
||||
// Sin datos no hay sección: no se dibujan filas con "Sin email"/"Sin notas".
|
||||
if (!phoneLabel && !email && !notes) return null
|
||||
if (!email && !notes) return null
|
||||
|
||||
return (
|
||||
<Section title="Contacto">
|
||||
<div className="divide-y divide-border/60">
|
||||
{phone && phoneLabel ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => copy(phone)}
|
||||
className={cn(ROW_CLASS, 'min-w-0 flex-1 text-left')}
|
||||
>
|
||||
<span className="truncate text-base text-primary">{phoneLabel}</span>
|
||||
<span className="flex shrink-0 items-center gap-1.5 text-xs font-medium text-foreground">
|
||||
{copied ? (
|
||||
<Check className="size-4 text-success" aria-hidden="true" />
|
||||
) : (
|
||||
<Copy className="size-4" aria-hidden="true" />
|
||||
)}
|
||||
{copied ? 'Copiado' : 'Copiar'}
|
||||
</span>
|
||||
</button>
|
||||
{/* La confirmación visible no se anuncia sola: va en una región viva
|
||||
aparte para no ensuciar el nombre accesible del botón. */}
|
||||
<span aria-live="polite" className="sr-only">
|
||||
{copied ? 'Teléfono copiado al portapapeles' : ''}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{email ? (
|
||||
<a href={`mailto:${email}`} className={ROW_CLASS}>
|
||||
<span className="truncate text-base text-primary">{email}</span>
|
||||
<span className="truncate text-sm text-primary">{email}</span>
|
||||
<Mail className="size-4 shrink-0 text-foreground" aria-hidden="true" />
|
||||
</a>
|
||||
) : null}
|
||||
|
||||
{notes ? (
|
||||
<p className="whitespace-pre-line py-2.5 text-sm leading-relaxed text-primary">
|
||||
{notes}
|
||||
</p>
|
||||
<p className="whitespace-pre-line py-2 text-sm leading-relaxed text-primary">{notes}</p>
|
||||
) : null}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { AttendeeActionsMenu } from './AttendeeActionsMenu'
|
||||
import { AttendeeAttendanceSection } from './AttendeeAttendanceSection'
|
||||
import { AttendeeContactActions } from './AttendeeContactActions'
|
||||
import { AttendeeContactSection } from './AttendeeContactSection'
|
||||
import { AttendeePhoneLine } from './AttendeePhoneLine'
|
||||
import { useAttendeeDetail } from './AttendeeDetailProvider'
|
||||
import { ConfirmRemoveAttendeeDialog } from './ConfirmRemoveAttendeeDialog'
|
||||
import { formatMemberSince } from './attendance'
|
||||
@@ -36,7 +37,7 @@ export function AttendeeDetailView() {
|
||||
</p>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="mt-4 px-0 text-accent hover:bg-transparent hover:text-accent-strong"
|
||||
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
|
||||
@@ -67,15 +68,17 @@ export function AttendeeDetailView() {
|
||||
<p className="mt-1 whitespace-nowrap text-sm text-foreground">
|
||||
Miembro desde {formatMemberSince(attendee.createdAt)}
|
||||
</p>
|
||||
<AttendeePhoneLine />
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<div className="mt-3">
|
||||
<AttendeeContactActions />
|
||||
</div>
|
||||
|
||||
{/* Orden por frecuencia de uso. Sumar Pagos es insertar un bloque más
|
||||
arriba de Asistencia; el layout no se toca. */}
|
||||
<div className="mt-6 space-y-5">
|
||||
arriba de Asistencia; cada sección lleva su propio aire, así que el
|
||||
layout no se toca. */}
|
||||
<div className="mt-5">
|
||||
<AttendeeAttendanceSection />
|
||||
<AttendeeContactSection />
|
||||
<AbsenceLinkSection />
|
||||
|
||||
45
apps/web/src/features/attendee-detail/AttendeePhoneLine.tsx
Normal file
45
apps/web/src/features/attendee-detail/AttendeePhoneLine.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Check } from 'lucide-react'
|
||||
import { formatPhoneDisplay } from '../../lib/format'
|
||||
import { useAttendeeDetail } from './AttendeeDetailProvider'
|
||||
import { useCopyToClipboard } from './useCopyToClipboard'
|
||||
|
||||
/** Teléfono como segunda línea del subtítulo.
|
||||
*
|
||||
* Vivía en una sección "Contacto" con una sola fila que repetía el número que
|
||||
* ya está a la vista detrás de los botones de WhatsApp y Llamar. Acá acompaña
|
||||
* al "Miembro desde…", se copia con un toque y tiene 44px de alto aunque el
|
||||
* texto sea de 14px: es un control, no un dato decorativo. */
|
||||
export function AttendeePhoneLine() {
|
||||
const { attendee } = useAttendeeDetail()
|
||||
const { copied, copy } = useCopyToClipboard()
|
||||
|
||||
const phone = attendee?.phone
|
||||
const label = formatPhoneDisplay(phone)
|
||||
if (!phone || !label) return null
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => copy(phone)}
|
||||
className="flex min-h-11 max-w-fit items-center gap-2 rounded-lg text-left transition-colors hover:bg-primary-soft active:scale-[0.98] motion-reduce:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
|
||||
>
|
||||
<span className="truncate text-sm text-foreground">{label}</span>
|
||||
{/* `aria-hidden`: la confirmación se anuncia desde la región viva de
|
||||
abajo, así no se cuela en el nombre del botón. */}
|
||||
{copied ? (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="flex shrink-0 items-center gap-1 text-xs font-medium text-accent-fg"
|
||||
>
|
||||
<Check className="size-3.5" />
|
||||
Número copiado
|
||||
</span>
|
||||
) : null}
|
||||
</button>
|
||||
<span aria-live="polite" className="sr-only">
|
||||
{copied ? 'Número copiado al portapapeles' : ''}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,40 +1,82 @@
|
||||
import { useId } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { ChevronDown } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
/* El gris va sin opacidad: sobre el fondo oscuro `text-foreground/50` cae a
|
||||
~2.7:1 y `/80` a ~4.2:1, los dos por debajo de AA. El token entero sí pasa. */
|
||||
export const SECTION_TITLE_CLASS = 'text-[11px] font-semibold uppercase tracking-wide text-foreground'
|
||||
|
||||
/* La fila que despliega la sección es un botón, no un título: por eso lleva
|
||||
superficie de hover y presión, se pinta en `primary` para que se lea
|
||||
distinta de los títulos fijos, y el chevron cae al borde derecho de la fila
|
||||
en vez de pegado al texto. */
|
||||
const TOGGLE_ROW_CLASS = cn(
|
||||
SECTION_TITLE_CLASS,
|
||||
'flex min-h-11 w-full items-center justify-between gap-2 rounded-lg text-left text-primary',
|
||||
'transition-colors hover:bg-primary-soft active:scale-[0.98] motion-reduce:active:scale-100',
|
||||
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent',
|
||||
)
|
||||
|
||||
type SectionProps = {
|
||||
/** Título de la sección. Un string por lo general; un botón cuando la
|
||||
* sección se despliega desde el propio título (ver Link de ausencias). */
|
||||
/** Título de la sección. Un string por lo general. */
|
||||
title: ReactNode
|
||||
/** A la derecha del título: el resumen de asistencia, por ejemplo. */
|
||||
trailing?: ReactNode
|
||||
/** Cuando está, el título entero es el disparador del contenido y `title` es
|
||||
* solo su rótulo: el `<h2>` sigue siendo el encabezado de la sección y el
|
||||
* botón ocupa la fila completa. */
|
||||
toggle?: { isOpen: boolean; panelId: string; onToggle: () => void }
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/** Bloque de sección: separador fino sobre el fondo, título chico en
|
||||
* mayúsculas y contenido sin padding propio (el de la pantalla).
|
||||
*
|
||||
* La pantalla se arma apilando secciones en este orden, así que sumar una
|
||||
* nueva (Pagos, por ejemplo) es insertar otro bloque y nada más. */
|
||||
export function Section({ title, trailing, children }: SectionProps) {
|
||||
* El aire vive acá y no en la pantalla: cada sección cierra con su propio
|
||||
* padding, así que el separador queda siempre a la misma distancia del
|
||||
* contenido de arriba. Sumar otra sección (Pagos, por ejemplo) es insertar
|
||||
* otro bloque y nada más. */
|
||||
export function Section({ title, trailing, toggle, children }: SectionProps) {
|
||||
const headingId = useId()
|
||||
|
||||
return (
|
||||
<section aria-labelledby={headingId} className="border-t border-border/70 pt-5">
|
||||
<section aria-labelledby={headingId} className="border-t border-border/70 py-4">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<h2 id={headingId} className={SECTION_TITLE_CLASS}>
|
||||
{title}
|
||||
</h2>
|
||||
{toggle ? (
|
||||
// El botón vive dentro del `<h2>`: el encabezado no se pierde y el
|
||||
// disparador sigue siendo un control de verdad (Enter, Espacio y foco
|
||||
// visible por teclado).
|
||||
<h2 id={headingId} className="min-w-0 flex-1">
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={toggle.isOpen}
|
||||
aria-controls={toggle.panelId}
|
||||
onClick={toggle.onToggle}
|
||||
className={TOGGLE_ROW_CLASS}
|
||||
>
|
||||
<span className="truncate">{title}</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
'size-4 shrink-0 transition-transform',
|
||||
toggle.isOpen && 'rotate-180',
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
</h2>
|
||||
) : (
|
||||
<h2 id={headingId} className={SECTION_TITLE_CLASS}>
|
||||
{title}
|
||||
</h2>
|
||||
)}
|
||||
{trailing ? (
|
||||
<div className="shrink-0 text-xs font-semibold tabular-nums text-foreground">
|
||||
{trailing}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="mt-2.5">{children}</div>
|
||||
<div className="mt-2">{children}</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,3 +6,10 @@
|
||||
* el mismo anillo de foco y feedback de presión que el `Button` de la app. */
|
||||
export const ACTION_BUTTON_CLASS =
|
||||
'inline-flex h-11 items-center justify-center gap-2 rounded-xl bg-primary-soft px-3 text-sm font-medium text-primary transition-colors hover:bg-accent-soft active:scale-[0.96] motion-reduce:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
||||
|
||||
/** Acción principal de un panel (Enviar por WhatsApp). Misma superficie que el
|
||||
* `Button` `primary` de la app —relleno `accent` con texto `on-accent`, que
|
||||
* da 6.8:1 en los dos temas— pero a ancho completo porque sola en la columna:
|
||||
* al lado de la secundaria al 50% los rótulos largos se parten en dos líneas. */
|
||||
export const PRIMARY_ACTION_CLASS =
|
||||
'inline-flex h-11 w-full items-center justify-center gap-2 rounded-xl bg-accent px-4 text-sm font-medium text-on-accent transition-colors hover:bg-accent-strong active:scale-[0.96] motion-reduce:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
||||
|
||||
@@ -70,8 +70,34 @@ export function visibleSessions(
|
||||
return showAll ? ordered : ordered.slice(0, HISTORY_PREVIEW)
|
||||
}
|
||||
|
||||
/** "3 de 5 clases", contando solo las sesiones que se están mostrando. */
|
||||
export function attendanceSummaryLabel(sessions: AttendanceSession[]): string {
|
||||
const present = sessions.filter((session) => session.status === 'PRESENT').length
|
||||
return `${present} de ${classCountLabel(sessions.length)}`
|
||||
/** Clases con asistencia registrada: asistió, faltó o faltó con aviso. Las
|
||||
* "Sin registrar" no cuentan: sin dato no hay ni asistencia ni ausencia, y
|
||||
* meterlas en el denominador hacía que "1 de 3" se leyera como dos ausencias. */
|
||||
function markedSessions(sessions: AttendanceSession[]): AttendanceSession[] {
|
||||
return sessions.filter((session) => session.status != null)
|
||||
}
|
||||
|
||||
export type AttendanceSummary = {
|
||||
/** "1 de 1 clase", o "Sin clases registradas" si no hay ninguna con dato. */
|
||||
label: string
|
||||
/** "2 sin registrar", o `null` si no hay clases sin registro. */
|
||||
unmarkedLabel: string | null
|
||||
}
|
||||
|
||||
/** Resumen de las filas que se están mostrando: cuántas clases registró la
|
||||
* persona sobre cuántas hay con dato, y cuántas quedaron sin registrar.
|
||||
*
|
||||
* El texto de las "sin registrar" se apaga cuando no hay ninguna clase
|
||||
* registrada: el resumen ya dice que no hay datos y los dos textos dirían lo
|
||||
* mismo dos veces. */
|
||||
export function attendanceSummary(sessions: AttendanceSession[]): AttendanceSummary {
|
||||
const marked = markedSessions(sessions)
|
||||
if (marked.length === 0) return { label: 'Sin clases registradas', unmarkedLabel: null }
|
||||
|
||||
const present = marked.filter((session) => session.status === 'PRESENT').length
|
||||
const unmarked = sessions.length - marked.length
|
||||
return {
|
||||
label: `${present} de ${classCountLabel(marked.length)}`,
|
||||
unmarkedLabel: unmarked > 0 ? `${unmarked} sin registrar` : null,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user