--1 версия кнопки декремента привилегии юзеру

This commit is contained in:
Nastya 2024-06-25 23:40:57 +03:00
parent fa26515652
commit a21cdc48b2
3 changed files with 92 additions and 1 deletions

@ -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<PrivilegeDecrementRequest, never>({
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,
};

@ -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 (
<Box>
<Typography variant="h6">Удалить единичку привилегии:</Typography>
<Button
onClick={handleClick}
disabled={disabled}
>
{
readyDecrement ?
"уменьшить"
:
"начать"
}
</Button>
<Typography
color="red"
>{info}</Typography>
</Box>
)
}

@ -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 (
<Box
sx={{
padding: "25px",
}}
>
<Box
sx={{
display: mobile ? "block" : "flex",
columnGap: "15px",
padding: "25px",
}}
>
<Box sx={{ maxWidth: "300px", width: "100%" }}>
@ -75,5 +81,9 @@ export const UserTab = ({ userId }: UserTabProps) => {
</Box>
</Box>
</Box>
<UserPrivilegeDecrement
userId={userId}
/>
</Box>
);
};