86 lines
2.5 KiB
TypeScript
86 lines
2.5 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 { 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 ComplainsDetails from "./ComplainsDetails";
|
|
import { toast } from "sonner";
|
|
import { ArrowRight } from "lucide-react";
|
|
|
|
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: (err: any | string) => {
|
|
toast(<>{err.response.data.detail}</>, {
|
|
className: "!bg-red-500 !text-white",
|
|
});
|
|
},
|
|
});
|
|
|
|
const printableContent = "This is the content to be printed.";
|
|
return (
|
|
<>
|
|
<div className="w-[90vw] sm:w-[90vw] lg:w-[85vw] xl:w-[75vw] 3xl:w-[70vw] pt-6 mx-auto">
|
|
<>
|
|
{/* <button
|
|
onClick={() => router.push("/FollowUp")}
|
|
className="flex gap-1 cursor-pointer text-blue"
|
|
>
|
|
<span>
|
|
<ArrowRight />
|
|
</span>
|
|
<p>بازگشت</p>
|
|
</button> */}
|
|
<ComplainsDetails
|
|
role="Citizen"
|
|
state="FollowResult"
|
|
/>
|
|
</>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|