Files
sgw-owner-app/state/use-ship-types.ts
2025-12-03 16:22:25 +07:00

25 lines
672 B
TypeScript

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,
}));