102 lines
3.6 KiB
TypeScript
102 lines
3.6 KiB
TypeScript
import type { StudentAtRiskDto } from '@gruperly/shared'
|
|
import { MessageCircle, MoreVertical, Pause, UserMinus } from 'lucide-react'
|
|
import { Avatar, Badge, Button } from '../../../components/ui'
|
|
import { formatPhoneDisplay } from '../../../lib/format'
|
|
|
|
export type StatusAction = { student: StudentAtRiskDto; status: 'PAUSED' | 'DROPPED' } | null
|
|
|
|
export function AtRiskStudentCard({
|
|
student,
|
|
menuOpen,
|
|
onToggleMenu,
|
|
onViewHistory,
|
|
onReengage,
|
|
onRequestStatusAction,
|
|
}: {
|
|
student: StudentAtRiskDto
|
|
menuOpen: boolean
|
|
onToggleMenu: () => void
|
|
onViewHistory: () => void
|
|
onReengage: () => void
|
|
onRequestStatusAction: (action: Exclude<StatusAction, null>) => void
|
|
}) {
|
|
return (
|
|
<li className="rounded-xl border border-border bg-surface p-4 transition-colors hover:border-accent/40">
|
|
<div className="flex items-center gap-3">
|
|
<button
|
|
type="button"
|
|
onClick={onViewHistory}
|
|
className="flex min-w-0 flex-1 items-center gap-3 text-left"
|
|
>
|
|
<Avatar name={student.fullName} />
|
|
<div className="min-w-0">
|
|
<p className="truncate text-sm font-semibold text-primary">{student.fullName}</p>
|
|
<p className="mt-0.5 text-xs text-foreground/50">
|
|
{student.phone
|
|
? `${formatPhoneDisplay(student.phone)} · `
|
|
: 'Sin teléfono · '}
|
|
{student.monthlyAttendanceRate}% de asistencia mensual
|
|
</p>
|
|
</div>
|
|
</button>
|
|
{student.riskLevel === 'HIGH' ? (
|
|
<Badge variant="danger">{student.consecutiveAbsences} faltas seguidas</Badge>
|
|
) : (
|
|
<Badge variant="warning">Baja asistencia</Badge>
|
|
)}
|
|
</div>
|
|
|
|
<div className="mt-3 flex items-center gap-2 border-t border-border pt-3">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
disabled={!student.phone}
|
|
onClick={onReengage}
|
|
className="flex-1 gap-2 border-0 bg-[#25D366] text-white hover:bg-[#1EBE5D] disabled:bg-foreground/10 disabled:text-foreground/40"
|
|
>
|
|
<MessageCircle className="size-4" />
|
|
Reenganchar por WhatsApp
|
|
</Button>
|
|
|
|
<div className="relative">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
aria-label="Gestión de la vacante"
|
|
onClick={onToggleMenu}
|
|
>
|
|
<MoreVertical className="size-4" />
|
|
</Button>
|
|
|
|
{menuOpen ? (
|
|
<>
|
|
<div
|
|
className="fixed inset-0 z-20"
|
|
onClick={onToggleMenu}
|
|
aria-hidden="true"
|
|
/>
|
|
<div className="absolute right-0 z-30 mt-1 w-44 animate-fade-in rounded-xl border border-border bg-surface p-1.5 shadow-xl">
|
|
<button
|
|
type="button"
|
|
onClick={() => onRequestStatusAction({ student, status: 'PAUSED' })}
|
|
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-primary transition-colors hover:bg-primary-soft"
|
|
>
|
|
<Pause className="size-4" />
|
|
Pausar vacante
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => onRequestStatusAction({ student, status: 'DROPPED' })}
|
|
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-danger transition-colors hover:bg-danger-soft"
|
|
>
|
|
<UserMinus className="size-4" />
|
|
Dar de baja
|
|
</button>
|
|
</div>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</li>
|
|
)
|
|
} |