Skip to content

🔥 The free & Open Source DocuSign alternative

feat: add yourself check box in add signer form

prafull-opensignlabs1195eb408c55
diff --git a/apps/OpenSign/src/components/AppendFormInForm.js b/apps/OpenSign/src/components/AppendFormInForm.js
index 494936742..d090348e3 100644
--- a/apps/OpenSign/src/components/AppendFormInForm.js
+++ b/apps/OpenSign/src/components/AppendFormInForm.js
@@ -1,1269 +1,304 @@
-import React, { Component } from "react";
-import { connect } from "react-redux";
-import {
- removeState,
- removeLevel2State,
- removeLevel3State
-} from "../redux/actions/index";
-import Engine from "json-rules-engine-simplified";
-import applyRules from "rjsf-conditionals";
-import Form from "@rjsf/core";
-import validator from "@rjsf/validator-ajv8";
-import "../styles/form.css";
-import "../styles/toast.css";
+import React, { useState, useEffect } from "react";
import Parse from "parse";
-import "../styles/loader.css";
-import LayoutField from "./fields/Rjsf-layout";
-import TimeWidget from "./fields/TimeWidget";
import axios from "axios";
-import { Navigate } from "react-router-dom";
-import HiddenField from "./fields/HiddenField";
-import ErrorBoundary from "./ErrorBoundary";
-import parse from "html-react-parser";
-import { formJson } from "../json/FormJson";
-const widget = {
- TimeWidget: TimeWidget
-};
-const fields = () => {
- return {
- layout: LayoutField,
- HiddenField: HiddenField
- };
-};
-
-class AppendFormInForm extends Component {
- state = {
- schema: {},
- ui_schema: {},
- extraActions: undefined,
- rules: [],
- isAppRequest: false,
- formData: {},
- persistentFields: [],
- successMassage: "Record inserted successfully.",
- title: "",
- active: true,
- buttons: {},
- schemaState: {},
- noValidate: false,
- liveValidate: false,
- _validate: null,
- userSchema: {},
- loading: false,
- parseBaseUrl: localStorage.getItem("baseUrl"),
- parseAppId: localStorage.getItem("parseAppId"),
- toastColor: "#5cb85c",
- toastDescription: "",
- redirect_type: "",
- redirect_id: "",
- FormACL: null,
- help: "",
- link: ""
- };
-
- async getForm(id) {
- this.setState({
- loading: true
- });
- try {
- // get json from data(jsonschema, uischema)
- const results = formJson(id);
- // console.log("results", id, results);
- if (results) {
- const resultjson = results;
- if (resultjson.userSchema !== undefined) {
- this.setState({
- userSchema: resultjson.userSchema
- });
- }
- for (let [value] of Object.entries(resultjson.jsonSchema.properties)) {
- if (typeof value === "object") {
- for (let [k, v] of Object.entries(value)) {
- if (k === "format" && v === "date") {
- let today = new Date();
- let date =
- today.getFullYear() +
- "-" +
- ("0" + (today.getMonth() + 1)).slice(-2) +
- "-" +
- ("0" + today.getDate()).slice(-2);
- value.default = date;
- }
- if (k === "component" && v === "DateTime") {
- value.default = new Date().toISOString();
- }
- }
- }
- }
- let txt,
- link,
- successMsg,
- _rules = [],
- persistentFields = [],
- _extraActions = {};
- if (resultjson.help) {
- if (resultjson.help.htmlbody) {
- txt = resultjson.help.htmlbody;
- }
- if (resultjson.help.link) {
- link = resultjson.help.link;
- }
- }
- if (resultjson.rules) {
- _rules = resultjson.rules;
- }
- if (resultjson.persistentFields) {
- persistentFields = resultjson.persistentFields;
- }
- if (resultjson.extraActions) {
- _extraActions = this.setExtraActions(resultjson.extraActions);
- }
- if (resultjson.success_message) {
- successMsg = resultjson.success_message;
- } else {
- successMsg = this.state.successMassage;
- }
- let _jsonSchema = JSON.stringify(resultjson.jsonSchema);
- _jsonSchema = _jsonSchema.replace("#$", "$");
- _jsonSchema = _jsonSchema.replace("#*", "$");
- _jsonSchema = _jsonSchema.replace("_DOT_", ".");
-
- let _replaceJSONSchema = JSON.parse(_jsonSchema);
- this.setState({
- redirect_type: resultjson.success_redirect,
- redirect_id: resultjson.redirect_id,
- FormACL: resultjson.formACL,
- help: txt,
- link: link,
- persistentFields: persistentFields,
- successMassage: successMsg,
- buttons: resultjson.buttons.add,
- schemaState: _replaceJSONSchema,
- ui_schema: resultjson.uiSchema,
- rules: _rules,
- extraActions: _extraActions,
- title: resultjson.class,
- _validate: resultjson.validFunction,
- noValidate: resultjson.noValidate,
- liveValidate: resultjson.liveValidate && resultjson.liveValidate,
- loading: false
- });
- localStorage.setItem(
- "jsonschema",
- JSON.stringify(resultjson.jsonSchema)
- );
- } else {
- alert("form not found");
- }
- } catch (e) {
- if (e.message === "Invalid session token") {
- let appdata = localStorage.getItem("userSettings");
- let applogo = localStorage.getItem("appLogo");
- let appName = localStorage.getItem("appName");
- let defaultmenuid = localStorage.getItem("defaultmenuid");
- let PageLanding = localStorage.getItem("PageLanding");
- let domain = localStorage.getItem("domain");
- let _appName = localStorage.getItem("_appName");
- let baseUrl = localStorage.getItem("BaseUrl12");
- let appid = localStorage.getItem("AppID12");
-
- localStorage.clear();
-
- localStorage.setItem("appLogo", applogo);
- localStorage.setItem("appName", appName);
- localStorage.setItem("_appName", _appName);
- localStorage.setItem("defaultmenuid", defaultmenuid);
- localStorage.setItem("PageLanding", PageLanding);
- localStorage.setItem("domain", domain);
- localStorage.setItem("userSettings", appdata);
- localStorage.setItem("BaseUrl12", baseUrl);
- localStorage.setItem("AppID12", appid);
-
- return <Navigate to="/" />;
- }
- console.log(e.message);
- console.error("Problem", e);
- this.setState({
- loading: false
- });
+const AppendFormInForm = (props) => {
+ const [name, setName] = useState("");
+ const [phone, setPhone] = useState("");
+ const [email, setEmail] = useState("");
+ const [addYourself, setAddYourself] = useState(false);
+ const [isLoader, setIsLoader] = useState(false);
+ const [isUserExist, setIsUserExist] = useState(false);
+ const parseBaseUrl = localStorage.getItem("baseUrl");
+ const parseAppId = localStorage.getItem("parseAppId");
+
+ useEffect(() => {
+ checkUserExist();
+ }, []);
+ // Load user details from localStorage when the component mounts
+ useEffect(() => {
+ const savedUserDetails = JSON.parse(
+ localStorage.getItem("UserInformation")
+ );
+ if (savedUserDetails && addYourself) {
+ setName(savedUserDetails.name);
+ setPhone(savedUserDetails.phone);
+ setEmail(savedUserDetails.email);
}
- }
-
- wrap = (s) => "{ return " + s + " };";
-
- // func = new Function(wrap(body));
+ }, [addYourself]);
- dynamicValidate = (formData, errors) => {
+ const checkUserExist = async () => {
+ const user = Parse.User.current();
try {
- let body = atob(this.state._validate);
- let res = new Function(this.wrap(body))
- .call(null)
- .call(null, formData, errors);
- return res;
- } catch (error) {
- console.log(error);
+ const query = new Parse.Query("contracts_Contactbook");
+ query.equalTo("CreatedBy", user);
+ query.equalTo("Email", user.getEmail());
+ const res = await query.first();
+ // console.log(res);
+ if (!res) {
+ setIsUserExist(true);
+ }
+ } catch (err) {
+ console.log("err", err);
}
};
-
- setExtraActions = (actions) => {
+ // Define a function to handle form submission
+ const handleSubmit = async (e) => {
+ e.preventDefault();
+ setIsLoader(true);
+ Parse.serverURL = parseBaseUrl;
+ Parse.initialize(parseAppId);
try {
- let result = {};
- Object.entries(actions).forEach(([key, value]) => {
- let body = atob(value);
- let res = new Function(this.wrap(body)).call(null);
- result[key] = res;
- });
- return result;
- } catch (error) {
- console.log(error);
- }
- };
-
- handleSubmit = async ({ formData }) => {
- this.setState({ active: false, loading: true });
- if (
- this.state.userSchema &&
- Object.entries(this.state.userSchema).length !== 0 &&
- this.state.userSchema.constructor === Object
- ) {
- try {
- let RowData = formData;
- RowData &&
- Object.entries(RowData).forEach(([key, value]) => {
- if (typeof value === "string") {
- RowData[key] = value.trim();
- }
- });
- let UserData = {};
- let RoleField = "";
- let _scanData = this.state.schemaState;
- if (_scanData.dependencies) {
- Object.keys(_scanData.dependencies).forEach((key) => {
- if (_scanData.dependencies[key].oneOf) {
- _scanData.dependencies[key].oneOf.forEach((val) => {
- Object.keys(val.properties).forEach((k) => {
- if (typeof val.properties[k] === "object") {
- if (val.properties[k].format === "date") {
- if (RowData[k]) {
- let newdate = new Date(RowData[k]);
- RowData[k] = newdate;
- }
- }
- if (val.properties[k].component === "HtmlEditor") {
- if (RowData[k]) {
- let newHtml = RowData[k]
- .replace(/<p[^>]*>/g, "")
- .replace(/<\/p>/g, " ");
- RowData[k] = newHtml;
- }
- }
- if (val.properties[k].component === "DateTime") {
- if (RowData[k]) {
- let newDate11 = new Date(RowData[k]);
- RowData[k] = newDate11;
- }
- }
- if (val.properties[k].component === "CurrencyInput") {
- if (val.properties[k].currencyColumn) {
- RowData[`${val.properties[k].currencyColumn}`] =
- val.properties[k].defaultcurrency;
- }
- }
- if (val.properties[k].type === "string") {
- if (typeof RowData[k] === "string")
- RowData[k] = RowData[k].trim();
- }
- if (val.properties[k].data !== undefined) {
- if (val.properties[k].data.isPointer) {
- let pointer = undefined;
- if (val.properties[k].data.class) {
- if (val.properties[k].data.savePointerClass) {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className:
- val.properties[k].data.savePointerClass,
- objectId: RowData[k]
- };
- }
- } else {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: val.properties[k].data.class,
- objectId: RowData[k]
- };
- }
- }
- } else {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: localStorage.getItem("extended_class"),
- objectId: RowData[k]
- };
- }
- }
- RowData[k] = pointer;
- }
- if (val.properties[k].data.FolderTypeValue) {
- if (RowData[k]) {
- let obj = {
- __type: "Pointer",
- className: val.properties[k].data.ClassName,
- objectId: RowData[k]
- };
- RowData[k] = obj;
- }
- }
- }
- }
- });
- });
- }
- });
- }
- let _userScheama = this.state.userSchema;
-
- Object.keys(_scanData).forEach(function (key) {
- let _dd = _scanData[key];
- typeof _dd === "object" &&
- Object.keys(_dd).forEach(function (k) {
- if (_dd[k].type === "array" && _dd[k].items) {
- let _prop = _dd[k].items.properties;
-
- if (_prop && Array.isArray(RowData[k])) {
- let newRow = [];
- RowData[k].forEach((t) => {
- let _newObj = t;
- if (typeof t === "object") {
- Object.keys(_prop).forEach(function (l) {
- if (_prop[l].data && _prop[l].data.isPointer) {
- if (typeof t[l] === "object") {
- let obj = {
- __type: "Pointer",
- className: _prop[l].data.class,
- objectId: t[l].objectId
- };
- _newObj = { ..._newObj, [l]: obj };
- } else {
- let obj = {
- __type: "Pointer",
- className: _prop[l].data.class,
- objectId: t[l]
- };
- _newObj = { ..._newObj, [l]: obj };
- }
- }
- });
- }
- newRow.push(_newObj);
- });
- RowData[k] = newRow;
- }
- }
-
- if (_dd[k].component === "AutoSuggest" && _dd[k].isPointer) {
- if (RowData[k]) {
- let pointer = {
- __type: "Pointer",
- className: _dd[k].class,
- objectId: RowData[k]
- };
- RowData[k] = pointer;
- }
- }
- if (_dd[k].format === "date") {
- let newdate = new Date(RowData[k]);
- RowData[k] = newdate;
- }
- if (_dd[k].component === "CurrencyInput") {
- RowData[`${_dd[k].currencyColumn}`] = _dd[k].defaultcurrency;
- }
- if (_dd[k].component === "HtmlEditor") {
- if (RowData[k]) {
- let newHtml = RowData[k]
- .replace(/<p[^>]*>/g, "")
- .replace(/<\/p>/g, " ");
- RowData[k] = newHtml;
- }
- }
- if (_dd[k].component === "DateTime") {
- let newDate;
- if (!RowData[k]) {
- newDate = new Date();
- } else {
- newDate = new Date(RowData[k]);
- }
- RowData[k] = newDate;
- }
- if (_dd[k].data !== undefined) {
- if (_dd[k].data.isPointer) {
- let pointer = undefined;
- if (_dd[k].data.savePointerClass) {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: _dd[k].data.savePointerClass,
- objectId: RowData[k]
- };
- RowData[k] = pointer;
- }
- } else if (RowData[k]) {
- if (_dd[k].data.class) {
- pointer = {
- __type: "Pointer",
- className: _dd[k].data.class,
- objectId: RowData[k]
- };
- } else {
- pointer = {
- __type: "Pointer",
- className: localStorage.getItem("extended_class"),
- objectId: RowData[k]
- };
- }
-
- RowData[k] = pointer;
- }
- }
- if (_dd[k].data.FolderTypeValue) {
- if (RowData[k]) {
- let obj = {
- __type: "Pointer",
- className: _dd[k].data.ClassName,
- objectId: RowData[k]
- };
- RowData[k] = obj;
- }
- }
- }
- if (_dd[k].type === "string") {
- let d = RowData[k];
- if (typeof d === "string") {
- RowData[k] = d.trim();
- }
- }
- });
- });
-
- Object.keys(_userScheama).forEach(function (kkey) {
- Object.keys(RowData).forEach(function (_k) {
- if (_userScheama[kkey].startsWith("$")) {
- let _uuu = _userScheama[kkey].replace("$", "");
- if (kkey === "Role" || kkey === "role") {
- if (RowData[_uuu] === RowData[_k]) {
- RoleField = RowData[_uuu];
- }
- } else if (_uuu === _k) {
- UserData[kkey] = RowData[_k];
- }
- } else {
- RoleField = _userScheama[kkey];
- }
- });
+ const contactQuery = new Parse.Object("contracts_Contactbook");
+ contactQuery.set("Name", name);
+ contactQuery.set("Phone", phone);
+ contactQuery.set("Email", email);
+ contactQuery.set("UserRole", "contracts_Guest");
+
+ if (localStorage.getItem("TenetId")) {
+ contactQuery.set("TenantId", {
+ __type: "Pointer",
+ className: "partners_Tenant",
+ objectId: localStorage.getItem("TenetId")
});
- Parse.serverURL = this.state.parseBaseUrl;
- Parse.initialize(this.state.parseAppId);
- var _users = Parse.Object.extend("User");
- var _user = new _users();
- let _uname = UserData.name;
- _user.set("name", _uname.toString().trim());
- if (UserData.username) {
- let _u_un = UserData.username;
- _user.set("username", _u_un.toString().trim());
- if (UserData.email) {
- let _email = UserData.email;
- _user.set("email", _email.trim());
- }
- } else if (UserData.email) {
- let _email = UserData.email;
- _user.set("email", _email.trim());
- _user.set("username", _email.trim());
- } else {
- _user.set("username", UserData.phone.toString().trim());
- }
- _user.set("phone", UserData.phone);
- _user.set("password", UserData.password);
- _user.save().then(
- (u) => {
- let roleurl = `${this.state.parseBaseUrl}functions/AddUserToRole`;
- const headers = {
- "Content-Type": "application/json",
- "X-Parse-Application-Id": this.state.parseAppId,
- sessionToken: localStorage.getItem("accesstoken")
- };
- let body = {
- appName: localStorage.getItem("_appName"),
- roleName: RoleField,
- userId: u.id
- };
- axios.post(roleurl, body, { headers: headers }).then(() => {
- const currentUser = Parse.User.current();
- let _fname = this.state.title;
- var forms = Parse.Object.extend(_fname);
- var form = new forms();
- form.set(
- "CreatedBy",
- Parse.User.createWithoutData(currentUser.id)
- );
- if (localStorage.getItem("TenetId")) {
- form.set("TenantId", {
- __type: "Pointer",
- className: "partners_Tenant",
- objectId: localStorage.getItem("TenetId")
- });
- }
- form.set("UserId", u);
- form.set("UserRole", RoleField);
- if (this.state["FormACL"]) {
- let ACL = {};
- for (let [key, value] of Object.entries(
- this.state["FormACL"]
- )) {
- if (key === "*") {
- ACL[key] = value;
- }
- if (key === "#currentUser#") {
- ACL[Parse.User.current().id] = value;
- }
- if (key.startsWith("role")) {
- ACL[key] = value;
- }
- }
- form.setACL(new Parse.ACL(ACL));
- }
- form.save(RowData).then(
- (formd) => {
- const parseData = JSON.parse(JSON.stringify(formd));
- this.props.details({
- value: parseData[this.props.valueKey],
- label: parseData[this.props.displayKey]
- });
- if (this.props.closePopup) {
- this.props.closePopup();
- }
- let filtered = {};
- if (this.state.redirect_type === "clearData") {
- if (
- this.state.persistentFields &&
- this.state.persistentFields.length
- ) {
- filtered = Object.keys(RowData)
- .filter((key) =>
- this.state.persistentFields.includes(key)
- )
- .reduce((obj, key) => {
- obj[key] = RowData[key];
- return obj;
- }, {});
- }
- } else {
- RowData = {};
- }
- this.setState(
- {
- formData: filtered,
- active: true,
- loading: false,
- toastColor: "#5cb85c",
- toastDescription: this.state.successMassage
- },
- () => {
- this.props.removeState();
- this.props.removeLevel2State();
- this.props.removeLevel3State();
- var x = document.getElementById("snackbar");
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
- }
- );
- },
- (error) => {
- console.log("error", error.message);
- this.setState({
- loading: false,
- active: true,
- toastColor: "#d9534f",
- toastDescription: error.message
- });
-
- var x = document.getElementById("snackbar");
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
- }
- );
- });
- },
- async (error) => {
- if (error.code === 202) {
- let params;
- if (UserData.username) {
- params = { username: UserData.username };
- } else if (UserData.email) {
- params = { email: UserData.email };
- } else {
- params = { username: UserData.phone };
- }
- const userRes = await Parse.Cloud.run("getUserId", params);
-
- try {
- let _emp = {
- __type: "Pointer",
- className: "_User",
- objectId: userRes.id
- };
- let roleurl = `${this.state.parseBaseUrl}functions/AddUserToRole`;
- const headers = {
- "Content-Type": "application/json",
- "X-Parse-Application-Id": this.state.parseAppId,
- sessionToken: localStorage.getItem("accesstoken")
- };
- let body = {
- appName: localStorage.getItem("_appName"),
- roleName: RoleField,
- userId: userRes.id
- };
- await axios
- .post(roleurl, body, { headers: headers })
- .then(() => {
- const currentUser = Parse.User.current();
- let _fname = this.state.title;
- var forms = Parse.Object.extend(_fname);
- var form = new forms();
- form.set(
- "CreatedBy",
- Parse.User.createWithoutData(currentUser.id)
- );
- if (localStorage.getItem("TenetId")) {
- form.set("TenantId", {
- __type: "Pointer",
- className: "partners_Tenant",
- objectId: localStorage.getItem("TenetId")
- });
- }
- form.set("UserId", _emp);
- form.set("UserRole", RoleField);
- if (this.state["FormACL"]) {
- let ACL = {};
- for (let [key, value] of Object.entries(
- this.state["FormACL"]
- )) {
- if (key === "*") {
- ACL[key] = value;
- }
- if (key === "#currentUser#") {
- ACL[Parse.User.current().id] = value;
- }
- if (key.startsWith("role")) {
- ACL[key] = value;
- }
- }
- form.setACL(new Parse.ACL(ACL));
- }
- form.save(RowData).then(
- (formd) => {
- const parseData = JSON.parse(JSON.stringify(formd));
- this.props.details({
- value: parseData[this.props.valueKey],
- label: parseData[this.props.displayKey]
- });
- if (this.props.closePopup) {
- this.props.closePopup();
- }
- let filtered = {};
- if (this.state.redirect_type === "clearData") {
- if (
- this.state.persistentFields &&
- this.state.persistentFields.length
- ) {
- filtered = Object.keys(RowData)
- .filter((key) =>
- this.state.persistentFields.includes(key)
- )
- .reduce((obj, key) => {
- obj[key] = RowData[key];
- return obj;
- }, {});
- }
- } else {
- RowData = {};
- }
- this.setState({
- formData: filtered,
- active: true,
- loading: false,
- toastColor: "#5cb85c",
- toastDescription: "Record inserted successfully."
- });
- // this.props.removeState();
- // this.props.removeLevel2State();
- // this.props.removeLevel3State();
- // var x = document.getElementById("snackbar");
- // x.className = "show";
- // setTimeout(function () {
- // x.className = x.className.replace("show", "");
- // }, 2000);
- },
- (error) => {
- this.setState({
- loading: false,
- active: true,
- toastColor: "#d9534f",
- toastDescription: error.message
- });
-
- var x = document.getElementById("snackbar");
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
- }
- );
- });
- } catch (error) {
- this.setState({
- loading: false,
- active: true,
- toastColor: "#d9534f",
- toastDescription: error.message
- });
-
- const x = document.getElementById("snackbar");
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
- }
- }
- }
- );
- } catch (e) {
- console.log("Problem", e.message);
- this.setState({ loading: false, active: true });
}
- } else {
- try {
- let RowData = formData;
- let _scanData = this.state.schemaState;
- if (_scanData.dependencies) {
- Object.keys(_scanData.dependencies).forEach((key) => {
- if (_scanData.dependencies[key].oneOf) {
- _scanData.dependencies[key].oneOf.forEach((val) => {
- Object.keys(val.properties).forEach((k) => {
- if (typeof val.properties[k] === "object") {
- if (val.properties[k].format === "date") {
- if (RowData[k]) {
- let newdate = new Date(RowData[k]);
- RowData[k] = newdate;
- }
- }
- if (val.properties[k].component === "HtmlEditor") {
- if (RowData[k]) {
- let newHtml = RowData[k]
- .replace(/<p[^>]*>/g, "")
- .replace(/<\/p>/g, " ");
- RowData[k] = newHtml;
- }
- }
- if (val.properties[k].component === "DateTime") {
- if (RowData[k]) {
- let newDate11 = new Date(RowData[k]);
- RowData[k] = newDate11;
- }
- }
- if (val.properties[k].component === "CurrencyInput") {
- if (val.properties[k].currencyColumn) {
- RowData[`${val.properties[k].currencyColumn}`] =
- val.properties[k].defaultcurrency;
- }
- }
- if (val.properties[k].type === "string") {
- if (typeof RowData[k] === "string")
- RowData[k] = RowData[k].trim();
- }
- if (val.properties[k].data !== undefined) {
- if (val.properties[k].data.isPointer) {
- let pointer = undefined;
- if (val.properties[k].data.savePointerClass) {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className:
- val.properties[k].data.savePointerClass,
- objectId: RowData[k]
- };
- }
- } else if (val.properties[k].data.class) {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: val.properties[k].data.class,
- objectId: RowData[k]
- };
- }
- } else {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: localStorage.getItem("extended_class"),
- objectId: RowData[k]
- };
- }
- }
- RowData[k] = pointer;
- }
- if (val.properties[k].data.FolderTypeValue) {
- if (RowData[k]) {
- let obj = {
- __type: "Pointer",
- className: val.properties[k].data.ClassName,
- objectId: RowData[k]
- };
- RowData[k] = obj;
- }
- }
- }
- }
- });
- });
- }
+ try {
+ const _users = Parse.Object.extend("User");
+ const _user = new _users();
+ _user.set("name", name);
+ _user.set("username", email);
+ _user.set("email", email);
+ _user.set("phone", phone);
+ _user.set("password", phone);
+
+ const user = await _user.save();
+ if (user) {
+ const roleurl = `${parseBaseUrl}functions/AddUserToRole`;
+ const headers = {
+ "Content-Type": "application/json",
+ "X-Parse-Application-Id": parseAppId,
+ sessionToken: localStorage.getItem("accesstoken")
+ };
+ const body = {
+ appName: localStorage.getItem("_appName"),
+ roleName: "contracts_Guest",
+ userId: user.id
+ };
+ await axios.post(roleurl, body, { headers: headers });
+ const currentUser = Parse.User.current();
+ contactQuery.set(
+ "CreatedBy",
+ Parse.User.createWithoutData(currentUser.id)
+ );
+
+ contactQuery.set("UserId", user);
+ const acl = new Parse.ACL();
+ acl.setPublicReadAccess(true);
+ acl.setPublicWriteAccess(true);
+ acl.setReadAccess(currentUser.id, true);
+ acl.setWriteAccess(currentUser.id, true);
+
+ contactQuery.setACL(acl);
+
+ const res = await contactQuery.save();
+
+ const parseData = JSON.parse(JSON.stringify(res));
+ props.details({
+ value: parseData[props.valueKey],
+ label: parseData[props.displayKey]
});
- }
- Object.keys(_scanData).forEach(function (key) {
- let _dd = _scanData[key];
- if (typeof _dd === "object") {
- Object.keys(_dd).forEach(function (k) {
- if (_dd[k].type === "array" && _dd[k].items) {
- let _prop = _dd[k].items.properties;
- if (_prop && Array.isArray(RowData[k])) {
- let newRow = [];
- RowData[k].forEach((t) => {
- let _newObj = t;
- if (typeof t === "object") {
- Object.keys(_prop).forEach(function (l) {
- if (_prop[l].data && _prop[l].data.isPointer) {
- if (typeof t[l] === "object") {
- let obj = {
- __type: "Pointer",
- className: _prop[l].data.class,
- objectId: t[l].objectId
- };
- _newObj = { ..._newObj, [l]: obj };
- } else {
- let obj = {
- __type: "Pointer",
- className: _prop[l].data.class,
- objectId: t[l]
- };
- _newObj = { ..._newObj, [l]: obj };
- }
- }
- });
- }
- newRow.push(_newObj);
- });
- RowData[k] = newRow;
- }
- }
-
- if (_dd[k].component === "AutoSuggest" && _dd[k].isPointer) {
- if (RowData[k]) {
- let pointer = {
- __type: "Pointer",
- className: _dd[k].class,
- objectId: RowData[k]
- };
- RowData[k] = pointer;
- }
- }
- if (_dd[k].format === "date") {
- let newdate = new Date(RowData[k]);
- RowData[k] = newdate;
- }
- if (_dd[k].component === "HtmlEditor") {
- if (RowData[k]) {
- let newHtml = RowData[k]
- .replace(/<p[^>]*>/g, "")
- .replace(/<\/p>/g, " ");
- RowData[k] = newHtml;
- }
- }
- if (_dd[k].component === "DateTime") {
- let newDate11;
- if (!RowData[k]) {
- newDate11 = new Date();
- } else {
- newDate11 = new Date(RowData[k]);
- }
- RowData[k] = newDate11;
- }
- if (_dd[k].component === "CurrencyInput") {
- if (_dd[k].currencyColumn) {
- RowData[`${_dd[k].currencyColumn}`] = _dd[k].defaultcurrency;
- }
- }
- if (_dd[k].data !== undefined) {
- if (_dd[k].data.isPointer) {
- let pointer = undefined;
- if (RowData[k] && RowData[k] !== "Select") {
- if (_dd[k].type === "array") {
- pointer = [];
- RowData[k] &&
- RowData[k].forEach((a) => {
- let _kk = {};
- if (_dd[k].data.savePointerClass) {
- _kk = {
- __type: "Pointer",
- className: _dd[k].data.savePointerClass,
- objectId: a
- };
- } else {
- _kk = {
- __type: "Pointer",
- className: _dd[k].data.class,
- objectId: a
- };
- }
-
- pointer.push(_kk);
- });
- } else if (_dd[k].data.class) {
- if (_dd[k].data.savePointerClass) {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: _dd[k].data.savePointerClass,
- objectId: RowData[k]
- };
- }
- } else if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: _dd[k].data.class,
- objectId: RowData[k]
- };
- }
- } else {
- if (RowData[k]) {
- pointer = {
- __type: "Pointer",
- className: localStorage.getItem("extended_class"),
- objectId: RowData[k]
- };
- }
- }
-
- RowData[k] = pointer;
- }
- }
- if (_dd[k].data.FolderTypeValue) {
- if (RowData[k]) {
- let obj = {
- __type: "Pointer",
- className: _dd[k].data.ClassName,
- objectId: RowData[k]
- };
- RowData[k] = obj;
- }
- }
- }
- if (_dd[k].type === "string") {
- let d = RowData[k];
- if (typeof d === "string") {
- RowData[k] = d.trim();
- }
- }
- });
+ if (props.closePopup) {
+ props.closePopup();
}
- });
- Parse.serverURL = this.state.parseBaseUrl;
- Parse.initialize(this.state.parseAppId);
- const currentUser = Parse.User.current();
- let _fname = this.state.title;
- var forms = Parse.Object.extend(_fname);
-
- var form = new forms();
-
- form.set("CreatedBy", Parse.User.createWithoutData(currentUser.id));
- if (this.state["FormACL"]) {
- let ACL = {};
- for (let [key, value] of Object.entries(this.state["FormACL"])) {
- if (key === "*") {
- ACL[key] = value;
- }
- if (key === "#currentUser#") {
- ACL[Parse.User.current().id] = value;
- } else if (key.startsWith("#")) {
- let arr = key.split("#");
- let new_arr = arr.filter((x) => x !== "");
- if (new_arr.length === 2) {
- let l = RowData[new_arr[0]];
- try {
- const Agent = Parse.Object.extend(l.className);
- const qu = new Parse.Query(Agent);
- qu.equalTo("objectId", l.objectId);
- qu.include(new_arr[1]);
- await qu.first();
- } catch (err) {
- console.log("Error while fetching Agent", err.massage);
- }
- }
- }
- if (key.startsWith("role")) {
- ACL[key] = value;
- }
- }
- form.setACL(new Parse.ACL(ACL));
+ setIsLoader(false);
+ // Reset the form fields
+ setAddYourself(false);
+ setName("");
+ setPhone("");
+ setEmail("");
}
-
- form.save(RowData).then(
- (form) => {
- const parseData = JSON.parse(JSON.stringify(form));
- this.props.details({
- value: parseData[this.props.valueKey],
- label: parseData[this.props.displayKey]
- });
- if (this.props.closePopup) {
- this.props.closePopup();
- }
- let filtered = {};
- if (this.state.redirect_type === "clearData") {
- if (
- this.state.persistentFields &&
- this.state.persistentFields.length
- ) {
- filtered = Object.keys(RowData)
- .filter((key) => this.state.persistentFields.includes(key))
- .reduce((obj, key) => {
- obj[key] = RowData[key];
- return obj;
- }, {});
- }
- } else {
- RowData = {};
- }
-
- this.setState(
- {
- formData: filtered,
- active: true,
- loading: false,
- toastColor: "#5cb85c",
- toastDescription: this.state.successMassage
- },
- () => {
- var x = document.getElementById("snackbar");
- this.props.removeState();
- this.props.removeLevel2State();
- this.props.removeLevel3State();
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
- }
- );
- },
- (error) => {
- this.setState({
- loading: false,
- active: true,
- toastColor: "#d9534f",
- toastDescription: error.message
- });
-
- var x = document.getElementById("snackbar");
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
+ } catch (err) {
+ console.log("err ", err);
+ if (err.code === 202) {
+ const params = { email: email };
+ const userRes = await Parse.Cloud.run("getUserId", params);
+ const roleurl = `${parseBaseUrl}functions/AddUserToRole`;
+ const headers = {
+ "Content-Type": "application/json",
+ "X-Parse-Application-Id": parseAppId,
+ sessionToken: localStorage.getItem("accesstoken")
+ };
+ const body = {
+ appName: localStorage.getItem("_appName"),
+ roleName: "contracts_Guest",
+ userId: userRes.id
+ };
+ await axios.post(roleurl, body, { headers: headers });
+ const currentUser = Parse.User.current();
+ contactQuery.set(
+ "CreatedBy",
+ Parse.User.createWithoutData(currentUser.id)
+ );
+
+ contactQuery.set("UserId", {
+ __type: "Pointer",
+ className: "_User",
+ objectId: userRes.id
+ });
+ const acl = new Parse.ACL();
+ acl.setPublicReadAccess(true);
+ acl.setPublicWriteAccess(true);
+ acl.setReadAccess(currentUser.id, true);
+ acl.setWriteAccess(currentUser.id, true);
+
+ contactQuery.setACL(acl);
+ const res = await contactQuery.save();
+
+ const parseData = JSON.parse(JSON.stringify(res));
+ props.details({
+ value: parseData[props.valueKey],
+ label: parseData[props.displayKey]
+ });
+ if (props.closePopup) {
+ props.closePopup();
}
- );
- } catch (error) {
- this.setState({
- loading: false,
- active: true,
- toastColor: "#d9534f",
- toastDescription: error.message
- });
-
- var x = document.getElementById("snackbar");
- x.className = "show";
- setTimeout(function () {
- x.className = x.className.replace("show", "");
- }, 2000);
+ setIsLoader(false);
+ // Reset the form fields
+ setAddYourself(false);
+ setName("");
+ setPhone("");
+ setEmail("");
+ }
}
+ } catch (err) {
+ // console.log("err", err);
+ setIsLoader(false);
+ alert("something went wrong!");
}
};
- componentDidMount() {
- let url = window.location.hash;
- if (url.includes("_app")) {
- this.setState({ isAppRequest: true });
- }
- let id = this.props.id;
- this.getForm(id);
- }
-
- render() {
- if (localStorage.getItem("accesstoken") === null) {
- return <Navigate to="/" />;
+ // Define a function to handle the "add yourself" checkbox
+ const handleAddYourselfChange = () => {
+ if (addYourself) {
+ setAddYourself(false);
+ setName("");
+ setPhone("");
+ setEmail("");
+ } else {
+ setAddYourself(true);
}
- let schema = this.state.schemaState;
- let uiSchema = this.state.ui_schema;
- let rules = this.state.rules;
- let extraActions = this.state.extraActions;
-
- let FormToDisplay = applyRules(
- schema,
- uiSchema,
- rules,
- Engine,
- extraActions
- )(Form);
- let formView = (
- <React.Fragment>
- <FormToDisplay
- validate={this.state.noValidate && this.dynamicValidate}
- showErrorList={false}
- widgets={widget}
- fields={fields()}
- formData={this.state.formData}
- liveValidate={this.state.liveValidate}
- onSubmit={this.handleSubmit}
- validator={validator}
- >
- <div>
- {this.state.active && this.state.buttons.submitText ? (
- <button className="btn btn-info submiBtn" type="submit">
- {this.state.buttons.submitText}
- </button>
- ) : (
- this.state.buttons.submitText && (
- <button className="btn submiBtn" type="submit" disabled>
- {this.state.buttons.submitText}
- </button>
- )
- )}
- &nbsp;&nbsp;
- {this.state.buttons.resetText && (
- <button
- className="btn resetBtn"
- onClick={(e) => {
- e.preventDefault();
- this.setState({
- loading: true,
- formData: {}
- });
- setTimeout(() => {
- this.setState({ loading: false });
- }, 1000);
- }}
- type="button"
- >
- {this.state.buttons.resetText}
- </button>
- )}
- </div>
- </FormToDisplay>
- </React.Fragment>
- );
+ };
+ const handleReset = () => {
+ setAddYourself(false);
+ };
- if (this.state.loading) {
- formView = (
- <div style={{ height: "300px" }}>
+ return (
+ <div className="h-full p-[20px]">
+ {isLoader && (
+ <div className="fixed inset-0 flex justify-center items-center bg-black bg-opacity-30">
<div
style={{
- marginLeft: "45%",
- marginTop: "150px",
fontSize: "45px",
color: "#3dd3e0"
}}
className="loader-37"
></div>
</div>
- );
- }
- return (
- <React.Fragment>
- {/* <Title
- title={
- this.state.schemaState.title ? this.state.schemaState.title : ""
- }
- /> */}
- <ErrorBoundary>
- <div className="row">
- <div className="col-md-12">
- {this.state.help ? (
- <div className="dropdown" style={{ marginTop: "-30px" }}>
- <i
- className="far fa-question-circle dropdown-toggle hovereffect"
- aria-hidden="true"
- id="dropdownMenuButton"
- data-toggle="dropdown"
- aria-haspopup="true"
- aria-expanded="false"
- style={{
- fontSize: "18px",
- color: "purple",
- cursor: "pointer !important",
- position: "relative",
- top: "40px",
- left: "98%"
- }}
- ></i>
- <div
- className="dropdown-menu"
- aria-labelledby="dropdownMenuButton"
- style={{
- marginleft: "-121px",
- margintop: "-14px",
- position: "absolute",
- padding: "10px",
- width: "300px",
- top: "102px!important"
- }}
- >
- {parse(`
- ${this.state.help}
- `)}
- <br />
- {this.state.link ? (
- <a
- onClick={(e) => {
- e.preventDefault();
- window.location.href = this.state.link;
- }}
- target="_blank"
- className="btn btn-xs btn-primary"
- >
- Read more..
- </a>
- ) : null}
- </div>
- </div>
- ) : null}
- <div style={{ fontSize: "13px" }}>{formView}</div>
- </div>
+ )}
+ <div className="w-full mx-auto p-2">
+ {isUserExist && (
+ <div className="mb-3">
+ <input
+ type="checkbox"
+ id="addYourself"
+ checked={addYourself}
+ onChange={handleAddYourselfChange}
+ className="form-checkbox"
+ />
+ <label htmlFor="addYourself" className="ml-2 text-gray-700">
+ Add Yourself
+ </label>
</div>
- <div id="snackbar" style={{ backgroundColor: this.state.toastColor }}>
- {this.state.toastDescription}
+ )}
+ <form onSubmit={handleSubmit}>
+ <div className="mb-3">
+ <label
+ htmlFor="name"
+ className="block text-xs text-gray-700 font-semibold"
+ >
+ Name
+ <span style={{ color: "red", fontSize: 13 }}> *</span>
+ </label>
+ <input
+ type="text"
+ id="name"
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ required
+ disabled={addYourself}
+ className="px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"
+ />
</div>
- </ErrorBoundary>
- </React.Fragment>
- );
- }
-}
-export default connect(null, {
- removeState,
- removeLevel2State,
- removeLevel3State
-})(AppendFormInForm);
+ <div className="mb-3">
+ <label
+ htmlFor="phone"
+ className="block text-xs text-gray-700 font-semibold"
+ >
+ Phone
+ <span style={{ color: "red", fontSize: 13 }}> *</span>
+ </label>
+ <input
+ type="text"
+ id="phone"
+ value={phone}
+ onChange={(e) => setPhone(e.target.value)}
+ required
+ disabled={addYourself}
+ className="px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"
+ />
+ </div>
+
+ <div className="mb-3">
+ <label
+ htmlFor="email"
+ className="block text-xs text-gray-700 font-semibold"
+ >
+ Email
+ <span style={{ color: "red", fontSize: 13 }}> *</span>
+ </label>
+ <input
+ type="email"
+ id="email"
+ value={email}
+ onChange={(e) => setEmail(e.target.value)}
+ required
+ disabled={addYourself}
+ className="px-3 py-2 w-full border-[1px] border-gray-300 rounded focus:outline-none text-xs"
+ />
+ </div>
+
+ <div className="mt-4 flex justify-start">
+ <button
+ type="submit"
+ className="bg-[#1ab6ce] text-sm text-white px-4 py-2 rounded shadow focus:outline-none"
+ >
+ Submit
+ </button>
+ <button
+ type="button"
+ onClick={() => handleReset()}
+ className="bg-[#188ae2] text-sm text-white px-4 py-2 rounded ml-2 shadow focus:outline-none"
+ >
+ Reset
+ </button>
+ </div>
+ </form>
+ </div>
+ </div>
+ );
+};
+
+export default AppendFormInForm;
diff --git a/apps/OpenSign/src/components/fields/MultiSelectField.js b/apps/OpenSign/src/components/fields/MultiSelectField.js
index d3b10fbd2..520e9398f 100644
--- a/apps/OpenSign/src/components/fields/MultiSelectField.js
+++ b/apps/OpenSign/src/components/fields/MultiSelectField.js
@@ -19,6 +19,7 @@ function arrayMove(array, from, to) {
*/
const MultiSelectField = (props) => {
+ Modal.setAppElement("body");
const [parseBaseUrl] = useState(localStorage.getItem("baseUrl"));
const [parseAppId] = useState(localStorage.getItem("parseAppId"));
const [state, setState] = useState(undefined);
@@ -647,42 +648,51 @@ const MultiSelectField = (props) => {
<Modal
isOpen={modalIsOpen}
onRequestClose={handleModalCloseClick}
+ shouldCloseOnOverlayClick={false}
contentLabel="Modal"
style={{
+ content: {
+ top: "50%",
+ left: "50%",
+ right: "auto",
+ bottom: "auto",
+ transform: "translate(-50%, -50%)",
+ padding: 0
+ },
overlay: {
- position: "fixed",
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: "rgba(255, 255, 255, 0.75)",
- zIndex: 50,
- maxHeight: 450
+ width: "100%",
+ backgroundColor: "rgba(0, 0, 0, 0.75)",
+ zIndex: 50
}
}}
>
- <div
- type="button"
- style={{ display: "flex", justifyContent: "space-between" }}
- >
- <div style={{ color: "transparent", width: "100%" }}>.</div>
- <button onClick={handleModalCloseClick}>
- <i
- style={{ fontSize: 25 }}
- className="fa fa-times-circle"
- aria-hidden="true"
- ></i>
- </button>
+ <div className="min-w-full md:min-w-[500px]">
+ <div
+ type="button"
+ className="flex justify-between items-center p-3 border-b-[1px] border-gray-300"
+ >
+ <div className=" text-black text-xl font-semibold pl-3">
+ Add Signer
+ </div>
+ <button onClick={handleModalCloseClick}>
+ <i
+ style={{ fontSize: 25 }}
+ className="fa fa-times-circle"
+ aria-hidden="true"
+ ></i>
+ </button>
+ </div>
+
+ {isModal && (
+ <AppendFormInForm
+ id={props.schema.data.quickAddFormId}
+ valueKey={props.schema.data.valueKey}
+ displayKey={props.schema.data.displayKey}
+ details={handleNewDetails}
+ closePopup={handleModalCloseClick}
+ />
+ )}
</div>
- {isModal && (
- <AppendFormInForm
- id={props.schema.data.quickAddFormId}
- valueKey={props.schema.data.valueKey}
- displayKey={props.schema.data.displayKey}
- details={handleNewDetails}
- closePopup={handleModalCloseClick}
- />
- )}
</Modal>
</div>
</React.Fragment>
diff --git a/apps/OpenSign/src/json/FormJson.js b/apps/OpenSign/src/json/FormJson.js
index e7276a9a4..bf67053a9 100644
--- a/apps/OpenSign/src/json/FormJson.js
+++ b/apps/OpenSign/src/json/FormJson.js
@@ -1,3 +1,4 @@
+import Parse from "parse";
export const formJson = (id) => {
let formData;
//json form for signYourself
@@ -104,6 +105,12 @@ export const formJson = (id) => {
}
//json form for request signature
else if (id === "8mZzFxbG1z") {
+ const user = Parse.User.current();
+ const userPtr = JSON.stringify({
+ __type: "Pointer",
+ className: "_User",
+ objectId: user.id
+ });
formData = {
jsonSchema: {
title: "New Document",
@@ -140,7 +147,7 @@ export const formJson = (id) => {
class: "contracts_Contactbook",
displayKey: "Name",
valueKey: "objectId",
- query: "keys=Name",
+ query: `where={"CreatedBy":${userPtr}}&keys=Name`,
isPointer: true,
helpbody: "",
helplink: "",
@@ -575,3 +582,4 @@ export const formJson = (id) => {
return formData;
}
};
+
diff --git a/apps/OpenSign/src/json/ReportJson.js b/apps/OpenSign/src/json/ReportJson.js
index 39d78c608..abdda66ca 100644
--- a/apps/OpenSign/src/json/ReportJson.js
+++ b/apps/OpenSign/src/json/ReportJson.js
@@ -37,7 +37,7 @@ export default function reportJson(id) {
textColor: "white",
btnIcon: "fa fa-plus",
redirectUrl:
- "remoteUrl=aHR0cDovL2xvY2FsaG9zdDozMDAwL21mYnVpbGQvcmVtb3RlRW50cnkuanM=&moduleToLoad=AppRoutes&remoteName=signmicroapp/draftDocument"
+ "remoteUrl=aHR0cHM6Ly9xaWstYWktb3JnLmdpdGh1Yi5pby9TaWduLU1pY3JvYXBwVjIvcmVtb3RlRW50cnkuanM=&moduleToLoad=AppRoutes&remoteName=signmicroapp/draftDocument"
}
]
};
diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.js
index 2956e9439..22cea983d 100644
--- a/apps/OpenSign/src/primitives/GetReportDisplay.js
+++ b/apps/OpenSign/src/primitives/GetReportDisplay.js
@@ -16,9 +16,25 @@ const ReportTable = ({ ReportName, List, actions }) => {
};
const handlemicroapp = (item, url) => {
localStorage.removeItem("rowlevel");
+ // const params = new URLSearchParams(url);
+ // let arr = [];
+ // for (let [key, value] of params.entries()) {
+ // if (key === "remoteUrl") {
+ // arr.push(
+ // `${key}=${window.btoa(
+ // window.location.origin + "/mfbuild/remoteEntry.js"
+ // )}`
+ // );
+ // } else {
+ // arr.push(`${key}=${value}`);
+ // }
+ // }
+ // const remoteUrl = arr.join("&");
+ // console.log("arr", remoteUrl);
+
navigate("/rpmf/" + url);
localStorage.setItem("rowlevel", JSON.stringify(item));
- // localStorage.setItem("rowlevelMicro")
+ // localStorage.setItem("rowlevelMicro");
};
const handlebtn = () => {
console.log("clicked");