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

41
state/use-group.ts Normal file
View 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,
}));