feat: Add more pages
This commit is contained in:
44
src/shared/store/UserStore/index.ts
Normal file
44
src/shared/store/UserStore/index.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
email: string;
|
||||
is_admin: boolean;
|
||||
name: string;
|
||||
};
|
||||
|
||||
class UserStore {
|
||||
users: User[] = [];
|
||||
user: User | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getUsers = async () => {
|
||||
const response = await authInstance.get("/user");
|
||||
|
||||
runInAction(() => {
|
||||
this.users = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
getUser = async (id: number) => {
|
||||
const response = await authInstance.get(`/user/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.user = response.data as User;
|
||||
});
|
||||
};
|
||||
|
||||
deleteUser = async (id: number) => {
|
||||
await authInstance.delete(`/users/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.users = this.users.filter((user) => user.id !== id);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const userStore = new UserStore();
|
||||
Reference in New Issue
Block a user