🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
refactor : add comment, handle unnecessary query call
RaktimaNXG8fd2d4210e18
diff --git a/apps/OpenSign/src/components/pdf/VerifyEmail.js b/apps/OpenSign/src/components/pdf/VerifyEmail.jsindex 1387efb42..48ed2b58b 100644--- a/apps/OpenSign/src/components/pdf/VerifyEmail.js+++ b/apps/OpenSign/src/components/pdf/VerifyEmail.js@@ -21,6 +21,7 @@ function VerifyEmail(props) {<div className="px-6 py-3"><label className="mb-2">Enter OTP</label><input+ requiredtype="tel"pattern="[0-9]{4}"className="px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"@@ -36,7 +37,7 @@ function VerifyEmail(props) {</button><buttonclassName={`${rejectBtn} ml-2`}- onClick={(e) => props.handleReset(e)}+ onClick={(e) => props.handleResend(e)}>Resend</button>diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.jsindex 8823a4863..3b3286cf7 100644--- a/apps/OpenSign/src/constant/Utils.js+++ b/apps/OpenSign/src/constant/Utils.js@@ -2008,6 +2008,8 @@ export const convertPdfArrayBuffer = async (url) => {return "Error";}};++//function to use send otp on user email using `SendOTPMailV1` cloud functionexport const handleSendOTP = async (email) => {try {let url = `${localStorage.getItem("baseUrl")}functions/SendOTPMailV1`;diff --git a/apps/OpenSign/src/pages/PdfRequestFiles.js b/apps/OpenSign/src/pages/PdfRequestFiles.jsindex 36c8c477f..211a50c68 100644--- a/apps/OpenSign/src/pages/PdfRequestFiles.js+++ b/apps/OpenSign/src/pages/PdfRequestFiles.js@@ -147,13 +147,15 @@ function PdfRequestFiles() {// eslint-disable-next-line react-hooks/exhaustive-deps}, [divRef.current]);- const handleReset = async (e) => {+ //function to use resend otp for email verification+ const handleResend = async (e) => {e.preventDefault();setOtpLoader(true);await handleSendOTP(Parse.User.current().getEmail());setOtpLoader(false);alert("OTP sent on you email");};+ //function to use verify email with otpconst handleVerifyEmail = async (e) => {e.preventDefault();setOtpLoader(true);@@ -178,6 +180,7 @@ function PdfRequestFiles() {}};+ //function to send otp on user mailconst handleVerifyBtn = async () => {setIsVerifyModal(true);await handleSendOTP(Parse.User.current().getEmail());@@ -288,13 +291,20 @@ function PdfRequestFiles() {!declined &&currDate < expireUpdateDate) {- const userQuery = new Parse.Query(Parse.User);- const user = await userQuery.get(jsonSender.objectId, {- sessionToken: localStorage.getItem("accesstoken")- });- if (user) {- const isEmailVerified = user?.get("emailVerified");+ const currentUser = JSON.parse(JSON.stringify(Parse.User.current()));+ let isEmailVerified;+ isEmailVerified = currentUser?.emailVerified;+ if (isEmailVerified) {setIsEmailVerified(isEmailVerified);+ } else {+ const userQuery = new Parse.Query(Parse.User);+ const user = await userQuery.get(currentUser.objectId, {+ sessionToken: localStorage.getItem("accesstoken")+ });+ if (user) {+ isEmailVerified = user?.get("emailVerified");+ setIsEmailVerified(isEmailVerified);+ }}}if (documentData.length > 0) {@@ -1247,7 +1257,7 @@ function PdfRequestFiles() {otp={otp}otpLoader={otpLoader}handleVerifyBtn={handleVerifyBtn}- handleReset={handleReset}+ handleResend={handleResend}/>)}diff --git a/apps/OpenSign/src/pages/SignyourselfPdf.js b/apps/OpenSign/src/pages/SignyourselfPdf.jsindex 54ad8373f..b281482bb 100644--- a/apps/OpenSign/src/pages/SignyourselfPdf.js+++ b/apps/OpenSign/src/pages/SignyourselfPdf.js@@ -235,13 +235,21 @@ function SignYourSelf() {}if (!isCompleted) {- const userQuery = new Parse.Query(Parse.User);- const user = await userQuery.get(jsonSender.objectId, {- sessionToken: localStorage.getItem("accesstoken")- });- if (user) {- const isEmailVerified = user?.get("emailVerified");+ //check current user email verified or not+ const currentUser = JSON.parse(JSON.stringify(Parse.User.current()));+ let isEmailVerified;+ isEmailVerified = currentUser?.emailVerified;+ if (isEmailVerified) {setIsEmailVerified(isEmailVerified);+ } else {+ const userQuery = new Parse.Query(Parse.User);+ const user = await userQuery.get(currentUser.objectId, {+ sessionToken: localStorage.getItem("accesstoken")+ });+ if (user) {+ isEmailVerified = user?.get("emailVerified");+ setIsEmailVerified(isEmailVerified);+ }}}} else if (@@ -552,13 +560,16 @@ function SignYourSelf() {setSignKey(key);};- const handleReset = async (e) => {+ //function to use resend otp for email verification+ const handleResend = async (e) => {e.preventDefault();setOtpLoader(true);await handleSendOTP(Parse.User.current().getEmail());setOtpLoader(false);alert("OTP sent on you email");};++ //function to use verify email with otpconst handleVerifyEmail = async (e) => {e.preventDefault();setOtpLoader(true);@@ -582,7 +593,7 @@ function SignYourSelf() {setOtpLoader(false);}};-+ //function to send otp on user mailconst handleVerifyBtn = async () => {setIsVerifyModal(true);await handleSendOTP(Parse.User.current().getEmail());@@ -1100,7 +1111,7 @@ function SignYourSelf() {otp={otp}otpLoader={otpLoader}handleVerifyBtn={handleVerifyBtn}- handleReset={handleReset}+ handleResend={handleResend}/>)}{/* this component used for UI interaction and show their functionality */}diff --git a/apps/OpenSign/src/pages/UserProfile.js b/apps/OpenSign/src/pages/UserProfile.jsindex ff5e19d17..9f7c4213a 100644--- a/apps/OpenSign/src/pages/UserProfile.js+++ b/apps/OpenSign/src/pages/UserProfile.js@@ -9,7 +9,7 @@ import axios from "axios";import PremiumAlertHeader from "../primitives/PremiumAlertHeader";import Tooltip from "../primitives/Tooltip";import { isEnableSubscription, rejectBtn, submitBtn } from "../constant/const";-import { checkIsSubscribed } from "../constant/Utils";+import { checkIsSubscribed, handleSendOTP } from "../constant/Utils";import Upgrade from "../primitives/Upgrade";import ModalUi from "../primitives/ModalUi";@@ -53,19 +53,20 @@ function UserProfile() {if (HeaderDocId) {setIsDisableDocId(HeaderDocId);}- const currentUser = JSON.parse(- localStorage.getItem(- `Parse/${localStorage.getItem("parseAppId")}/currentUser`- )- );- // const isEmailVerified = Parse.User.current()?.attributes?.emailVerified;- const userQuery = new Parse.Query(Parse.User);- const user = await userQuery.get(currentUser.objectId, {- sessionToken: localStorage.getItem("accesstoken")- });- if (user) {- const isEmailVerified = user?.get("emailVerified");+ const currentUser = JSON.parse(JSON.stringify(Parse.User.current()));+ let isEmailVerified;+ isEmailVerified = currentUser?.emailVerified;+ if (isEmailVerified) {setIsEmailVerified(isEmailVerified);+ } else {+ const userQuery = new Parse.Query(Parse.User);+ const user = await userQuery.get(currentUser.objectId, {+ sessionToken: localStorage.getItem("accesstoken")+ });+ if (user) {+ isEmailVerified = user?.get("emailVerified");+ setIsEmailVerified(isEmailVerified);+ }}setIsLoader(false);@@ -198,27 +199,16 @@ function UserProfile() {const handleDisableDocId = () => {setIsDisableDocId((prevChecked) => !prevChecked);};+ //function to send otp on user mailconst handleVerifyBtn = async () => {setIsVerifyModal(true);- await handleSendOTP();+ await handleSendOTP(Parse.User.current().getEmail());};const handleCloseVerifyModal = async () => {setIsVerifyModal(false);};- const handleSendOTP = async () => {- try {- let url = `${parseBaseUrl}functions/SendOTPMailV1`;- const headers = {- "Content-Type": "application/json",- "X-Parse-Application-Id": parseAppId- };- const body = { email: Parse.User.current().getEmail() };- await axios.post(url, body, { headers: headers });- } catch (error) {- alert(error.message);- }- };+ //function to use verify email with otpconst handleVerifyEmail = async (e) => {e.preventDefault();setOtpLoader(true);@@ -241,7 +231,8 @@ function UserProfile() {setOtpLoader(false);}};- const handleReset = async (e) => {+ //function to use resend otp for email verification+ const handleResend = async (e) => {e.preventDefault();setOtpLoader(true);await handleSendOTP();@@ -510,6 +501,7 @@ function UserProfile() {<div className="px-6 py-3"><label className="mb-2">Enter OTP</label><input+ requiredtype="tel"pattern="[0-9]{4}"className="px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"@@ -525,7 +517,7 @@ function UserProfile() {</button><buttonclassName={`${rejectBtn} ml-2`}- onClick={(e) => handleReset(e)}+ onClick={(e) => handleResend(e)}>Resend</button>