diff --git a/src/api/account.ts b/src/api/account.ts new file mode 100644 index 0000000..96e2d13 --- /dev/null +++ b/src/api/account.ts @@ -0,0 +1,41 @@ +import { makeRequest } from "@frontend/kitui"; + +type Name = { + firstname: string; + secondname: string; + middlename: string; + orgname: string; +}; + +type Wallet = { + currency: string; + cash: number; + purchasesAmount: number; + spent: number; + money: number; +}; + +export type Account = { + _id: string; + userId: string; + cart: string[]; + status: string; + isDeleted: boolean; + createdAt: string; + updatedAt: string; + deletedAt: string; + name: Name; + wallet: Wallet; +}; + +const baseUrl = + process.env.NODE_ENV === "production" + ? "/customer/account" + : "https://admin.pena.digital/customer/account"; + +export const getAccountInfo = async (id: string) => + makeRequest({ + url: `${baseUrl}/${id}`, + method: "GET", + useToken: true, + }); diff --git a/src/api/user.ts b/src/api/user.ts new file mode 100644 index 0000000..2181524 --- /dev/null +++ b/src/api/user.ts @@ -0,0 +1,15 @@ +import { makeRequest } from "@frontend/kitui"; + +import type { UserType } from "@root/api/roles"; + +const baseUrl = + process.env.NODE_ENV === "production" + ? "/user" + : "https://admin.pena.digital/user"; + +export const getUserInfo = async (id: string) => + makeRequest({ + url: `${baseUrl}/${id}`, + method: "GET", + useToken: true, + }); diff --git a/src/pages/dashboard/ModalUser/UserTab.tsx b/src/pages/dashboard/ModalUser/UserTab.tsx index 391f2c0..3bc517b 100644 --- a/src/pages/dashboard/ModalUser/UserTab.tsx +++ b/src/pages/dashboard/ModalUser/UserTab.tsx @@ -1,9 +1,27 @@ +import { useState, useEffect } from "react"; import { Box, Typography, useTheme, useMediaQuery } from "@mui/material"; +import { useParams } from "react-router-dom"; + +import { getUserInfo } from "@root/api/user"; +import { getAccountInfo } from "@root/api/account"; + +import type { UserType } from "@root/api/roles"; +import type { Account } from "@root/api/account"; export const UserTab = () => { + const [user, setUser] = useState(null); + const [account, setAccount] = useState(null); + const { userId } = useParams(); const theme = useTheme(); const mobile = useMediaQuery(theme.breakpoints.down(700)); + useEffect(() => { + if (userId) { + getUserInfo(userId).then(setUser); + getAccountInfo(userId).then(setAccount); + } + }, []); + return ( { ID - {" "} - 2810 + {user?._id} Дата регистрации - 17.02.2023 + {new Date(user?.createdAt || "").toLocaleDateString()} Email - emailexamle@gmail.com + {user?.email} Телефон - +7 123 456 78 90 + {user?.phoneNumber} Тип: - НКО + {account?.status === "no" ? "НКО" : "Юр. лицо"} @@ -49,7 +66,9 @@ export const UserTab = () => { ФИО: - Куликов Геннадий Викторович + {`${account?.name.secondname || ""} ${ + account?.name.firstname || "" + } ${account?.name.middlename || ""}`} @@ -57,7 +76,9 @@ export const UserTab = () => { Внутренний кошелек - 2 096 руб. + {`${account?.wallet.money || ""} ${ + account?.wallet.currency || "RUB" + }.`}