112 lines
3.6 KiB
TypeScript
112 lines
3.6 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
import ReactDOM from "react-dom";
|
|
import Image from "next/image";
|
|
import Resultimg from "../public/img/result.png";
|
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useRouter } from "next/navigation";
|
|
import { Button } from "./ui/button";
|
|
import { useReactToPrint } from "react-to-print";
|
|
import { getSingleWebContents } from "@/utils/commonApi";
|
|
import PrintButton from "./PrintButton";
|
|
import PrintPage from "./printPage";
|
|
|
|
export default function Result() {
|
|
const [trackingNumber, setTrackingNumber] = useState<any>();
|
|
const [password, setPassword] = useState<any>();
|
|
const componentRef = useRef<HTMLDivElement | null>(null);
|
|
const [title, setTitle] = useState("AfterRegistration");
|
|
|
|
const router = useRouter();
|
|
useEffect(() => {
|
|
const tn = localStorage.getItem("trackingNumber");
|
|
const pw = localStorage.getItem("password");
|
|
setTrackingNumber(tn);
|
|
setPassword(pw);
|
|
}, []);
|
|
|
|
// const handlePrint = useReactToPrint({
|
|
// content: () => componentRef.current,
|
|
// });
|
|
|
|
const contentRef = useRef<any>();
|
|
const handlePrint = useReactToPrint({
|
|
// content: () => contentRef.current,
|
|
content: () => {
|
|
return contentRef.current;
|
|
},
|
|
});
|
|
|
|
// const [fetchedContent, setFetchedContent] = useState("");
|
|
|
|
const { data, isLoading, isError, refetch } = useQuery({
|
|
queryKey: ["WebContents", title],
|
|
queryFn: () => getSingleWebContents(title),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
|
|
useEffect(() => {
|
|
refetch();
|
|
}, [title, refetch]);
|
|
|
|
const fetchedContent = data?.content || "";
|
|
|
|
return (
|
|
<div
|
|
className={`w-full sm:w-2/3 md:w-3/4 lg:w-1/2 max-sm:p-8 sm:bg-[url('/img/Result1.png')]
|
|
h-[85vh] bg-50% bg-no-repeat bg-center flex flex-col gap-4`}
|
|
>
|
|
<div
|
|
className=" flex flex-col justify-center font-[yekan] sm:pt-12 px-3 text-justify
|
|
text-[#7C838A] dark:text-white text-sm font-medium leading-6 tracking-wide 3xl:text-base 3xl:font-bold"
|
|
// ref={componentRef}
|
|
ref={contentRef}
|
|
dir="rtl"
|
|
>
|
|
{/* Display fetched content */}
|
|
<div dangerouslySetInnerHTML={{ __html: fetchedContent }} />
|
|
|
|
<p
|
|
className="text-sm font-medium leading-6 tracking-wide text-[#7C838A] dark:text-white mt-4
|
|
3xl:text-base 3xl:font-bold "
|
|
>
|
|
کد پیگیری :
|
|
<span className="text-slate-500 mx-2 font-bold">{`${trackingNumber}`}</span>
|
|
</p>
|
|
|
|
<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 !font-mono font-extrabold">{`${password}`}</span>
|
|
</p>
|
|
|
|
{/* <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 className=" w-full flex flex-col justify-between items-end mt-2">
|
|
<div className="hidden">
|
|
<PrintPage
|
|
contentRef={contentRef}
|
|
fetchedContent={fetchedContent}
|
|
trackingNumber={trackingNumber}
|
|
password={password}
|
|
/>
|
|
</div>
|
|
|
|
<PrintButton handlePrint={handlePrint} />
|
|
</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>
|
|
);
|
|
}
|