diff --git a/src/api/user/requests.ts b/src/api/user/requests.ts index 408256b..3d91213 100644 --- a/src/api/user/requests.ts +++ b/src/api/user/requests.ts @@ -8,6 +8,9 @@ export type UsersListResponse = { totalPages: number; users: UserType[]; }; +export type PrivilegeDecrementRequest = { + id: string; +}; const API_URL = `${process.env.REACT_APP_DOMAIN}/user`; @@ -72,9 +75,28 @@ const getAdminList = async (page = 1, limit = 10): Promise<[UsersListResponse | } }; +const privilegeDecrement = async (userId: string) => { + try { + const adminResponse = await makeRequest({ + method: "POST", + url: `${process.env.REACT_APP_DOMAIN}/squiz/account/manualdone`, + body: { + id: userId + } + }); + + return [adminResponse]; + } catch (nativeError) { + const [error] = parseAxiosError(nativeError); + + return [null, `Ошибка при получении админов. ${error}`]; + } +} + export const userApi = { getUserInfo, getUserList, getManagerList, getAdminList, + privilegeDecrement, }; diff --git a/src/pages/dashboard/ModalUser/UserPrivilegeDecrement.tsx b/src/pages/dashboard/ModalUser/UserPrivilegeDecrement.tsx new file mode 100644 index 0000000..eee3fa4 --- /dev/null +++ b/src/pages/dashboard/ModalUser/UserPrivilegeDecrement.tsx @@ -0,0 +1,59 @@ +import { Box, Button, Typography } from "@mui/material" +import { useState } from "react" +import { userApi } from "../../../api/user/requests" + +export const UserPrivilegeDecrement = ({ userId }: { userId: string }) => { + + const [disabled, setDisabled] = useState(false) + const [readyDecrement, setReadyDecrement] = useState(false) + const [info, setInfo] = useState("") + + const handleClick = () => { + if (readyDecrement) { + readyHC() + } else { + notReadyHC() + } + } + const readyHC = async () => { + setDisabled(true) + // await userApi.privilegeDecrement(userId) + await userApi.privilegeDecrement("656fa783f827770622bb8774") + setReadyDecrement(false) + setDisabled(false) + setInfo("Привилегия была успешно уменьшена :)") + setInterval(() => { + setInfo("") + }, 5000) + } + const notReadyHC = () => { + setDisabled(true) + setInfo("Подтвердите действие через 5 секунд") + setReadyDecrement(true) + setInterval(() => { + setDisabled(false) + setInfo("") + }, 5000) + } + + return ( + + Удалить единичку привилегии: + + {info} + + + ) +} diff --git a/src/pages/dashboard/ModalUser/UserTab.tsx b/src/pages/dashboard/ModalUser/UserTab.tsx index 89b66cb..a817c26 100644 --- a/src/pages/dashboard/ModalUser/UserTab.tsx +++ b/src/pages/dashboard/ModalUser/UserTab.tsx @@ -6,6 +6,7 @@ import { getAccountInfo } from "@root/api/account"; import type { UserType } from "@root/api/roles"; import type { Account } from "@root/api/account"; +import { UserPrivilegeDecrement } from "./UserPrivilegeDecrement"; type UserTabProps = { userId: string; @@ -25,11 +26,16 @@ export const UserTab = ({ userId }: UserTabProps) => { }, []); return ( + @@ -75,5 +81,9 @@ export const UserTab = ({ userId }: UserTabProps) => { + + ); };