Added loading notification during verification. Commit message.

This commit is contained in:
ArtChaos189 2023-08-14 18:04:13 +03:00
parent 9640516e31
commit d80d8bc3d5

@ -2,7 +2,6 @@ import { useState, useEffect } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { Box, Typography, TextField, Button } from "@mui/material"; import { Box, Typography, TextField, Button } from "@mui/material";
import type { ChangeEvent } from "react"; import type { ChangeEvent } from "react";
import { makeRequest } from "@frontend/kitui"; import { makeRequest } from "@frontend/kitui";
@ -27,22 +26,29 @@ type PatchVerificationBody = {
accepted: boolean; accepted: boolean;
}; };
const baseUrl = const baseUrl = process.env.NODE_ENV === "production" ? "" : "https://hub.pena.digital";
process.env.NODE_ENV === "production" ? "" : "https://hub.pena.digital";
export const VerificationTab = () => { export const VerificationTab = () => {
const [user, setUser] = useState<Verification | null>(null); const [user, setUser] = useState<Verification | null>(null);
const [comment, setComment] = useState<string>(""); const [comment, setComment] = useState<string>("");
const [isLoading, setIsLoading] = useState<boolean>(true);
const { userId } = useParams(); const { userId } = useParams();
const requestVefification = async () => const requestVefification = async () => {
makeRequest<never, Verification>({ setIsLoading(true);
try {
const verification = await makeRequest<never, Verification>({
method: "get", method: "get",
url: baseUrl + `/verification/verification/${userId}`, url: baseUrl + `/verification/verification/${userId}`,
}).then((verification) => { });
setUser(verification); setUser(verification);
setComment(verification.comment); setComment(verification.comment);
}); } catch (error) {
console.error("Error fetching verification:", error);
} finally {
setIsLoading(false);
}
};
useEffect(() => { useEffect(() => {
requestVefification(); requestVefification();
@ -67,7 +73,9 @@ export const VerificationTab = () => {
}); });
await requestVefification(); await requestVefification();
} catch {} } catch (error) {
console.error("Error verifying:", error);
}
}; };
return ( return (
@ -81,7 +89,10 @@ export const VerificationTab = () => {
> >
{user?.accepted ? "Верификация пройдена" : "Не верифицирован"} {user?.accepted ? "Верификация пройдена" : "Не верифицирован"}
</Typography> </Typography>
{user?.files?.map(({ name, url }, index) => ( {isLoading ? (
<Typography sx={{ fontWeight: "bold", fontSize: "18px", marginBottom: "25px" }}>Загрузка данных...</Typography>
) : user && user.files.length > 0 ? (
user.files.map(({ name, url }, index) => (
<Box sx={{ marginBottom: "25px" }} key={name + url}> <Box sx={{ marginBottom: "25px" }} key={name + url}>
<Typography sx={{ fontWeight: "bold", fontSize: "18px" }}> <Typography sx={{ fontWeight: "bold", fontSize: "18px" }}>
{index + 1}.{" "} {index + 1}.{" "}
@ -106,13 +117,15 @@ export const VerificationTab = () => {
</a> </a>
</Typography> </Typography>
</Box> </Box>
))} ))
) : (
<Typography sx={{ fontWeight: "bold", fontSize: "18px", marginBottom: "25px" }}>
Пользователь не загружал данные
</Typography>
)}
{user?.comment && ( {user?.comment && (
<Box sx={{ marginBottom: "15px" }}> <Box sx={{ marginBottom: "15px" }}>
<Typography <Typography component="span" sx={{ fontWeight: "bold", marginBottom: "10px" }}>
component="span"
sx={{ fontWeight: "bold", marginBottom: "10px" }}
>
Комментарий: Комментарий:
</Typography> </Typography>
<Typography component="span"> {user.comment}</Typography> <Typography component="span"> {user.comment}</Typography>
@ -129,23 +142,13 @@ export const VerificationTab = () => {
maxWidth: "500px", maxWidth: "500px",
marginBottom: "10px", marginBottom: "10px",
}} }}
onChange={(event: ChangeEvent<HTMLTextAreaElement>) => onChange={(event: ChangeEvent<HTMLTextAreaElement>) => setComment(event.target.value)}
setComment(event.target.value)
}
/> />
<Box sx={{ display: "flex", columnGap: "10px" }}> <Box sx={{ display: "flex", columnGap: "10px" }}>
<Button <Button variant="text" sx={{ background: "#9A9AAF" }} onClick={() => verify(false)}>
variant="text"
sx={{ background: "#9A9AAF" }}
onClick={() => verify(false)}
>
Отклонить Отклонить
</Button> </Button>
<Button <Button variant="text" sx={{ background: "#9A9AAF" }} onClick={() => verify(true)}>
variant="text"
sx={{ background: "#9A9AAF" }}
onClick={() => verify(true)}
>
Подтвердить Подтвердить
</Button> </Button>
</Box> </Box>