190 lines
6.7 KiB
TypeScript
190 lines
6.7 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';
|
||
|
||
export default function FollowResult() {
|
||
const router = useRouter();
|
||
const [trackingNumber, setTrackingNumber] = useState<any>();
|
||
const [password, setPassword] = useState<any>();
|
||
const [complaintData, setComplaintData] = useState<any>();
|
||
|
||
|
||
// Print component Data
|
||
const componentRef = useRef<HTMLDivElement>(null);
|
||
const handlePrint = useReactToPrint({
|
||
content: () => componentRef.current
|
||
});
|
||
|
||
|
||
useEffect(() => {
|
||
setTrackingNumber(localStorage.getItem("trackingNumber2"));
|
||
setPassword(localStorage.getItem("password2"));
|
||
}, []);
|
||
|
||
const complaintPrintMutation = useMutation({
|
||
mutationKey: ["complaintPrint"],
|
||
mutationFn: postComplaintTracking,
|
||
|
||
onSuccess: (res) => {
|
||
console.log(res);
|
||
// alert("SuccessPrint");
|
||
console.log("Success Folllow Result");
|
||
console.log(res);
|
||
|
||
setComplaintData(res);
|
||
console.log(complaintData);
|
||
},
|
||
onError: (error) => {
|
||
console.log(error);
|
||
console.log(error?.message);
|
||
},
|
||
});
|
||
|
||
function onSubmit() {
|
||
console.log("SuccessPrinttttttttttt");
|
||
|
||
complaintPrintMutation.mutate({
|
||
Data: { trackingNumber: trackingNumber, password: password },
|
||
});
|
||
}
|
||
|
||
|
||
const printableContent = 'This is the content to be printed.';
|
||
|
||
return (
|
||
<div className="w-full h-full sm:w-2/3 md:w-3/4 lg:w-1/2 max-sm:p-8 pt-12">
|
||
<div className="h-full flex flex-col justify-center">
|
||
<p
|
||
className="text-sm font-medium leading-6 tracking-wide text-[#7C838A] dark:text-white
|
||
3xl:text-base 3xl:font-bold"
|
||
>
|
||
درخواست شما با کد رهگیری
|
||
<span className="text-slate-500 mx-2">{`${trackingNumber}`}</span>و
|
||
رمز عبور
|
||
<span className="text-slate-500 mx-2">{`${password}`}</span>
|
||
در دست بررسی و اقدام می باشد. در صورت تمایل می توانید با شماره تلفن
|
||
0353286545 جهت پشتیبانی تماس حاصل کنید.
|
||
</p>
|
||
|
||
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
|
||
<AlertDialog>
|
||
<AlertDialogTrigger asChild>
|
||
<Button
|
||
variant="outline"
|
||
type="submit"
|
||
onClick={() => onSubmit()}
|
||
className="w-1/2 sm:w-1/3 lg:w-1/4 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">
|
||
{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]" id="details" ref={componentRef} >
|
||
<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>
|
||
{/* <AlertDialogCancel>Cancel</AlertDialogCancel> */}
|
||
<Button
|
||
className="bg-blue text-white w-1/2 sm:w-1/6"
|
||
onClick={handlePrint}
|
||
>
|
||
پرینت گزارش
|
||
</Button>
|
||
|
||
</AlertDialogFooter>
|
||
</AlertDialogContent>
|
||
</AlertDialog>
|
||
</div>
|
||
|
||
<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>
|
||
);
|
||
}
|