hiển thị thuyền thông tin tàu
This commit is contained in:
24
state/use-ship-types.ts
Normal file
24
state/use-ship-types.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { queryShipTypes } from "@/controller/DeviceController";
|
||||
import { create } from "zustand";
|
||||
|
||||
type ShipType = {
|
||||
shipTypes: Model.ShipType[] | [];
|
||||
getShipTypes: () => Promise<void>;
|
||||
error: string | null;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const useShipTypes = create<ShipType>((set) => ({
|
||||
shipTypes: [],
|
||||
getShipTypes: async () => {
|
||||
try {
|
||||
const response = await queryShipTypes();
|
||||
set({ shipTypes: response.data, loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetch shipTypes: ", error);
|
||||
set({ error: "Failed to fetch shipTypes data", loading: false });
|
||||
set({ shipTypes: [] });
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
}));
|
||||
Reference in New Issue
Block a user