feat(improvement): add pagination to endpoints and pages + sync navbar when data changes
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user