update tab nhật ký (Lọc, Ngôn ngữ,...)
This commit is contained in:
31
state/use-tripslist.ts
Normal file
31
state/use-tripslist.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { queryTripsList } from "@/controller/TripController";
|
||||
import { create } from "zustand";
|
||||
|
||||
type TripsListState = {
|
||||
tripsList: Model.TripsListResponse | null;
|
||||
getTripsList: (body: Model.TripListBody) => Promise<void>;
|
||||
error: string | null;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const useTripsList = create<TripsListState>((set) => ({
|
||||
tripsList: null,
|
||||
getTripsList: async (body: Model.TripListBody) => {
|
||||
set({ loading: true, error: null });
|
||||
try {
|
||||
const response = await queryTripsList(body);
|
||||
console.log("Trip fetching API: ", response.data.trips?.length);
|
||||
|
||||
set({ tripsList: response.data ?? [], loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetch things: ", error);
|
||||
set({
|
||||
error: "Failed to fetch things data",
|
||||
loading: false,
|
||||
tripsList: null,
|
||||
});
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
loading: false,
|
||||
}));
|
||||
Reference in New Issue
Block a user