Merge branch 'Kahdooei'

Kahdooei
Hossein Rahmani 2024-02-03 01:20:38 +03:30
commit f9130e9ec2
8 changed files with 78 additions and 49 deletions

View File

@ -1,13 +0,0 @@
/* 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

@ -0,0 +1,18 @@
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,14 +9,13 @@ 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 componentRef2 = useRef<HTMLDivElement | null>(null);
// const [componentData, setComponentData] = useState<React.ReactNode | null>(null);
const [title, setTitle] = useState("AfterRegistration");
const router = useRouter();
@ -27,14 +26,17 @@ export default function Result() {
setPassword(pw);
}, []);
// useEffect(() => {
// const content1 = componentRef.current?.innerText || "";
// const content2 = componentRef2.current?.innerText || "";
// setComponentData(<div>{content1 + content2}</div>);
// }, []);
// const handlePrint = useReactToPrint({
// content: () => componentRef.current,
// });
const contentRef = useRef<any>();
const handlePrint = useReactToPrint({
content: () => componentRef.current,
// content: () => contentRef.current,
content: () => {
console.log(contentRef.current); // Log the content to the console
return contentRef.current;
},
});
// const [fetchedContent, setFetchedContent] = useState("");
@ -54,12 +56,13 @@ export default function Result() {
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`}
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={componentRef}
ref={contentRef}
dir="rtl"
>
{/* Display fetched content */}
@ -87,32 +90,17 @@ export default function Result() {
/> */}
</div>
<div className=" w-full flex flex-col justify-between items-end mt-2">
{/* <div className="pr-4">
<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>
</p>
<div className="hidden">
<PrintPage
contentRef={contentRef}
fetchedContent={fetchedContent}
trackingNumber={trackingNumber}
password={password}
/>
</div>
<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>
<PrintButton handlePrint={handlePrint} />
</div>
{/* <Image
alt="icon"

36
components/printPage.tsx Normal file
View File

@ -0,0 +1,36 @@
// 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;

BIN
public/img/bg-print.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 KiB

BIN
public/img/bg-print1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

BIN
public/img/logo-print.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 KiB