"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(null); const router = useRouter(); const storeData = useData((state) => state.data); let data; const openFileInNewTab = ( base64Data: any, fileType: any, fileName?: string ) => { 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 { downloadFile(base64Data, fileName, fileType); } 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 }); }; useEffect(() => { useData.persist.rehydrate(); if (state == "FollowResult") { setOpen(false); } }, []); useEffect(() => { const tk = localStorage.getItem("trackingNumber2"); const pw = localStorage.getItem("password2"); if (tk && pw) { getComplaintMutation.mutate({ Data: { trackingNumber: tk, password: pw }, }); } }, []); data = getComplaintMutation?.data; const possibleOperations = data?.possibleOperationsWithDescription; if (possibleOperations?.length == 0) { localStorage.removeItem("trackingNumber2"); localStorage.removeItem("password2"); } return ( <> رمز عبور برای مشاهده گزارش رمز عبور خود را وارد نمایید.
{/* */} setPassword(e.target.value)} className="bg-white hover:bg-white focus:bg-white text-center" />
{/* */} {/* */}
{getComplaintMutation.data && !getComplaintMutation.isPending ? ( <> {/* {state !== "FollowResult" && ( )} */} {/* Editt */}
{/* 1 */}
{/* ***** */}

انجام عملیات

getComplaintMutation.mutate({ Data: payload }) } role={role} complaintData={data} password={password} />
{/* 2 */}
{data?.user == null ? ( <>

اطلاعات کلی

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

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

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

کد پیگیری:{" "} {data.trackingNumber ? data.trackingNumber : "-"}

زمان ثبت:{" "} {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, index: any, array: any) => { return ( <>
{array.length - index}
{/* {array.length - index} */}

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

{convertFullTime(item.dateTime)}

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

{item.title}

{/* downloadFile( item.data, item.title, item.mimeType ) } /> */}
); } )}
); })}
{/* 3 */} {/* ****** */}
) : ( <> {getComplaintMutation.isPending && (
)} )} ); }