Fix: Add pagination to admin appointments endpoint
- Added pagination with page/per_page query params - Fixed N+1 query by using eager-loaded user relationship - Removed unused _get_user_email helper function - Updated frontend to handle paginated response - Regenerated API types
This commit is contained in:
parent
1cd60b4bbc
commit
77e7f98e1e
4 changed files with 70 additions and 28 deletions
|
|
@ -9,6 +9,7 @@ import { useRequireAuth } from "../../hooks/useRequireAuth";
|
|||
import { components } from "../../generated/api";
|
||||
|
||||
type AppointmentResponse = components["schemas"]["AppointmentResponse"];
|
||||
type PaginatedAppointments = components["schemas"]["PaginatedResponse_AppointmentResponse_"];
|
||||
|
||||
// Helper to format datetime
|
||||
function formatDateTime(isoString: string): string {
|
||||
|
|
@ -200,8 +201,9 @@ export default function AdminAppointmentsPage() {
|
|||
|
||||
const fetchAppointments = useCallback(async () => {
|
||||
try {
|
||||
const data = await api.get<AppointmentResponse[]>("/api/admin/appointments");
|
||||
setAppointments(data);
|
||||
// Fetch with large per_page to get all appointments for now
|
||||
const data = await api.get<PaginatedAppointments>("/api/admin/appointments?per_page=100");
|
||||
setAppointments(data.records);
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch appointments:", err);
|
||||
setError("Failed to load appointments");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue