Skip to content

Commit add01cb

Browse files
feat: auto assign free plan in google signup flow
1 parent cea1653 commit add01cb

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

apps/OpenSign/src/pages/Login.js

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,18 @@ function Login() {
395395
const setThirdpartyLoader = (value) => {
396396
setState({ ...state, thirdpartyLoader: value });
397397
};
398+
const handleFreePlan = async (id) => {
399+
try {
400+
const params = { userId: id };
401+
const res = await Parse.Cloud.run("freesubscription", params);
402+
if (res.status === "error") {
403+
alert(res.result);
404+
}
405+
} catch (err) {
406+
console.log("err in free subscribe", err.message);
407+
alert("Somenthing went wrong, please try again later!");
408+
}
409+
};
398410
const thirdpartyLoginfn = async (sessionToken, billingDate) => {
399411
const baseUrl = localStorage.getItem("baseUrl");
400412
const parseAppId = localStorage.getItem("parseAppId");
@@ -404,6 +416,11 @@ function Login() {
404416
"X-Parse-Application-Id": parseAppId
405417
}
406418
});
419+
const param = new URLSearchParams(location.search);
420+
const isFreeplan = param?.get("subscription") === "freeplan";
421+
if (isFreeplan) {
422+
await handleFreePlan(res.data.objectId);
423+
}
407424
await Parse.User.become(sessionToken).then(() => {
408425
window.localStorage.setItem("accesstoken", sessionToken);
409426
});
@@ -580,13 +597,23 @@ function Login() {
580597
if (billingDate > new Date()) {
581598
localStorage.removeItem("userDetails");
582599
navigate(redirectUrl);
600+
} else {
601+
if (isFreeplan) {
602+
navigate(redirectUrl);
603+
} else {
604+
navigate(`/subscription`, {
605+
replace: true
606+
});
607+
}
608+
}
609+
} else {
610+
if (isFreeplan) {
611+
navigate(redirectUrl);
583612
} else {
584613
navigate(`/subscription`, {
585614
replace: true
586615
});
587616
}
588-
} else {
589-
navigate(`/subscription`, { replace: true });
590617
}
591618
} else {
592619
navigate(redirectUrl);
@@ -608,10 +635,22 @@ function Login() {
608635
// Redirect to the appropriate URL after successful login
609636
navigate(redirectUrl);
610637
} else {
611-
navigate(`/subscription`, { replace: true });
638+
if (isFreeplan) {
639+
navigate(redirectUrl);
640+
} else {
641+
navigate(`/subscription`, {
642+
replace: true
643+
});
644+
}
612645
}
613646
} else {
614-
navigate(`/subscription`, { replace: true });
647+
if (isFreeplan) {
648+
navigate(redirectUrl);
649+
} else {
650+
navigate(`/subscription`, {
651+
replace: true
652+
});
653+
}
615654
}
616655
} else {
617656
navigate(redirectUrl);
@@ -1112,7 +1151,11 @@ function Login() {
11121151
</button>
11131152
<NavLink
11141153
className="rounded-sm cursor-pointer bg-white border-[1px] border-[#15b4e9] text-[#15b4e9] w-full py-3 shadow uppercase"
1115-
to="/signup"
1154+
to={
1155+
location.search
1156+
? "/signup" + location.search
1157+
: "/signup"
1158+
}
11161159
style={width < 768 ? { textAlign: "center" } : {}}
11171160
>
11181161
Create Account

apps/OpenSign/src/pages/Signup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ const Signup = () => {
657657
</button>
658658
<NavLink
659659
className="rounded-sm cursor-pointer bg-white border-[1px] border-[#15b4e9] text-[#15b4e9] w-full py-3 shadow uppercase"
660-
to="/"
660+
to={location.search ? "/" + location.search : "/"}
661661
style={width < 768 ? { textAlign: "center" } : {}}
662662
>
663663
Login

0 commit comments

Comments
 (0)