diff --git a/index.html b/index.html index e4b78ea..c118459 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - Vite + React + TS + Sign Made Easy
diff --git a/src/components/client/SignDocument.tsx b/src/components/client/SignDocument.tsx index a8a02e2..9d33213 100644 --- a/src/components/client/SignDocument.tsx +++ b/src/components/client/SignDocument.tsx @@ -141,7 +141,6 @@ const fitObj = [ const SignDocument = () => { - const { recipientId } = useParams(); const dispatch = useDispatch(); @@ -232,8 +231,6 @@ const SignDocument = () => { }, [droppedItems]) - console.log(droppedItems, "{droppedItems[selectedTag.key][selectedTag.index]}") - useEffect(() => { if (recSignStatus === "COMPLETED") { // setHideTags(true); @@ -372,9 +369,23 @@ const SignDocument = () => { }); } - + const handleToastError = (msg: string) => { + toast.dismiss(); + toast.error(msg, { + position: "top-center", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: false, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "light", + transition: Bounce, + }); + } const handleFormSubmit = () => { + // e.preventDefault(); const submitData: TagsSubmitDataObj = { tags: [] @@ -398,37 +409,15 @@ const SignDocument = () => { } } - if (signInitialsCount !== Object.keys(signConfObj).length) { - toast.error("Please ensure all signature and initials are signed", { - position: "bottom-right", - autoClose: 5000, - hideProgressBar: false, - closeOnClick: false, - pauseOnHover: true, - draggable: true, - progress: undefined, - theme: "light", - transition: Bounce, - }); + handleToastError("Please ensure all signature and initials are signed") return; } + console.log(droppedItems, "Line 417") for (const tag of droppedItems) { - - // if ((tag.type === "SIGNATURE" || tag.subType === "INITIALS") && !tag.value) { - if (("required" in tag && tag.required) && ((tag.type !== "SIGNATURE" && tag.type !== "INITIALS") && (tag.value === "" || !("value" in tag)))) { - toast.error(`${tag.label} is required`, { - position: "bottom-right", - autoClose: 5000, - hideProgressBar: false, - closeOnClick: false, - pauseOnHover: true, - draggable: true, - progress: undefined, - theme: "light", - transition: Bounce, - }); + if ("required" in tag && tag.required && ((tag.type !== "SIGNATURE" && tag.type !== "INITIALS") && (tag.value === undefined || tag.value === null || tag.value === "" || !("value" in tag)))) { + handleToastError(`${tag.label} is required`) return; } @@ -453,39 +442,8 @@ const SignDocument = () => { } } - // for (const tag of tagJson) { - // if (data[tag.id as string]) { - // const tagData: TagSubmitData = { - // id: tag.id as string, - // type: tag.type, - // subType: tag.subType ? tag.subType : "", - // signed: true, - // value: data[tag.id as string] as string - // } - // submitData.tags.push(tagData) - // } - - // if (tag.type === "SIGNATURE") { - // submitData.tags.push({ - // id: tag.id as string, - // type: "SIGNATURE", - // subType: "DRAW", - // signed: true, - // value: "" - // }) - // } - - // if (tag.type === "INITIALS") { - // submitData.tags.push({ - // id: tag.id as string, - // type: "INITIALS", - // subType: "DRAW", - // signed: true, - // value: "" - // }) - // } - - // } + console.log(submitData, "submitData Line 491"); + // return; dispatch(showLoader("Signing ...")); axios.post(`${import.meta.env.VITE_BASE_URI}/api/sign?recipientId=${recipientId}`, submitData, { headers: { "ngrok-skip-browser-warning": "69420", } }) @@ -585,6 +543,7 @@ const SignDocument = () => { const handleTagUpdate = (updateIndx: number, updateValue: string) => { + console.log(updateIndx, updateValue, "LINEE636") if (droppedItems && droppedItems.length) { const updatedTag = droppedItems.map((val, indx) => { if (indx === updateIndx) { @@ -608,6 +567,60 @@ const SignDocument = () => { } + const handlePrefillValues = () => { + const prefilledTags = ["NAME", "EMAIL", "TEXT", "COMPANY", "TEMPORAL"] + + const updatedItems = droppedItems.map((item, index) => { + if (prefilledTags.includes(item.type)) { + + let value = null; + let isUpdate = false + + switch (item.type) { + case "NAME": + value = recipient?.firstName + " " + recipient?.lastName; + isUpdate = true; + break; + case "EMAIL": + value = recipient?.email; + isUpdate = true; + break; + case "TEXT": + value = item.value; + isUpdate = true; + break; + case "COMPANY": + value = item.value; + isUpdate = true; + break; + case "TEMPORAL": + if (item.currentTimeStamp) isUpdate = true; + if (isUpdate) { + value = dayjs(Date.now()).format(item.format); + } + break; + default: + break; + } + return { ...item, value } + } else { + return item + } + }) + + setDroppedItems(updatedItems); + } + + console.log(droppedItems, "droppedItems Line 652") + + useEffect(() => { + if (droppedItems.length > 0) { + console.log("Dropped Items handlePrefillValues:") + handlePrefillValues(); + } + }, [droppedItems.length]) + + // HANDLE DROP - START const handleDrop = (event: React.DragEvent, docId: string, documentId: number, pageIndex: number) => { event.preventDefault(); @@ -689,7 +702,7 @@ const SignDocument = () => { isDeleted: false } - if(prepData.type === "NAME") { + if (prepData.type === "NAME") { prepData.firstName = true prepData.lastName = true } @@ -848,18 +861,13 @@ const SignDocument = () => { // Updated handleRemoveTag function with your existing API logic and group handling const handleRemoveTag = (key: string, targetIndex: number) => { - - console.log("Removing tag:", key, targetIndex, droppedItems); - const tag: DroppedItem = droppedItems[targetIndex]; const recipientId = tag.recipientId; - console.log(tag, "line 776"); - (async () => { if ("id" in tag) { try { - const response = await api.delete(`/api/sign/tags?recipientId=${recipientId}`, { data: [ { tagId: tag.id } ] }) + const response = await api.delete(`/api/sign/tags?recipientId=${recipientId}`, { data: [{ tagId: tag.id }] }) if (response.status !== 200) throw "Tag Deletion error" } catch (err) { return; @@ -927,7 +935,6 @@ const SignDocument = () => { // }, 100); } } else { - console.log("Listening to 895") // Handle non-group item removal (your existing logic) setDroppedItems(prevState => prevState.filter((item, idx) => { return idx !== targetIndex; @@ -1032,10 +1039,11 @@ const SignDocument = () => { {/* Send */} {(!transparentTags && !hideTags) ?