25 lines
672 B
TypeScript
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,
|
|
}));
|