Spaces:
Runtime error
Runtime error
File size: 3,844 Bytes
099a820 413032b 099a820 413032b 099a820 e3aabbe 099a820 e3aabbe 099a820 413032b 099a820 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | import { useState, useEffect } from 'react';
import { listSectionSchedules, type SectionSchedule } from '../services/sectionScheduleService';
import LoadingState from './LoadingState';
import ScheduleGrid from './ScheduleGrid';
import { useAuthStore } from '../store/authStore';
export interface ScheduleViewerModalProps {
open: boolean;
sectionId: number;
sectionName: string;
academicPeriod?: string | null;
onClose: () => void;
}
export default function ScheduleViewerModal({
open,
sectionId,
sectionName,
academicPeriod,
onClose,
}: ScheduleViewerModalProps) {
const [items, setItems] = useState<SectionSchedule[]>([]);
const [loading, setLoading] = useState(false);
const organizationName = useAuthStore((s) => s.user?.organization_name || '');
useEffect(() => {
if (!open) return;
setLoading(true);
listSectionSchedules(sectionId)
.then(setItems)
.catch(() => setItems([]))
.finally(() => setLoading(false));
}, [open, sectionId]);
if (!open) return null;
const printDate = new Date().toLocaleDateString('es-VE', {
day: '2-digit',
month: 'long',
year: 'numeric',
});
return (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4 print-overlay"
onClick={onClose}
>
<div
className="bg-white rounded-2xl shadow-2xl max-w-5xl w-full max-h-[90vh] flex flex-col print-modal-box"
onClick={(e) => e.stopPropagation()}
>
{/* Modal header — hidden in print */}
<div className="no-print sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between rounded-t-2xl shrink-0">
<div>
<h2 className="text-xl font-bold">Horario — {sectionName}</h2>
{academicPeriod && (
<p className="text-sm text-gray-400 mt-0.5">{academicPeriod}</p>
)}
</div>
<button
onClick={onClose}
className="text-gray-400 hover:text-gray-600 text-2xl leading-none"
aria-label="Cerrar"
>
×
</button>
</div>
{/* Printable grid area */}
<div className="schedule-print-area p-4 overflow-auto flex-1">
{/* Print-only title: school name primary, section as subtitle */}
<div className="hidden print:block text-center mb-2">
{organizationName && <h1 className="text-lg font-bold leading-tight">{organizationName}</h1>}
<p className="text-sm text-gray-700 leading-tight">
Horario — {sectionName}
{academicPeriod ? ` · ${academicPeriod}` : ''}
</p>
<p className="text-[10px] text-gray-400">Generado: {printDate}</p>
</div>
{loading ? (
<div className="flex items-center justify-center py-24">
<LoadingState />
</div>
) : items.length === 0 ? (
<p className="text-center text-gray-400 py-16">Sin bloques de horario registrados.</p>
) : (
<ScheduleGrid items={items} compact />
)}
</div>
{/* Modal footer — hidden in print */}
<div className="no-print sticky bottom-0 bg-white border-t border-gray-200 px-6 py-4 flex items-center justify-end gap-3 rounded-b-2xl shrink-0">
<button
onClick={onClose}
className="px-4 py-2 rounded-lg border border-gray-300 text-gray-600 hover:bg-gray-50 transition text-sm"
>
Cerrar
</button>
<button
onClick={() => window.print()}
className="px-4 py-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700 transition text-sm"
>
Descargar PDF
</button>
</div>
</div>
</div>
);
}
|