adminFront/src/pages/dashboard/ModalUser/UserTab.tsx

92 lines
3.3 KiB
TypeScript
Raw Normal View History

import { useState, useEffect } from "react";
2023-07-26 10:49:08 +00:00
import { Box, Typography, useTheme, useMediaQuery } from "@mui/material";
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";
2023-07-25 07:47:20 +00:00
2023-08-14 11:58:12 +00:00
type UserTabProps = {
userId: string;
};
export const UserTab = ({ userId }: UserTabProps) => {
const [user, setUser] = useState<UserType | null>(null);
const [account, setAccount] = useState<Account | null>(null);
2023-07-26 10:49:08 +00:00
const theme = useTheme();
const mobile = useMediaQuery(theme.breakpoints.down(700));
useEffect(() => {
if (userId) {
2023-08-31 14:30:48 +00:00
getUserInfo(userId).then(([userInfo]) => setUser(userInfo));
2023-08-31 12:46:34 +00:00
getAccountInfo(userId).then(([accountsInfo]) => setAccount(accountsInfo));
}
}, []);
2023-07-26 10:49:08 +00:00
return (
<Box
sx={{
display: mobile ? "block" : "flex",
columnGap: "15px",
padding: "25px",
}}
>
<Box sx={{ maxWidth: "300px", width: "100%" }}>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>ID</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
{user?._id}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>Дата регистрации</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
{new Date(user?.createdAt || "").toLocaleDateString()}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>Email</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
{user?.email}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>Телефон</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
{user?.phoneNumber}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>Тип:</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
2023-08-09 06:58:43 +00:00
{account?.status === "no" && "Физ. лицо"}
{account?.status === "org" && "Юр. лицо"}
{account?.status === "nko" && "НКО"}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
2023-07-25 07:47:20 +00:00
</Box>
2023-07-26 10:49:08 +00:00
<Box sx={{ maxWidth: "300px", width: "100%" }}>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>ФИО:</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
{`${account?.name.secondname || ""} ${
account?.name.firstname || ""
} ${account?.name.middlename || ""}`}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
<Box sx={{ marginBottom: "25px" }}>
<Typography sx={{ lineHeight: "20px" }}>
Внутренний кошелек
</Typography>
<Typography sx={{ lineHeight: "20px", fontWeight: "bold" }}>
2023-08-14 11:58:12 +00:00
{`${account?.wallet.money || 0} ${
account?.wallet.currency || "RUB"
}.`}
2023-07-26 10:49:08 +00:00
</Typography>
</Box>
2023-07-25 07:47:20 +00:00
</Box>
</Box>
2023-07-26 10:49:08 +00:00
);
};