diff --git a/src/api/account.ts b/src/api/account.ts index 05e9c9a..c2bc0e7 100644 --- a/src/api/account.ts +++ b/src/api/account.ts @@ -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 { diff --git a/src/api/history/requests.ts b/src/api/history/requests.ts index bd9ecae..1e7765f 100644 --- a/src/api/history/requests.ts +++ b/src/api/history/requests.ts @@ -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 { diff --git a/src/api/quizStatistics/index.ts b/src/api/quizStatistics/index.ts index 865d918..07d3001 100644 --- a/src/api/quizStatistics/index.ts +++ b/src/api/quizStatistics/index.ts @@ -40,7 +40,7 @@ export const getStatisticSchild = async (from: number, to: number): Promise<[Qui try { const statisticResponse = await makeRequest({ 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>({ method: "POST", - url: `${API_URL}/customer/promocode/ltv`, + url: `${API_URL}/customer/v1.0.0/promocode/ltv`, body: { to, from }, useToken: true, }); 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) => { + + ); };