feat(improvement): add pagination to endpoints and pages + sync navbar when data changes

This commit is contained in:
2026-03-13 10:30:27 +08:00
parent a9ebbf6a4a
commit 56404792c6
14 changed files with 543 additions and 210 deletions

View File

@@ -1,9 +1,17 @@
import { authFetch } from "./client";
import { type PaginatedClientList } from "../types/client";
export const getClients = async (workspaceId: string, search: string = "", ordering: string = "") => {
const queryParams = new URLSearchParams({ workspace: workspaceId });
export const getClients = async (
workspaceId: string,
search: string = "",
ordering: string = "",
limit: number = 10,
offset: number = 0
) => {
const queryParams = new URLSearchParams({
workspace: workspaceId,
limit: limit.toString(),
offset: offset.toString()
});
if (search) queryParams.append("search", search);
if (ordering) queryParams.append("ordering", ordering);
@@ -12,7 +20,7 @@ export const getClients = async (workspaceId: string, search: string = "", order
if (!response.ok) {
throw new Error("Failed to fetch clients");
}
return response.json();
return response.json();
};
export const createClient = async (workspaceId: string, data: { name: string; notes: string }) => {
@@ -54,7 +62,6 @@ export const deleteClient = async (id: string) => {
throw new Error(errorData?.detail || errorData?.message || "Failed to delete client");
}
// DELETE requests often return 204 No Content, which throws an error on .json()
if (response.status === 204) {
return { success: true };
}