call API trip

This commit is contained in:
2025-11-05 23:47:54 +07:00
parent 62b18e5bc0
commit 6288e79622
7 changed files with 115 additions and 3 deletions

26
state/use-trip.ts Normal file
View File

@@ -0,0 +1,26 @@
import { queryTrip } from "@/controller/TripController";
import { create } from "zustand";
type Trip = {
trip: Model.Trip | null;
getTrip: () => Promise<void>;
error: string | null;
loading?: boolean;
};
export const useTrip = create<Trip>((set) => ({
trip: null,
getTrip: async () => {
try {
const response = await queryTrip();
console.log("Trip fetching: ", response.data);
set({ trip: response.data, loading: false });
} catch (error) {
console.error("Error when fetch trip: ", error);
set({ error: "Failed to fetch trip data", loading: false });
set({ trip: null });
}
},
error: null,
}));