Spaces:
Runtime error
Runtime error
Download frontend/src/pages/CheckInPage.tsx from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 26.9 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/pages/CheckInPage.tsx
- Command line
-
hf download hf://spaces/Talosware/talos-access/frontend/src/pages/CheckInPage.tsx
-
curl -L -o CheckInPage.tsx https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/pages/CheckInPage.tsx
26.9 kB
| import { useState, FormEvent, useEffect, useCallback, useRef } from 'react'; | |
| import { useAuthStore } from '../store/authStore'; | |
| import { checkin, checkout, getTodayCheckins, getCurrentMode, adminEarlyCheckout, type TodayCheckIn, type CurrentMode } from '../services/attendanceService'; | |
| import { Fingerprint, Clock, BarChart3, CheckCircle, AlertCircle, LogOut, Lock, Unlock, ShieldAlert, Eye } from 'lucide-react'; | |
| import HeatmapModal from '../components/HeatmapModal'; | |
| const LATE_REASONS_IN = [ | |
| 'Me levanté tarde', | |
| 'Tráfico', | |
| 'Baja recurrencia de transporte público', | |
| ]; | |
| const LATE_REASONS_OUT = [ | |
| 'Enfermedad', | |
| 'Retiro por permiso del plantel', | |
| 'Emergencia personal', | |
| ]; | |
| export default function CheckInPage() { | |
| const user = useAuthStore((s) => s.user); | |
| const isAdmin = user?.role === 'admin'; | |
| const [cardId, setCardId] = useState(''); | |
| const [mode, setMode] = useState<'in' | 'out'>('in'); | |
| const [locked, setLocked] = useState(false); | |
| const [adminUnlock, setAdminUnlock] = useState(false); | |
| const [scheduleInfo, setScheduleInfo] = useState<string | null>(null); | |
| const [exitTime, setExitTime] = useState<string | null>(null); | |
| const [todayArrivals, setTodayArrivals] = useState<TodayCheckIn[]>([]); | |
| const [message, setMessage] = useState<{ type: 'ok' | 'err'; text: string } | null>(null); | |
| const [loading, setLoading] = useState(false); | |
| const [heatmapTarget, setHeatmapTarget] = useState<{ id: number; name: string } | null>(null); | |
| const [showLateModal, setShowLateModal] = useState(false); | |
| const [pendingCardId, setPendingCardId] = useState(''); | |
| const [pendingMode, setPendingMode] = useState<'in' | 'out'>('in'); | |
| const [selectedReason, setSelectedReason] = useState(''); | |
| const [customReason, setCustomReason] = useState(''); | |
| const [showEarlyModal, setShowEarlyModal] = useState(false); | |
| const [pendingEarlyUser, setPendingEarlyUser] = useState<{ id: number; name: string } | null>(null); | |
| const [timelineTarget, setTimelineTarget] = useState<TodayCheckIn | null>(null); | |
| const pollRef = useRef<ReturnType<typeof setInterval>>(); | |
| const refreshMode = useCallback(() => { | |
| getCurrentMode().then((m: CurrentMode) => { | |
| setMode(m.mode as 'in' | 'out'); | |
| setLocked(m.locked ?? false); | |
| if (m.schedule) { | |
| setScheduleInfo(`Entrada ${m.schedule.entry} — Salida ${m.schedule.exit}`); | |
| setExitTime(m.schedule.exit); | |
| } else { | |
| setScheduleInfo(null); | |
| setExitTime(null); | |
| } | |
| }).catch(() => {}); | |
| }, []); | |
| useEffect(() => { | |
| refreshMode(); | |
| pollRef.current = setInterval(refreshMode, 30000); | |
| const onFocus = () => refreshMode(); | |
| window.addEventListener('focus', onFocus); | |
| return () => { | |
| clearInterval(pollRef.current); | |
| window.removeEventListener('focus', onFocus); | |
| }; | |
| }, [refreshMode]); | |
| const loadToday = useCallback(async () => { | |
| try { setTodayArrivals(await getTodayCheckins()); } catch { /* ignore */ } | |
| }, []); | |
| useEffect(() => { loadToday(); }, [loadToday]); | |
| const handleEarlyCheckout = async () => { | |
| if (!pendingEarlyUser) return; | |
| const reason = selectedReason === '__custom__' ? customReason : selectedReason; | |
| setLoading(true); | |
| setShowEarlyModal(false); | |
| try { | |
| await adminEarlyCheckout(pendingEarlyUser.id, reason || 'Sin especificar'); | |
| setMessage({ type: 'ok', text: `Salida temprana aprobada para ${pendingEarlyUser.name}` }); | |
| loadToday(); | |
| } catch (err: any) { | |
| setMessage({ type: 'err', text: err?.response?.data?.detail || 'Error al registrar' }); | |
| } | |
| setLoading(false); | |
| setPendingEarlyUser(null); | |
| }; | |
| const doCheckin = async (card: string, lateNote?: string) => { | |
| const result = await checkin({ card_id: card, late_note: lateNote }); | |
| const label = 'entrada'; | |
| const name = 'user_name' in result ? `${result.user_name} ${result.user_lastname}` : card; | |
| setMessage({ type: 'ok', text: `${name} — ${label} registrada` }); | |
| setCardId(''); | |
| loadToday(); | |
| if (adminUnlock) setAdminUnlock(false); | |
| }; | |
| const doCheckout = async (card: string, lateNote?: string) => { | |
| const result = await checkout(card, lateNote); | |
| const name = 'user_name' in result ? `${result.user_name} ${result.user_lastname}` : card; | |
| setMessage({ type: 'ok', text: `${name} — salida registrada` }); | |
| setCardId(''); | |
| loadToday(); | |
| if (adminUnlock) setAdminUnlock(false); | |
| }; | |
| const isEarlyCheckout = useCallback(() => { | |
| if (!exitTime) return false; | |
| const [h, m] = exitTime.split(':').map(Number); | |
| const now = new Date(); | |
| return now.getHours() * 60 + now.getMinutes() < h * 60 + m; | |
| }, [exitTime]); | |
| const handleSubmit = async (e: FormEvent) => { | |
| e.preventDefault(); | |
| if (!cardId.trim()) return; | |
| const onCampusCard = onCampus.find((a) => a.card_id === cardId.trim()); | |
| const detectedMode = onCampusCard ? 'out' : mode; | |
| if (adminUnlock || (detectedMode === 'out' && isAdmin && isEarlyCheckout())) { | |
| setPendingCardId(cardId.trim()); | |
| setPendingMode(detectedMode); | |
| setSelectedReason(''); | |
| setCustomReason(''); | |
| setShowLateModal(true); | |
| return; | |
| } | |
| setLoading(true); | |
| setMessage(null); | |
| try { | |
| if (detectedMode === 'in') await doCheckin(cardId.trim()); | |
| else await doCheckout(cardId.trim()); | |
| } catch (err: any) { | |
| setMessage({ type: 'err', text: err?.response?.data?.detail || 'Error al registrar' }); | |
| } | |
| setLoading(false); | |
| }; | |
| const confirmLateRecord = async () => { | |
| setShowLateModal(false); | |
| const reason = selectedReason === '__custom__' ? customReason : selectedReason; | |
| setLoading(true); | |
| setMessage(null); | |
| try { | |
| if (pendingMode === 'in') await doCheckin(pendingCardId, reason || 'Sin especificar'); | |
| else await doCheckout(pendingCardId, reason || 'Sin especificar'); | |
| } catch (err: any) { | |
| setMessage({ type: 'err', text: err?.response?.data?.detail || 'Error al registrar' }); | |
| } | |
| setLoading(false); | |
| }; | |
| const parseNote = (note: string | null | undefined) => { | |
| const info = { lateReason: null as string | null, lateBy: null as string | null, earlyReason: null as string | null, earlyBy: null as string | null }; | |
| if (!note) return info; | |
| const rx = /RETRASO:\s*([^|]+)/.exec(note); | |
| if (rx) { | |
| info.lateReason = rx[1].trim(); | |
| const by = rx[0].split('Check-in by '); | |
| if (by.length > 1) info.lateBy = by[1].split(' - ')[0].trim(); | |
| } | |
| const sx = /SALIDA TEMPRANA:\s*([^|]+)/.exec(note); | |
| if (sx) { | |
| info.earlyReason = sx[1].trim(); | |
| const by = sx[0].split('Check-out approved by '); | |
| if (by.length > 1) info.earlyBy = by[1].trim(); | |
| else { | |
| const by2 = sx[0].split('Check-out by '); | |
| if (by2.length > 1) info.earlyBy = by2[1].split(' - ')[0].trim(); | |
| } | |
| } | |
| return info; | |
| }; | |
| const canSwitch = !locked || adminUnlock; | |
| const onCampus = todayArrivals.filter((a) => !a.checkout_time); | |
| const leftToday = todayArrivals.filter((a) => a.checkout_time); | |
| return ( | |
| <div className="space-y-6"> | |
| <div className="flex items-center justify-between"> | |
| <h1>Control de Asistencia</h1> | |
| </div> | |
| {isAdmin && locked && ( | |
| <div className="bg-white rounded-xl shadow-sm border border-gray-200 p-4 flex items-center justify-between"> | |
| <div className="flex items-center gap-3"> | |
| <ShieldAlert size={20} className="text-amber-500" /> | |
| <div> | |
| <p className="text-sm font-medium text-gray-800">Modo administrador</p> | |
| <p className="text-xs text-gray-500">Sistema bloqueado por horario. Active el desbloqueo para forzar registros.</p> | |
| </div> | |
| </div> | |
| <button | |
| className={`px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 inline-flex items-center justify-center gap-2 ${adminUnlock ? 'bg-blue-600 text-white hover:bg-blue-700 border-blue-600' : ''}`} | |
| onClick={() => { setAdminUnlock(!adminUnlock); setMessage(null); }} | |
| > | |
| {adminUnlock ? <Unlock size={14} /> : <Lock size={14} />} | |
| {adminUnlock ? 'Desbloqueado' : 'Desbloquear'} | |
| </button> | |
| </div> | |
| )} | |
| <div className="grid grid-cols-1 lg:grid-cols-[380px_1fr] gap-6 items-start"> | |
| <div className="bg-white rounded-xl shadow-sm border border-gray-200 p-4"> | |
| <h2 className="flex items-center gap-2 mb-4"> | |
| {mode === 'in' ? <Fingerprint size={20} /> : <LogOut size={20} />} | |
| {mode === 'in' ? 'Registrar Entrada' : 'Registrar Salida'} | |
| </h2> | |
| <div className="flex gap-2 mb-3"> | |
| <button | |
| className={`px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 flex-1 justify-center inline-flex items-center gap-2 ${mode === 'in' ? 'bg-blue-600 text-white hover:bg-blue-700 border-blue-600' : ''}`} | |
| onClick={() => { if (canSwitch) { setMode('in'); setMessage(null); } }} | |
| disabled={!canSwitch && mode !== 'in'} | |
| > | |
| {locked && !adminUnlock && mode === 'in' ? <Lock size={12} /> : mode === 'in' ? <Unlock size={12} /> : null} Entrada | |
| </button> | |
| <button | |
| className={`px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 flex-1 justify-center inline-flex items-center gap-2 ${mode === 'out' ? 'bg-blue-600 text-white hover:bg-blue-700 border-blue-600' : ''}`} | |
| onClick={() => { if (canSwitch) { setMode('out'); setMessage(null); } }} | |
| disabled={!canSwitch && mode !== 'out'} | |
| > | |
| {locked && !adminUnlock && mode === 'out' ? <Lock size={12} /> : mode === 'out' ? <Unlock size={12} /> : null} Salida | |
| </button> | |
| </div> | |
| {scheduleInfo && ( | |
| <p className="text-xs text-gray-400 text-center mb-3"> | |
| {locked && !adminUnlock ? <Lock size={10} className="inline mr-1" /> : <Unlock size={10} className="inline mr-1" />} | |
| Horario: {scheduleInfo} | |
| {adminUnlock && <span className="text-amber-500 ml-1 font-medium">(forzado)</span>} | |
| </p> | |
| )} | |
| <form onSubmit={handleSubmit} className="space-y-3"> | |
| <div> | |
| <label className="block text-sm font-medium text-gray-700 mb-1">Cédula / Carnet del Estudiante</label> | |
| <input value={cardId} onChange={(e) => setCardId(e.target.value)} placeholder="Ej: CARD-7 o 12345678" required autoFocus className="w-full border border-gray-300 rounded-lg px-3 py-2" /> | |
| </div> | |
| <button type="submit" className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition text-sm w-full flex items-center justify-center gap-2 disabled:opacity-50" disabled={loading}> | |
| {loading ? 'Registrando...' : mode === 'in' ? 'Registrar Entrada' : 'Registrar Salida'} | |
| </button> | |
| </form> | |
| {message && ( | |
| <div className={`mt-3 p-3 rounded-xl flex items-center gap-2 text-sm ${message.type === 'ok' ? 'bg-green-50 text-green-700' : 'bg-red-50 text-red-700'}`}> | |
| {message.type === 'ok' ? <CheckCircle size={16} /> : <AlertCircle size={16} />} | |
| {message.text} | |
| </div> | |
| )} | |
| </div> | |
| <div className="space-y-4"> | |
| <div className="bg-white rounded-xl shadow-sm border border-gray-200 p-4"> | |
| <h3 className="flex items-center gap-2 mb-4"> | |
| <Clock size={18} /> En el Plantel ({onCampus.length}) | |
| </h3> | |
| {onCampus.length === 0 ? ( | |
| <p className="text-gray-400 text-sm text-center py-8">Nadie en el plantel</p> | |
| ) : ( | |
| <div className="overflow-x-auto"> | |
| <table className="w-full text-sm min-w-[700px] lg:min-w-0"> | |
| <thead><tr className="border-b border-gray-200 text-left text-gray-500"><th className="pb-2 font-medium pl-3 pr-2">Estudiante</th><th className="pb-2 font-medium pr-2">Sección</th><th className="pb-2 font-medium pr-2">Ingreso</th><th className="pb-2 font-medium pr-2">Tardanza</th><th className="pb-2 font-medium">Acción</th></tr></thead> | |
| <tbody> | |
| {onCampus.map((a) => ( | |
| <tr key={a.id} className="border-b border-gray-100"> | |
| <td className="py-2 font-medium pl-3 pr-2">{a.user_lastname}, {a.user_name}</td> | |
| <td className="py-2 text-gray-500 pr-2">{a.section_name || '-'}</td> | |
| <td className="py-2 text-gray-500 pr-2">{a.time_log ? new Date(a.time_log).toLocaleTimeString() : '-'}</td> | |
| <td className="py-2 pr-2"> | |
| {a.is_late ? ( | |
| <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-700" title={a.late_reason || ''}>{a.late_reason}</span> | |
| ) : '-'} | |
| </td> | |
| <td className="py-2"> | |
| <div className="flex gap-1"> | |
| <button className="px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 inline-flex items-center justify-center gap-2" title="Bitácora del día" onClick={() => setTimelineTarget(a)}> | |
| <Eye size={14} /> | |
| </button> | |
| {isAdmin && ( | |
| <button className="px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 inline-flex items-center justify-center gap-2 text-xs" title="Aprobar salida temprana" | |
| onClick={() => { | |
| setPendingEarlyUser({ id: a.user_id, name: `${a.user_lastname}, ${a.user_name}` }); | |
| setSelectedReason(''); | |
| setCustomReason(''); | |
| setShowEarlyModal(true); | |
| }}> | |
| Salida | |
| </button> | |
| )} | |
| <button className="px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 inline-flex items-center justify-center gap-2" title="Mapa de calor" onClick={() => setHeatmapTarget({ id: a.user_id, name: `${a.user_lastname}, ${a.user_name}` })}> | |
| <BarChart3 size={14} /> | |
| </button> | |
| </div> | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </div> | |
| )} | |
| </div> | |
| {leftToday.length > 0 && ( | |
| <div className="bg-white rounded-xl shadow-sm border border-gray-200 p-4"> | |
| <h3 className="flex items-center gap-2 mb-4 text-gray-400"><LogOut size={18} /> Salieron Hoy ({leftToday.length})</h3> | |
| <div className="overflow-x-auto"> | |
| <table className="w-full text-sm min-w-[700px] lg:min-w-0"> | |
| <thead><tr className="border-b border-gray-200 text-left text-gray-500"><th className="pb-2 font-medium pl-3 pr-2">Estudiante</th><th className="pb-2 font-medium pr-2">Entrada</th><th className="pb-2 font-medium pr-2">Salida</th><th className="pb-2 font-medium pr-2">Motivo</th><th className="pb-2 font-medium"></th></tr></thead> | |
| <tbody> | |
| {leftToday.map((a) => ( | |
| <tr key={a.id} className="border-b border-gray-100"> | |
| <td className="py-2 font-medium pl-3 pr-2">{a.user_lastname}, {a.user_name}</td> | |
| <td className="py-2 text-gray-500 pr-2">{a.time_log ? new Date(a.time_log).toLocaleTimeString() : '-'}</td> | |
| <td className="py-2 text-gray-500 pr-2">{a.checkout_time ? new Date(a.checkout_time).toLocaleTimeString() : '-'}</td> | |
| <td className="py-2 pr-2"> | |
| {a.is_late ? ( | |
| <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-700" title={a.late_reason || ''}>{a.late_reason}</span> | |
| ) : '-'} | |
| </td> | |
| <td className="py-2"> | |
| <button className="px-3 py-1.5 bg-gray-50 border border-gray-200 rounded-lg text-sm hover:bg-blue-50 hover:border-blue-300 transition-colors disabled:opacity-30 inline-flex items-center justify-center gap-2" title="Bitácora del día" onClick={() => setTimelineTarget(a)}> | |
| <Eye size={14} /> | |
| </button> | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| {/* Late note modal */} | |
| {showLateModal && ( | |
| <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onClick={() => setShowLateModal(false)}> | |
| <div className="bg-white rounded-2xl shadow-2xl max-w-md w-full max-h-[90vh] overflow-y-auto" onClick={(e) => e.stopPropagation()}> | |
| <div className="sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between rounded-t-2xl"> | |
| <h2 className="text-xl font-bold">{pendingMode === 'in' ? 'Registro fuera de horario' : 'Salida temprana'}</h2> | |
| <button onClick={() => setShowLateModal(false)} className="text-gray-400 hover:text-gray-600 text-2xl leading-none">×</button> | |
| </div> | |
| <div className="p-6 space-y-6"> | |
| <p className="text-sm text-gray-500">{pendingMode === 'in' ? 'Seleccione el motivo del retraso:' : 'Seleccione el motivo del retiro temprano:'}</p> | |
| <div className="space-y-2"> | |
| {(pendingMode === 'in' ? LATE_REASONS_IN : LATE_REASONS_OUT).map((reason) => ( | |
| <label key={reason} className="flex items-center gap-3 p-3 rounded-xl border border-gray-200 cursor-pointer hover:bg-gray-50 transition"> | |
| <input type="radio" name="late_reason" value={reason} checked={selectedReason === reason} onChange={() => setSelectedReason(reason)} className="accent-blue-500" /> | |
| <span className="text-sm text-gray-700">{reason}</span> | |
| </label> | |
| ))} | |
| <label className="flex items-center gap-3 p-3 rounded-xl border border-gray-200 cursor-pointer hover:bg-gray-50 transition"> | |
| <input type="radio" name="late_reason" value="__custom__" checked={selectedReason === '__custom__'} onChange={() => setSelectedReason('__custom__')} className="accent-blue-500" /> | |
| <span className="text-sm text-gray-700">Otro:</span> | |
| </label> | |
| </div> | |
| {selectedReason === '__custom__' && ( | |
| <input value={customReason} onChange={(e) => setCustomReason(e.target.value)} placeholder="Especifique el motivo..." className="w-full border border-gray-300 rounded-lg px-3 py-2" autoFocus /> | |
| )} | |
| <div className="flex justify-end gap-2"> | |
| <button className="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition text-sm inline-flex items-center justify-center gap-2" onClick={() => setShowLateModal(false)}>Cancelar</button> | |
| <button className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition text-sm inline-flex items-center justify-center gap-2 disabled:opacity-50" onClick={confirmLateRecord} disabled={loading}> | |
| {loading ? 'Registrando...' : 'Confirmar'} | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {showEarlyModal && ( | |
| <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onClick={() => setShowEarlyModal(false)}> | |
| <div className="bg-white rounded-2xl shadow-2xl max-w-md w-full max-h-[90vh] overflow-y-auto" onClick={(e) => e.stopPropagation()}> | |
| <div className="sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between rounded-t-2xl"> | |
| <h2 className="text-xl font-bold">Aprobar salida temprana</h2> | |
| <button onClick={() => setShowEarlyModal(false)} className="text-gray-400 hover:text-gray-600 text-2xl leading-none">×</button> | |
| </div> | |
| <div className="p-6 space-y-6"> | |
| <p className="text-sm text-gray-500">Estudiante: <strong>{pendingEarlyUser?.name}</strong></p> | |
| <p className="text-sm text-gray-500">Seleccione el motivo del retiro temprano:</p> | |
| <div className="space-y-2"> | |
| {LATE_REASONS_OUT.map((reason) => ( | |
| <label key={reason} className="flex items-center gap-3 p-3 rounded-xl border border-gray-200 cursor-pointer hover:bg-gray-50 transition"> | |
| <input type="radio" name="early_reason" value={reason} checked={selectedReason === reason} onChange={() => setSelectedReason(reason)} className="accent-blue-500" /> | |
| <span className="text-sm text-gray-700">{reason}</span> | |
| </label> | |
| ))} | |
| <label className="flex items-center gap-3 p-3 rounded-xl border border-gray-200 cursor-pointer hover:bg-gray-50 transition"> | |
| <input type="radio" name="early_reason" value="__custom__" checked={selectedReason === '__custom__'} onChange={() => setSelectedReason('__custom__')} className="accent-blue-500" /> | |
| <span className="text-sm text-gray-700">Otro:</span> | |
| </label> | |
| </div> | |
| {selectedReason === '__custom__' && ( | |
| <input value={customReason} onChange={(e) => setCustomReason(e.target.value)} placeholder="Especifique el motivo..." className="w-full border border-gray-300 rounded-lg px-3 py-2" autoFocus /> | |
| )} | |
| <div className="flex justify-end gap-2"> | |
| <button className="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition text-sm inline-flex items-center justify-center gap-2" onClick={() => setShowEarlyModal(false)}>Cancelar</button> | |
| <button className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition text-sm inline-flex items-center justify-center gap-2 disabled:opacity-50" onClick={handleEarlyCheckout} disabled={loading}> | |
| {loading ? 'Registrando...' : 'Confirmar salida'} | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {timelineTarget && ( | |
| <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onClick={() => setTimelineTarget(null)}> | |
| <div className="bg-white rounded-2xl shadow-2xl max-w-md w-full max-h-[90vh] overflow-y-auto" onClick={(e) => e.stopPropagation()}> | |
| <div className="sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between rounded-t-2xl"> | |
| <h2 className="text-xl font-bold">Bitácora del día</h2> | |
| <button onClick={() => setTimelineTarget(null)} className="text-gray-400 hover:text-gray-600 text-2xl leading-none">×</button> | |
| </div> | |
| <div className="p-6 space-y-6"> | |
| <p className="text-sm text-gray-500">{timelineTarget.user_lastname}, {timelineTarget.user_name}</p> | |
| <div className="relative pl-8 space-y-6"> | |
| <div className="absolute left-[11px] top-2 bottom-2 w-0.5 bg-gray-200" /> | |
| <div className="relative"> | |
| <div className="absolute -left-[21px] top-1 w-3 h-3 rounded-full bg-emerald-500 ring-2 ring-white" /> | |
| <p className="text-sm font-medium text-emerald-700">Ingreso</p> | |
| <p className="text-xs text-gray-500">{timelineTarget.time_log ? new Date(timelineTarget.time_log).toLocaleTimeString() : '-'}</p> | |
| {(() => { | |
| const info = parseNote(timelineTarget.note); | |
| return info.lateReason ? ( | |
| <div className="mt-1 p-2 rounded-lg bg-amber-50 border border-amber-200"> | |
| <p className="text-xs text-amber-700 font-medium">Retraso: {info.lateReason}</p> | |
| {info.lateBy && <p className="text-xs text-amber-500">Autorizado por: {info.lateBy}</p>} | |
| </div> | |
| ) : null; | |
| })()} | |
| </div> | |
| <div className="relative"> | |
| <div className="absolute -left-[21px] top-1 w-3 h-3 rounded-full bg-gray-400 ring-2 ring-white" /> | |
| <p className="text-sm font-medium text-gray-600">Salida</p> | |
| <p className="text-xs text-gray-500">{timelineTarget.checkout_time ? new Date(timelineTarget.checkout_time).toLocaleTimeString() : 'Aún en el plantel'}</p> | |
| {(() => { | |
| const info = parseNote(timelineTarget.note); | |
| return info.earlyReason ? ( | |
| <div className="mt-1 p-2 rounded-lg bg-blue-50 border border-blue-200"> | |
| <p className="text-xs text-blue-700 font-medium">Salida temprana: {info.earlyReason}</p> | |
| {info.earlyBy && <p className="text-xs text-blue-500">Aprobado por: {info.earlyBy}</p>} | |
| </div> | |
| ) : null; | |
| })()} | |
| </div> | |
| </div> | |
| <div className="flex justify-end"> | |
| <button className="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition text-sm inline-flex items-center justify-center gap-2" onClick={() => setTimelineTarget(null)}>Cerrar</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {heatmapTarget && ( | |
| <HeatmapModal studentId={heatmapTarget.id} studentName={heatmapTarget.name} onClose={() => setHeatmapTarget(null)} /> | |
| )} | |
| </div> | |
| ); | |
| } | |