"use client"; import React, { useEffect, useState } from "react"; import { CgMenuRightAlt } from "react-icons/cg"; import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer"; import { Button } from "../ui/button"; import { IoClose } from "react-icons/io5"; import { useQuery } from "@tanstack/react-query"; import { getReportHistory } from "@/utils/CitizenReport"; import { convertDate, convertFullTime, convertTime } from "@/lib/utils"; import { log } from "console"; import Image from "next/image"; import imgdocument from "@/assets/images/icons8-document-50.png"; import imgimage from "@/assets/images/icons8-image-50.png"; import imgvideo from "@/assets/images/icons8-video-camera-50.png"; import imgvoice from "@/assets/images/icons8-voice-id-50.png"; import axios from "axios"; // Define types for props interface RequestProcessProps { reportId: string; } interface Media { url: string; url3: string; mediaType: number; } interface Reason { description: string; id: number; reasonMeaning: number; title: string; transitions: []; } // Define types for History interface History { id: string; message: string; attachments: Media[]; dateTime: string; isPublic: boolean; reason: Reason; } const RequestProcess: React.FC = ({ reportId }) => { // Component state const [history, setHistory] = useState([]); const [step, setStep] = useState(); const { data, isLoading, isError, isSuccess, refetch } = useQuery({ queryKey: ["History", reportId], queryFn: () => getReportHistory(reportId), // refetchOnWindowFocus: false, }); // let newArr = []; useEffect(() => { console.log("Fetched data:", data); // Log the fetched data if (data) { setHistory(data?.data); setStep(data?.data?.length); } }, [data]); const handleDownload = async (url: string) => { try { const response = await axios.get(url, { responseType: "blob", // دریافت فایل به صورت blob }); const filename = getFilenameFromUrl(url); const blob = new Blob([response.data], { type: response.data.type }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(link.href); } catch (error) { console.error("Download failed:", error); } }; const getFilenameFromUrl = (url: string) => { return url.split("/").pop() || "downloaded-file"; }; return (
e.stopPropagation()}>
مشاهده روند بررسی
{history.map((history, index, array) => ( <>
  1. {array.length - index}
    {history.message}
    0 && `border-b-[1px] border-blue` }`} > {history?.reason?.title}
    {history?.attachments?.length > 0 && (
    پیوست ها
    {history?.attachments?.map((attachment, index) => (
    handleDownload(attachment.url)} key={index} > {attachment.mediaType == 0 && ( picture )} {attachment.mediaType == 1 && ( picture )} {attachment.mediaType == 2 && ( picture )} {attachment.mediaType == 3 && ( picture )}
    ))}
    )}
  2. {convertTime(history.dateTime)} {convertDate(history.dateTime)}
))}
); }; export default RequestProcess;