diff --git a/src/pages/dashboard/ModalUser/VerificationTab.tsx b/src/pages/dashboard/ModalUser/VerificationTab.tsx index 25c3307..91275f4 100644 --- a/src/pages/dashboard/ModalUser/VerificationTab.tsx +++ b/src/pages/dashboard/ModalUser/VerificationTab.tsx @@ -2,7 +2,6 @@ import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; import { Box, Typography, TextField, Button } from "@mui/material"; - import type { ChangeEvent } from "react"; import { makeRequest } from "@frontend/kitui"; @@ -27,22 +26,29 @@ type PatchVerificationBody = { accepted: boolean; }; -const baseUrl = - process.env.NODE_ENV === "production" ? "" : "https://hub.pena.digital"; +const baseUrl = process.env.NODE_ENV === "production" ? "" : "https://hub.pena.digital"; export const VerificationTab = () => { const [user, setUser] = useState(null); const [comment, setComment] = useState(""); + const [isLoading, setIsLoading] = useState(true); const { userId } = useParams(); - const requestVefification = async () => - makeRequest({ - method: "get", - url: baseUrl + `/verification/verification/${userId}`, - }).then((verification) => { + const requestVefification = async () => { + setIsLoading(true); + try { + const verification = await makeRequest({ + method: "get", + url: baseUrl + `/verification/verification/${userId}`, + }); setUser(verification); setComment(verification.comment); - }); + } catch (error) { + console.error("Error fetching verification:", error); + } finally { + setIsLoading(false); + } + }; useEffect(() => { requestVefification(); @@ -67,7 +73,9 @@ export const VerificationTab = () => { }); await requestVefification(); - } catch {} + } catch (error) { + console.error("Error verifying:", error); + } }; return ( @@ -81,38 +89,43 @@ export const VerificationTab = () => { > {user?.accepted ? "Верификация пройдена" : "Не верифицирован"} - {user?.files?.map(({ name, url }, index) => ( - - - {index + 1}.{" "} - {name === "inn" - ? "Скан ИНН организации (выписка из ЕГЮРЛ)" - : name === "rule" - ? "Устав организации" - : name === "certificate" - ? "Свидетельство о регистрации НКО" - : `Скан документа ${index + 1}`} - - - - {url.split("/").pop()?.split(".")?.[0]} - - - - ))} + {isLoading ? ( + Загрузка данных... + ) : user && user.files.length > 0 ? ( + user.files.map(({ name, url }, index) => ( + + + {index + 1}.{" "} + {name === "inn" + ? "Скан ИНН организации (выписка из ЕГЮРЛ)" + : name === "rule" + ? "Устав организации" + : name === "certificate" + ? "Свидетельство о регистрации НКО" + : `Скан документа ${index + 1}`} + + + + {url.split("/").pop()?.split(".")?.[0]} + + + + )) + ) : ( + + Пользователь не загружал данные + + )} {user?.comment && ( - + Комментарий: {user.comment} @@ -129,23 +142,13 @@ export const VerificationTab = () => { maxWidth: "500px", marginBottom: "10px", }} - onChange={(event: ChangeEvent) => - setComment(event.target.value) - } + onChange={(event: ChangeEvent) => setComment(event.target.value)} /> - -