import { UserTypes } from "@/Constant/enums"; import React, { useEffect, useRef } from "react"; interface ModalProps { onClose: () => void; orderLength?: number; } const OrderSuccessModal: React.FC = ({ onClose, orderLength }) => { const modalRef = useRef(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { // Check if the click is on the modal backdrop (outside the modal content) const target = event.target as HTMLElement; if ( target.classList.contains("modal-backdrop") || (modalRef.current && !modalRef.current.contains(target)) ) { // First close the modal if (onClose) { onClose(); } // Then redirect window.location.href = "/my-orders?_=in_progress"; } }; document.addEventListener("mousedown", handleClickOutside); return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [onClose]); // Function to handle the download click const handleDownloadClick = (e: React.MouseEvent) => { // Prevent the default anchor link behavior e.preventDefault(); // Open a new tab and navigate to /address-print const newTab = orderLength ? window.open(`/address-print?len=${orderLength}`, "_blank") : window.open(`/address-print`, "_blank"); // Redirect the current tab to /my-orders window.location.href = "/my-orders?_=in_progress"; // Focus on the newly opened tab (optional, but helpful) if (newTab) { newTab.focus(); } }; const storedUser = localStorage.getItem("ALL_DATA"); const allData = storedUser ? JSON.parse(storedUser)?.data : null; return ( <>

Order placed successfully.

{allData?.userType?.id === UserTypes.NormalCustomer ? (

Payment will be collected by the delivery person when the package is picked up.

) : ''}

You can download all addresses in this order.

 Print Address
); }; export default OrderSuccessModal;