204 lines
7.4 KiB
TypeScript
204 lines
7.4 KiB
TypeScript
"use client";
|
|
import React, { useEffect, useState, useRef } from "react";
|
|
import Image from "next/image";
|
|
import Resultimg from "../public/img/followResult.png";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { ThreeDots } from "react-loader-spinner";
|
|
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
AlertDialogTrigger,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import { IoMdClose } from "react-icons/io";
|
|
import { postComplaintTracking } from "@/utils/citizenApi";
|
|
import { useMutation } from "@tanstack/react-query";
|
|
import { useReactToPrint } from "react-to-print";
|
|
|
|
import "../app/print-styles.css";
|
|
import ComplainsDetails from "./ComplainsDetails";
|
|
|
|
export default function FollowResult() {
|
|
const router = useRouter();
|
|
const [trackingNumber, setTrackingNumber] = useState<any>();
|
|
const [password, setPassword] = useState<any>();
|
|
const [complaintData, setComplaintData] = useState<any>();
|
|
const [printStyle, setPrintStyle] = useState<boolean>(true);
|
|
|
|
// Print component Data
|
|
const componentRef = useRef<HTMLDivElement>(null);
|
|
const handlePrint = useReactToPrint({
|
|
content: () => componentRef.current,
|
|
// onBeforePrint() {
|
|
// setPrintStyle(!printStyle);
|
|
// },
|
|
// onAfterPrint() {
|
|
// setPrintStyle(!printStyle)
|
|
// },
|
|
});
|
|
|
|
useEffect(() => {
|
|
setTrackingNumber(localStorage.getItem("trackingNumber2"));
|
|
setPassword(localStorage.getItem("password2"));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (trackingNumber && password) {
|
|
complaintPrintMutation.mutate({
|
|
Data: { trackingNumber: trackingNumber, password: password },
|
|
});
|
|
}
|
|
}, [trackingNumber, password]);
|
|
|
|
const complaintPrintMutation = useMutation({
|
|
mutationKey: ["complaintPrint"],
|
|
mutationFn: postComplaintTracking,
|
|
onSuccess: (res) => {
|
|
setComplaintData(res);
|
|
},
|
|
onError: (error) => {
|
|
console.log(error);
|
|
console.log(error?.message);
|
|
},
|
|
});
|
|
|
|
function onSubmit() {
|
|
console.log("SuccessPrinttttttttttt");
|
|
|
|
// complaintPrintMutation.mutate({
|
|
// Data: { trackingNumber: trackingNumber, password: password },
|
|
// });
|
|
}
|
|
// const possibleOperations = complaintPrintMutation.data?.possibleOperations;
|
|
// const selectOptions = Operations.filter((item, index) =>
|
|
// possibleOperations.includes(index)
|
|
// );
|
|
|
|
const printableContent = "This is the content to be printed.";
|
|
console.log(complaintPrintMutation?.data);
|
|
return (
|
|
<>
|
|
<div className="w-[90vw] sm:w-[90vw] lg:w-[85vw] xl:w-[75vw] 3xl:w-[70vw] max-sm:mt-16 pt-12 mx-auto mb-10">
|
|
{complaintPrintMutation?.data ? (
|
|
<>
|
|
{/* <div className="flex justify-center sm:justify-end gap-2 mb-2">
|
|
<AlertDialog>
|
|
<AlertDialogTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
type="submit"
|
|
onClick={() => onSubmit()}
|
|
className="w-fit bg-blue text-white p-2 rounded-xl text-center"
|
|
>
|
|
پرینت درخواست
|
|
</Button>
|
|
</AlertDialogTrigger>
|
|
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>
|
|
<p className="text-[#464646] text-base font-bold">
|
|
گزارش شکایات
|
|
</p>
|
|
|
|
<AlertDialogCancel className="p-0 border-0 h-auto">
|
|
<IoMdClose />
|
|
</AlertDialogCancel>
|
|
</AlertDialogTitle>
|
|
|
|
<AlertDialogDescription className="h-full px-0 py-0 sm:px-0 sm:pt-0 ">
|
|
{complaintPrintMutation.isPending ? (
|
|
<div className="felx justify-center items-center self-center h-full">
|
|
<ThreeDots
|
|
visible={true}
|
|
height="80"
|
|
width="100"
|
|
color="#003778"
|
|
radius="9"
|
|
ariaLabel="three-dots-loading"
|
|
wrapperStyle={{}}
|
|
wrapperClass=""
|
|
/>
|
|
</div>
|
|
) : (
|
|
<div
|
|
dir="rtl"
|
|
className=" font-[yekan] px-10 py-4 sm:px-28 sm:pt-9 "
|
|
id="details"
|
|
ref={componentRef}
|
|
// style={{ border: printStyle ? 'none' : '5px solid black' , margin: printStyle ? 'auto': '1em' }}
|
|
>
|
|
<p className="text-[#464646] text-sm font-medium">
|
|
{" "}
|
|
موضوع شکایت:{" "}
|
|
<span className="text-[#7C838A] text-sm font-medium">
|
|
{`${complaintData?.title}`}
|
|
</span>
|
|
</p>
|
|
<p className="text-[#464646] text-sm font-medium">
|
|
{" "}
|
|
متن شکایت:{" "}
|
|
<span className="text-[#7C838A] text-sm font-medium">
|
|
{`${complaintData?.contents[0]?.text}`}
|
|
</span>
|
|
</p>
|
|
<br />
|
|
|
|
<p className="text-[#464646] text-sm font-medium">
|
|
{" "}
|
|
جزئیات شکایت:
|
|
</p>
|
|
<br />
|
|
<p className="text-[#464646] text-sm font-medium">
|
|
درخواست شما با کد رهگیری
|
|
<span className="text-slate-500 mx-2">{`${trackingNumber}`}</span>
|
|
و رمز عبور
|
|
<span className="text-slate-500 mx-2">{`${password}`}</span>
|
|
در دست بررسی و اقدام می باشد. در صورت تمایل می
|
|
توانید با شماره تلفن 0353286545 جهت پشتیبانی تماس
|
|
حاصل کنید.
|
|
</p>
|
|
</div>
|
|
)}
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<Button
|
|
className="bg-blue text-white w-1/2 sm:w-1/6"
|
|
onClick={handlePrint}
|
|
>
|
|
پرینت گزارش
|
|
</Button>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div> */}
|
|
<ComplainsDetails
|
|
role="Citizen"
|
|
state="FollowResult"
|
|
Data={complaintPrintMutation?.data}
|
|
/>
|
|
</>
|
|
) : (
|
|
""
|
|
)}
|
|
|
|
{/* <Image
|
|
alt="icon"
|
|
src={Resultimg}
|
|
className="self-center w-3/5 mt-5 sm:w-[23em] sm:h-[20em] 3xl:w-3/5 3xl:h-[30em] object-contain"
|
|
/> */}
|
|
{/* </div> */}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|