WIPVOLONT
This commit is contained in:
@@ -10,7 +10,7 @@ const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL;
|
||||
const statusMap = {
|
||||
pending_moderation: { label: "На модерации", color: "#E9D171" },
|
||||
approved: { label: "Принята", color: "#94E067" },
|
||||
in_progress: { label: "В процессе", color: "#E971E1" },
|
||||
inprogress: { label: "В процессе", color: "#E971E1" },
|
||||
completed: { label: "Выполнена", color: "#71A5E9" },
|
||||
cancelled: { label: "Отменена", color: "#FF8282" },
|
||||
rejected: { label: "Отклонена", color: "#FF8282" },
|
||||
@@ -19,7 +19,7 @@ const statusMap = {
|
||||
const HistoryRequestPage = () => {
|
||||
const [userName, setUserName] = useState("Волонтёр");
|
||||
|
||||
const [requests, setRequests] = useState([]); // истории заявок волонтёра
|
||||
const [requests, setRequests] = useState([]);
|
||||
const [selectedRequest, setSelectedRequest] = useState(null);
|
||||
|
||||
const [error, setError] = useState("");
|
||||
@@ -32,7 +32,7 @@ const HistoryRequestPage = () => {
|
||||
return authUser?.accessToken || null;
|
||||
};
|
||||
|
||||
// подгружаем имя
|
||||
// имя
|
||||
useEffect(() => {
|
||||
const fetchProfile = async () => {
|
||||
if (!API_BASE) return;
|
||||
@@ -49,20 +49,18 @@ const HistoryRequestPage = () => {
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
const fullName =
|
||||
[data.first_name, data.last_name]
|
||||
.filter(Boolean)
|
||||
.join(" ")
|
||||
.trim() || data.email;
|
||||
[data.first_name, data.last_name].filter(Boolean).join(" ").trim() ||
|
||||
data.email;
|
||||
setUserName(fullName);
|
||||
} catch {
|
||||
// оставляем дефолт
|
||||
//
|
||||
}
|
||||
};
|
||||
|
||||
fetchProfile();
|
||||
}, []);
|
||||
|
||||
// загружаем историю заявок волонтёра
|
||||
// история: /requests/my
|
||||
useEffect(() => {
|
||||
const fetchVolunteerRequests = async () => {
|
||||
if (!API_BASE) {
|
||||
@@ -78,8 +76,12 @@ const HistoryRequestPage = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
// вариант 1 (рекомендуется на бэке): отдельный эндпоинт, здесь предположим, что бек отдаёт RequestListItem[]
|
||||
const res = await fetch(`${API_BASE}/requests/my?role=volunteer`, {
|
||||
const params = new URLSearchParams({
|
||||
limit: "50",
|
||||
offset: "0",
|
||||
});
|
||||
|
||||
const res = await fetch(`${API_BASE}/requests/my?${params}`, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
@@ -100,10 +102,11 @@ const HistoryRequestPage = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json(); // массив RequestListItem[file:519]
|
||||
const data = await res.json(); // RequestListItem[][web:598]
|
||||
|
||||
const mapped = data.map((item) => {
|
||||
const m = statusMap[item.status] || {
|
||||
const key = String(item.status || "").toLowerCase();
|
||||
const m = statusMap[key] || {
|
||||
label: item.status,
|
||||
color: "#E2E2E2",
|
||||
};
|
||||
@@ -157,7 +160,7 @@ const HistoryRequestPage = () => {
|
||||
{/* Header */}
|
||||
<header className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-full border border-white flex items-center justify-center">
|
||||
<div className="w-8 h-8 rounded-full border border-white flex items.center justify-center">
|
||||
<FaUser className="text-white text-sm" />
|
||||
</div>
|
||||
<p className="font-montserrat font-extrabold text-[20px] leading-[11px] text-white">
|
||||
@@ -201,9 +204,8 @@ const HistoryRequestPage = () => {
|
||||
key={req.id}
|
||||
type="button"
|
||||
onClick={() => handleOpen(req)}
|
||||
className="w-full text-left bg-white rounded-xl px-3.py-2 flex flex-col gap-1"
|
||||
className="w-full text-left bg-white rounded-xl px-3 py-2 flex flex-col gap-1"
|
||||
>
|
||||
{/* верхняя строка: статус + дата/время */}
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span
|
||||
className="inline-flex items-center justify-center px-2 py-0.5 rounded-full font-montserrat text-[12px] font-light text-black"
|
||||
@@ -221,13 +223,11 @@ const HistoryRequestPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Заголовок заявки */}
|
||||
<p className="font-montserrat font-semibold text-[15px] leading-[18px] text-black mt-1">
|
||||
{req.title}
|
||||
</p>
|
||||
|
||||
{/* Кнопка "Развернуть" */}
|
||||
<div className="mt-2 w-full bg-[#94E067] rounded-lg py-3 flex.items-center justify-center">
|
||||
<div className="mt-2 w-full bg-[#94E067] rounded-lg py-3 flex items-center justify-center">
|
||||
<span className="font-montserrat font-bold text-[15px] leading-[18px] text-white">
|
||||
Развернуть
|
||||
</span>
|
||||
@@ -236,7 +236,6 @@ const HistoryRequestPage = () => {
|
||||
))}
|
||||
</main>
|
||||
|
||||
{/* Попап */}
|
||||
{selectedRequest && (
|
||||
<RequestDetailsModal request={selectedRequest} onClose={handleClose} />
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user