import React, { useEffect } from "react"; import { FaCheck, FaFileAlt, FaUsers, FaEnvelope, FaClock, FaDownload, FaShare, FaShieldAlt, FaLock, FaPen, FaCheckCircle } from 'react-icons/fa'; import { fetchRecipients } from "../../../store/slices/selectedRecipientsSlice"; import { fetchDocuments } from "../../../store/slices/documentSlice"; import { useDispatch, useSelector } from "react-redux"; import { Link, useNavigate, useParams } from "react-router-dom"; import Loader from "../../dashboard/Loader"; import confetti from 'canvas-confetti' import { IoClose } from "react-icons/io5"; import { IoMdClose, IoMdHome } from "react-icons/io"; import { Bounce, toast } from "react-toastify"; type Signer = { id: number; name: string; email: string; routingOrder: number; completed: boolean; }; // Signers List Component const SignersList: React.FC<{ signers: Signer[] }> = ({ signers }) => { return (

Signature Status

{signers.filter(s => s.completed).length} of {signers.length} signed
{signers.map((signer) => (
{signer.name.length > 2 ? signer.name.split(" ").map(n => n[0].toUpperCase()).join("") : signer.email.split("").map(n => n[0].toUpperCase()).join("")}
{signer.name}
{signer.email}
Order: {signer.routingOrder}
{signer.completed ? (
Signed
) : (
Pending
)}
))}
); }; // Fixed Signing Order Diagram Component const SigningOrderDiagram: React.FC<{ signers: Signer[] }> = ({ signers }) => { const groupByRoutingOrder = (data: Signer[]) => { const grouped: Record = {}; data.forEach((signer) => { if (!grouped[signer.routingOrder]) { grouped[signer.routingOrder] = []; } grouped[signer.routingOrder].push(signer); }); return grouped; }; const getInitials = (name: string) => { return name .split(" ") .map((n) => n[0].toUpperCase()) .join(""); }; const grouped = groupByRoutingOrder(signers); const sortedOrders = Object.keys(grouped) .map(Number) .sort((a, b) => a - b); const currentProcessingOrder = sortedOrders.find((order) => grouped[order].some((signer) => !signer.completed) ) || -1; return (

Signing Flow

{/* Mail icon */}

Sent

{/* Dotted line */}
{/* Signers by routing order */}
{sortedOrders.map((order, index) => (
Step {order}
{grouped[order].map((signer) => { let bgColor = ""; let icon = null; if (signer.completed) { bgColor = "bg-[var(--primary)]"; icon = ; } else if (order === currentProcessingOrder) { bgColor = "bg-yellow-500"; icon = ; } else { bgColor = "bg-gray-400"; icon = ; } return (
{getInitials(signer.name)} {icon}

{signer.name.split(" ")[0]}

); })}
{index < sortedOrders.length - 1 && (
)}
))}
); }; // Main DocumentCompletionScreen Component const DocumentCompletionScreen = () => { const documentList = [ { title: 'Document 1', pages: 12 }, { title: 'Document 2', pages: 8 }, { title: 'Document 3', pages: 5 }, { title: 'Document 4', pages: 22 }, { title: 'Document 5', pages: 10 }, { title: 'Document 6', pages: 15 }, { title: 'Document 7', pages: 7 }, { title: 'Document 8', pages: 9 }, { title: 'Document 9', pages: 6 }, { title: 'Document 10', pages: 11 }, { title: 'Document 11', pages: 4 }, // Won't be shown due to slice ]; const { accountId, transactionId } = useParams<{ accountId: string, transactionId: string }>(); const [showConfetti, setShowConfetti] = React.useState(true) if (!accountId || !transactionId) { window.location.href = "/"; return null; } // const transactionId = useSelector((state: RootState) => state.transaction.transactionId) const navigate = useNavigate(); const dispatch = useDispatch(); const selectedRecipients = useSelector((state: RootState) => state.selectedRecipients.recipients); // const selectedDocuments = useSelector((state: RootState) => state.selectedDocuments.selectedDocuments) const selectedDocuments = useSelector((state: RootState) => state.documents.documents) useEffect(() => { selectedRecipients.length === 0 && dispatch(fetchRecipients({ accountId, transactionId })); selectedDocuments.length === 0 && dispatch(fetchDocuments({ accountId, transactionId })); }, []) useEffect(() => { // toast.dismiss(); // toast.success("Your document has been successfully sent for signature.", { // position: "top-center", // autoClose: 1500, // hideProgressBar: false, // closeOnClick: false, // pauseOnHover: true, // draggable: true, // progress: undefined, // theme: "light", // transition: Bounce, // }); if (showConfetti) { const duration = 3000; const end = Date.now() + duration; const interval = setInterval(() => { if (Date.now() > end) { clearInterval(interval); return; } confetti({ particleCount: 5, // fewer particles per burst for smoothness angle: 90, // falling straight down spread: 30, // slight spread startVelocity: 8, // gentle falling speed origin: { x: Math.random(), // random horizontal position across the top y: 0, }, scalar: 1, zIndex: 9999, }); }, 50); // fire every 50ms for continuous effect return () => clearInterval(interval); } }, [showConfetti]); return ( <>
{/* Top Banner */}

🎉 Awesome! The document’s been sent for signature. 🎉

Edit {/* */}
{(selectedRecipients.length > 0 && selectedDocuments.length > 0) ?
{/* Header */}
{/* Left Section - Document Details */}
{/* Document Preview Card */}
{selectedDocuments?.map((item, index) => (
{/* */} document

Name : {item.name ?? '--'}

Status : {item.status ?? '--'}
))}
{/* Right Section - Signer Components */}
{/* Signing Order Diagram */} {/* Signers List */}
: }
); }; export default DocumentCompletionScreen;