Implement inline editing and image upload/delete/edit

This commit is contained in:
april
2024-01-15 16:33:26 -06:00
parent 325730a9da
commit 924252b38f
17 changed files with 1213 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
import { useQuery } from "@tanstack/react-query";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useApi } from "./api";
export function useAircraft() {
@@ -31,3 +31,24 @@ export function useFlights(filter: string = "", value: string = "") {
return flights;
}
export function usePatchFlight(
id: string,
field: string,
onSuccess: () => void
) {
const client = useApi();
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (value: string | string[] | number | Date | null) =>
await client
.patch(`/flights/${id}`, { [field]: value })
.then((res) => res.data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [id] });
queryClient.invalidateQueries({ queryKey: ["flights-list"] });
onSuccess();
},
});
}