Skip to content

Commit 0d5f898

Browse files
refactor: change in checking subscription
1 parent 598aa29 commit 0d5f898

File tree

11 files changed

+155
-101
lines changed

11 files changed

+155
-101
lines changed

apps/OpenSign/src/constant/Utils.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,44 @@ export const openInNewTab = (url) => {
1313
window.open(url, "_blank", "noopener,noreferrer");
1414
};
1515

16+
export async function fetchSubscription() {
17+
try {
18+
const extClass = localStorage.getItem("Extand_Class");
19+
const jsonSender = JSON.parse(extClass);
20+
const baseURL = localStorage.getItem("baseUrl");
21+
const url = `${baseURL}functions/getsubscriptions`;
22+
const headers = {
23+
"Content-Type": "application/json",
24+
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
25+
sessionToken: localStorage.getItem("accesstoken")
26+
};
27+
const params = { extUserId: jsonSender[0].objectId };
28+
const tenatRes = await axios.post(url, params, { headers: headers });
29+
const plan = tenatRes.data?.result?.result?.PlanName;
30+
const billingDate = tenatRes.data?.result?.result?.Next_billing_date?.iso;
31+
return { plan, billingDate };
32+
} catch (err) {
33+
console.log("Err in fetch subscription", err);
34+
return { plan: "", billingDate: "" };
35+
}
36+
}
1637
//function to get subcripition details from Extand user class
1738
export async function checkIsSubscribed() {
18-
const extClass = localStorage.getItem("Extand_Class");
19-
const jsonSender = JSON.parse(extClass);
20-
const user = await Parse.Cloud.run("getUserDetails", {
21-
email: jsonSender[0].Email
22-
});
23-
const freeplan = user?.get("Plan") && user?.get("Plan")?.plan_code;
24-
const billingDate =
25-
user?.get("Next_billing_date") && user?.get("Next_billing_date");
26-
if (freeplan === "freeplan") {
27-
return false;
28-
} else if (billingDate) {
29-
if (billingDate > new Date()) {
30-
return true;
39+
try {
40+
const res = await fetchSubscription();
41+
if (res.plan === "freeplan") {
42+
return false;
43+
} else if (res.billingDate) {
44+
if (new Date(res.billingDate) > new Date()) {
45+
return true;
46+
} else {
47+
return false;
48+
}
3149
} else {
3250
return false;
3351
}
34-
} else {
52+
} catch (err) {
53+
console.log("Err in fetch subscription", err);
3554
return false;
3655
}
3756
}
@@ -1229,8 +1248,8 @@ export const multiSignEmbed = async (
12291248
position.type === radioButtonWidget
12301249
? 10
12311250
: position.type === "checkbox"
1232-
? 10
1233-
: newUpdateHeight;
1251+
? 10
1252+
: newUpdateHeight;
12341253
const newHeight = ind ? (ind > 0 ? widgetHeight : 0) : widgetHeight;
12351254

12361255
if (signyourself) {

apps/OpenSign/src/layout/HomeLayout.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ModalUi from "../primitives/ModalUi";
1111
import { useNavigate, useLocation, Outlet } from "react-router-dom";
1212
import { isEnableSubscription } from "../constant/const";
1313
import { useCookies } from "react-cookie";
14+
import { fetchSubscription } from "../constant/Utils";
1415

1516
const HomeLayout = () => {
1617
const navigate = useNavigate();
@@ -36,7 +37,7 @@ const HomeLayout = () => {
3637
sessionToken: localStorage.getItem("accesstoken")
3738
});
3839
if (user) {
39-
localStorage.setItem("profileImg", user.get('ProfilePic'));
40+
localStorage.setItem("profileImg", user.get("ProfilePic") || "");
4041
checkIsSubscribed();
4142
} else {
4243
setIsUserValid(false);
@@ -69,19 +70,13 @@ const HomeLayout = () => {
6970
};
7071

7172
async function checkIsSubscribed() {
72-
const currentUser = Parse.User.current();
73-
const user = await Parse.Cloud.run("getUserDetails", {
74-
email: currentUser.get("email")
75-
});
7673
if (isEnableSubscription) {
77-
const freeplan = user?.get("Plan") && user?.get("Plan").plan_code;
78-
const billingDate =
79-
user?.get("Next_billing_date") && user?.get("Next_billing_date");
80-
if (freeplan === "freeplan") {
74+
const res = await fetchSubscription();
75+
if (res.plan === "freeplan") {
8176
setIsUserValid(true);
8277
setIsLoader(false);
83-
} else if (billingDate) {
84-
if (billingDate > new Date()) {
78+
} else if (res.billingDate) {
79+
if (new Date(res.billingDate) > new Date()) {
8580
setIsUserValid(true);
8681
setIsLoader(false);
8782
} else {

apps/OpenSign/src/pages/Login.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Alert from "../primitives/Alert";
1919
import { appInfo } from "../constant/appinfo";
2020
import { fetchAppInfo } from "../redux/reducers/infoReducer";
2121
import { showTenant } from "../redux/reducers/ShowTenant";
22-
import { getAppLogo } from "../constant/Utils";
22+
import { fetchSubscription, getAppLogo } from "../constant/Utils";
2323
function Login() {
2424
const navigate = useNavigate();
2525
const location = useLocation();
@@ -169,7 +169,7 @@ function Login() {
169169
await Parse.Cloud.run("getUserDetails", {
170170
email: currentUser.get("email")
171171
}).then(
172-
(result) => {
172+
async (result) => {
173173
let tenentInfo = [];
174174
const results = [result];
175175
if (results) {
@@ -270,16 +270,15 @@ function Login() {
270270
"userDetails",
271271
JSON.stringify(LocalUserDetails)
272272
);
273-
const freeplan =
274-
results[0].get("Plan") &&
275-
results[0].get("Plan").plan_code;
276-
const billingDate =
277-
results[0].get("Next_billing_date") &&
278-
results[0].get("Next_billing_date");
273+
const res = await fetchSubscription();
274+
const freeplan = res.plan;
275+
const billingDate = res.billingDate;
279276
if (freeplan === "freeplan") {
280277
navigate(redirectUrl);
281278
} else if (billingDate) {
282-
if (billingDate > new Date()) {
279+
if (
280+
new Date(billingDate) > new Date()
281+
) {
283282
localStorage.removeItem(
284283
"userDetails"
285284
);
@@ -814,7 +813,7 @@ function Login() {
814813
await Parse.Cloud.run("getUserDetails", {
815814
email: currentUser.get("email")
816815
}).then(
817-
(result) => {
816+
async (result) => {
818817
let tenentInfo = [];
819818
const results = [result];
820819
if (results) {
@@ -866,17 +865,13 @@ function Login() {
866865
"userDetails",
867866
JSON.stringify(LocalUserDetails)
868867
);
869-
const billingDate =
870-
results[0].get("Next_billing_date") &&
871-
results[0].get("Next_billing_date");
872-
const freeplan =
873-
results[0]?.get("Plan") &&
874-
results[0]?.get("Plan").plan_code;
875-
868+
const res = await fetchSubscription();
869+
const billingDate = res.billingDate;
870+
const freeplan = res.plan;
876871
if (freeplan === "freeplan") {
877872
navigate(redirectUrl);
878873
} else if (billingDate) {
879-
if (billingDate > new Date()) {
874+
if (new Date(billingDate) > new Date()) {
880875
localStorage.removeItem("userDetails");
881876
// Redirect to the appropriate URL after successful login
882877
navigate(redirectUrl);

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
onSaveImage,
2323
addDefaultSignatureImg,
2424
radioButtonWidget,
25-
replaceMailVaribles
25+
replaceMailVaribles,
26+
fetchSubscription
2627
} from "../constant/Utils";
2728
import Loader from "../primitives/LoaderWithMsg";
2829
import HandleError from "../primitives/HandleError";
@@ -32,7 +33,6 @@ import PdfDeclineModal from "../primitives/PdfDeclineModal";
3233
import Title from "../components/Title";
3334
import DefaultSignature from "../components/pdf/DefaultSignature";
3435
import ModalUi from "../primitives/ModalUi";
35-
import Parse from "parse";
3636

3737
function PdfRequestFiles() {
3838
const { docId } = useParams();
@@ -135,17 +135,14 @@ function PdfRequestFiles() {
135135
// eslint-disable-next-line react-hooks/exhaustive-deps
136136
}, [divRef.current]);
137137

138-
async function checkIsSubscribed(email) {
139-
const user = await Parse.Cloud.run("getUserDetails", {
140-
email: email
141-
});
142-
const freeplan = user?.get("Plan") && user?.get("Plan").plan_code;
143-
const billingDate =
144-
user?.get("Next_billing_date") && user?.get("Next_billing_date");
138+
async function checkIsSubscribed() {
139+
const res = await fetchSubscription();
140+
const freeplan = res.plan;
141+
const billingDate = res.billingDate;
145142
if (freeplan === "freeplan") {
146143
return true;
147144
} else if (billingDate) {
148-
if (billingDate > new Date()) {
145+
if (new Date(billingDate) > new Date()) {
149146
return true;
150147
} else {
151148
if (location.pathname.includes("/load/")) {
@@ -1095,9 +1092,9 @@ function PdfRequestFiles() {
10951092
isDecline.currnt === "Sure"
10961093
? "Are you sure want to decline this document ?"
10971094
: isDecline.currnt === "YouDeclined"
1098-
? "You have declined this document!"
1099-
: isDecline.currnt === "another" &&
1100-
"You cannot sign this document as it has been declined by one or more recipient(s)."
1095+
? "You have declined this document!"
1096+
: isDecline.currnt === "another" &&
1097+
"You cannot sign this document as it has been declined by one or more recipient(s)."
11011098
}
11021099
footerMessage={isDecline.currnt === "Sure"}
11031100
declineDoc={declineDoc}

apps/OpenSign/src/pages/PlaceHolderSign.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
color,
3333
getTenantDetails,
3434
replaceMailVaribles,
35-
copytoData
35+
copytoData,
36+
fetchSubscription
3637
} from "../constant/Utils";
3738
import RenderPdf from "../components/pdf/RenderPdf";
3839
import { useNavigate } from "react-router-dom";
@@ -238,17 +239,14 @@ function PlaceHolderSign() {
238239
// eslint-disable-next-line react-hooks/exhaustive-deps
239240
}, [divRef.current]);
240241

241-
async function checkIsSubscribed(email) {
242-
const user = await Parse.Cloud.run("getUserDetails", {
243-
email: email
244-
});
245-
const freeplan = user?.get("Plan") && user?.get("Plan").plan_code;
246-
const billingDate =
247-
user?.get("Next_billing_date") && user?.get("Next_billing_date");
242+
async function checkIsSubscribed() {
243+
const res = await fetchSubscription();
244+
const freeplan = res.plan;
245+
const billingDate = res.billingDate;
248246
if (freeplan === "freeplan") {
249247
return true;
250248
} else if (billingDate) {
251-
if (billingDate > new Date()) {
249+
if (new Date(billingDate) > new Date()) {
252250
setIsSubscribe(true);
253251
return true;
254252
} else {

apps/OpenSign/src/pages/TemplatePlaceholder.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
defaultWidthHeight,
2424
addWidgetOptions,
2525
textInputWidget,
26-
radioButtonWidget
26+
radioButtonWidget,
27+
fetchSubscription
2728
} from "../constant/Utils";
2829
import RenderPdf from "../components/pdf/RenderPdf";
2930
import "../styles/AddUser.css";
@@ -35,7 +36,6 @@ import AddRoleModal from "../components/pdf/AddRoleModal";
3536
import PlaceholderCopy from "../components/pdf/PlaceholderCopy";
3637
import TourContentWithBtn from "../primitives/TourContentWithBtn";
3738
import DropdownWidgetOption from "../components/pdf/DropdownWidgetOption";
38-
import Parse from "parse";
3939
const TemplatePlaceholder = () => {
4040
const navigate = useNavigate();
4141
const { templateId } = useParams();
@@ -170,17 +170,14 @@ const TemplatePlaceholder = () => {
170170
}
171171
// eslint-disable-next-line react-hooks/exhaustive-deps
172172
}, [divRef.current]);
173-
async function checkIsSubscribed(email) {
174-
const user = await Parse.Cloud.run("getUserDetails", {
175-
email: email
176-
});
177-
const freeplan = user?.get("Plan") && user?.get("Plan").plan_code;
178-
const billingDate =
179-
user?.get("Next_billing_date") && user?.get("Next_billing_date");
173+
async function checkIsSubscribed() {
174+
const res = await fetchSubscription();
175+
const freeplan = res.plan;
176+
const billingDate = res.billingDate;
180177
if (freeplan === "freeplan") {
181178
return true;
182179
} else if (billingDate) {
183-
if (billingDate > new Date()) {
180+
if (new Date(billingDate) > new Date()) {
184181
setIsSubscribe(true);
185182
return true;
186183
} else {

apps/OpenSignServer/cloud/customRoute/saveInvoice.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export default async function saveInvoice(request, response) {
3131
className: '_User',
3232
objectId: extUser.get('UserId').id,
3333
});
34+
if (extUser?.get('TenantId')?.id) {
35+
createInvoice.set('TenantId', {
36+
__type: 'Pointer',
37+
className: 'partners_Tenant',
38+
objectId: extUser.get('TenantId').id,
39+
});
40+
}
3441
await createInvoice.save(null, { useMasterKey: true });
3542
return response.status(200).json({ status: 'create invoice!' });
3643
}

apps/OpenSignServer/cloud/customRoute/savePayments.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export default async function savePayments(request, response) {
3030
className: '_User',
3131
objectId: extUser.get('UserId').id,
3232
});
33+
if (extUser?.get('TenantId')?.id) {
34+
createPayment.set('TenantId', {
35+
__type: 'Pointer',
36+
className: 'partners_Tenant',
37+
objectId: extUser.get('TenantId').id,
38+
});
39+
}
3340
await createPayment.save(null, { useMasterKey: true });
3441
return response.status(200).json({ status: 'create payments!' });
3542
}

apps/OpenSignServer/cloud/customRoute/saveSubscription.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export default async function saveSubscription(request, response) {
99
const extUser = await extUserCls.first({ useMasterKey: true });
1010
if (extUser) {
1111
const subcriptionCls = new Parse.Query('contracts_Subscriptions');
12-
subcriptionCls.equalTo('SubscriptionId', SubscriptionId);
12+
subcriptionCls.equalTo('TenantId', {
13+
__type: 'Pointer',
14+
className: 'partners_Tenant',
15+
objectId: extUser.get('TenantId').id,
16+
});
1317
const subscription = await subcriptionCls.first({ useMasterKey: true });
1418
if (subscription) {
1519
const updateSubscription = new Parse.Object('contracts_Subscriptions');
@@ -31,6 +35,11 @@ export default async function saveSubscription(request, response) {
3135
className: '_User',
3236
objectId: extUser.get('UserId').id,
3337
});
38+
createSubscription.set('TenantId', {
39+
__type: 'Pointer',
40+
className: 'partners_Tenant',
41+
objectId: extUser.get('TenantId').id,
42+
});
3443
await createSubscription.save(null, { useMasterKey: true });
3544
return response.status(200).json({ status: 'create subscription!' });
3645
}

0 commit comments

Comments
 (0)