diff --git a/apps/OpenSign/src/components/AddUser.js b/apps/OpenSign/src/components/AddUser.js
index 40509c40e..6a1d21c78 100644
--- a/apps/OpenSign/src/components/AddUser.js
+++ b/apps/OpenSign/src/components/AddUser.js
@@ -4,7 +4,6 @@ import Title from "./Title";
import Loader from "../primitives/Loader";
import { copytoData, fetchSubscriptionInfo } from "../constant/Utils";
import { isEnableSubscription } from "../constant/const";
-import ModalUi from "../primitives/ModalUi";
import { useTranslation } from "react-i18next";
function generatePassword(length) {
const characters =
@@ -48,6 +47,7 @@ const AddUser = (props) => {
useEffect(() => {
getTeamList();
+ // eslint-disable-next-line
}, []);
const getTeamList = async () => {
@@ -73,6 +73,13 @@ const AddUser = (props) => {
const res = await Parse.Cloud.run("allowedusers", {
tenantId: extUser?.TenantId?.objectId
});
+ if (props.setFormHeader) {
+ if (res > 0) {
+ props.setFormHeader(t("add-user"));
+ } else {
+ props.setFormHeader(t("Add-seats"));
+ }
+ }
setAllowedUser(res);
} else {
setAllowedUser(0);
@@ -121,9 +128,7 @@ const AddUser = (props) => {
if (res) {
props.setIsAlert({ type: "danger", msg: t("user-already-exist") });
setIsFormLoader(false);
- setTimeout(() => {
- props.setIsAlert({ type: "success", msg: "" });
- }, 1000);
+ setTimeout(() => props.setIsAlert({ type: "success", msg: "" }), 1000);
} else {
try {
const extUser = new Parse.Object("contracts_Users");
@@ -276,10 +281,7 @@ const AddUser = (props) => {
if (name === "email") {
value = value?.toLowerCase()?.replace(/\s/g, "");
}
- setFormdata((prev) => ({
- ...prev,
- [name]: value
- }));
+ setFormdata((prev) => ({ ...prev, [name]: value }));
};
const copytoclipboard = (text) => {
@@ -313,172 +315,134 @@ const AddUser = (props) => {
if (resAddon) {
const _resAddon = JSON.parse(JSON.stringify(resAddon));
if (_resAddon.status === "success") {
- setAllowedUser(_resAddon.addon);
+ setAllowedUser(amount.quantity);
+ setPlanInfo((obj) => ({ ...obj, totalAllowedUser: _resAddon.addon }));
}
}
} catch (err) {
console.log("Err in buy addon", err);
- props.setIsAlert({
- type: "danger",
- msg: t("something-went-wrong-mssg")
- });
+ props.setIsAlert({ type: "danger", msg: t("something-went-wrong-mssg") });
} finally {
setTimeout(() => props.setIsAlert({ type: "success", msg: "" }), 2000);
setIsFormLoader(false);
}
};
return (
- 0 ? t("add-user") : t("Add-seats")}
- handleClose={props.closePopup}
- >
-
-
- {isFormLoader && (
-
-
-
- )}
- {!isLoader ? (
- <>
- {err ? (
-
- {err}
-
- ) : (
-
- {!isEnableSubscription || allowedUser > 0 ? (
-
)}
-
+ title={formHeader}
+ handleClose={handleFormModal}
+ >
+
+
) : (
diff --git a/apps/OpenSignServer/cloud/customRoute/saveSubscription.js b/apps/OpenSignServer/cloud/customRoute/saveSubscription.js
index 904c2e7e1..d355368f6 100644
--- a/apps/OpenSignServer/cloud/customRoute/saveSubscription.js
+++ b/apps/OpenSignServer/cloud/customRoute/saveSubscription.js
@@ -5,7 +5,27 @@ export default async function saveSubscription(request, response) {
const Next_billing_date = request.body?.data?.subscription?.next_billing_at;
const planCode = request.body?.data?.subscription?.plan?.plan_code;
const addons = request.body?.data?.subscription?.addons || [];
- const existAddon = addons.reduce((acc, curr) => acc + curr.quantity, 1);
+ let existAddon = 0;
+ if (addons?.length > 0) {
+ let allowedUsersMonthly = 0;
+ let allowedUsersYearly = 0;
+ addons?.forEach(item => {
+ if (item.addon_code === 'extra-teams-users-monthly') {
+ allowedUsersMonthly += item.quantity;
+ } else if (item.addon_code === 'extra-teams-users-yearly') {
+ allowedUsersYearly += item.quantity;
+ } else if (item.addon_code === 'extra-users') {
+ allowedUsersMonthly += item.quantity;
+ }
+ });
+ if (allowedUsersMonthly > 0 || allowedUsersYearly > 0) {
+ existAddon = allowedUsersMonthly + allowedUsersYearly + 1;
+ }
+ } else {
+ if (planCode === 'teams-yearly' || planCode === 'teams-monthly' || planCode === 'team-weekly') {
+ existAddon = 1;
+ }
+ }
try {
const extUserCls = new Parse.Query('contracts_Users');
extUserCls.equalTo('Email', Email);
@@ -29,7 +49,9 @@ export default async function saveSubscription(request, response) {
updateSubscription.unset('Next_billing_date');
}
updateSubscription.set('PlanCode', planCode);
- updateSubscription.set('AllowedUsers', parseInt(existAddon));
+ if (existAddon > 0) {
+ updateSubscription.set('AllowedUsers', parseInt(existAddon));
+ }
await updateSubscription.save(null, { useMasterKey: true });
return response.status(200).json({ status: 'update subscription!' });
} else {
@@ -57,7 +79,9 @@ export default async function saveSubscription(request, response) {
createSubscription.unset('Next_billing_date');
}
createSubscription.set('PlanCode', planCode);
- createSubscription.set('AllowedUsers', parseInt(existAddon));
+ if (existAddon > 0) {
+ createSubscription.set('AllowedUsers', parseInt(existAddon));
+ }
await createSubscription.save(null, { useMasterKey: true });
return response.status(200).json({ status: 'create subscription!' });
}
diff --git a/apps/OpenSignServer/cloud/parsefunction/BuyAddon.js b/apps/OpenSignServer/cloud/parsefunction/BuyAddon.js
index ad089a389..a47aed0d4 100644
--- a/apps/OpenSignServer/cloud/parsefunction/BuyAddon.js
+++ b/apps/OpenSignServer/cloud/parsefunction/BuyAddon.js
@@ -36,13 +36,32 @@ export default async function Buyaddon(request) {
const price = _resSub?.SubscriptionDetails?.data?.subscription?.plan?.price;
const plan_code = _resSub?.SubscriptionDetails?.data?.subscription?.plan?.plan_code;
const addonsArr = _resSub?.SubscriptionDetails?.data?.subscription?.addons || [];
- const addon = addonsArr.reduce((acc, curr) => acc + curr.quantity, 0);
+ let addon = 0;
+ if (addonsArr?.length > 0) {
+ let allowedUsersMonthly = 0;
+ let allowedUsersYearly = 0;
+ addonsArr?.forEach(item => {
+ if (item.addon_code === 'extra-teams-users-monthly') {
+ allowedUsersMonthly += item.quantity;
+ } else if (item.addon_code === 'extra-teams-users-yearly') {
+ allowedUsersYearly += item.quantity;
+ } else if (item.addon_code === 'extra-users') {
+ allowedUsersMonthly += item.quantity;
+ }
+ });
+ if (allowedUsersMonthly > 0 || allowedUsersYearly > 0) {
+ addon = allowedUsersMonthly + allowedUsersYearly;
+ }
+ }
const quantity = parseInt(users) + parseInt(addon);
+ const addoncode = plan_code.includes('yearly')
+ ? 'extra-teams-users-yearly'
+ : 'extra-teams-users-monthly';
const data = JSON.stringify({
plan: { plan_code: plan_code },
addons: [
{
- addon_code: 'extra-users',
+ addon_code: addoncode,
addon_description: 'Extra users',
price: price,
quantity: quantity,
diff --git a/apps/OpenSignServer/cloud/parsefunction/saveSubscription.js b/apps/OpenSignServer/cloud/parsefunction/saveSubscription.js
index 3fac359fc..12fbbdcdd 100644
--- a/apps/OpenSignServer/cloud/parsefunction/saveSubscription.js
+++ b/apps/OpenSignServer/cloud/parsefunction/saveSubscription.js
@@ -8,7 +8,7 @@ export default async function saveSubscription(request) {
const body = subscription;
const Next_billing_date = subscription.data.subscription.next_billing_at;
const planCode = subscription.data.subscription.plan.plan_code;
-
+ let existAddon = 0;
try {
const userRes = await axios.get(serverUrl + '/users/me', {
headers: {
@@ -33,7 +33,32 @@ export default async function saveSubscription(request) {
});
const resSubscription = await subcriptionCls.first({ useMasterKey: true });
const addons = subscription?.data?.subscription?.addons || [];
- const existAddon = addons.reduce((acc, curr) => acc + curr.quantity, 1);
+ if (addons?.length > 0) {
+ let allowedUsersMonthly = 0;
+ let allowedUsersYearly = 0;
+ addons?.forEach(item => {
+ if (item.addon_code === 'extra-teams-users-monthly') {
+ allowedUsersMonthly += item.quantity;
+ } else if (item.addon_code === 'extra-teams-users-yearly') {
+ allowedUsersYearly += item.quantity;
+ } else if (item.addon_code === 'extra-users') {
+ allowedUsersMonthly += item.quantity;
+ }
+ });
+ if (allowedUsersMonthly > 0 || allowedUsersYearly > 0) {
+ existAddon = allowedUsersMonthly + allowedUsersYearly + 1;
+ }
+ } else {
+ if (
+ planCode === 'teams-yearly' ||
+ planCode === 'teams-monthly' ||
+ planCode === 'team-weekly'
+ ) {
+ existAddon = 1;
+ }
+ }
+
+ // const existAddon = addons.reduce((acc, curr) => acc + curr.quantity, 1);
if (resSubscription) {
const updateSubscription = new Parse.Object('contracts_Subscriptions');
updateSubscription.id = resSubscription.id;
@@ -41,7 +66,9 @@ export default async function saveSubscription(request) {
updateSubscription.set('SubscriptionDetails', body);
updateSubscription.set('Next_billing_date', new Date(Next_billing_date));
updateSubscription.set('PlanCode', planCode);
- updateSubscription.set('AllowedUsers', parseInt(existAddon));
+ if (existAddon > 0) {
+ updateSubscription.set('AllowedUsers', parseInt(existAddon));
+ }
await updateSubscription.save(null, { useMasterKey: true });
return { status: 'update subscription!' };
} else {
@@ -65,7 +92,9 @@ export default async function saveSubscription(request) {
});
createSubscription.set('Next_billing_date', new Date(Next_billing_date));
createSubscription.set('PlanCode', planCode);
- createSubscription.set('AllowedUsers', parseInt(existAddon));
+ if (existAddon > 0) {
+ createSubscription.set('AllowedUsers', parseInt(existAddon));
+ }
await createSubscription.save(null, { useMasterKey: true });
return { status: 'create subscription!' };
}