refactor : add comment, handle unnecessary query call

This commit is contained in:
RaktimaNXG
2024-05-06 11:32:30 +05:30
parent c240eb133d
commit 8fd2d4210e
5 changed files with 63 additions and 47 deletions
@@ -21,6 +21,7 @@ function VerifyEmail(props) {
<div className="px-6 py-3">
<label className="mb-2">Enter OTP</label>
<input
required
type="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>
<button
className={`${rejectBtn} ml-2`}
onClick={(e) => props.handleReset(e)}
onClick={(e) => props.handleResend(e)}
>
Resend
</button>
+2
View File
@@ -2008,6 +2008,8 @@ export const convertPdfArrayBuffer = async (url) => {
return "Error";
}
};
//function to use send otp on user email using `SendOTPMailV1` cloud function
export const handleSendOTP = async (email) => {
try {
let url = `${localStorage.getItem("baseUrl")}functions/SendOTPMailV1`;
+18 -8
View File
@@ -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 otp
const handleVerifyEmail = async (e) => {
e.preventDefault();
setOtpLoader(true);
@@ -178,6 +180,7 @@ function PdfRequestFiles() {
}
};
//function to send otp on user mail
const 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}
/>
)}
+20 -9
View File
@@ -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 otp
const handleVerifyEmail = async (e) => {
e.preventDefault();
setOtpLoader(true);
@@ -582,7 +593,7 @@ function SignYourSelf() {
setOtpLoader(false);
}
};
//function to send otp on user mail
const 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 */}
+21 -29
View File
@@ -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 mail
const 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 otp
const 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
required
type="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>
<button
className={`${rejectBtn} ml-2`}
onClick={(e) => handleReset(e)}
onClick={(e) => handleResend(e)}
>
Resend
</button>