Reload flight list when new flight is added
This commit is contained in:
parent
a52eab9105
commit
c857a18619
@ -45,7 +45,7 @@ export const links: LinksFunction = () => [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
rel: "icon",
|
rel: "icon",
|
||||||
href: "/favicon/favicon-16x1166.png",
|
href: "/favicon/favicon-16x16.png",
|
||||||
type: "image/png",
|
type: "image/png",
|
||||||
sizes: "16x16",
|
sizes: "16x16",
|
||||||
},
|
},
|
||||||
|
@ -21,7 +21,7 @@ import { FlightFormSchema, flightCreateHelper } from "@/util/types";
|
|||||||
import { HourInput, ZeroHourInput } from "@/ui/form/hour-input";
|
import { HourInput, ZeroHourInput } from "@/ui/form/hour-input";
|
||||||
import { ZeroIntInput } from "@/ui/form/int-input";
|
import { ZeroIntInput } from "@/ui/form/int-input";
|
||||||
import ListInput from "@/ui/form/list-input";
|
import ListInput from "@/ui/form/list-input";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { client } from "@/util/api";
|
import { client } from "@/util/api";
|
||||||
import { useNavigate } from "@remix-run/react";
|
import { useNavigate } from "@remix-run/react";
|
||||||
|
|
||||||
@ -77,16 +77,22 @@ export default function NewFlight() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const createFlight = useMutation({
|
const createFlight = useMutation({
|
||||||
mutationFn: async (values: FlightFormSchema) => {
|
mutationFn: async (values: FlightFormSchema) => {
|
||||||
const newFlight = flightCreateHelper(values);
|
const newFlight = flightCreateHelper(values);
|
||||||
const res = await client.post("/flights", newFlight);
|
const res = await client.post("/flights", newFlight);
|
||||||
navigate(`/logbook/flights/${res.data.id}`);
|
console.log(res);
|
||||||
|
return res.data;
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
},
|
},
|
||||||
|
onSuccess: async (data: { id: string }) => {
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ["flights-list"] });
|
||||||
|
navigate(`/logbook/flights/${data.id}`);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user