feat: enhance group management features with improved attendance tracking and UI components
This commit is contained in:
@@ -17,6 +17,15 @@ export type GroupLike = Pick<GroupListItem, 'attendeesCount' | 'capacity'>
|
||||
* proporcionales. */
|
||||
export const SEGMENTED_CAPACITY_MAX = 10
|
||||
|
||||
export type MemberStatus = 'high_risk' | 'attention' | 'ok'
|
||||
|
||||
export type GroupMember = {
|
||||
id: string
|
||||
name: string
|
||||
status: MemberStatus
|
||||
absences: number
|
||||
}
|
||||
|
||||
export type CapacityCounts = {
|
||||
riesgoAlto: number
|
||||
atencion: number
|
||||
@@ -24,6 +33,128 @@ export type CapacityCounts = {
|
||||
libres: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Conteos derivados directamente de una lista de miembros y el cupo.
|
||||
*/
|
||||
export function capacityCountsFromMembers(
|
||||
members: GroupMember[],
|
||||
capacity: number,
|
||||
): CapacityCounts {
|
||||
let riesgoAlto = 0
|
||||
let atencion = 0
|
||||
let ok = 0
|
||||
|
||||
for (const m of members) {
|
||||
if (m.status === 'high_risk') riesgoAlto++
|
||||
else if (m.status === 'attention') atencion++
|
||||
else ok++
|
||||
}
|
||||
|
||||
const libres = Math.max(capacity - members.length, 0)
|
||||
|
||||
return {
|
||||
riesgoAlto,
|
||||
atencion,
|
||||
ok,
|
||||
libres,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reglas de texto de alerta a partir de los miembros:
|
||||
* - 1 en riesgo alto: "{Nombre}: {N} faltas" + (si hay atención > 0) " · {K} en atención"
|
||||
* - 2 o más en riesgo alto: "{N} en riesgo alto" + (si hay atención > 0) " · {K} en atención"
|
||||
* - 0 en riesgo alto pero atención > 0: "{K} en atención"
|
||||
* - Ninguno: null
|
||||
*/
|
||||
export function alertTextFromMembers(members: GroupMember[]): string | null {
|
||||
const highRisk = members.filter((m) => m.status === 'high_risk')
|
||||
const attention = members.filter((m) => m.status === 'attention')
|
||||
|
||||
const kAtencion = attention.length > 0 ? ` · ${attention.length} en atención` : ''
|
||||
|
||||
if (highRisk.length === 1) {
|
||||
const first = highRisk[0]
|
||||
const nombre = firstName(first.name)
|
||||
const faltas = `${first.absences} ${first.absences === 1 ? 'falta' : 'faltas'}`
|
||||
return `${nombre}: ${faltas}${kAtencion}`
|
||||
}
|
||||
|
||||
if (highRisk.length >= 2) {
|
||||
return `${highRisk.length} en riesgo alto${kAtencion}`
|
||||
}
|
||||
|
||||
if (attention.length > 0) {
|
||||
return `${attention.length} en atención`
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Convierte un GroupListItem y GroupRiskSummary en una lista de GroupMember
|
||||
* para unificar la representación interna.
|
||||
*/
|
||||
export function membersFromGroupAndRisk(
|
||||
group: Pick<GroupListItem, 'attendeesCount' | 'capacity'>,
|
||||
risk: GroupRiskSummary | undefined,
|
||||
): GroupMember[] {
|
||||
const members: GroupMember[] = []
|
||||
const urgentes = risk?.urgentes ?? []
|
||||
|
||||
for (const u of urgentes) {
|
||||
if (u.level === 'riesgo_alto') {
|
||||
members.push({
|
||||
id: u.attendeeId,
|
||||
name: u.fullName,
|
||||
status: 'high_risk',
|
||||
absences: u.consecutiveAbsences,
|
||||
})
|
||||
} else if (u.level === 'atencion') {
|
||||
members.push({
|
||||
id: u.attendeeId,
|
||||
name: u.fullName,
|
||||
status: 'attention',
|
||||
absences: u.consecutiveAbsences,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const currentHigh = members.filter((m) => m.status === 'high_risk').length
|
||||
const remainingHigh = Math.max((risk?.riesgoAlto ?? 0) - currentHigh, 0)
|
||||
for (let i = 0; i < remainingHigh; i++) {
|
||||
members.push({
|
||||
id: `high-risk-extra-${i}`,
|
||||
name: `Alumno ${members.length + 1}`,
|
||||
status: 'high_risk',
|
||||
absences: 1,
|
||||
})
|
||||
}
|
||||
|
||||
const currentAttention = members.filter((m) => m.status === 'attention').length
|
||||
const remainingAttention = Math.max((risk?.atencion ?? 0) - currentAttention, 0)
|
||||
for (let i = 0; i < remainingAttention; i++) {
|
||||
members.push({
|
||||
id: `attention-extra-${i}`,
|
||||
name: `Alumno ${members.length + 1}`,
|
||||
status: 'attention',
|
||||
absences: 0,
|
||||
})
|
||||
}
|
||||
|
||||
const remainingOk = Math.max(group.attendeesCount - members.length, 0)
|
||||
for (let i = 0; i < remainingOk; i++) {
|
||||
members.push({
|
||||
id: `ok-${i}`,
|
||||
name: `Alumno ${members.length + 1}`,
|
||||
status: 'ok',
|
||||
absences: 0,
|
||||
})
|
||||
}
|
||||
|
||||
return members
|
||||
}
|
||||
|
||||
/**
|
||||
* Conteos que consume el indicador de cupo y asistencia.
|
||||
*
|
||||
@@ -154,3 +285,57 @@ function firstName(fullName: string): string {
|
||||
function membersLabel(count: number): string {
|
||||
return count === 1 ? '1 miembro' : `${count} miembros`
|
||||
}
|
||||
|
||||
/**
|
||||
* Casos de prueba solicitados para verificación contra la imagen de referencia.
|
||||
*/
|
||||
export const MOCK_TEST_CASES = [
|
||||
{
|
||||
id: 'mock-tai-chi',
|
||||
name: 'Tai Chi Martes',
|
||||
capacity: 5,
|
||||
members: [
|
||||
{ id: 'tc-1', name: 'Sofía Ramírez', status: 'high_risk' as const, absences: 4 },
|
||||
{ id: 'tc-2', name: 'Lucas Rossi', status: 'attention' as const, absences: 1 },
|
||||
{ id: 'tc-3', name: 'Martín Paz', status: 'ok' as const, absences: 0 },
|
||||
{ id: 'tc-4', name: 'Elena Gómez', status: 'ok' as const, absences: 0 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'mock-pilates',
|
||||
name: 'Pilates Sábado',
|
||||
capacity: 15,
|
||||
members: [
|
||||
{ id: 'p-1', name: 'Sofía Ramírez', status: 'high_risk' as const, absences: 4 },
|
||||
{ id: 'p-2', name: 'Lucas Rossi', status: 'attention' as const, absences: 1 },
|
||||
{ id: 'p-3', name: 'Mateo Díaz', status: 'attention' as const, absences: 1 },
|
||||
...Array.from({ length: 9 }, (_, i) => ({
|
||||
id: `p-ok-${i}`,
|
||||
name: `Alumno ${i + 1}`,
|
||||
status: 'ok' as const,
|
||||
absences: 0,
|
||||
})),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'mock-natacion',
|
||||
name: 'Natación Adultos',
|
||||
capacity: 30,
|
||||
members: [
|
||||
{ id: 'n-1', name: 'Alumno 1', status: 'high_risk' as const, absences: 3 },
|
||||
{ id: 'n-2', name: 'Alumno 2', status: 'high_risk' as const, absences: 2 },
|
||||
{ id: 'n-3', name: 'Alumno 3', status: 'high_risk' as const, absences: 4 },
|
||||
{ id: 'n-4', name: 'Alumno 4', status: 'attention' as const, absences: 1 },
|
||||
{ id: 'n-5', name: 'Alumno 5', status: 'attention' as const, absences: 1 },
|
||||
{ id: 'n-6', name: 'Alumno 6', status: 'attention' as const, absences: 2 },
|
||||
{ id: 'n-7', name: 'Alumno 7', status: 'attention' as const, absences: 1 },
|
||||
...Array.from({ length: 15 }, (_, i) => ({
|
||||
id: `n-ok-${i}`,
|
||||
name: `Alumno ${i + 8}`,
|
||||
status: 'ok' as const,
|
||||
absences: 0,
|
||||
})),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user