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

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