From 910bd801ac3e80f4a044dd787e7106d2cc6e3b86 Mon Sep 17 00:00:00 2001 From: RaktimaNXG Date: Mon, 20 Nov 2023 16:46:27 +0530 Subject: [PATCH 1/2] remove contracts_Document & contracts_Users query from frontend and call cloud function --- .../src/Component/DraftDocument.js | 68 ++-- .../src/Component/LegaDrive/LegaDrive.js | 186 ++++----- .../src/Component/PdfRequestFiles.js | 293 +++++++-------- .../src/Component/SignYourselfPdf.js | 87 ++--- .../src/Component/placeHolderSign.js | 80 ++-- .../src/Component/recipientSignPdf.js | 354 +++++++++--------- .../SignDocuments/src/utils/Utils.js | 126 ++++--- 7 files changed, 557 insertions(+), 637 deletions(-) diff --git a/microfrontends/SignDocuments/src/Component/DraftDocument.js b/microfrontends/SignDocuments/src/Component/DraftDocument.js index 79806a94e..8c5884c87 100644 --- a/microfrontends/SignDocuments/src/Component/DraftDocument.js +++ b/microfrontends/SignDocuments/src/Component/DraftDocument.js @@ -1,61 +1,46 @@ import React, { useEffect, useState } from "react"; -import axios from "axios"; import { useNavigate } from "react-router-dom"; import Loader from "./component/loader"; -import { getHostUrl } from "../utils/Utils"; +import { contractDocument, getHostUrl } from "../utils/Utils"; function DraftDocument() { const navigate = useNavigate(); const [pdfDetails, setPdfDetails] = useState([]); const [isLoading, setIsLoading] = useState({ isLoad: true, - message: "This might take some time", + message: "This might take some time" }); const rowLevel = localStorage.getItem("rowlevel") && JSON.parse(localStorage.getItem("rowlevel")); - const signObjId = + const docId = rowLevel && rowLevel?.id ? rowLevel.id : rowLevel?.objectId && rowLevel.objectId; + useEffect(() => { - if (signObjId) { + if (docId) { getDocumentDetails(); } }, []); //get document details const getDocumentDetails = async () => { - await axios - .get( - `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( - "_appName" - )}_Document?where={"objectId":"${signObjId}"}&include=ExtUserPtr,Signers`, - { - headers: { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - "X-Parse-Session-Token": localStorage.getItem("accesstoken"), - }, - } - ) - .then((Listdata) => { - const json = Listdata.data; - const res = json.results; - - if (res[0] && res.length > 0) { - setPdfDetails(res); - const loadObj = { - isLoad: false, - }; - setIsLoading(loadObj); - } else { - alert("No data found!"); - } - }) - .catch((err) => { - console.log("axois err ", err); - }); + //getting document details + const documentData = await contractDocument(docId); + if (documentData && documentData !== "no data found!" && documentData[0]) { + if (documentData[0] && documentData.length > 0) { + setPdfDetails(documentData); + const loadObj = { + isLoad: false + }; + setIsLoading(loadObj); + } + } else if (documentData === "no data found!") { + alert("No data found!"); + } else if (documentData === "Error: Something went wrong!") { + alert("Error: Something went wrong!"); + } }; //check document type and render on signyour self and placeholder route @@ -63,24 +48,25 @@ function DraftDocument() { const data = pdfDetails[0]; const checkSignerExist = pdfDetails[0] && pdfDetails[0].Signers && pdfDetails[0].Signers; - const isPlaceholder = + const isPlaceholder = pdfDetails[0].Placeholders && pdfDetails[0].Placeholders; const isDecline = data.IsDeclined && data.IsDeclined; const signUrl = data.SignedUrl && data.SignedUrl; - const expireDate = pdfDetails[0] && pdfDetails[0].ExpiryDate.iso && pdfDetails[0].ExpiryDate.iso; + const expireDate = + pdfDetails[0] && + pdfDetails[0].ExpiryDate.iso && + pdfDetails[0].ExpiryDate.iso; const expireUpdateDate = new Date(expireDate).getTime(); const currDate = new Date().getTime(); const hostUrl = getHostUrl(); //checking document is completed and signer exist then navigate to pdfRequestFiles file if (data.IsCompleted && checkSignerExist) { - navigate(`${hostUrl}pdfRequestFiles`); + navigate(`${hostUrl}pdfRequestFiles`); } //checking document is completed and signer does not exist then navigate to recipientSignPdf file else if (data.IsCompleted && !checkSignerExist) { - navigate( - `${hostUrl}signaturePdf` - ); + navigate(`${hostUrl}signaturePdf`); } //checking document is declined by someone then navigate to pdfRequestFiles file else if (isDecline) { diff --git a/microfrontends/SignDocuments/src/Component/LegaDrive/LegaDrive.js b/microfrontends/SignDocuments/src/Component/LegaDrive/LegaDrive.js index cd004168a..ed456ec96 100644 --- a/microfrontends/SignDocuments/src/Component/LegaDrive/LegaDrive.js +++ b/microfrontends/SignDocuments/src/Component/LegaDrive/LegaDrive.js @@ -6,6 +6,7 @@ import PdfFileComponent from "./FolderDrive/legaDriveComponent"; import Modal from "react-bootstrap/Modal"; import ModalHeader from "react-bootstrap/esm/ModalHeader"; import { themeColor, iconColor } from "../../utils/ThemeColor/backColor"; +import { getDrive } from "../../utils/Utils"; function PdfFile() { const scrollRef = useRef(null); @@ -22,22 +23,13 @@ function PdfFile() { const [isShowSort, setIsShowSort] = useState(false); const [isLoading, setIsLoading] = useState({ isLoad: true, - message: "This might take some time", + message: "This might take some time" }); const [docId, setDocId] = useState(); const [handleError, setHandleError] = useState(); const [folderName, setFolderName] = useState([]); - const senderUser = - localStorage.getItem( - `Parse/${localStorage.getItem("parseAppId")}/currentUser` - ) && - localStorage.getItem( - `Parse/${localStorage.getItem("parseAppId")}/currentUser` - ); - const jsonSender = JSON.parse(senderUser); - useEffect(() => { if (docId) { getPdfFolderDocumentList(); @@ -50,104 +42,59 @@ function PdfFile() { const getPdfDocumentList = async () => { const load = { isLoad: true, - message: "This might take some time", + message: "This might take some time" }; setIsLoading(load); - //?where={"Type":"Folder" }&include=ExtUserPtr,Signers - //?where={"$or":[{"Type":{"$exists":true}},{"Folder":{"$exists":false}}]}&include=ExtUserPtr,Signers - // "CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${jsonSender.objectId}"} - // where={"Folder":{"$exists":false} }&include=ExtUserPtr,Signers`, - await axios - .get( - `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( - "_appName" - )}_Document?where={"Folder":{"$exists":false},"$or":[{"CreatedBy":{"$exists":false}},{"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${ - jsonSender.objectId - }"}}]}&include=ExtUserPtr,Signers`, - { - headers: { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - "X-Parse-Session-Token": localStorage.getItem("accesstoken"), - }, - } - ) - .then((Listdata) => { - const json = Listdata.data; - const res = json.results; - // console.log("result", res); - if (res[0] && res.length > 0) { - setPdfData(res); - } + const driveDetails = await getDrive(); - const data = [ - { - name: "OpenSignDrive™", - objectId: "", - }, - ]; - setFolderName(data); - const loadObj = { - isLoad: false, - }; - setIsLoading(loadObj); - }) - .catch((err) => { - const loadObj = { - isLoad: false, - }; - setHandleError("Error: Something went wrong!"); - setIsLoading(loadObj); - }); + if (driveDetails) { + if (driveDetails && driveDetails.length > 0) { + setPdfData(driveDetails); + } + const data = [ + { + name: "OpenSignDrive™", + objectId: "" + } + ]; + setFolderName(data); + const loadObj = { + isLoad: false + }; + setIsLoading(loadObj); + } else if (driveDetails === "Error: Something went wrong!") { + const loadObj = { + isLoad: false + }; + setHandleError("Error: Something went wrong!"); + setIsLoading(loadObj); + } }; //function for get parent folder document list const getPdfFolderDocumentList = async () => { const load = { isLoad: true, - message: "This might take some time", + message: "This might take some time" }; setIsLoading(load); - //{"$inQuery":{"where":{"objectId":"${docId}"},"className":"${appName}_Document"}} - //"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${jsonSender.objectId}"} - await axios - .get( - `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem( - "_appName" - )}_Document?where={"Folder":{"__type":"Pointer","className":"${localStorage.getItem( - "_appName" - )}_Document","objectId":"${docId}"},"$or":[{"CreatedBy":{"$exists":false}},{"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${ - jsonSender.objectId - }"}}]}&include=ExtUserPtr,Signers,Folder`, - { - headers: { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - "X-Parse-Session-Token": localStorage.getItem("accesstoken"), - }, - } - ) - .then((Listdata) => { - const json = Listdata.data; - const res = json.results; - - if (res[0] && res.length > 0) { - setPdfData(res); - } else { - setPdfData([]); - } - - const loadObj = { - isLoad: false, - }; - setIsLoading(loadObj); - }) - .catch((err) => { - const loadObj = { - isLoad: false, - }; - setHandleError("Error: Something went wrong!"); - setIsLoading(loadObj); - }); + const driveDetails = await getDrive(docId); + if (driveDetails) { + if (driveDetails && driveDetails.length > 0) { + setPdfData(driveDetails); + } else { + setPdfData([]); + } + const loadObj = { + isLoad: false + }; + setIsLoading(loadObj); + } else if (driveDetails === "Error: Something went wrong!") { + const loadObj = { + isLoad: false + }; + setHandleError("Error: Something went wrong!"); + setIsLoading(loadObj); + } }; //function for get all pdf document list @@ -158,7 +105,7 @@ function PdfFile() { const handleRoute = (data) => { let loadObj = { isLoad: true, - message: "This might take some time", + message: "This might take some time" }; if (data.name === "LegaDrive™") { setIsLoading(loadObj); @@ -167,7 +114,7 @@ function PdfFile() { } else { setTimeout(() => { const loadObj = { - isLoad: false, + isLoad: false }; setIsLoading(loadObj); }, 1000); @@ -176,12 +123,11 @@ function PdfFile() { setIsLoading(loadObj); setTimeout(() => { const loadObj = { - isLoad: false, + isLoad: false }; setIsLoading(loadObj); }, 1000); } else { - // console.log("go here1",data.objectId) const findIndex = folderName.findIndex( (fold) => fold.objectId === data.objectId ); @@ -216,13 +162,13 @@ function PdfFile() { Folder: { __type: "Pointer", className: `${localStorage.getItem("_appName")}_Document`, - objectId: isParentId, - }, + objectId: isParentId + } }; } else { data = { Name: newFolderName, - Type: "Folder", + Type: "Folder" }; } @@ -237,8 +183,8 @@ function PdfFile() { headers: { "Content-Type": "application/json", "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - "X-Parse-Session-Token": localStorage.getItem("accesstoken"), - }, + "X-Parse-Session-Token": localStorage.getItem("accesstoken") + } } ) @@ -388,7 +334,7 @@ function PdfFile() { display: "flex", flexDirection: "column", justifyContent: "center", - alignItems: "center", + alignItems: "center" }} > Name* @@ -428,7 +374,7 @@ function PdfFile() { display: "flex", alignItems: "flex-end", justifyContent: "flex-end", - alignContent: "flex-end", + alignContent: "flex-end" }} >