feat: getUserInfo getAccountInfo requests
This commit is contained in:
parent
36727dcdb4
commit
77a7b8d0a7
41
src/api/account.ts
Normal file
41
src/api/account.ts
Normal file
@ -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<never, Account>({
|
||||
url: `${baseUrl}/${id}`,
|
||||
method: "GET",
|
||||
useToken: true,
|
||||
});
|
||||
15
src/api/user.ts
Normal file
15
src/api/user.ts
Normal file
@ -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<never, UserType>({
|
||||
url: `${baseUrl}/${id}`,
|
||||
method: "GET",
|
||||
useToken: true,
|
||||
});
|
||||
@ -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<UserType | null>(null);
|
||||
const [account, setAccount] = useState<Account | null>(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 (
|
||||
<Box
|
||||
sx={{
|
||||
@ -16,32 +34,31 @@ export const UserTab = () => {
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
<Typography sx={{ lineHeight: "20px" }}>ID</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
{" "}
|
||||
2810
|
||||
{user?._id}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
<Typography sx={{ lineHeight: "20px" }}>Дата регистрации</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
17.02.2023
|
||||
{new Date(user?.createdAt || "").toLocaleDateString()}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
<Typography sx={{ lineHeight: "20px" }}>Email</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
emailexamle@gmail.com
|
||||
{user?.email}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
<Typography sx={{ lineHeight: "20px" }}>Телефон</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
+7 123 456 78 90
|
||||
{user?.phoneNumber}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
<Typography sx={{ lineHeight: "20px" }}>Тип:</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
НКО
|
||||
{account?.status === "no" ? "НКО" : "Юр. лицо"}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@ -49,7 +66,9 @@ export const UserTab = () => {
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
<Typography sx={{ lineHeight: "20px" }}>ФИО:</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
Куликов Геннадий Викторович
|
||||
{`${account?.name.secondname || ""} ${
|
||||
account?.name.firstname || ""
|
||||
} ${account?.name.middlename || ""}`}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ marginBottom: "25px" }}>
|
||||
@ -57,7 +76,9 @@ export const UserTab = () => {
|
||||
Внутренний кошелек
|
||||
</Typography>
|
||||
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
|
||||
2 096 руб.
|
||||
{`${account?.wallet.money || ""} ${
|
||||
account?.wallet.currency || "RUB"
|
||||
}.`}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user