Skip to content

Commit 0787820

Browse files
fix: validation of api token
1 parent 669ba9e commit 0787820

File tree

2 files changed

+81
-49
lines changed

2 files changed

+81
-49
lines changed

apps/OpenSign/src/components/BulkSendUi.js

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import { useTranslation } from "react-i18next";
66
import Parse from "parse";
77
import ModalUi from "../primitives/ModalUi";
88
import { isEnableSubscription } from "../constant/const";
9+
import { fetchSubscription } from "../constant/Utils";
10+
import { useNavigate } from "react-router-dom";
911
const BulkSendUi = (props) => {
1012
const { t } = useTranslation();
13+
const navigate = useNavigate();
1114
const [forms, setForms] = useState([]);
1215
const [formId, setFormId] = useState(2);
1316
const formRef = useRef(null);
@@ -25,6 +28,7 @@ const BulkSendUi = (props) => {
2528
});
2629
const [isQuotaReached, setIsQuotaReached] = useState(false);
2730
const [isLoader, setIsLoader] = useState(false);
31+
const [isFreePlan, setIsFreePlan] = useState(false);
2832
const allowedSigners = 50;
2933
useEffect(() => {
3034
signatureExist();
@@ -36,6 +40,10 @@ const BulkSendUi = (props) => {
3640
if (isEnableSubscription) {
3741
setIsLoader(true);
3842
try {
43+
const subscription = await fetchSubscription();
44+
if (subscription?.plan === "freeplan") {
45+
setIsFreePlan(true);
46+
}
3947
const allowedquicksend = await Parse.Cloud.run("allowedquicksend");
4048
if (allowedquicksend > 0) {
4149
setIsBulkAvailable(true);
@@ -273,6 +281,9 @@ const BulkSendUi = (props) => {
273281
const handleCloseQuotaReached = () => {
274282
setIsQuotaReached(false);
275283
};
284+
const handleNavigation = () => {
285+
navigate("/subscription");
286+
};
276287
return (
277288
<>
278289
{isLoader ? (
@@ -385,46 +396,62 @@ const BulkSendUi = (props) => {
385396
)}
386397
</>
387398
) : (
388-
<form onSubmit={handleAddOnQuickSubmit} className="p-3">
389-
<p className="flex justify-center text-center mx-2 mb-3 text-base op-text-accent font-medium">
390-
{t("additional-quicksend")}
391-
</p>
392-
<div className="mb-3 flex justify-between">
393-
<label
394-
htmlFor="quantity"
395-
className="block text-xs text-gray-700 font-semibold"
396-
>
397-
{t("quantityofquicksend")}
398-
<span className="text-[red] text-[13px]">*</span>
399-
</label>
400-
<select
401-
value={amount.quantity}
402-
onChange={(e) => handlePricePerQuick(e)}
403-
name="quantity"
404-
className="op-select op-select-bordered op-select-sm focus:outline-none hover:border-base-content w-1/4 text-xs"
405-
required
406-
>
407-
{quantityList.length > 0 &&
408-
quantityList.map((x) => (
409-
<option key={x} value={x}>
410-
{x}
411-
</option>
412-
))}
413-
</select>
414-
</div>
415-
<div className="mb-3 flex justify-between">
416-
<label className="block text-xs text-gray-700 font-semibold">
417-
{t("Price")} (1 * {amount.priceperbulksend})
418-
</label>
419-
<div className="w-1/4 flex justify-center items-center text-sm">
420-
USD {amount.price}
399+
<>
400+
{isFreePlan ? (
401+
<div className="w-full h-[130px] flex flex-col justify-center items-center text-center p-4">
402+
<p className="text-base font-medium mb-2.5">
403+
Please upgrade to Professional or Team plan to use quicksend
404+
</p>
405+
<button
406+
onClick={() => handleNavigation()}
407+
className="op-btn op-btn-primary"
408+
>
409+
Upgrade Now
410+
</button>
421411
</div>
422-
</div>
423-
<hr className="text-base-content mb-3" />
424-
<button className="op-btn op-btn-primary w-full mt-2">
425-
{t("Proceed")}
426-
</button>
427-
</form>
412+
) : (
413+
<form onSubmit={handleAddOnQuickSubmit} className="p-3">
414+
<p className="flex justify-center text-center mx-2 mb-3 text-base op-text-accent font-medium">
415+
{t("additional-quicksend")}
416+
</p>
417+
<div className="mb-3 flex justify-between">
418+
<label
419+
htmlFor="quantity"
420+
className="block text-xs text-gray-700 font-semibold"
421+
>
422+
{t("quantityofquicksend")}
423+
<span className="text-[red] text-[13px]">*</span>
424+
</label>
425+
<select
426+
value={amount.quantity}
427+
onChange={(e) => handlePricePerQuick(e)}
428+
name="quantity"
429+
className="op-select op-select-bordered op-select-sm focus:outline-none hover:border-base-content w-1/4 text-xs"
430+
required
431+
>
432+
{quantityList.length > 0 &&
433+
quantityList.map((x) => (
434+
<option key={x} value={x}>
435+
{x}
436+
</option>
437+
))}
438+
</select>
439+
</div>
440+
<div className="mb-3 flex justify-between">
441+
<label className="block text-xs text-gray-700 font-semibold">
442+
{t("Price")} (1 * {amount.priceperbulksend})
443+
</label>
444+
<div className="w-1/4 flex justify-center items-center text-sm">
445+
USD {amount.price}
446+
</div>
447+
</div>
448+
<hr className="text-base-content mb-3" />
449+
<button className="op-btn op-btn-primary w-full mt-2">
450+
{t("Proceed")}
451+
</button>
452+
</form>
453+
)}
454+
</>
428455
)}
429456
</>
430457
)}

apps/OpenSign/src/pages/GenerateToken.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Tooltip from "../primitives/Tooltip";
99
import Loader from "../primitives/Loader";
1010
import SubscribeCard from "../primitives/SubscribeCard";
1111
import Tour from "reactour";
12-
import { validplan } from "../json/plansArr";
1312
import { useTranslation } from "react-i18next";
1413
import Parse from "parse";
1514

@@ -65,7 +64,7 @@ function GenerateToken() {
6564
};
6665
const handleSubmit = async (e) => {
6766
e.preventDefault();
68-
if (!validplan[isSubscribe.plan] && isEnableSubscription) {
67+
if (isSubscribe?.plan === "freeplan" && isEnableSubscription) {
6968
setIsTour(true);
7069
} else {
7170
setIsLoader(true);
@@ -103,11 +102,15 @@ function GenerateToken() {
103102
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500); // Reset copied state after 1.5 seconds
104103
};
105104
const handleModal = () => {
106-
setIsModal((obj) => ({ ...obj, generateapi: !obj.generateapi }));
105+
if (isSubscribe?.plan === "freeplan" && isEnableSubscription) {
106+
setIsTour(true);
107+
} else {
108+
setIsModal((obj) => ({ ...obj, generateapi: !obj.generateapi }));
109+
}
107110
};
108111

109112
const handleBuyAPIsModal = () => {
110-
if (!validplan[isSubscribe.plan] && isEnableSubscription) {
113+
if (isSubscribe?.plan === "freeplan" && isEnableSubscription) {
111114
setIsTour(true);
112115
} else {
113116
setIsModal((obj) => ({ ...obj, buyapis: !obj.buyapis }));
@@ -176,16 +179,18 @@ function GenerateToken() {
176179
<span
177180
id="token"
178181
className={`${
179-
validplan[isSubscribe.plan]
180-
? ""
181-
: "bg-white/20 pointer-events-none select-none"
182+
isSubscribe?.plan === "freeplan"
183+
? "bg-white/20 pointer-events-none select-none"
184+
: ""
182185
} md:text-end py-2 md:py-0`}
183186
>
184187
<span
185188
className="cursor-pointer"
186189
onClick={() => copytoclipboard(apiToken)}
187190
>
188-
{apiToken ? apiToken : "_____"}
191+
{isSubscribe?.plan !== "freeplan" && apiToken
192+
? apiToken
193+
: "_____"}
189194
</span>
190195
<button
191196
className="op-btn op-btn-accent op-btn-outline op-btn-sm ml-2 cursor-pointer"
@@ -303,9 +308,9 @@ function GenerateToken() {
303308
</form>
304309
</ModalUi>
305310
</div>
306-
{!validplan[isSubscribe.plan] && isEnableSubscription && (
311+
{isSubscribe?.plan === "freeplan" && isEnableSubscription && (
307312
<div data-tut="apisubscribe">
308-
<SubscribeCard plan_code={isSubscribe.plan} />
313+
<SubscribeCard plan_code={isSubscribe?.plan} />
309314
</div>
310315
)}
311316
</>

0 commit comments

Comments
 (0)