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);
method: "get", try {
url: baseUrl + `/verification/verification/${userId}`, const verification = await makeRequest<never, Verification>({
}).then((verification) => { method: "get",
url: baseUrl + `/verification/verification/${userId}`,
});
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,38 +89,43 @@ export const VerificationTab = () => {
> >
{user?.accepted ? "Верификация пройдена" : "Не верифицирован"} {user?.accepted ? "Верификация пройдена" : "Не верифицирован"}
</Typography> </Typography>
{user?.files?.map(({ name, url }, index) => ( {isLoading ? (
<Box sx={{ marginBottom: "25px" }} key={name + url}> <Typography sx={{ fontWeight: "bold", fontSize: "18px", marginBottom: "25px" }}>Загрузка данных...</Typography>
<Typography sx={{ fontWeight: "bold", fontSize: "18px" }}> ) : user && user.files.length > 0 ? (
{index + 1}.{" "} user.files.map(({ name, url }, index) => (
{name === "inn" <Box sx={{ marginBottom: "25px" }} key={name + url}>
? "Скан ИНН организации (выписка из ЕГЮРЛ)" <Typography sx={{ fontWeight: "bold", fontSize: "18px" }}>
: name === "rule" {index + 1}.{" "}
? "Устав организации" {name === "inn"
: name === "certificate" ? "Скан ИНН организации (выписка из ЕГЮРЛ)"
? "Свидетельство о регистрации НКО" : name === "rule"
: `Скан документа ${index + 1}`} ? "Устав организации"
</Typography> : name === "certificate"
<Typography> ? "Свидетельство о регистрации НКО"
<a : `Скан документа ${index + 1}`}
style={{ </Typography>
color: "#7E2AEA", <Typography>
textDecoration: "none", <a
fontSize: "18px", style={{
}} color: "#7E2AEA",
href={url} textDecoration: "none",
> fontSize: "18px",
{url.split("/").pop()?.split(".")?.[0]} }}
</a> href={url}
</Typography> >
</Box> {url.split("/").pop()?.split(".")?.[0]}
))} </a>
</Typography>
</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>