Greg Claude Opus 4.7 (1M context) commited on
Commit
257cf06
·
1 Parent(s): c11bebb

feat(ui): show spinner during list page load instead of empty-state

Browse files

10 list pages now display a LoadingState spinner on mount while data fetches,
preventing the misleading "No hay registros" flash before results arrive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

frontend/src/pages/AttendanceReportsPage.tsx CHANGED
@@ -5,9 +5,11 @@ import type { User } from '../types';
5
  import { BarChart3, Search, Download } from 'lucide-react';
6
  import { translateRole } from '../utils/roles';
7
  import HeatmapModal from '../components/HeatmapModal';
 
8
 
9
  export default function AttendanceReportsPage() {
10
  const [items, setItems] = useState<Attendance[]>([]);
 
11
  const [total, setTotal] = useState(0);
12
  const [page, setPage] = useState(1);
13
  const [totalPages, setTotalPages] = useState(1);
@@ -24,6 +26,7 @@ export default function AttendanceReportsPage() {
24
  }, []);
25
 
26
  const loadAttendances = useCallback(async () => {
 
27
  try {
28
  const atts = await listAttendances({
29
  page, per_page: 20,
@@ -34,7 +37,9 @@ export default function AttendanceReportsPage() {
34
  type: tab !== 'all' ? tab : undefined,
35
  });
36
  setItems(atts.items); setTotal(atts.total); setPage(atts.page); setTotalPages(atts.total_pages);
37
- } catch { /* ignore */ }
 
 
38
  }, [page, filters, selectedStudent, tab]);
39
 
40
  useEffect(() => { load(); }, [load]);
@@ -127,7 +132,11 @@ export default function AttendanceReportsPage() {
127
  </tr>
128
  </thead>
129
  <tbody>
130
- {items.length === 0 && <tr><td colSpan={8} className="text-gray-400 text-sm text-center py-8">Sin registros de asistencia</td></tr>}
 
 
 
 
131
  {items.map((a) => {
132
  const fmt = (s?: string | null) => s ? new Date(s).toLocaleString('es-VE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false }) : null;
133
  return (
 
5
  import { BarChart3, Search, Download } from 'lucide-react';
6
  import { translateRole } from '../utils/roles';
7
  import HeatmapModal from '../components/HeatmapModal';
8
+ import LoadingState from '../components/LoadingState';
9
 
10
  export default function AttendanceReportsPage() {
11
  const [items, setItems] = useState<Attendance[]>([]);
12
+ const [loading, setLoading] = useState(true);
13
  const [total, setTotal] = useState(0);
14
  const [page, setPage] = useState(1);
15
  const [totalPages, setTotalPages] = useState(1);
 
26
  }, []);
27
 
28
  const loadAttendances = useCallback(async () => {
29
+ setLoading(true);
30
  try {
31
  const atts = await listAttendances({
32
  page, per_page: 20,
 
37
  type: tab !== 'all' ? tab : undefined,
38
  });
39
  setItems(atts.items); setTotal(atts.total); setPage(atts.page); setTotalPages(atts.total_pages);
40
+ } catch { /* ignore */ } finally {
41
+ setLoading(false);
42
+ }
43
  }, [page, filters, selectedStudent, tab]);
44
 
45
  useEffect(() => { load(); }, [load]);
 
132
  </tr>
133
  </thead>
134
  <tbody>
135
+ {loading ? (
136
+ <tr><td colSpan={8}><LoadingState /></td></tr>
137
+ ) : items.length === 0 ? (
138
+ <tr><td colSpan={8} className="text-gray-400 text-sm text-center py-8">Sin registros de asistencia</td></tr>
139
+ ) : null}
140
  {items.map((a) => {
141
  const fmt = (s?: string | null) => s ? new Date(s).toLocaleString('es-VE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false }) : null;
142
  return (
frontend/src/pages/AuditLogsPage.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { useState, useEffect } from 'react';
2
  import api from '../services/api';
3
  import { Search } from 'lucide-react';
 
4
 
5
  interface AuditLog {
6
  id: number;
@@ -16,6 +17,7 @@ interface AuditLog {
16
 
17
  export default function AuditLogsPage() {
18
  const [logs, setLogs] = useState<AuditLog[]>([]);
 
19
  const [total, setTotal] = useState(0);
20
  const [page, setPage] = useState(1);
21
  const [totalPages, setTotalPages] = useState(1);
@@ -23,6 +25,7 @@ export default function AuditLogsPage() {
23
  const [dateFrom, setDateFrom] = useState('');
24
 
25
  const load = async () => {
 
26
  try {
27
  const params = new URLSearchParams({ page: String(page), per_page: '50' });
28
  if (actionFilter) params.set('action', actionFilter);
@@ -32,7 +35,9 @@ export default function AuditLogsPage() {
32
  setTotal(data.total);
33
  setPage(data.page);
34
  setTotalPages(data.total_pages);
35
- } catch { /* ignore */ }
 
 
36
  };
37
 
38
  useEffect(() => { load(); }, [page, actionFilter, dateFrom]);
@@ -76,7 +81,9 @@ export default function AuditLogsPage() {
76
  </div>
77
 
78
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
79
- {logs.length === 0 ? (
 
 
80
  <div className="text-center text-gray-400 py-12 text-sm">No se encontraron registros de auditoría</div>
81
  ) : (
82
  <div className="overflow-x-auto">
 
1
  import { useState, useEffect } from 'react';
2
  import api from '../services/api';
3
  import { Search } from 'lucide-react';
4
+ import LoadingState from '../components/LoadingState';
5
 
6
  interface AuditLog {
7
  id: number;
 
17
 
18
  export default function AuditLogsPage() {
19
  const [logs, setLogs] = useState<AuditLog[]>([]);
20
+ const [loading, setLoading] = useState(true);
21
  const [total, setTotal] = useState(0);
22
  const [page, setPage] = useState(1);
23
  const [totalPages, setTotalPages] = useState(1);
 
25
  const [dateFrom, setDateFrom] = useState('');
26
 
27
  const load = async () => {
28
+ setLoading(true);
29
  try {
30
  const params = new URLSearchParams({ page: String(page), per_page: '50' });
31
  if (actionFilter) params.set('action', actionFilter);
 
35
  setTotal(data.total);
36
  setPage(data.page);
37
  setTotalPages(data.total_pages);
38
+ } catch { /* ignore */ } finally {
39
+ setLoading(false);
40
+ }
41
  };
42
 
43
  useEffect(() => { load(); }, [page, actionFilter, dateFrom]);
 
81
  </div>
82
 
83
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
84
+ {loading ? (
85
+ <LoadingState />
86
+ ) : logs.length === 0 ? (
87
  <div className="text-center text-gray-400 py-12 text-sm">No se encontraron registros de auditoría</div>
88
  ) : (
89
  <div className="overflow-x-auto">
frontend/src/pages/CardTemplatesPage.tsx CHANGED
@@ -1,19 +1,26 @@
1
  import { useState, useEffect } from 'react';
2
  import { useNavigate } from 'react-router-dom';
3
  import { Plus, Pencil, Trash2, QrCode, Download } from 'lucide-react';
 
4
  import { listCardTemplates, deleteCardTemplate } from '../services/cardTemplateService';
5
  import type { CardTemplate } from '../types';
6
 
7
  export default function CardTemplatesPage() {
8
  const navigate = useNavigate();
9
  const [templates, setTemplates] = useState<CardTemplate[]>([]);
 
10
  const [page, setPage] = useState(1);
11
  const [totalPages, setTotalPages] = useState(1);
12
 
13
  const load = async () => {
14
- const res = await listCardTemplates({ page, per_page: 20 });
15
- setTemplates(res.items);
16
- setTotalPages(res.total_pages);
 
 
 
 
 
17
  };
18
 
19
  useEffect(() => { load(); }, [page]);
@@ -50,9 +57,11 @@ export default function CardTemplatesPage() {
50
  </tr>
51
  </thead>
52
  <tbody>
53
- {templates.length === 0 && (
 
 
54
  <tr><td colSpan={4} className="text-center py-8 text-gray-400">No hay plantillas aún</td></tr>
55
- )}
56
  {templates.map((t) => (
57
  <tr key={t.id} className="border-b border-gray-100 hover:bg-gray-50">
58
  <td className="px-4 py-3 text-sm font-medium text-gray-800">{t.name}</td>
 
1
  import { useState, useEffect } from 'react';
2
  import { useNavigate } from 'react-router-dom';
3
  import { Plus, Pencil, Trash2, QrCode, Download } from 'lucide-react';
4
+ import LoadingState from '../components/LoadingState';
5
  import { listCardTemplates, deleteCardTemplate } from '../services/cardTemplateService';
6
  import type { CardTemplate } from '../types';
7
 
8
  export default function CardTemplatesPage() {
9
  const navigate = useNavigate();
10
  const [templates, setTemplates] = useState<CardTemplate[]>([]);
11
+ const [loading, setLoading] = useState(true);
12
  const [page, setPage] = useState(1);
13
  const [totalPages, setTotalPages] = useState(1);
14
 
15
  const load = async () => {
16
+ setLoading(true);
17
+ try {
18
+ const res = await listCardTemplates({ page, per_page: 20 });
19
+ setTemplates(res.items);
20
+ setTotalPages(res.total_pages);
21
+ } catch { /* ignore */ } finally {
22
+ setLoading(false);
23
+ }
24
  };
25
 
26
  useEffect(() => { load(); }, [page]);
 
57
  </tr>
58
  </thead>
59
  <tbody>
60
+ {loading ? (
61
+ <tr><td colSpan={4}><LoadingState /></td></tr>
62
+ ) : templates.length === 0 ? (
63
  <tr><td colSpan={4} className="text-center py-8 text-gray-400">No hay plantillas aún</td></tr>
64
+ ) : null}
65
  {templates.map((t) => (
66
  <tr key={t.id} className="border-b border-gray-100 hover:bg-gray-50">
67
  <td className="px-4 py-3 text-sm font-medium text-gray-800">{t.name}</td>
frontend/src/pages/DeveloperPage.tsx CHANGED
@@ -1,5 +1,6 @@
1
  import { useEffect, useState } from 'react';
2
  import { useAuthStore } from '../store/authStore';
 
3
  import {
4
  getDeveloperDashboard,
5
  toggleAccountActive,
@@ -21,7 +22,9 @@ import {
21
  export default function DeveloperPage() {
22
  const user = useAuthStore((s) => s.user);
23
  const [data, setData] = useState<DeveloperDashboard | null>(null);
 
24
  const [logs, setLogs] = useState<PaginatedLogs | null>(null);
 
25
  const [logPage, setLogPage] = useState(1);
26
  const [logLevel, setLogLevel] = useState('');
27
  const [searchAcct, setSearchAcct] = useState('');
@@ -29,17 +32,23 @@ export default function DeveloperPage() {
29
  const [tab, setTab] = useState<'dashboard' | 'accounts' | 'logs'>('dashboard');
30
 
31
  const loadDashboard = async () => {
 
32
  try {
33
  const d = await getDeveloperDashboard();
34
  setData(d);
35
- } catch { /* ignore */ }
 
 
36
  };
37
 
38
  const loadLogs = async () => {
 
39
  try {
40
  const l = await getSystemLogs(logPage, 20, logLevel || undefined);
41
  setLogs(l);
42
- } catch { /* ignore */ }
 
 
43
  };
44
 
45
  useEffect(() => { loadDashboard(); }, []);
@@ -194,7 +203,10 @@ export default function DeveloperPage() {
194
  </tr>
195
  </thead>
196
  <tbody>
197
- {(data?.accounts || [])
 
 
 
198
  .filter((a) => !searchAcct || a.name.toLowerCase().includes(searchAcct.toLowerCase()))
199
  .map((a) => (
200
  <tr key={a.id} className="border-b border-gray-100">
@@ -227,7 +239,7 @@ export default function DeveloperPage() {
227
  </td>
228
  </tr>
229
  ))}
230
- {(!data?.accounts || data.accounts.length === 0) && (
231
  <tr><td colSpan={7} className="text-gray-400 text-sm text-center py-8">No hay colegios</td></tr>
232
  )}
233
  </tbody>
@@ -266,7 +278,10 @@ export default function DeveloperPage() {
266
  </tr>
267
  </thead>
268
  <tbody>
269
- {logs?.items.map((l) => (
 
 
 
270
  <tr key={l.id} className="border-b border-gray-100">
271
  <td className="py-2 pl-3 pr-2 text-gray-500 text-xs">
272
  {l.created_at ? new Date(l.created_at).toLocaleString() : '-'}
@@ -282,7 +297,7 @@ export default function DeveloperPage() {
282
  <td className="py-2 pr-2 text-gray-500 text-xs">{l.account_id || '-'}</td>
283
  </tr>
284
  ))}
285
- {(!logs || logs.items.length === 0) && (
286
  <tr><td colSpan={6} className="text-gray-400 text-sm text-center py-8">No hay errores registrados</td></tr>
287
  )}
288
  </tbody>
 
1
  import { useEffect, useState } from 'react';
2
  import { useAuthStore } from '../store/authStore';
3
+ import LoadingState from '../components/LoadingState';
4
  import {
5
  getDeveloperDashboard,
6
  toggleAccountActive,
 
22
  export default function DeveloperPage() {
23
  const user = useAuthStore((s) => s.user);
24
  const [data, setData] = useState<DeveloperDashboard | null>(null);
25
+ const [loading, setLoading] = useState(true);
26
  const [logs, setLogs] = useState<PaginatedLogs | null>(null);
27
+ const [logsLoading, setLogsLoading] = useState(false);
28
  const [logPage, setLogPage] = useState(1);
29
  const [logLevel, setLogLevel] = useState('');
30
  const [searchAcct, setSearchAcct] = useState('');
 
32
  const [tab, setTab] = useState<'dashboard' | 'accounts' | 'logs'>('dashboard');
33
 
34
  const loadDashboard = async () => {
35
+ setLoading(true);
36
  try {
37
  const d = await getDeveloperDashboard();
38
  setData(d);
39
+ } catch { /* ignore */ } finally {
40
+ setLoading(false);
41
+ }
42
  };
43
 
44
  const loadLogs = async () => {
45
+ setLogsLoading(true);
46
  try {
47
  const l = await getSystemLogs(logPage, 20, logLevel || undefined);
48
  setLogs(l);
49
+ } catch { /* ignore */ } finally {
50
+ setLogsLoading(false);
51
+ }
52
  };
53
 
54
  useEffect(() => { loadDashboard(); }, []);
 
203
  </tr>
204
  </thead>
205
  <tbody>
206
+ {loading ? (
207
+ <tr><td colSpan={7}><LoadingState /></td></tr>
208
+ ) : null}
209
+ {!loading && (data?.accounts || [])
210
  .filter((a) => !searchAcct || a.name.toLowerCase().includes(searchAcct.toLowerCase()))
211
  .map((a) => (
212
  <tr key={a.id} className="border-b border-gray-100">
 
239
  </td>
240
  </tr>
241
  ))}
242
+ {!loading && (!data?.accounts || data.accounts.length === 0) && (
243
  <tr><td colSpan={7} className="text-gray-400 text-sm text-center py-8">No hay colegios</td></tr>
244
  )}
245
  </tbody>
 
278
  </tr>
279
  </thead>
280
  <tbody>
281
+ {logsLoading ? (
282
+ <tr><td colSpan={6}><LoadingState /></td></tr>
283
+ ) : null}
284
+ {!logsLoading && logs?.items.map((l) => (
285
  <tr key={l.id} className="border-b border-gray-100">
286
  <td className="py-2 pl-3 pr-2 text-gray-500 text-xs">
287
  {l.created_at ? new Date(l.created_at).toLocaleString() : '-'}
 
297
  <td className="py-2 pr-2 text-gray-500 text-xs">{l.account_id || '-'}</td>
298
  </tr>
299
  ))}
300
+ {!logsLoading && (!logs || logs.items.length === 0) && (
301
  <tr><td colSpan={6} className="text-gray-400 text-sm text-center py-8">No hay errores registrados</td></tr>
302
  )}
303
  </tbody>
frontend/src/pages/EnrollmentsPage.tsx CHANGED
@@ -8,6 +8,7 @@ import { listSubjects } from '../services/subjectService';
8
  import { Plus, Trash2, Search, BookOpen, ChevronLeft, ChevronRight, Users, GraduationCap, AlertTriangle, Edit3, Clock, Upload } from 'lucide-react';
9
  import ScheduleModal from '../components/ScheduleModal';
10
  import BulkUploadModal from '../components/BulkUploadModal';
 
11
 
12
  interface SectionTeacher {
13
  teacher_id: number;
@@ -26,6 +27,7 @@ export default function EnrollmentsPage() {
26
  const [showModal, setShowModal] = useState(false);
27
  const [selectedStudentIds, setSelectedStudentIds] = useState<number[]>([]);
28
  const [loading, setLoading] = useState(false);
 
29
  const [studentSearch, setStudentSearch] = useState('');
30
  const [teacherSearch, setTeacherSearch] = useState('');
31
  const [sectionsLoaded, setSectionsLoaded] = useState(false);
@@ -98,8 +100,12 @@ export default function EnrollmentsPage() {
98
  }, [sections]);
99
 
100
  useEffect(() => {
101
- if (!selectedSectionId) { setEnrollments([]); return; }
102
- listEnrollments({ section_id: Number(selectedSectionId), per_page: 500 }).then((r) => setEnrollments(r.items)).catch(() => {});
 
 
 
 
103
  }, [selectedSectionId]);
104
 
105
  const currentIndex = sections.findIndex((s) => String(s.id) === selectedSectionId);
@@ -446,9 +452,11 @@ export default function EnrollmentsPage() {
446
  </tr>
447
  </thead>
448
  <tbody>
449
- {enrollments.length === 0 && (
 
 
450
  <tr><td colSpan={4} className="text-gray-400 text-sm text-center py-8">No hay estudiantes matriculados en esta sección</td></tr>
451
- )}
452
  {enrollments.map((enr) => {
453
  const student = allStudents.find((s) => s.id === enr.student_id);
454
  const incomplete = student && isIncompleteStudent(student);
 
8
  import { Plus, Trash2, Search, BookOpen, ChevronLeft, ChevronRight, Users, GraduationCap, AlertTriangle, Edit3, Clock, Upload } from 'lucide-react';
9
  import ScheduleModal from '../components/ScheduleModal';
10
  import BulkUploadModal from '../components/BulkUploadModal';
11
+ import LoadingState from '../components/LoadingState';
12
 
13
  interface SectionTeacher {
14
  teacher_id: number;
 
27
  const [showModal, setShowModal] = useState(false);
28
  const [selectedStudentIds, setSelectedStudentIds] = useState<number[]>([]);
29
  const [loading, setLoading] = useState(false);
30
+ const [listLoading, setListLoading] = useState(true);
31
  const [studentSearch, setStudentSearch] = useState('');
32
  const [teacherSearch, setTeacherSearch] = useState('');
33
  const [sectionsLoaded, setSectionsLoaded] = useState(false);
 
100
  }, [sections]);
101
 
102
  useEffect(() => {
103
+ if (!selectedSectionId) { setEnrollments([]); setListLoading(false); return; }
104
+ setListLoading(true);
105
+ listEnrollments({ section_id: Number(selectedSectionId), per_page: 500 })
106
+ .then((r) => setEnrollments(r.items))
107
+ .catch(() => {})
108
+ .finally(() => setListLoading(false));
109
  }, [selectedSectionId]);
110
 
111
  const currentIndex = sections.findIndex((s) => String(s.id) === selectedSectionId);
 
452
  </tr>
453
  </thead>
454
  <tbody>
455
+ {listLoading ? (
456
+ <tr><td colSpan={4}><LoadingState /></td></tr>
457
+ ) : enrollments.length === 0 ? (
458
  <tr><td colSpan={4} className="text-gray-400 text-sm text-center py-8">No hay estudiantes matriculados en esta sección</td></tr>
459
+ ) : null}
460
  {enrollments.map((enr) => {
461
  const student = allStudents.find((s) => s.id === enr.student_id);
462
  const incomplete = student && isIncompleteStudent(student);
frontend/src/pages/HolidaysPage.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { useState, useEffect, FormEvent } from 'react';
2
  import api from '../services/api';
3
  import { Plus, Trash2 } from 'lucide-react';
 
4
 
5
  interface Holiday {
6
  id: number;
@@ -34,15 +35,19 @@ function formatRange(h: Holiday): string {
34
 
35
  export default function HolidaysPage() {
36
  const [holidays, setHolidays] = useState<Holiday[]>([]);
 
37
  const [year, setYear] = useState(new Date().getFullYear());
38
  const [showForm, setShowForm] = useState(false);
39
  const [form, setForm] = useState({ name: '', start_date: '', end_date: '', type: 'national' });
40
 
41
  const load = async () => {
 
42
  try {
43
  const { data } = await api.get(`/settings/holidays?year=${year}`);
44
  setHolidays(data);
45
- } catch { /* ignore */ }
 
 
46
  };
47
 
48
  useEffect(() => { load(); }, [year]);
@@ -122,7 +127,9 @@ export default function HolidaysPage() {
122
  )}
123
 
124
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
125
- {holidays.length === 0 ? (
 
 
126
  <div className="text-center text-gray-400 py-12 text-sm">No hay feriados registrados para {year}</div>
127
  ) : (
128
  <table className="w-full text-sm">
 
1
  import { useState, useEffect, FormEvent } from 'react';
2
  import api from '../services/api';
3
  import { Plus, Trash2 } from 'lucide-react';
4
+ import LoadingState from '../components/LoadingState';
5
 
6
  interface Holiday {
7
  id: number;
 
35
 
36
  export default function HolidaysPage() {
37
  const [holidays, setHolidays] = useState<Holiday[]>([]);
38
+ const [loading, setLoading] = useState(true);
39
  const [year, setYear] = useState(new Date().getFullYear());
40
  const [showForm, setShowForm] = useState(false);
41
  const [form, setForm] = useState({ name: '', start_date: '', end_date: '', type: 'national' });
42
 
43
  const load = async () => {
44
+ setLoading(true);
45
  try {
46
  const { data } = await api.get(`/settings/holidays?year=${year}`);
47
  setHolidays(data);
48
+ } catch { /* ignore */ } finally {
49
+ setLoading(false);
50
+ }
51
  };
52
 
53
  useEffect(() => { load(); }, [year]);
 
127
  )}
128
 
129
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
130
+ {loading ? (
131
+ <LoadingState />
132
+ ) : holidays.length === 0 ? (
133
  <div className="text-center text-gray-400 py-12 text-sm">No hay feriados registrados para {year}</div>
134
  ) : (
135
  <table className="w-full text-sm">
frontend/src/pages/LateArrivalsPage.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { useState, useEffect } from 'react';
2
  import api from '../services/api';
3
  import { Download } from 'lucide-react';
 
4
  import { translateRole } from '../utils/roles';
5
 
6
  interface LateArrival {
@@ -18,6 +19,7 @@ interface LateArrival {
18
 
19
  export default function LateArrivalsPage() {
20
  const [items, setItems] = useState<LateArrival[]>([]);
 
21
  const [roleFilter, setRoleFilter] = useState('');
22
  const [dateFrom, setDateFrom] = useState(() => {
23
  const d = new Date(); d.setDate(d.getDate() - 30);
@@ -34,10 +36,13 @@ export default function LateArrivalsPage() {
34
  };
35
 
36
  const load = async () => {
 
37
  try {
38
  const { data } = await api.get(`/reports/late-arrivals?${buildParams()}`);
39
  setItems(data.items);
40
- } catch { /* ignore */ }
 
 
41
  };
42
 
43
  const downloadCSV = async () => {
@@ -84,7 +89,9 @@ export default function LateArrivalsPage() {
84
  </div>
85
 
86
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
87
- {items.length === 0 ? (
 
 
88
  <div className="text-center text-gray-400 py-12 text-sm">No hay datos en el período seleccionado</div>
89
  ) : (
90
  <div className="overflow-x-auto">
 
1
  import { useState, useEffect } from 'react';
2
  import api from '../services/api';
3
  import { Download } from 'lucide-react';
4
+ import LoadingState from '../components/LoadingState';
5
  import { translateRole } from '../utils/roles';
6
 
7
  interface LateArrival {
 
19
 
20
  export default function LateArrivalsPage() {
21
  const [items, setItems] = useState<LateArrival[]>([]);
22
+ const [loading, setLoading] = useState(true);
23
  const [roleFilter, setRoleFilter] = useState('');
24
  const [dateFrom, setDateFrom] = useState(() => {
25
  const d = new Date(); d.setDate(d.getDate() - 30);
 
36
  };
37
 
38
  const load = async () => {
39
+ setLoading(true);
40
  try {
41
  const { data } = await api.get(`/reports/late-arrivals?${buildParams()}`);
42
  setItems(data.items);
43
+ } catch { /* ignore */ } finally {
44
+ setLoading(false);
45
+ }
46
  };
47
 
48
  const downloadCSV = async () => {
 
89
  </div>
90
 
91
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
92
+ {loading ? (
93
+ <LoadingState />
94
+ ) : items.length === 0 ? (
95
  <div className="text-center text-gray-400 py-12 text-sm">No hay datos en el período seleccionado</div>
96
  ) : (
97
  <div className="overflow-x-auto">
frontend/src/pages/StudentReportPage.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { useState, useEffect } from 'react';
2
  import api from '../services/api';
3
  import { AlertTriangle, Search } from 'lucide-react';
 
4
 
5
  interface StudentRow {
6
  id: number;
@@ -16,12 +17,14 @@ interface StudentRow {
16
 
17
  export default function StudentReportPage() {
18
  const [items, setItems] = useState<StudentRow[]>([]);
 
19
  const [nameFilter, setNameFilter] = useState('');
20
  const [sectionFilter, setSectionFilter] = useState('');
21
  const [cardFilter, setCardFilter] = useState('');
22
 
23
  useEffect(() => {
24
- api.get('/reports/students').then(({ data }) => setItems(data)).catch(() => {});
 
25
  }, []);
26
 
27
  const sectionOptions = Array.from(new Set(items.flatMap((i) => i.section_names))).sort();
@@ -77,7 +80,9 @@ export default function StudentReportPage() {
77
  </div>
78
 
79
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
80
- {filtered.length === 0 ? (
 
 
81
  <div className="text-center text-gray-400 py-12 text-sm">Sin resultados</div>
82
  ) : (
83
  <div className="overflow-x-auto">
 
1
  import { useState, useEffect } from 'react';
2
  import api from '../services/api';
3
  import { AlertTriangle, Search } from 'lucide-react';
4
+ import LoadingState from '../components/LoadingState';
5
 
6
  interface StudentRow {
7
  id: number;
 
17
 
18
  export default function StudentReportPage() {
19
  const [items, setItems] = useState<StudentRow[]>([]);
20
+ const [loading, setLoading] = useState(true);
21
  const [nameFilter, setNameFilter] = useState('');
22
  const [sectionFilter, setSectionFilter] = useState('');
23
  const [cardFilter, setCardFilter] = useState('');
24
 
25
  useEffect(() => {
26
+ setLoading(true);
27
+ api.get('/reports/students').then(({ data }) => setItems(data)).catch(() => {}).finally(() => setLoading(false));
28
  }, []);
29
 
30
  const sectionOptions = Array.from(new Set(items.flatMap((i) => i.section_names))).sort();
 
80
  </div>
81
 
82
  <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
83
+ {loading ? (
84
+ <LoadingState />
85
+ ) : filtered.length === 0 ? (
86
  <div className="text-center text-gray-400 py-12 text-sm">Sin resultados</div>
87
  ) : (
88
  <div className="overflow-x-auto">
frontend/src/pages/TeacherAttendancePage.tsx CHANGED
@@ -1,5 +1,6 @@
1
  import { useState, useEffect, useRef, useCallback } from 'react';
2
  import { useSearchParams } from 'react-router-dom';
 
3
  import {
4
  getTeacherSections, getSectionStudents, submitSwipeAttendance, getAttendanceSummary, batchToggleAttendance,
5
  getStudentProfile, downloadAttendanceCSV,
@@ -26,6 +27,7 @@ export default function TeacherAttendancePage() {
26
  const cardRef = useRef<HTMLDivElement>(null);
27
 
28
  const [summary, setSummary] = useState<AttendanceSummaryItem[]>([]);
 
29
  const [summaryDate, setSummaryDate] = useState(new Date().toISOString().slice(0, 10));
30
  const [toast, setToast] = useState<{ text: string; type: 'error' | 'success' } | null>(null);
31
  const [profile, setProfile] = useState<StudentProfile | null>(null);
@@ -90,7 +92,10 @@ export default function TeacherAttendancePage() {
90
 
91
  // Load summary for list view
92
  const loadSummary = useCallback(async (sectionId: number, dateStr: string) => {
93
- try { setSummary(await getAttendanceSummary(sectionId, dateStr)); } catch { /* ignore */ }
 
 
 
94
  }, []);
95
 
96
  useEffect(() => {
@@ -358,7 +363,11 @@ export default function TeacherAttendancePage() {
358
  </tr>
359
  </thead>
360
  <tbody>
361
- {summary.length === 0 && <tr><td colSpan={5} className="text-gray-400 text-sm text-center py-8">Sin estudiantes</td></tr>}
 
 
 
 
362
  {(() => {
363
  const sorted = [...summary].sort((a, b) => {
364
  const aEff = getEffectiveStatus(a);
 
1
  import { useState, useEffect, useRef, useCallback } from 'react';
2
  import { useSearchParams } from 'react-router-dom';
3
+ import LoadingState from '../components/LoadingState';
4
  import {
5
  getTeacherSections, getSectionStudents, submitSwipeAttendance, getAttendanceSummary, batchToggleAttendance,
6
  getStudentProfile, downloadAttendanceCSV,
 
27
  const cardRef = useRef<HTMLDivElement>(null);
28
 
29
  const [summary, setSummary] = useState<AttendanceSummaryItem[]>([]);
30
+ const [listLoading, setListLoading] = useState(true);
31
  const [summaryDate, setSummaryDate] = useState(new Date().toISOString().slice(0, 10));
32
  const [toast, setToast] = useState<{ text: string; type: 'error' | 'success' } | null>(null);
33
  const [profile, setProfile] = useState<StudentProfile | null>(null);
 
92
 
93
  // Load summary for list view
94
  const loadSummary = useCallback(async (sectionId: number, dateStr: string) => {
95
+ setListLoading(true);
96
+ try { setSummary(await getAttendanceSummary(sectionId, dateStr)); } catch { /* ignore */ } finally {
97
+ setListLoading(false);
98
+ }
99
  }, []);
100
 
101
  useEffect(() => {
 
363
  </tr>
364
  </thead>
365
  <tbody>
366
+ {listLoading ? (
367
+ <tr><td colSpan={5}><LoadingState /></td></tr>
368
+ ) : summary.length === 0 ? (
369
+ <tr><td colSpan={5} className="text-gray-400 text-sm text-center py-8">Sin estudiantes</td></tr>
370
+ ) : null}
371
  {(() => {
372
  const sorted = [...summary].sort((a, b) => {
373
  const aEff = getEffectiveStatus(a);
frontend/src/pages/UsersPage.tsx CHANGED
@@ -1,5 +1,6 @@
1
  import { useState, useEffect, FormEvent } from 'react';
2
  import { useAuthStore } from '../store/authStore';
 
3
  import { listUsers, createUser, updateUser, deactivateUser, listUserPermissions, setUserPermissions as setUserPerms, getAvailablePermissions, type UserFilters } from '../services/userService';
4
  import { adminResetPassword } from '../services/authService';
5
  import type { User } from '../types';
@@ -15,6 +16,7 @@ const EMPTY_FORM = { name: '', lastname: '', email: '', role: 'student', card_id
15
  export default function UsersPage() {
16
  const user = useAuthStore((s) => s.user);
17
  const [users, setUsers] = useState<User[]>([]);
 
18
  const [total, setTotal] = useState(0);
19
  const [page, setPage] = useState(1);
20
  const [totalPages, setTotalPages] = useState(1);
@@ -32,13 +34,16 @@ export default function UsersPage() {
32
  const [resetLoading, setResetLoading] = useState(false);
33
 
34
  const load = async () => {
 
35
  try {
36
  const res = await listUsers({ ...filters, page, per_page: 20 });
37
  setUsers(res.items);
38
  setTotal(res.total);
39
  setPage(res.page);
40
  setTotalPages(res.total_pages);
41
- } catch { /* ignore */ }
 
 
42
  };
43
 
44
  useEffect(() => { load(); }, [page, filters]);
@@ -160,7 +165,11 @@ export default function UsersPage() {
160
  </tr>
161
  </thead>
162
  <tbody>
163
- {users.length === 0 && <tr><td colSpan={7} className="text-gray-400 text-sm text-center py-8">No se encontraron usuarios</td></tr>}
 
 
 
 
164
  {users.map((u) => (
165
  <tr key={u.id} className="border-b border-gray-100">
166
  <td className="py-2 pl-3 pr-2">
 
1
  import { useState, useEffect, FormEvent } from 'react';
2
  import { useAuthStore } from '../store/authStore';
3
+ import LoadingState from '../components/LoadingState';
4
  import { listUsers, createUser, updateUser, deactivateUser, listUserPermissions, setUserPermissions as setUserPerms, getAvailablePermissions, type UserFilters } from '../services/userService';
5
  import { adminResetPassword } from '../services/authService';
6
  import type { User } from '../types';
 
16
  export default function UsersPage() {
17
  const user = useAuthStore((s) => s.user);
18
  const [users, setUsers] = useState<User[]>([]);
19
+ const [loading, setLoading] = useState(true);
20
  const [total, setTotal] = useState(0);
21
  const [page, setPage] = useState(1);
22
  const [totalPages, setTotalPages] = useState(1);
 
34
  const [resetLoading, setResetLoading] = useState(false);
35
 
36
  const load = async () => {
37
+ setLoading(true);
38
  try {
39
  const res = await listUsers({ ...filters, page, per_page: 20 });
40
  setUsers(res.items);
41
  setTotal(res.total);
42
  setPage(res.page);
43
  setTotalPages(res.total_pages);
44
+ } catch { /* ignore */ } finally {
45
+ setLoading(false);
46
+ }
47
  };
48
 
49
  useEffect(() => { load(); }, [page, filters]);
 
165
  </tr>
166
  </thead>
167
  <tbody>
168
+ {loading ? (
169
+ <tr><td colSpan={7}><LoadingState /></td></tr>
170
+ ) : users.length === 0 ? (
171
+ <tr><td colSpan={7} className="text-gray-400 text-sm text-center py-8">No se encontraron usuarios</td></tr>
172
+ ) : null}
173
  {users.map((u) => (
174
  <tr key={u.id} className="border-b border-gray-100">
175
  <td className="py-2 pl-3 pr-2">