fixed bug: Now you dont have to reload the page twice, after creating a loan
This commit is contained in:
11
frontend/src/utils/queryClient.ts
Normal file
11
frontend/src/utils/queryClient.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
|
||||
// Central QueryClient instance so utilities (e.g. file upload) can invalidate queries.
|
||||
export const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
});
|
@@ -1,5 +1,6 @@
|
||||
import { myToast } from "./toastify";
|
||||
import Cookies from "js-cookie";
|
||||
import { queryClient } from "./queryClient";
|
||||
|
||||
export const handleDeleteLoan = async (loanID: number): Promise<boolean> => {
|
||||
try {
|
||||
@@ -92,5 +93,10 @@ export const createLoan = async (startDate: string, endDate: string) => {
|
||||
removeArr = [];
|
||||
Cookies.set("removeArr", "[]");
|
||||
myToast("Ausleihe erfolgreich erstellt!", "success");
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: ["userLoans"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["allLoans"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["borrowableItems"] });
|
||||
|
||||
return true;
|
||||
};
|
||||
|
Reference in New Issue
Block a user