"use client"; import React, { useEffect, useState } from "react"; import greenIcon from "../public/img/greenPoint.svg"; import blueIcon from "../public/img/bluepoint.svg"; import Image from "next/image"; import { ComplainDetailsItems } from "@/constants"; import { useMutation } from "@tanstack/react-query"; import useData from "@/store/useData"; import { convertDate , convertFullTime } from "@/lib/utils"; import { Badge } from "./ui/badge"; import InspectorOperations from "./InspectorOperations"; import { postComplaintTracking } from "@/utils/citizenApi"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Input } from "./ui/input"; import { toast } from "sonner"; import { useRouter } from "next/navigation"; import { Triangle } from "react-loader-spinner"; import { ArrowDownToLine, ArrowRight, File } from "lucide-react"; export default function ComplainsDetails({ id, role, Data, state, }: { id?: number; role: string; Data?: any; state?: string; }) { const [open, setOpen] = useState( state == "FollowResult" ? false : true ); const [password, setPassword] = useState(true); const router = useRouter(); const storeData = useData((state) => state.data); let data; const openFileInNewTab = (base64Data: any, fileType: any) => { const blob = b64toBlob(base64Data, fileType); const blobUrl = URL.createObjectURL(blob); const newTab = window.open(); if (newTab) { newTab.document.write( 'File Preview' ); // Check the file type and handle accordingly if (fileType.includes("image")) { newTab.document.write( `File Preview` ); } else if (fileType === "application/pdf") { newTab.document.write( `` ); } else { newTab.document.write( `Open in New Tab` ); } newTab.document.write(""); newTab.document.close(); URL.revokeObjectURL(blobUrl); } else { console.error("Unable to open a new tab."); } }; const downloadFile = (base64Data: any, fileName: any, fileType: any) => { const blob = b64toBlob(base64Data, fileType); const blobUrl = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = blobUrl; link.download = fileName; link.click(); URL.revokeObjectURL(blobUrl); }; const b64toBlob = (b64Data: any, contentType = "", sliceSize = 512) => { const byteCharacters = atob(b64Data); const byteArrays = []; for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { const slice = byteCharacters.slice(offset, offset + sliceSize); const byteNumbers = new Array(slice.length); for (let i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray); } return new Blob(byteArrays, { type: contentType }); }; const getComplaintMutation = useMutation({ mutationKey: ["Complaint", id], mutationFn: postComplaintTracking, onSuccess: (res) => { setOpen(false); }, onError: (err: any | string) => { toast(<>{err.response.data.detail}, { className: "!bg-red-500 !text-white", }); }, }); const handelPassword = () => { const payload = { ...storeData, password: password }; getComplaintMutation.mutate({ Data: payload }); }; console.log(storeData); useEffect(() => { useData.persist.rehydrate(); if (state == "FollowResult") { setOpen(false); } }, []); if (getComplaintMutation.isSuccess && !Data) { data = getComplaintMutation.data; } else { data = Data; } return ( <> رمز عبور برای مشاهده درخواست پسورد خود را وارد نمایید.
{/* */} setPassword(e.target.value)} className="bg-white hover:bg-white focus:bg-white" />
{/* */} {/* */}
{data ? ( <> {state !== "FollowResult" && ( )} {/* Editt */}
{/* 1 */}
{/* ***** */}

انجام عملیات

getComplaintMutation.mutate(storeData)} role={role} complaintData={data} />
{/* 2 */}
{data.user == null ? ( <>

اطلاعات کلی

موضوع شکایت:{" "} {data?.title}

دستگاه مربوطه:{" "} {data?.complaintOrganization ? data?.complaintOrganization.title : "-"}

فرد مربوطه:{" "} {data.complaining ? data.complaining : "-"}

زمان ثبت:{" "} {convertFullTime(data.registeredAt)}

) : ( <>

اطلاعات کلی

موضوع شکایت:{" "} {data?.title}

دستگاه مربوطه:{" "} {data?.complaintOrganization ? data?.complaintOrganization.title : "-"}

فرد مربوطه:{" "} {data.complaining ? data.complaining : "-"}

زمان ثبت:{" "} {convertFullTime(data.registeredAt)}

اطلاعات شاکی

نام:{" "} {data.user?.firstName ? data.user?.firstName : "-"}

نام خانوادگی:{" "} {data.user?.lastName ? data.user?.lastName : "-"}

کدملی:{" "} {data.user?.nationalId ? data.user?.nationalId : "-"}

شماره موبایل:{" "} {data.user?.phoneNumber ? data.user?.phoneNumber : "-"}

)}

روند شکایت

{data.contents?.map((item: any) => { return (

{item.sender == 0 ? "شهروند" : "بازرس"}

تاریخ : {convertDate(item.dateTime)}

{item.text ? item.text : "-"}
{/* {item.media.length !== 0 && ( )} */}
{item?.media.map((item: any, index: number) => { return ( ); })}
); })}
{/* 3 */} {/* ****** */}

انجام عملیات

getComplaintMutation.mutate(storeData)} role={role} complaintData={data} />
) : ( <> {getComplaintMutation.isPending && (
)} )} ); }