thêm giao diện quản lý thuyền

This commit is contained in:
Tran Anh Tuan
2025-12-10 19:49:54 +07:00
parent df4318fed4
commit 3e1c4dcbc5
24 changed files with 2091 additions and 135 deletions

24
state/use-ship.tsx Normal file
View File

@@ -0,0 +1,24 @@
import { queryAllShips } from "@/controller/DeviceController";
import { create } from "zustand";
type Ship = {
ships: Model.Ship[] | null;
getShip: () => Promise<void>;
error: string | null;
loading?: boolean;
};
export const useShip = create<Ship>((set) => ({
ships: null,
getShip: async () => {
try {
const response = await queryAllShips({});
set({ ships: response.data?.ships, loading: false });
} catch (error) {
console.error("Error when fetch Ship: ", error);
set({ error: "Failed to fetch Ship data", loading: false });
set({ ships: null });
}
},
error: null,
}));