import { useEffect, useState } from 'react'; import { RootState } from '../../../store/store'; import { useDispatch, useSelector } from 'react-redux'; import FieldList from './FieldList'; import { addColorsToRecipient, fetchRecipients, recipientType, toggleToTemplates, TRANSACTION_TEMPLATE_TOGGLE } from '../../../store/slices/selectedRecipientsSlice'; import { IoCheckmark } from 'react-icons/io5' import { MdKeyboardArrowDown, MdOutlineNavigateNext } from 'react-icons/md' import { useParams } from 'react-router-dom'; import { fetchDocuments } from '../../../store/slices/documentSlice'; import { GrFormPrevious } from 'react-icons/gr'; import { LuTableOfContents } from 'react-icons/lu'; import { IoIosDocument, IoMdClose } from 'react-icons/io'; import { FaAngleUp, FaChevronRight } from 'react-icons/fa'; interface LeftSideBarProps { isFields: boolean; isPages: boolean; selectedRecipientIndx: number; setSelectedRecipient: React.Dispatch> handleSetIsFields: (setTo: boolean) => void; handleSetIsPages: (setTo: boolean) => void; } const LeftSideBar: React.FC = ({ isFields, isPages, selectedRecipientIndx, setSelectedRecipient, handleSetIsFields, handleSetIsPages }) => { let transactionTemplateToggle = TRANSACTION_TEMPLATE_TOGGLE.TRANSACTIONS; const dispatch = useDispatch(); const params = useParams<{ accountId?: string; transactionId?: string; templateId?: string }>(); const accountId = params.accountId; let transactionId = params.transactionId if (!transactionId) { transactionTemplateToggle = TRANSACTION_TEMPLATE_TOGGLE.TEMPLATES; transactionId = params.templateId; dispatch(toggleToTemplates()); } if (!accountId || !transactionId) { window.location.href = "/"; return null; } const selectedRecipients = useSelector((state: RootState) => state.selectedRecipients.recipients) const selectedDocuments = useSelector((state: RootState) => state.documents.documents) const [currentPage, setCurrentPage] = useState(0); useEffect(() => { if (selectedRecipients.length == 0) { dispatch(fetchRecipients({ accountId, transactionId })); } }, [dispatch, accountId, transactionId, selectedRecipients.length]); useEffect(() => { if (selectedDocuments.length == 0) { dispatch(fetchDocuments({ accountId, transactionId })); } }, [dispatch, accountId, transactionId, selectedDocuments.length]); // For Recipient const [dropDownToggle, setDropDownToggle] = useState(false); const [dropDownTogglePage, setDropDownTogglePage] = useState(""); const selectedRecipient = selectedRecipients[selectedRecipientIndx]; useEffect(() => { if (selectedRecipients.length) { if ("color" in selectedRecipients[0]) return; dispatch(addColorsToRecipient()) } }, []) useEffect(() => { if (selectedRecipient && selectedRecipient.type == recipientType.CC) { for (const [indx, recip] of selectedRecipients.entries()) { if (recip.type != recipientType.CC) { setSelectedRecipient(indx); break; } } }; }, [selectedRecipient]) if (selectedRecipient && selectedRecipient.type == recipientType.CC) { return
; } return ( <> {/* Left Side Bar - START */} { (isPages || isFields) &&
{ handleSetIsPages(false) handleSetIsFields(false) }} className='absolute top-[5px] right-[5px] bg-white rounded-full'>
handleSetIsFields(!isFields)} className={`flex items-center gap-1 cursor-pointer text-xs w-full justify-center py-1.5 rounded-2xl ${isFields ? 'bg-[var(--primary)] text-white' : ''} transition-all duration-300`}>

Tags

handleSetIsPages(!isPages)} className={`flex items-center gap-1 cursor-pointer text-xs w-full justify-center py-1.5 rounded-2xl ${isPages ? 'bg-[var(--primary)] text-white' : ''} transition-all duration-300`}>

Pages

{selectedRecipients.length > 0 && isFields && <> {/* Fields List and Recipeint - Start */} {/* Side Bar showing Recipients */}
setDropDownToggle(false)}> {/* Selected Recipient */}
setDropDownToggle(!dropDownToggle)} className='flex items-center justify-between gap-2 w-full p-2 text-xs rounded-sm border-1 border-slate-200 cursor-pointer'>

{/* */}

{ selectedRecipient.firstName.length == 0 && selectedRecipient.lastName.length == 0 ? (selectedRecipient.email.length == 0 ? selectedRecipient.roleName : selectedRecipient.email) : `${selectedRecipient.firstName + " " + selectedRecipient.lastName}` }

{selectedRecipients.length && selectedRecipients.map((recipient, indx) => { if (recipient.type == recipientType.CC) return null; // Skip CC recipients return (
{ setSelectedRecipient(indx); setTimeout(() => { setDropDownToggle(false); }, 0) }} >

{/* */}

{ recipient.firstName.length == 0 && recipient.lastName.length == 0 ? (recipient.email.length == 0 ? recipient.roleName : recipient.email) : `${recipient.firstName + " " + recipient.lastName}` }

{selectedRecipientIndx == indx && }
) })}
{/* Side Bar showing Recipients - ENDS*/} {/* Drag Drop Tags Start */}
{/* Fields List and Recipeint - End */} } {isPages && <> {/* Pages - START */}
{selectedDocuments.length && selectedDocuments.map((document, indx) => { return (
setDropDownTogglePage('')} >
setDropDownTogglePage(`${(dropDownTogglePage == 'pageDropDown' + indx) ? '' : 'pageDropDown' + indx}`)} className={`p-2 ${(dropDownTogglePage == 'pageDropDown' + indx) ? "bg-[var(--primary)]" : "bg-slate-200"} flex flex-col justify-center items-center gap-2 rounded`}> { document.pages != undefined && }

{document.name}

{ dropDownTogglePage == 'pageDropDown' + indx &&
{/* Prev Button */} { if (currentPage == 0) e.preventDefault(); else setCurrentPage(currentPage - 1); }} > {/* Page Selector */} / {document.pages?.length} {/* Next Button */} { if (currentPage == document.pages?.length - 1) e.preventDefault(); else setCurrentPage(currentPage + 1); }} >
}
) })}
{/* Pages - END */} }
} {/* Left Side Bar - END */} {/* Small Devices - START */}
{/* Left Side Pages */} {!isPages &&
{ handleSetIsPages(true) handleSetIsFields(false) }} className='sm:hidden fixed top-[8%] left-0 bg-[var(--primary)] z-50 flex items-center text-white rounded-tr-md rounded-br-md cursor-pointer opacity-30 hover:opacity-100 transition-all duration-300'>

P A G E S

}
{ handleSetIsPages(false) handleSetIsFields(true) }} >

T A G S

{/* Small Devices - END */} ) } export default LeftSideBar