feat: admin users state
This commit is contained in:
28
web/src/store/admin/users.ts
Normal file
28
web/src/store/admin/users.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { adminGetUsersApi } from "@/api/admin/users";
|
||||||
|
import type { UserProfile } from "@/types";
|
||||||
|
import { create } from "zustand";
|
||||||
|
|
||||||
|
export interface IUsersState {
|
||||||
|
users: UserProfile[];
|
||||||
|
fetching: boolean;
|
||||||
|
|
||||||
|
fetchUsers: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUsers = create<IUsersState>((set) => ({
|
||||||
|
users: [],
|
||||||
|
fetching: false,
|
||||||
|
|
||||||
|
fetchUsers: async () => {
|
||||||
|
set({ fetching: true });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await adminGetUsersApi();
|
||||||
|
set({ users: response.items });
|
||||||
|
} catch (err) {
|
||||||
|
console.log("ERR: Failed to fetch users for admin:", err);
|
||||||
|
} finally {
|
||||||
|
set({ fetching: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
Reference in New Issue
Block a user