From fa26515652a2bc1e238428b1f26b6e7f237d864e Mon Sep 17 00:00:00 2001 From: Nastya Date: Sun, 9 Jun 2024 19:54:40 +0300 Subject: [PATCH 1/2] customer v1.0.0 --- src/api/account.ts | 2 +- src/api/history/requests.ts | 2 +- src/api/quizStatistics/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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, }); From a21cdc48b2c74ff448274029c5df89bd30fc366d Mon Sep 17 00:00:00 2001 From: Nastya Date: Tue, 25 Jun 2024 23:40:57 +0300 Subject: [PATCH 2/2] =?UTF-8?q?--1=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=B4=D0=B5=D0=BA?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=D0=B5=D0=B3=D0=B8=D0=B8=20=D1=8E=D0=B7=D0=B5?= =?UTF-8?q?=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user/requests.ts | 22 +++++++ .../ModalUser/UserPrivilegeDecrement.tsx | 59 +++++++++++++++++++ src/pages/dashboard/ModalUser/UserTab.tsx | 12 +++- 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/pages/dashboard/ModalUser/UserPrivilegeDecrement.tsx 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) => { + + ); };