Skip to content

Commit cea1653

Browse files
feat: auto assign free plan to new signup
1 parent 79e3762 commit cea1653

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

apps/OpenSign/src/pages/PlanSubscriptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ const PlanSubscriptions = () => {
116116
Yearly (10% off)
117117
</span>
118118
</div>
119-
<ul className=" flex flex-col md:flex-row h-full bg-white justify-center">
119+
<ul className="flex flex-col md:flex-row h-full bg-white justify-center">
120120
{plansArr.map((item) => (
121121
<li
122-
className="flex flex-col md:my-0 text-center border-[1px] border-gray-300 w-[260px]"
122+
className="flex flex-col md:my-0 text-center border-collapse border-[1px] border-gray-300 w-[260px]"
123123
key={item.planName}
124124
>
125125
<div className="p-2 flex flex-col justify-center items-center min-h-[320px]">

apps/OpenSign/src/pages/Signup.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
22
import Parse from "parse";
33
import axios from "axios";
44
import Title from "../components/Title";
5-
import { useNavigate, NavLink } from "react-router-dom";
5+
import { useNavigate, NavLink, useLocation } from "react-router-dom";
66
import login_img from "../assets/images/login_img.svg";
77
import { useWindowSize } from "../hook/useWindowSize";
88
import Alert from "../primitives/Alert";
@@ -14,6 +14,7 @@ import { isEnableSubscription } from "../constant/const";
1414
const Signup = () => {
1515
const { width } = useWindowSize();
1616
const navigate = useNavigate();
17+
const location = useLocation();
1718
const dispatch = useDispatch();
1819
const [name, setName] = useState("");
1920
const [phone, setPhone] = useState("");
@@ -68,6 +69,19 @@ const Signup = () => {
6869
localStorage.setItem("baseUrl", baseUrl);
6970
localStorage.setItem("parseAppId", appid);
7071
};
72+
73+
const handleFreePlan = async (id) => {
74+
try {
75+
const params = { userId: id };
76+
const res = await Parse.Cloud.run("freesubscription", params);
77+
if (res.status === "error") {
78+
alert(res.result);
79+
}
80+
} catch (err) {
81+
console.log("err in free subscribe", err.message);
82+
alert("Somenthing went wrong, please try again later!");
83+
}
84+
};
7185
const handleSubmit = (event) => {
7286
event.preventDefault();
7387
if (lengthValid && caseDigitValid && specialCharValid) {
@@ -111,7 +125,13 @@ const Signup = () => {
111125
params
112126
);
113127
if (usersignup) {
114-
handleNavigation(r.getSessionToken());
128+
const param = new URLSearchParams(location.search);
129+
const isFreeplan =
130+
param?.get("subscription") === "freeplan";
131+
if (isFreeplan) {
132+
await handleFreePlan(r.id);
133+
}
134+
handleNavigation(r.getSessionToken(), isFreeplan);
115135
}
116136
} catch (err) {
117137
alert(err.message);
@@ -156,7 +176,7 @@ const Signup = () => {
156176
}
157177
};
158178

159-
const handleNavigation = async (sessionToken) => {
179+
const handleNavigation = async (sessionToken, isFreeplan = false) => {
160180
const baseUrl = localStorage.getItem("baseUrl");
161181
const parseAppId = localStorage.getItem("parseAppId");
162182
const res = await axios.get(baseUrl + "users/me", {
@@ -325,7 +345,13 @@ const Signup = () => {
325345
);
326346
setState({ loading: false });
327347
if (isEnableSubscription) {
328-
navigate(`/subscription`, { replace: true });
348+
if (isFreeplan) {
349+
navigate(
350+
`/${element.pageType}/${element.pageId}`
351+
);
352+
} else {
353+
navigate(`/subscription`, { replace: true });
354+
}
329355
} else {
330356
alert("Registered user successfully");
331357
navigate(
@@ -343,7 +369,13 @@ const Signup = () => {
343369
localStorage.setItem("pageType", element.pageType);
344370
setState({ loading: false });
345371
if (isEnableSubscription) {
346-
navigate(`/subscription`, { replace: true });
372+
if (isFreeplan) {
373+
navigate(
374+
`/${element.pageType}/${element.pageId}`
375+
);
376+
} else {
377+
navigate(`/subscription`, { replace: true });
378+
}
347379
} else {
348380
navigate(
349381
`/${element.pageType}/${element.pageId}`

0 commit comments

Comments
 (0)