Skip to content

Commit

Permalink
Merge pull request #1396 from OpenSignLabs/validation
Browse files Browse the repository at this point in the history
feat: draft template api
  • Loading branch information
nxglabs authored Oct 29, 2024
2 parents b3fecca + 9952afc commit 32eba21
Show file tree
Hide file tree
Showing 32 changed files with 3,391 additions and 557 deletions.
5 changes: 5 additions & 0 deletions apps/OpenSign/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const GenerateToken = lazy(() => import("./pages/GenerateToken"));
const Webhook = lazy(() => import("./pages/Webhook"));
const AddAdmin = lazy(() => import("./pages/AddAdmin"));
const UpdateExistUserAdmin = lazy(() => import("./pages/UpdateExistUserAdmin"));
const DraftTemplate = lazy(() => import("./pages/DraftTemplate"));

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`;
const AppLoader = () => {
Expand Down Expand Up @@ -200,6 +201,10 @@ function App() {
<Route path="/users" element={<UserList />} />
</Route>
<Route path="/sso" element={<SSOVerify />} />
<Route
path="/drafttemplate/:jwttoken"
element={<DraftTemplate />}
/>
<Route path="*" element={<PageNotFound />} />
</Routes>
</BrowserRouter>
Expand Down
33 changes: 26 additions & 7 deletions apps/OpenSign/src/components/BulkSendUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,21 @@ const BulkSendUi = (props) => {
if (subscription?.plan === "freeplan") {
setIsFreePlan(true);
}
const resCredits = await Parse.Cloud.run("allowedcredits");
const token = props.jwttoken
? { jwttoken: props.jwttoken }
: { "X-Parse-Session-Token": localStorage.getItem("accesstoken") };
const axiosres = await axios.post(
`${localStorage.getItem("baseUrl")}functions/allowedcredits`,
{},
{
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
...token
}
}
);
const resCredits = axiosres.data && axiosres.data.result;
if (resCredits) {
const allowedcredits = resCredits?.allowedcredits || 0;
const addoncredits = resCredits?.addoncredits || 0;
Expand All @@ -81,7 +95,7 @@ const BulkSendUi = (props) => {
}
setAmount((obj) => ({ ...obj, totalcredits: totalcredits }));
}
const getPlaceholder = props.item?.Placeholders;
const getPlaceholder = props?.Placeholders;
const checkIsSignatureExistt = getPlaceholder?.every((placeholderObj) =>
placeholderObj?.placeHolder?.some((holder) =>
holder?.pos?.some((posItem) => posItem?.type === "signature")
Expand All @@ -97,7 +111,7 @@ const BulkSendUi = (props) => {
} else {
setIsBulkAvailable(true);
setAdmin((obj) => ({ ...obj, isAdmin: true }));
const getPlaceholder = props.item?.Placeholders;
const getPlaceholder = props?.Placeholders;
const checkIsSignatureExistt = getPlaceholder?.every((placeholderObj) =>
placeholderObj?.placeHolder?.some((holder) =>
holder?.pos?.some((posItem) => posItem?.type === "signature")
Expand Down Expand Up @@ -194,7 +208,7 @@ const BulkSendUi = (props) => {
setIsSubmit(true);

// Create a copy of Placeholders array from props.item
let Placeholders = [...props.item.Placeholders];
let Placeholders = [...props.Placeholders];
// Initialize an empty array to store updated documents
let Documents = [];
// Loop through each form
Expand Down Expand Up @@ -251,12 +265,16 @@ const BulkSendUi = (props) => {
};

const batchQuery = async (Documents) => {
const serverUrl = localStorage.getItem("baseUrl");
const functionsUrl = `${serverUrl}functions/batchdocuments`;
const token = props.jwttoken
? { jwttoken: props.jwttoken }
: { "X-Parse-Session-Token": localStorage.getItem("accesstoken") };
const functionsUrl = `${localStorage.getItem(
"baseUrl"
)}functions/batchdocuments`;
const headers = {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
sessionToken: localStorage.getItem("accesstoken")
...token
};
const params = { Documents: JSON.stringify(Documents) };
try {
Expand Down Expand Up @@ -362,6 +380,7 @@ const BulkSendUi = (props) => {
fieldIndex
)
}
jwttoken={props?.jwttoken}
/>
</div>
))}
Expand Down
26 changes: 14 additions & 12 deletions apps/OpenSign/src/components/shared/fields/SelectSigners.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import Parse from "parse";
import AsyncSelect from "react-select/async";
import { useTranslation } from "react-i18next";
import axios from "axios";

const SelectSigners = (props) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -31,17 +31,19 @@ const SelectSigners = (props) => {

const loadOptions = async (inputValue) => {
try {
const currentUser = Parse.User.current();
const contactbook = new Parse.Query("contracts_Contactbook");
contactbook.equalTo(
"CreatedBy",
Parse.User.createWithoutData(currentUser.id)
);
if (inputValue.length > 1) {
contactbook.matches("Name", new RegExp(inputValue, "i"));
}
contactbook.notEqualTo("IsDeleted", true);
const contactRes = await contactbook.find();
const baseURL = localStorage.getItem("baseUrl");
const url = `${baseURL}functions/getsigners`;
const token = props?.jwttoken
? { jwttoken: props?.jwttoken }
: { "X-Parse-Session-Token": localStorage.getItem("accesstoken") };
const headers = {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
...token
};
const search = inputValue;
const axiosRes = await axios.post(url, { search }, { headers });
const contactRes = axiosRes?.data?.result || [];
if (contactRes) {
const res = JSON.parse(JSON.stringify(contactRes));
//compareArrays is a function where compare between two array (total signersList and dcument signers list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SuggestionInput = (props) => {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
(async () => {
const res = await findContact(inputValue);
const res = await findContact(inputValue, props.jwttoken);
if (res?.length > 0) {
setSuggestions(res);
setShowSuggestions(true);
Expand All @@ -37,6 +37,7 @@ const SuggestionInput = (props) => {
}, 1000);
}
return () => clearTimeout(timer);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inputValue]);

const handleInputChange = async (e) => {
Expand Down
87 changes: 59 additions & 28 deletions apps/OpenSign/src/constant/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export async function fetchSubscription(
extUserId,
contactObjId,
isGuestSign = false,
isPublic = false
isPublic = false,
jwtToken
) {
try {
const Extand_Class = localStorage.getItem("Extand_Class");
Expand All @@ -48,10 +49,13 @@ export async function fetchSubscription(
}
const baseURL = localStorage.getItem("baseUrl");
const url = `${baseURL}functions/getsubscriptions`;
const token = jwtToken
? { jwttoken: jwtToken }
: { sessionToken: localStorage.getItem("accesstoken") };
const headers = {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
sessionToken: localStorage.getItem("accesstoken")
...token
};
const params = isGuestSign
? { contactId: contactObjId }
Expand Down Expand Up @@ -226,12 +230,25 @@ export const pdfNewWidthFun = (divRef) => {
};

//`contractUsers` function is used to get contract_User details
export const contractUsers = async () => {
export const contractUsers = async (jwttoken) => {
try {
const userDetails = await Parse.Cloud.run("getUserDetails");
const url = `${localStorage.getItem("baseUrl")}functions/getUserDetails`;
const parseAppId = localStorage.getItem("parseAppId");
const accesstoken = localStorage.getItem("accesstoken");
const token = jwttoken
? { jwttoken: jwttoken }
: { "X-Parse-Session-Token": accesstoken };
const headers = {
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": parseAppId,
...token
}
};
const userDetails = await axios.post(url, {}, headers);
let data = [];
if (userDetails) {
const json = JSON.parse(JSON.stringify(userDetails));
if (userDetails?.data?.result) {
const json = JSON.parse(JSON.stringify(userDetails.data.result));
data.push(json);
}
return data;
Expand Down Expand Up @@ -1762,14 +1779,17 @@ export const contactBook = async (objectId) => {
};

//function for getting document details from contract_Documents class
export const contractDocument = async (documentId) => {
export const contractDocument = async (documentId, JwtToken) => {
const data = { docId: documentId };
const token = JwtToken
? { jwtToken: JwtToken }
: { sessionToken: localStorage.getItem("accesstoken") };
const documentDeatils = await axios
.post(`${localStorage.getItem("baseUrl")}functions/getDocument`, data, {
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
sessionToken: localStorage.getItem("accesstoken")
...token
}
})
.then((Listdata) => {
Expand Down Expand Up @@ -1969,20 +1989,28 @@ export const getAppLogo = async () => {
}
};

export const getTenantDetails = async (objectId) => {
export const getTenantDetails = async (objectId, jwttoken) => {
try {
const tenantCreditsQuery = new Parse.Query("partners_Tenant");
tenantCreditsQuery.equalTo("UserId", {
__type: "Pointer",
className: "_User",
objectId: objectId
const url = `${localStorage.getItem("baseUrl")}functions/gettenant`;
const parseAppId = localStorage.getItem("parseAppId");
const accesstoken = localStorage.getItem("accesstoken");
const token = jwttoken
? { jwttoken: jwttoken }
: { "X-Parse-Session-Token": accesstoken };
const data = jwttoken ? {} : { userId: objectId };
const res = await axios.post(url, data, {
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": parseAppId,
...token
}
});
const res = await tenantCreditsQuery.first();
if (res) {
const updateRes = JSON.parse(JSON.stringify(res));
const updateRes = JSON.parse(JSON.stringify(res.data.result));
return updateRes;
}
} catch (e) {
} catch (err) {
console.log("err in gettenant", err);
return "user does not exist!";
}
};
Expand Down Expand Up @@ -2231,18 +2259,21 @@ export const handleDownloadCertificate = async (
}
}
};
export async function findContact(value) {
export async function findContact(value, jwttoken) {
try {
const currentUser = Parse.User.current();
const contactbook = new Parse.Query("contracts_Contactbook");
contactbook.equalTo(
"CreatedBy",
Parse.User.createWithoutData(currentUser.id)
);
contactbook.notEqualTo("IsDeleted", true);
contactbook.matches("Email", new RegExp(value, "i"));

const contactRes = await contactbook.find();
const baseURL = localStorage.getItem("baseUrl");
const url = `${baseURL}functions/getsigners`;
const token = jwttoken
? { jwttoken: jwttoken }
: { "X-Parse-Session-Token": localStorage.getItem("accesstoken") };
const headers = {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
...token
};
const searchEmail = value;
const axiosRes = await axios.post(url, { searchEmail }, { headers });
const contactRes = axiosRes?.data?.result || [];
if (contactRes) {
const res = JSON.parse(JSON.stringify(contactRes));
return res;
Expand Down
Loading

0 comments on commit 32eba21

Please sign in to comment.