Compare commits

..

No commits in common. "f9130e9ec28d940bf2fe78195c1940f69dcc2f96" and "0fee5b0379029a78e1d9c2194de54ca2f96391b1" have entirely different histories.

8 changed files with 49 additions and 78 deletions

13
app/print-styles.css Normal file
View File

@ -0,0 +1,13 @@
/* styles/print-styles.css */
@media print {
/* Add styles for the print window */
body {
font-size: larger;
color: red;
background-color: aquamarine;
padding: 2em;
/* Add any other print-specific styles */
}
}

View File

@ -1,18 +0,0 @@
import React from "react";
interface PrintButtonProps {
handlePrint: () => void;
}
const PrintButton: React.FC<PrintButtonProps> = ({ handlePrint }) => {
return (
<button
onClick={handlePrint}
className="w-full sm:w-fit bg-blue text-white p-2 rounded-xl text-center "
>
پرینت
</button>
);
};
export default PrintButton;

View File

@ -9,13 +9,14 @@ import { useRouter } from "next/navigation";
import { Button } from "./ui/button"; import { Button } from "./ui/button";
import { useReactToPrint } from "react-to-print"; import { useReactToPrint } from "react-to-print";
import { getSingleWebContents } from "@/utils/commonApi"; import { getSingleWebContents } from "@/utils/commonApi";
import PrintButton from "./PrintButton";
import PrintPage from "./printPage";
export default function Result() { export default function Result() {
const [trackingNumber, setTrackingNumber] = useState<any>(); const [trackingNumber, setTrackingNumber] = useState<any>();
const [password, setPassword] = useState<any>(); const [password, setPassword] = useState<any>();
const componentRef = useRef<HTMLDivElement | null>(null); const componentRef = useRef<HTMLDivElement | null>(null);
// const componentRef2 = useRef<HTMLDivElement | null>(null);
// const [componentData, setComponentData] = useState<React.ReactNode | null>(null);
const [title, setTitle] = useState("AfterRegistration"); const [title, setTitle] = useState("AfterRegistration");
const router = useRouter(); const router = useRouter();
@ -26,17 +27,14 @@ export default function Result() {
setPassword(pw); setPassword(pw);
}, []); }, []);
// const handlePrint = useReactToPrint({ // useEffect(() => {
// content: () => componentRef.current, // const content1 = componentRef.current?.innerText || "";
// }); // const content2 = componentRef2.current?.innerText || "";
// setComponentData(<div>{content1 + content2}</div>);
// }, []);
const contentRef = useRef<any>();
const handlePrint = useReactToPrint({ const handlePrint = useReactToPrint({
// content: () => contentRef.current, content: () => componentRef.current,
content: () => {
console.log(contentRef.current); // Log the content to the console
return contentRef.current;
},
}); });
// const [fetchedContent, setFetchedContent] = useState(""); // const [fetchedContent, setFetchedContent] = useState("");
@ -56,13 +54,12 @@ export default function Result() {
return ( return (
<div <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')] 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`} h-[85vh] bg-50% bg-no-repeat bg-center flex flex-col gap-4`}
> >
<div <div
className=" flex flex-col justify-center font-[yekan] sm:pt-12 px-3 text-justify 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" text-[#7C838A] dark:text-white text-sm font-medium leading-6 tracking-wide 3xl:text-base 3xl:font-bold"
// ref={componentRef} ref={componentRef}
ref={contentRef}
dir="rtl" dir="rtl"
> >
{/* Display fetched content */} {/* Display fetched content */}
@ -90,17 +87,32 @@ export default function Result() {
/> */} /> */}
</div> </div>
<div className=" w-full flex flex-col justify-between items-end mt-2"> <div className=" w-full flex flex-col justify-between items-end mt-2">
{/* <div className="pr-4">
<div className="hidden"> <p
<PrintPage className="text-sm font-medium leading-6 tracking-wide text-[#7C838A] dark:text-white
contentRef={contentRef} 3xl:text-base 3xl:font-bold "
fetchedContent={fetchedContent} >
trackingNumber={trackingNumber} کد پیگیری :
password={password} <span className="text-slate-500 mx-2">{`${trackingNumber}`}</span>
/> </p>
</div>
<PrintButton handlePrint={handlePrint} /> <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">{`${password}`}</span>
</p>
</div> */}
<Button
variant="outline"
type="submit"
onClick={handlePrint}
className="w-full sm:w-fit bg-blue text-white p-2 rounded-xl text-center "
>
پرینت
</Button>
</div> </div>
{/* <Image {/* <Image
alt="icon" alt="icon"

View File

@ -1,36 +0,0 @@
// components/PrintPage.tsx
import React from "react";
interface PrintPageProps {
contentRef: React.RefObject<any>;
fetchedContent: string;
trackingNumber: string;
password: string;
}
const PrintPage: React.FC<PrintPageProps> = ({
contentRef,
fetchedContent,
trackingNumber,
password,
}) => {
return (
<div
ref={contentRef}
className="w-screen h-screen border-2 border-spacing-6 p-36 bg-slate-200 bg-[url('/img/bg-print.jpg')] bg-no-repeat bg-bottom bg-cover font-[yekan]"
dir="rtl"
>
<div dangerouslySetInnerHTML={{ __html: fetchedContent }} className=" " />
<p >
کد پیگیری : <span>{trackingNumber}</span>
</p>
<p>
رمز عبور : <span>{password}</span>
</p>
</div>
);
};
export default PrintPage;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 737 KiB