feat: una sola regla de riesgo y preinscripciones pendientes en Inicio
- Estadísticas ("Alumnos en riesgo") y el job de reenganche usan la misma
regla de dominio que la lista de grupos e Inicio
(summarizeMemberAttendance). El armado del historial por alumno vive en
analytics/lib/member-attendance.ts y se borra el clasificador viejo
(racha o asistencia mensual < 50%).
- El badge de alumnos en riesgo muestra el motivo real (faltas seguidas,
días sin venir o asistencia en baja).
- GET /home devuelve pendingPreRegistrations por grupo (en la misma
consulta de grupos) y "Para atender" las lista con link a la ficha en
la pestaña Pendientes (?section=pending).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -185,7 +185,7 @@ export function AnalyticsView() {
|
||||
) : null}
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-foreground/60">
|
||||
Alumnos con ausencias consecutivas o baja asistencia mensual.
|
||||
Alumnos con faltas seguidas, que dejaron de venir o cuya asistencia viene en baja.
|
||||
</p>
|
||||
|
||||
{atRisk.length === 0 ? (
|
||||
|
||||
@@ -39,11 +39,9 @@ export function AtRiskStudentCard({
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
{student.riskLevel === 'HIGH' ? (
|
||||
<Badge variant="danger">{student.consecutiveAbsences} faltas seguidas</Badge>
|
||||
) : (
|
||||
<Badge variant="warning">Baja asistencia</Badge>
|
||||
)}
|
||||
<Badge variant={student.riskLevel === 'HIGH' ? 'danger' : 'warning'}>
|
||||
{riskReason(student)}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex items-center gap-2 border-t border-border pt-3">
|
||||
@@ -99,4 +97,18 @@ export function AtRiskStudentCard({
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const DAY_MS = 86_400_000
|
||||
|
||||
/* The same reasons the domain rule weighs, in its order: an absence streak,
|
||||
then the time without coming, and last the declining trend (the only thing
|
||||
left that can flag someone with neither). */
|
||||
function riskReason(student: StudentAtRiskDto): string {
|
||||
if (student.consecutiveAbsences >= 2) return `${student.consecutiveAbsences} faltas seguidas`
|
||||
if (student.riskLevel === 'HIGH' && student.lastAttendedAt) {
|
||||
const days = Math.floor((Date.now() - new Date(student.lastAttendedAt).getTime()) / DAY_MS)
|
||||
return `${days} días sin venir`
|
||||
}
|
||||
return 'Asistencia en baja'
|
||||
}
|
||||
|
||||
@@ -91,13 +91,22 @@ type GroupDetailContextValue = {
|
||||
|
||||
const GroupDetailContext = createContext<GroupDetailContextValue | null>(null)
|
||||
|
||||
export function GroupDetailProvider({ groupId, children }: { groupId: string; children: ReactNode }) {
|
||||
export function GroupDetailProvider({
|
||||
groupId,
|
||||
initialSection = 'members',
|
||||
children,
|
||||
}: {
|
||||
groupId: string
|
||||
/** Lets a link open the detail straight on Pendientes (Home's "Para atender"). */
|
||||
initialSection?: ListSection
|
||||
children: ReactNode
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const toast = useToast()
|
||||
const { user } = useAuth()
|
||||
|
||||
const [isInviteModalOpen, setIsInviteModalOpen] = useState(false)
|
||||
const [listSection, setListSectionState] = useState<ListSection>('members')
|
||||
const [listSection, setListSectionState] = useState<ListSection>(initialSection)
|
||||
const [attendeeToRemove, setAttendeeToRemove] = useState<AttendeeDto | null>(null)
|
||||
const [selectedWaitlistEntry, setSelectedWaitlistEntry] = useState<GroupWaitlistEntryDto | null>(null)
|
||||
const [selectedPreRegistration, setSelectedPreRegistration] = useState<GroupPreRegistrationDto | null>(null)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { CheckCircle2, ChevronRight, Wallet } from 'lucide-react'
|
||||
import type { PendingPreRegistrations } from '@gruperly/shared'
|
||||
import { CheckCircle2, ChevronRight, Inbox, Wallet } from 'lucide-react'
|
||||
import { Avatar } from '../../components/ui'
|
||||
import { getGroupsRiskOverview, getPayments } from '../../lib/api'
|
||||
import { absenceReason } from '../groups/card'
|
||||
@@ -11,8 +12,13 @@ const MAX_AT_RISK = 4
|
||||
/* "Para atender": what the teacher has to act on today, across all groups.
|
||||
Nothing is computed here: the at-risk people are the high-risk `urgentes` of
|
||||
`GET /groups-risk/overview` (same query key as the group list, so the cache
|
||||
is shared) and the overdue payments are just the total of the filtered list. */
|
||||
export function AttentionList() {
|
||||
is shared), the overdue payments are just the total of the filtered list and
|
||||
the pending pre-registrations come with the Home summary. */
|
||||
export function AttentionList({
|
||||
pendingPreRegistrations,
|
||||
}: {
|
||||
pendingPreRegistrations: PendingPreRegistrations[]
|
||||
}) {
|
||||
const riskQuery = useQuery({
|
||||
queryKey: ['groups-risk-overview'],
|
||||
queryFn: getGroupsRiskOverview,
|
||||
@@ -41,10 +47,10 @@ export function AttentionList() {
|
||||
<div>
|
||||
<h2 className="text-lg font-bold text-primary">Para atender</h2>
|
||||
|
||||
{atRisk.length === 0 && overdue === 0 ? (
|
||||
{atRisk.length === 0 && overdue === 0 && pendingPreRegistrations.length === 0 ? (
|
||||
<p className="mt-3 flex items-center gap-2 rounded-xl border border-border bg-surface px-4 py-3 text-sm text-foreground/70">
|
||||
<CheckCircle2 className="size-4 shrink-0 text-success" aria-hidden="true" />
|
||||
Todo en orden: nadie en riesgo y sin cobros vencidos.
|
||||
Todo en orden: nadie en riesgo, sin cobros vencidos ni preinscripciones.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="mt-3 divide-y divide-border overflow-hidden rounded-xl border border-border bg-surface">
|
||||
@@ -65,6 +71,32 @@ export function AttentionList() {
|
||||
</li>
|
||||
) : null}
|
||||
|
||||
{/* Someone waiting for an answer goes before the at-risk list: it's
|
||||
the only item where the other side is actively waiting. */}
|
||||
{pendingPreRegistrations.map((group) => (
|
||||
<li key={group.groupId}>
|
||||
<Link
|
||||
to="/groups/$groupId"
|
||||
params={{ groupId: group.groupId }}
|
||||
search={{ section: 'pending' }}
|
||||
className={ROW_CLASS_NAME}
|
||||
>
|
||||
<span className="flex size-10 shrink-0 items-center justify-center rounded-full bg-accent-soft text-accent">
|
||||
<Inbox className="size-5" aria-hidden="true" />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block text-sm font-semibold text-primary">
|
||||
{group.count === 1
|
||||
? '1 preinscripción por aprobar'
|
||||
: `${group.count} preinscripciones por aprobar`}
|
||||
</span>
|
||||
<span className="block truncate text-xs text-foreground/60">{group.groupName}</span>
|
||||
</span>
|
||||
<ChevronRight className="size-4 shrink-0 text-foreground/40" aria-hidden="true" />
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
|
||||
{atRisk.slice(0, MAX_AT_RISK).map((member) => (
|
||||
<li key={member.attendeeId}>
|
||||
<Link
|
||||
|
||||
@@ -95,7 +95,7 @@ export function HomeView() {
|
||||
|
||||
<SummaryStats summary={summaryQuery.data} />
|
||||
|
||||
<AttentionList />
|
||||
<AttentionList pendingPreRegistrations={summaryQuery.data.pendingPreRegistrations} />
|
||||
|
||||
<div>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
|
||||
Reference in New Issue
Block a user