thêm giao diện quản lý thuyền
This commit is contained in:
41
state/use-group.ts
Normal file
41
state/use-group.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
queryChilrentOfGroups,
|
||||
queryUserGroup,
|
||||
} from "@/controller/GroupController";
|
||||
import { create } from "zustand";
|
||||
|
||||
type Groups = {
|
||||
groups: Model.GroupResponse | null;
|
||||
childrenOfGroups?: Model.GroupResponse | null;
|
||||
getChildrenOfGroups: (group_id: string) => Promise<void>;
|
||||
getUserGroups: () => Promise<void>;
|
||||
error: string | null;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const useGroup = create<Groups>((set) => ({
|
||||
groups: null,
|
||||
childrenOfGroups: null,
|
||||
getUserGroups: async () => {
|
||||
try {
|
||||
const response = await queryUserGroup();
|
||||
set({ groups: response.data, loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetch Port: ", error);
|
||||
set({ error: "Failed to fetch Port data", loading: false });
|
||||
set({ groups: null });
|
||||
}
|
||||
},
|
||||
getChildrenOfGroups: async (group_id: string) => {
|
||||
try {
|
||||
set({ loading: true });
|
||||
const response = await queryChilrentOfGroups(group_id);
|
||||
set({ childrenOfGroups: response.data, loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetching children of groups: ", error);
|
||||
set({ error: "Failed to fetch children of groups", loading: false });
|
||||
set({ childrenOfGroups: null });
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
}));
|
||||
32
state/use-ports.ts
Normal file
32
state/use-ports.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { queryPorts } from "@/controller/PortController";
|
||||
import { create } from "zustand";
|
||||
|
||||
type Ports = {
|
||||
ports: Model.PortResponse | null;
|
||||
getPorts: () => Promise<void>;
|
||||
error: string | null;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const usePort = create<Ports>((set) => ({
|
||||
ports: null,
|
||||
getPorts: async (body?: Model.SearchThingBody) => {
|
||||
try {
|
||||
if (body === undefined) {
|
||||
body = {
|
||||
offset: 0,
|
||||
limit: 50,
|
||||
dir: "asc",
|
||||
order: "id",
|
||||
};
|
||||
}
|
||||
const response = await queryPorts(body);
|
||||
set({ ports: response.data, loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetch Port: ", error);
|
||||
set({ error: "Failed to fetch Port data", loading: false });
|
||||
set({ ports: null });
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
}));
|
||||
24
state/use-ship-groups.ts
Normal file
24
state/use-ship-groups.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { queryShipGroups } from "@/controller/DeviceController";
|
||||
import { create } from "zustand";
|
||||
|
||||
type ShipGroups = {
|
||||
shipGroups: Model.ShipGroup[] | null;
|
||||
getShipGroups: () => Promise<void>;
|
||||
error: string | null;
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export const useShipGroups = create<ShipGroups>((set) => ({
|
||||
shipGroups: null,
|
||||
getShipGroups: async () => {
|
||||
try {
|
||||
const response = await queryShipGroups();
|
||||
set({ shipGroups: response.data, loading: false });
|
||||
} catch (error) {
|
||||
console.error("Error when fetch Port: ", error);
|
||||
set({ error: "Failed to fetch Port data", loading: false });
|
||||
set({ shipGroups: null });
|
||||
}
|
||||
},
|
||||
error: null,
|
||||
}));
|
||||
24
state/use-ship.tsx
Normal file
24
state/use-ship.tsx
Normal 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,
|
||||
}));
|
||||
Reference in New Issue
Block a user