diff --git a/src/components/CommonNav.tsx b/src/components/CommonNav.tsx index 8a3d33f..ff09abc 100644 --- a/src/components/CommonNav.tsx +++ b/src/components/CommonNav.tsx @@ -300,7 +300,7 @@ const CommonNav: React.FC = () => { aria-expanded={open} aria-haspopup="true" > -
+
{user ? ( {(user?.name?.slice(0, 2)).toUpperCase()} diff --git a/src/components/process/processStepOne/ProcessStepOne.tsx b/src/components/process/processStepOne/ProcessStepOne.tsx index 9c0274d..cd3f0c1 100644 --- a/src/components/process/processStepOne/ProcessStepOne.tsx +++ b/src/components/process/processStepOne/ProcessStepOne.tsx @@ -39,6 +39,11 @@ const ProcessStepOne = () => { dispatch(toggleToTemplates()); } + const [editCase , setEditCase] = useState("") + const [editRecipient , setEditRecipient] = useState({}) + + + // if (!accountId || !transactionId) { // window.location.href = "/"; // return null; @@ -54,6 +59,11 @@ const ProcessStepOne = () => { console.log("selectedRecipients", selectedRecipients) useEffect(() => { + (async () => { + const res = await api.get(`/api/accounts/${accountId}/${transactionTemplateToggle}/${transactionId}`) + console.log(res.data); + })() + selectedRecipients.length === 0 && dispatch(fetchRecipients({ accountId, transactionId })); selectedDocuments.length === 0 && dispatch(fetchDocuments({ accountId, transactionId })); }, []) @@ -149,7 +159,9 @@ const ProcessStepOne = () => { accessCodeDelivery: true, language: "en", name: `${recipient.firstName} ${recipient.lastName}`, - roleName: recipient.roleName + roleName: recipient.roleName, + allowSenderToEdit: recipient.allowSenderToEdit , + allowSenderToDelete: recipient.allowSenderToDelete, })); let recipientsDataTemp = recipientsData; @@ -291,9 +303,9 @@ const ProcessStepOne = () => { < section className="mt-8">

Signers

- + {/* {signType !== "self-sign" && } */} - +
} diff --git a/src/components/process/processStepOne/RecipientAddCard.tsx b/src/components/process/processStepOne/RecipientAddCard.tsx index aa26f85..8711c50 100644 --- a/src/components/process/processStepOne/RecipientAddCard.tsx +++ b/src/components/process/processStepOne/RecipientAddCard.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef, useState } from "react"; import { FaPlus } from "react-icons/fa"; -import { addRecipient, Recipient, recipientType } from "../../../store/slices/selectedRecipientsSlice"; +import { addRecipient, Recipient, recipientType, updateRecipient } from "../../../store/slices/selectedRecipientsSlice"; import { useDispatch } from "react-redux"; import { AppDispatch } from "../../../store/store"; import api from "../../../config/api"; @@ -8,6 +8,8 @@ import ContactModal from "./ContactModal"; import useDebouncedEffect from "../../../utlity/useDebounce"; import { IoIosSettings } from "react-icons/io"; import { FiEdit, FiTrash } from "react-icons/fi"; +import { v4 as uuidv4 } from 'uuid'; + interface ContactType { id: string; @@ -21,7 +23,8 @@ export interface ContactTypeObj { contacts: ContactType[]; } -const RecipientAddCard = ({ transactionTemplateToggle }) => { + +const RecipientAddCard = ({ transactionTemplateToggle, editRecipient, editCase ,setEditRecipient, setEditCase }) => { const [contactData, setContactData] = useState({ type: "", contacts: [] }); const [openContactModal, setOpenContactModal] = useState(false); @@ -29,29 +32,79 @@ const RecipientAddCard = ({ transactionTemplateToggle }) => { const dispatch = useDispatch(); const formRef = useRef(null); - const [recipient, setRecipients] = useState({ firstName: "", lastName: "", email: "", hostName: "", hostEmail: "", roleName: "", type: recipientType.SIGNER, allowSenderToEdit: Boolean, allowSenderToRemove: Boolean }); + const [recipient, setRecipients] = useState({ uuid:null, newOne:false, firstName: "", lastName: "", email: "", hostName: "", hostEmail: "", roleName: "", type: recipientType.SIGNER, allowSenderToEdit: false, allowSenderToDelete: false }); const [showAdvanceSettings, setShowAdvanceSettings] = useState(false) console.log(recipient) - const handleRecipientAdd = (e: React.FormEvent) => { - e.preventDefault(); - - if (recipient.lastName === "" || recipient.email === "" || !recipient.type) return; - - // Validate Email Format - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - if (!emailRegex.test(recipient.email)) { - console.log("Invalid email format"); - return; + useEffect(() => { + if (editCase === "Edit" && editRecipient) { + setRecipients({ + // id:editRecipient.id, + firstName: editRecipient.firstName || "", + lastName: editRecipient.lastName || "", + email: editRecipient.email || "", + hostName: editRecipient.hostName || "", + hostEmail: editRecipient.hostEmail || "", + roleName: editRecipient.roleName || "", + type: editRecipient.type || recipientType.SIGNER, + allowSenderToEdit: editRecipient.allowSenderToEdit ?? false, + allowSenderToDelete: editRecipient.allowSenderToDelete ?? false, + uuid: String(editRecipient?.id ?? editRecipient?.uuid ?? ''), + newOne:editRecipient.newOne ?? false + }); } - // Validation Ends + }, [editCase, editRecipient]); - dispatch(addRecipient(recipient)); - setRecipients({ firstName: "", lastName: "", email: "", hostName: "", hostEmail: "", roleName: "", type: recipientType.SIGNER, allowSenderToEdit: false, allowSenderToRemove: false }); - formRef.current?.reset(); + + const handleRecipientAdd = (e: React.FormEvent) => { + e.preventDefault(); + + console.log("recipientrecipient",recipient) + + if (!recipient.lastName || !recipient.email || !recipient.type) return; + + // ✅ Email format validation + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + if (!emailRegex.test(recipient.email)) { + console.log("Invalid email format"); + return; } + if (editCase === 'Edit') { + dispatch(updateRecipient(recipient)); + } else { + dispatch(addRecipient({ + ...recipient, + uuid:uuidv4(), + newOne:true + })); + } + + // ✅ Reset state and form + setRecipients({ + firstName: "", + lastName: "", + email: "", + hostName: "", + hostEmail: "", + roleName: "", + type: recipientType.SIGNER, + allowSenderToEdit: false, + allowSenderToDelete: false, + uuid:"", + newOne:false + }); + + // setRecipients(null), + setEditCase("") + + formRef.current?.reset(); +}; + + + + // useEffect(() => { // if (!recipient.firstName.length) return; @@ -133,10 +186,10 @@ const RecipientAddCard = ({ transactionTemplateToggle }) => { } overflow-hidden`} >
- {recipient.allowSenderToEdit && recipient.allowSenderToRemove && "Full permissions granted"} - {recipient.allowSenderToEdit && !recipient.allowSenderToRemove && "Edit permission granted"} - {!recipient.allowSenderToEdit && recipient.allowSenderToRemove && "Delete permission granted"} - {!recipient.allowSenderToEdit && !recipient.allowSenderToRemove && "No permissions granted"} + {recipient.allowSenderToEdit && recipient.allowSenderToDelete && "Full permissions granted"} + {recipient.allowSenderToEdit && !recipient.allowSenderToDelete && "Edit permission granted"} + {!recipient.allowSenderToEdit && recipient.allowSenderToDelete && "Delete permission granted"} + {!recipient.allowSenderToEdit && !recipient.allowSenderToDelete && "No permissions granted"}
{/* Animated Permission Controls */} @@ -178,23 +231,23 @@ const RecipientAddCard = ({ transactionTemplateToggle }) => { {/* Delete Permission */}
@@ -332,7 +385,7 @@ const RecipientAddCard = ({ transactionTemplateToggle }) => { type="submit" className="inline-flex items-center gap-2 bg-[var(--primary)] hover:bg-[var(--primaryLight2)] text-white text-sm font-semibold px-5 py-2 rounded-md transition" > - Add Recipient + {editCase === "Edit" ? "Edit Recipient" : "Add Recipient"}
diff --git a/src/components/process/processStepOne/RecipientCards.tsx b/src/components/process/processStepOne/RecipientCards.tsx index 97897d8..68116c6 100644 --- a/src/components/process/processStepOne/RecipientCards.tsx +++ b/src/components/process/processStepOne/RecipientCards.tsx @@ -13,6 +13,7 @@ import { useState } from "react"; import SigningOrderDiagram from "../../../SigningOrderDiagram "; import { IoCloseOutline } from "react-icons/io5"; import { useParams } from "react-router-dom"; +import { FiEdit } from "react-icons/fi"; const getInitials = (name: string) => { if (!name) return ""; @@ -23,7 +24,13 @@ const getInitials = (name: string) => { .toUpperCase(); }; -const RecipientCards = () => { +type CardsData = { + setEditRecipient: (recipient: any) => void; // Replace `any` with the actual type if known + setEditCase: (string: any) => void; + transactionTemplateToggle: string +}; + +const RecipientCards = ({ setEditRecipient, setEditCase, transactionTemplateToggle }: CardsData) => { const templateId = useParams<{ templateId: string }>().templateId; let { accountId, transactionId } = useParams<{ accountId: string, transactionId: string }>(); @@ -32,9 +39,9 @@ const RecipientCards = () => { if (!transactionId) { transactionId = templateId; } - + const recipients = useSelector((state: RootState) => state.selectedRecipients.recipients); - console.log("recipients.length",recipients) + console.log("recipients.length", recipients) // const signingOrder = useSelector((state: RootState) => state.selectedRecipients.signingOrder); const signType = useSelector((state: RootState) => state.selectedDocuments.signType); @@ -44,15 +51,24 @@ const RecipientCards = () => { dispatch(updateRecipientOrder({ id, routingOrder: value })); }; + const handleEditRecipient = (recipient) => { + // alert(JSON.stringify(recipient)) + setEditCase('Edit') + setEditRecipient(recipient) + } + const handleRemoveRecipient = (recipient) => { if (!accountId || !transactionId) return; - // dispatch(removeSelectedRecipient(recipient)) - dispatch(removeRecipientAsync({ - recipientId: recipient.id, - email: recipient.email, - accountId: accountId, - transactionId: transactionId, - })) + if (recipient.uuid) { + dispatch(removeSelectedRecipient(recipient)) + } else { + dispatch(removeRecipientAsync({ + recipientId: recipient.id, + email: recipient.email, + accountId: accountId, + transactionId: transactionId, + })) + } if (recipients.length === 2) { let leftRecipient = recipients.filter((obj) => { if ("id" in obj && "id" in recipient) { @@ -144,14 +160,45 @@ const RecipientCards = () => {
{signType !== "self-sign" && ( - +
+ {/* Edit Button */} + + + {/* Delete Button */} + +
+ + )} ))} diff --git a/src/components/setting/Signature/AddSignatureModal.tsx b/src/components/setting/Signature/AddSignatureModal.tsx index 1b05709..9478964 100644 --- a/src/components/setting/Signature/AddSignatureModal.tsx +++ b/src/components/setting/Signature/AddSignatureModal.tsx @@ -55,7 +55,7 @@ const AddSignatureModal: React.FC = ({ getAllSignatures, editingSignature }) => { - const [activeTab, setActiveTab] = useState<'TYPE' | 'DRAW' | 'UPLOAD' | 'SELECT'>('TYPE'); + const [activeTab, setActiveTab] = useState<'TYPE' | 'DRAW' | 'UPLOAD' >('TYPE'); const [fullName, setFullName] = useState(''); const [initials, setInitials] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); @@ -110,7 +110,7 @@ const AddSignatureModal: React.FC = ({ { id: 'TYPE', label: 'TYPE', icon: }, { id: 'DRAW', label: 'DRAW', icon: }, { id: 'UPLOAD', label: 'UPLOAD', icon: }, - { id: 'SELECT', label: 'SELECT', icon: }, + // { id: 'SELECT', label: 'SELECT', icon: }, ]; // Initialize form with editing signature data @@ -394,14 +394,14 @@ const AddSignatureModal: React.FC = ({ ); - case 'SELECT': - return ( -
-
-

Select Signature

-
-
- ); + // case 'SELECT': + // return ( + //
+ //
+ //

Select Signature

+ //
+ //
+ // ); default: return null; } diff --git a/src/components/setting/Signature/Signature.tsx b/src/components/setting/Signature/Signature.tsx index 45074b7..5ff4581 100644 --- a/src/components/setting/Signature/Signature.tsx +++ b/src/components/setting/Signature/Signature.tsx @@ -232,7 +232,7 @@ const SignatureManager: React.FC = () => { {/* Empty State (if no signatures) */} {signatures.length === 0 && ( -
+
diff --git a/src/components/templates/Templates.tsx b/src/components/templates/Templates.tsx index d281a71..47c22c6 100644 --- a/src/components/templates/Templates.tsx +++ b/src/components/templates/Templates.tsx @@ -149,7 +149,7 @@ const Templates = () => { {item.name || 'Dummy'} {formatDate(item.createdAt)} {formatDate(item.lastModifiedAt)} - handleUseClick(item)}>Use + handleUseClick(item)}>Use {/* Dropdown Trigger + Tooltip */}