feat: create user state
This commit is contained in:
@ -1,4 +1,9 @@
|
|||||||
import { adminGetUserApi, adminGetUsersApi } from "@/api/admin/users";
|
import {
|
||||||
|
adminGetUserApi,
|
||||||
|
adminGetUsersApi,
|
||||||
|
postUser,
|
||||||
|
type CreateUserRequest,
|
||||||
|
} from "@/api/admin/users";
|
||||||
import type { UserProfile } from "@/types";
|
import type { UserProfile } from "@/types";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
@ -9,6 +14,9 @@ export interface IUsersState {
|
|||||||
current: UserProfile | null;
|
current: UserProfile | null;
|
||||||
fetchingCurrent: boolean;
|
fetchingCurrent: boolean;
|
||||||
|
|
||||||
|
creating: boolean;
|
||||||
|
createUser: (req: CreateUserRequest) => Promise<void>;
|
||||||
|
|
||||||
fetchUsers: () => Promise<void>;
|
fetchUsers: () => Promise<void>;
|
||||||
fetchUser: (id: string) => Promise<void>;
|
fetchUser: (id: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
@ -17,9 +25,24 @@ export const useUsers = create<IUsersState>((set) => ({
|
|||||||
users: [],
|
users: [],
|
||||||
fetching: false,
|
fetching: false,
|
||||||
|
|
||||||
|
creating: false,
|
||||||
|
|
||||||
current: null,
|
current: null,
|
||||||
fetchingCurrent: false,
|
fetchingCurrent: false,
|
||||||
|
|
||||||
|
createUser: async (req: CreateUserRequest) => {
|
||||||
|
set({ creating: true });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await postUser(req);
|
||||||
|
console.log("INFO: User has been created:", response);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("ERR: Failed to create user:", err);
|
||||||
|
} finally {
|
||||||
|
set({ creating: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
fetchUsers: async () => {
|
fetchUsers: async () => {
|
||||||
set({ fetching: true });
|
set({ fetching: true });
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user