diff --git a/apps/OpenSign/public/locales/en/translation.json b/apps/OpenSign/public/locales/en/translation.json index a2481a50d..bce494e2c 100644 --- a/apps/OpenSign/public/locales/en/translation.json +++ b/apps/OpenSign/public/locales/en/translation.json @@ -608,5 +608,9 @@ "buyapiaddon":"Buy APIs", "quantityofapis" :"Quantity of APIs", "additionalapis":"Please purchase add-on APIs", - "remainingapis":"Remaining APIs:" + "remainingapis": "Remaining APIs Credits:", + "additional-quicksend": "Please purchase add-on quick send", + "quantityofquicksend": "Quantity of Quick send", + "quotaerrquicksend": "Quota Reached, You don't have enough credits.", + "buycredits": "Buy credits" } \ No newline at end of file diff --git a/apps/OpenSign/public/locales/fr/translation.json b/apps/OpenSign/public/locales/fr/translation.json index 7bcd7e372..ead8ea1b3 100644 --- a/apps/OpenSign/public/locales/fr/translation.json +++ b/apps/OpenSign/public/locales/fr/translation.json @@ -608,5 +608,10 @@ "buyapiaddon":"Acheter des API", "quantityofapis":"Quantité d'API", "additionalapis":"Veuillez acheter des API complémentaires", - "remainingapis":"API restantes :" + "remainingapis":"API restantes Crédits:", + "additional-quicksend":"Veuillez acheter le module complémentaire quick send", + "quantityofquicksend": "Quantité de Quick send", + "quotaerrquicksend": "Quota atteint, vous n'avez pas assez de crédits.", + "buycredits": "Acheter des crédits" + } diff --git a/apps/OpenSign/src/components/AddUser.js b/apps/OpenSign/src/components/AddUser.js index 6a1d21c78..f1c77eb1c 100644 --- a/apps/OpenSign/src/components/AddUser.js +++ b/apps/OpenSign/src/components/AddUser.js @@ -52,9 +52,6 @@ const AddUser = (props) => { const getTeamList = async () => { if (isEnableSubscription) { - const extUser = - localStorage.getItem("Extand_Class") && - JSON.parse(localStorage.getItem("Extand_Class"))?.[0]; try { setIsLoader(true); const resSub = await fetchSubscriptionInfo(); @@ -70,9 +67,7 @@ const AddUser = (props) => { price: resSub.price, totalPrice: resSub.price + resSub.totalPrice })); - const res = await Parse.Cloud.run("allowedusers", { - tenantId: extUser?.TenantId?.objectId - }); + const res = await Parse.Cloud.run("allowedusers"); if (props.setFormHeader) { if (res > 0) { props.setFormHeader(t("add-user")); @@ -304,13 +299,9 @@ const AddUser = (props) => { e.preventDefault(); e.stopPropagation(); setIsFormLoader(true); - const extUser = - localStorage.getItem("Extand_Class") && - JSON.parse(localStorage.getItem("Extand_Class"))?.[0]; try { - const resAddon = await Parse.Cloud.run("buyaddon", { - users: amount.quantity, - tenantId: extUser?.TenantId?.objectId + const resAddon = await Parse.Cloud.run("buyaddonusers", { + users: amount.quantity }); if (resAddon) { const _resAddon = JSON.parse(JSON.stringify(resAddon)); @@ -352,7 +343,7 @@ const AddUser = (props) => { allowedUser < 2 ? "op-text-accent" : "op-text-primary" } font-medium ml-1`} > - {allowedUser} of {planInfo.totalAllowedUser} + {allowedUser} {t("of")} {planInfo.totalAllowedUser}

diff --git a/apps/OpenSign/src/components/BulkSendUi.js b/apps/OpenSign/src/components/BulkSendUi.js index dfeea9921..0ca90d39e 100644 --- a/apps/OpenSign/src/components/BulkSendUi.js +++ b/apps/OpenSign/src/components/BulkSendUi.js @@ -3,7 +3,8 @@ import axios from "axios"; import SuggestionInput from "./shared/fields/SuggestionInput"; import Loader from "../primitives/Loader"; import { useTranslation } from "react-i18next"; - +import Parse from "parse"; +import ModalUi from "../primitives/ModalUi"; const BulkSendUi = (props) => { const { t } = useTranslation(); const [forms, setForms] = useState([]); @@ -13,6 +14,16 @@ const BulkSendUi = (props) => { const [isSubmit, setIsSubmit] = useState(false); const [allowedForm, setAllowedForm] = useState(0); const [isSignatureExist, setIsSignatureExist] = useState(); + const [isBulkAvailable, setIsBulkAvailable] = useState(false); + const quantityList = [500, 1000, 5000, 50000]; + const [amount, setAmount] = useState({ + price: (75.0).toFixed(2), + quantity: 500, + totalPrice: 0, + priceperbulksend: 0.15, + totalQuickSend: 0 + }); + const [isQuotaReached, setIsQuotaReached] = useState(false); const allowedSigners = 50; useEffect(() => { signatureExist(); @@ -20,14 +31,26 @@ const BulkSendUi = (props) => { }, []); //function to check atleast one signature field exist - const signatureExist = () => { - const getPlaceholder = props.item?.Placeholders; - const checkIsSignatureExistt = getPlaceholder?.every((placeholderObj) => - placeholderObj?.placeHolder?.some((holder) => - holder?.pos?.some((posItem) => posItem?.type === "signature") - ) - ); - setIsSignatureExist(checkIsSignatureExistt); + const signatureExist = async () => { + setIsSubmit(true); + try { + const allowedquicksend = await Parse.Cloud.run("allowedquicksend"); + if (allowedquicksend > 0) { + setIsBulkAvailable(true); + const getPlaceholder = props.item?.Placeholders; + const checkIsSignatureExistt = getPlaceholder?.every((placeholderObj) => + placeholderObj?.placeHolder?.some((holder) => + holder?.pos?.some((posItem) => posItem?.type === "signature") + ) + ); + setIsSignatureExist(checkIsSignatureExistt); + } + setAmount((obj) => ({ ...obj, totalQuickSend: allowedquicksend })); + setIsSubmit(false); + } catch (err) { + setIsSubmit(false); + console.log("Err", err); + } }; useEffect(() => { if (scrollOnNextUpdate && formRef.current) { @@ -76,29 +99,33 @@ const BulkSendUi = (props) => { const handleAddForm = (e) => { e.preventDefault(); // Check if the quick send limit has been reached - if (forms?.length < allowedForm) { - if (props?.Placeholders.length > 0) { - let newForm = []; - props?.Placeholders?.forEach((element) => { - if (!element.signerObjId) { - newForm = [ - ...newForm, - { - fieldId: element.Id, - email: "", - label: element.Role, - signer: {} - } - ]; - } - }); - setForms([...forms, { Id: formId, fields: newForm }]); + if (forms.length <= amount.totalQuickSend) { + if (forms?.length < allowedForm) { + if (props?.Placeholders.length > 0) { + let newForm = []; + props?.Placeholders?.forEach((element) => { + if (!element.signerObjId) { + newForm = [ + ...newForm, + { + fieldId: element.Id, + email: "", + label: element.Role, + signer: {} + } + ]; + } + }); + setForms([...forms, { Id: formId, fields: newForm }]); + } + setFormId(formId + 1); + setScrollOnNextUpdate(true); + } else { + // If the limit has been reached, throw an error with the appropriate message + alert(t("quick-send-alert-4")); } - setFormId(formId + 1); - setScrollOnNextUpdate(true); } else { - // If the limit has been reached, throw an error with the appropriate message - alert(t("quick-send-alert-4")); + setIsQuotaReached(true); } }; @@ -162,13 +189,9 @@ const BulkSendUi = (props) => { : [...existSigner] }); } else { - Documents.push({ - ...props.item, - Placeholders: updatedPlaceholders - }); + Documents.push({ ...props.item, Placeholders: updatedPlaceholders }); } }); - //console.log("Documents ", Documents); await batchQuery(Documents); }; @@ -180,9 +203,7 @@ const BulkSendUi = (props) => { "X-Parse-Application-Id": localStorage.getItem("parseAppId"), sessionToken: localStorage.getItem("accesstoken") }; - const params = { - Documents: JSON.stringify(Documents) - }; + const params = { Documents: JSON.stringify(Documents) }; try { const res = await axios.post(functionsUrl, params, { headers: headers }); // console.log("res ", res); @@ -196,7 +217,48 @@ const BulkSendUi = (props) => { setIsSubmit(false); } }; - + const handleAddOnQuickSubmit = async (e) => { + e.preventDefault(); + e.stopPropagation(); + setIsSubmit(true); + try { + const resAddon = await Parse.Cloud.run("buyquicksend", { + quicksend: amount.quantity + }); + if (resAddon) { + const _resAddon = JSON.parse(JSON.stringify(resAddon)); + if (_resAddon.status === "success") { + setIsBulkAvailable(true); + handleCloseQuotaReached(); + setAmount((obj) => ({ + ...obj, + quantity: 500, + priceperapi: 0.15, + price: (75.0).toFixed(2), + totalapis: _resAddon.addon + })); + } + } + } catch (err) { + console.log("Err in buy addon", err); + alert(t("something-went-wrong-mssg")); + } finally { + setIsSubmit(false); + } + }; + const handlePricePerQuick = async (e) => { + const quantity = e.target?.value; + const price = + quantity > 0 + ? (Math.round(quantity * amount.priceperbulksend * 100) / 100).toFixed( + 2 + ) + : 500 * amount.priceperbulksend; + setAmount((prev) => ({ ...prev, quantity: quantity, price: price })); + }; + const handleCloseQuotaReached = () => { + setIsQuotaReached(false); + }; return ( <> {isSubmit && ( @@ -204,75 +266,141 @@ const BulkSendUi = (props) => {
)} - {props.Placeholders?.length > 0 ? ( - isSignatureExist ? ( - <> - {props.Placeholders?.some((x) => !x.signerObjId) ? ( -
-
- {forms?.map((form, index) => ( -
- {form?.fields?.map((field, fieldIndex) => ( -
- - - handleInputChange(index, signer, fieldIndex) - } - /> -
- ))} - {forms?.length > 1 && ( + {isBulkAvailable ? ( + <> + {props.Placeholders?.length > 0 ? ( + isSignatureExist ? ( + <> + {props.Placeholders?.some((x) => !x.signerObjId) ? ( +
+ +
+ {forms?.map((form, index) => ( +
+ {form?.fields?.map((field, fieldIndex) => ( +
+ + + handleInputChange(index, signer, fieldIndex) + } + /> +
+ ))} + {forms?.length > 1 && ( + + )} +
+
+ ))} +
+
- )} -
-
- ))} -
-
- - -
- + +
+ + handleCloseQuotaReached()} + > +
+

+ {t("quotaerrquicksend")} +

+ +
+
+
+ ) : ( +
+ {t("quick-send-alert-1")} +
+ )} + ) : (
- {t("quick-send-alert-1")} + {t("quick-send-alert-2")}
- )} - - ) : ( -
- {t("quick-send-alert-2")} -
- ) + ) + ) : ( +
+ {t("quick-send-alert-3")} +
+ )} + ) : ( -
- {t("quick-send-alert-3")} -
+
+

+ {t("additional-quicksend")} +

+
+ + +
+
+ +
+ USD {amount.price} +
+
+
+ +
)} ); diff --git a/apps/OpenSign/src/pages/GenerateToken.js b/apps/OpenSign/src/pages/GenerateToken.js index 89e896c0a..0611aa238 100644 --- a/apps/OpenSign/src/pages/GenerateToken.js +++ b/apps/OpenSign/src/pages/GenerateToken.js @@ -27,12 +27,13 @@ function GenerateToken() { const [isAlert, setIsAlert] = useState({ type: "success", msg: "" }); const [isTour, setIsTour] = useState(false); const [amount, setAmount] = useState({ - quantity: 1, + quantity: 500, priceperapi: 0.15, totalapis: 0, - price: 0.15 + price: (75.0).toFixed(2) }); const [isFormLoader, setIsFormLoader] = useState(false); + const quantityList = [500, 1000, 5000, 50000]; useEffect(() => { fetchToken(); // eslint-disable-next-line @@ -49,14 +50,9 @@ function GenerateToken() { const subscribe = await checkIsSubscribed(); setIsSubscribe(subscribe); } - const extUser = - localStorage.getItem("Extand_Class") && - JSON.parse(localStorage.getItem("Extand_Class"))?.[0]; const res = await Parse.Cloud.run("getapitoken"); if (res) { - const allowedapis = await Parse.Cloud.run("allowedapis", { - tenantId: extUser?.TenantId?.objectId - }); + const allowedapis = await Parse.Cloud.run("allowedapis"); setAmount((obj) => ({ ...obj, totalapis: allowedapis })); SetApiToken(res?.result); } @@ -119,7 +115,7 @@ function GenerateToken() { const price = quantity > 0 ? (Math.round(quantity * amount.priceperapi * 100) / 100).toFixed(2) - : 1 * amount.priceperapi; + : 500 * amount.priceperapi; setAmount((prev) => ({ ...prev, quantity: quantity, price: price })); }; const handleAddOnApiSubmit = async (e) => { @@ -137,7 +133,7 @@ function GenerateToken() { ...obj, quantity: 1, priceperapi: 0.15, - price: 0.15, + price: (75.0).toFixed(2), totalapis: _resAddon.addon })); } @@ -276,14 +272,20 @@ function GenerateToken() { {t("quantityofapis")} * - handlePricePerAPIs(e)} - className="w-1/4 op-input op-input-bordered op-input-sm focus:outline-none hover:border-base-content text-xs" + name="quantity" + className="op-select op-select-bordered op-select-sm focus:outline-none hover:border-base-content w-1/4 text-xs" required - /> + > + {quantityList.length > 0 && + quantityList.map((x) => ( + + ))} +