feat(cache): add stale get caching for report filters and summaries
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { authFetch } from "./client";
|
||||
import { invalidateApiCache } from "./cache";
|
||||
|
||||
export interface TimeEntryProjectDetails {
|
||||
id: string;
|
||||
@@ -109,7 +110,9 @@ export const createTimeEntry = async (payload: TimeEntryPayload) => {
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!response.ok) throw new Error("Failed to create time entry");
|
||||
return response.json();
|
||||
const data = await response.json();
|
||||
invalidateApiCache(["reports"]);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const updateTimeEntry = async (id: string, payload: TimeEntryPayload) => {
|
||||
@@ -118,7 +121,9 @@ export const updateTimeEntry = async (id: string, payload: TimeEntryPayload) =>
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!response.ok) throw new Error("Failed to update time entry");
|
||||
return response.json();
|
||||
const data = await response.json();
|
||||
invalidateApiCache(["reports"]);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const stopTimeEntry = async (id: string, endTime?: string) => {
|
||||
@@ -127,7 +132,9 @@ export const stopTimeEntry = async (id: string, endTime?: string) => {
|
||||
body: JSON.stringify(endTime ? { end_time: endTime } : {}),
|
||||
});
|
||||
if (!response.ok) throw new Error("Failed to stop time entry");
|
||||
return response.json();
|
||||
const data = await response.json();
|
||||
invalidateApiCache(["reports"]);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const deleteTimeEntry = async (id: string) => {
|
||||
@@ -135,4 +142,5 @@ export const deleteTimeEntry = async (id: string) => {
|
||||
method: "DELETE",
|
||||
});
|
||||
if (!response.ok) throw new Error("Failed to delete time entry");
|
||||
invalidateApiCache(["reports"]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user