Merge branch 'dev' into 'staging'

Dev

See merge request frontend/admin!97
This commit is contained in:
Nastya 2024-06-25 20:41:33 +00:00
commit a0ef7a987c
6 changed files with 96 additions and 5 deletions

@ -30,7 +30,7 @@ export type Account = {
wallet: Wallet;
};
const API_URL = `${process.env.REACT_APP_DOMAIN}/customer`;
const API_URL = `${process.env.REACT_APP_DOMAIN}/customer/v1.0.0`;
export const getAccountInfo = async (id: string): Promise<[Account | null, string?]> => {
try {

@ -23,7 +23,7 @@ type HistoryResponse = {
totalPages: number;
};
const API_URL = `${process.env.REACT_APP_DOMAIN}/customer`;
const API_URL = `${process.env.REACT_APP_DOMAIN}/customer/v1.0.0`;
const getUserHistory = async (accountId: string, page: number): Promise<[HistoryResponse | null, string?]> => {
try {

@ -40,7 +40,7 @@ export const getStatisticSchild = async (from: number, to: number): Promise<[Qui
try {
const statisticResponse = await makeRequest<GetStatisticSchildBody, QuizStatisticsItem[]>({
method: "POST",
url: `${API_URL}/customer/quizlogo/stat`,
url: `${API_URL}/customer/v1.0.0/quizlogo/stat`,
body: { to, from, page: 0, limit: 100 },
useToken: true,
});
@ -74,7 +74,7 @@ export const getStatisticsPromocode = async (
try {
const statisticsPromocode = await makeRequest<GetPromocodeStatisticsBody, Record<string, AllPromocodeStatistics>>({
method: "POST",
url: `${API_URL}/customer/promocode/ltv`,
url: `${API_URL}/customer/v1.0.0/promocode/ltv`,
body: { to, from },
useToken: true,
});

@ -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>
);
};