shahrbin-citizen/components/Requests/RequestProcess.tsx

140 lines
4.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"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";
// Define types for props
interface RequestProcessProps {
reportId: string;
}
interface Media {
url3: string;
}
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<RequestProcessProps> = ({ reportId }) => {
// Component state
const [history, setHistory] = useState<History[]>([]);
const [step, setStep] = useState<number>();
// 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);
// for (let i = 1; i <= data.data.length; i++) {
// // setStep.push(i);
// newArr.push(i);
// }
console.log("History state updated:", data);
console.log("🚀 ~ useEffect ~ data?.data?.length:", data?.data?.length);
}
console.log("🚀 ~ useEffect ~ setStep:", step);
}, [data]);
return (
<div className="">
<Drawer direction="right">
<DrawerTrigger onClick={(e) => e.stopPropagation()}>
<div className="text-xs text-gray-500 flex items-center cursor-pointer rounded-md">
<CgMenuRightAlt className="ml-1 text-lg" />
<span>مشاهده روند بررسی</span>
</div>
</DrawerTrigger>
<DrawerContent className=" px-20 w-1/2 h-screen z-[1000] overflow-y-auto scrollbar-thin scrollbar-thumb-yellow scrollbar-track-white">
<DrawerHeader className="mb-4"></DrawerHeader>
{history.map((history, index, array) => (
<>
<ol
key={history.id}
className="relative border-s border-gray-300 dark:border-gray-700 mr-48"
>
<li className="mb-10 ms-6">
<span className="absolute flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full -start-4 ring-8 ring-white bg-blue2 ">
{array.length - index}
</span>
<div className=" bg-white border-2 border-gray-300 rounded-lg shadow-sm dark:bg-gray-700 dark:border-gray-600 w-full">
<div className="flex items-center justify-center bg-blue text-white rounded-t-lg p-2 border-2 text-sm">
{history.message}
</div>
<div
className={`p-5 m-1 italic font-normal text-black rounded-lg text-sm text-center ${
history?.attachments?.length > 0 &&
`border-b-[1px] border-blue`
}`}
>
{history?.reason?.title}
</div>
<div>
</div>
</div>
</li>
<span className="absolute -right-44 top-0 ">
{convertTime(history.dateTime)}
</span>
<span className="absolute -right-44 top-5 ">
{convertDate(history.dateTime)}
</span>
</ol>
</>
))}
<DrawerFooter className=" absolute top-0 left-0 w-14 h-14">
<DrawerClose asChild>
<Button variant="outline" className="p-0 border-0">
<IoClose className=" w-full h-full text-gray-600" />
</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</div>
);
};
export default RequestProcess;