Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions apps/OpenSign/src/components/pdf/WidgetNameModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@ const WidgetNameModal = (props) => {
e.preventDefault();
if (props.handleData) {
if (["signature", "initials"].includes(props.defaultdata?.type)) {
const data = { ...formdata, signatureType };
props.handleData(data, props.defaultdata?.type);
const enabledSignTypes = signatureType?.filter((x) => x.enabled);
const isDefaultSignTypeOnly =
enabledSignTypes?.length === 1 &&
enabledSignTypes[0]?.name === "default";
if (enabledSignTypes.length === 0) {
alert("Please enable at least one signature type");
} else if (isDefaultSignTypeOnly) {
alert("Please enable one more signature type other than default");
} else {
const data = { ...formdata, signatureType };
props.handleData(data, props.defaultdata?.type);
}
} else {
props.handleData(formdata);
}
Expand Down Expand Up @@ -287,7 +297,7 @@ const WidgetNameModal = (props) => {
</div>
</div>
)}
{props.defaultdata?.type === "signature" && (
{["signature", "initials"].includes(props.defaultdata?.type) && (
<div className="mb-[0.75rem]">
<label htmlFor="signaturetype" className="text-[14px] mb-[0.7rem]">
{t("allowed-signature-types")}
Expand Down
42 changes: 25 additions & 17 deletions apps/OpenSign/src/pages/Preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const Preferences = () => {
setIsTopLoader(false);
}
};
console.log("sign", signatureType);

// `handleCheckboxChange` is trigger when user enable/disable checkbox of respective type
const handleCheckboxChange = (index) => {
// Create a copy of the signatureType array
const updatedSignatureType = [...signatureType];
Expand All @@ -64,31 +65,38 @@ const Preferences = () => {
// Update the state with the modified array
setSignatureType(updatedSignatureType);
};

// `handleSave` is used save updated value signature type
const handleSave = async () => {
console.log("submit", signatureType);
setIsLoader(true);
const isEnabled = signatureType.some((x) => x.enabled === true);
if (isEnabled) {
const enabledSignTypes = signatureType?.filter((x) => x.enabled);
const isDefaultSignTypeOnly =
enabledSignTypes?.length === 1 && enabledSignTypes[0]?.name === "default";
if (enabledSignTypes.length === 0) {
setIsAlert({
type: "danger",
msg: "Please enable at least one signature type"
});
} else if (isDefaultSignTypeOnly) {
setIsAlert({
type: "danger",
msg: "Please enable one more signature type other than default"
});
} else {
try {
const params = { SignatureType: signatureType };
const updateRes = await Parse.Cloud.run("updatesignaturetype", params);
const updateRes = await Parse.Cloud.run("updatesignaturetype", {
SignatureType: signatureType
});
if (updateRes) {
setIsAlert({ type: "success", msg: "Saved successfully." });
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
}
} catch (err) {
console.log("err while updating signtype", err);
} finally {
setIsLoader(false);
console.log("Error updating signature type", err);
setIsAlert({ type: "danger", msg: err.message });
}
} else {
setIsAlert({
type: "danger",
msg: "Please enable at least one signature type"
});
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
setIsLoader(false);
}
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
setIsLoader(false);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const createDocumentFromTemplate = async (template, existContact, index) => {
object.set('IsEnableOTP', template?.IsEnableOTP || false);
object.set('IsTourEnabled', template?.IsTourEnabled || false);
object.set('FileAdapterId', template?.FileAdapterId || '');
if (template?.SignatureType?.length > 0) {
object.set('SignatureType', template?.SignatureType);
}
let signers = template?.Signers || [];
const signerobj = {
__type: 'Pointer',
Expand Down Expand Up @@ -254,6 +257,7 @@ const deductcount = async _resSub => {
export default async function PublicUserLinkContactToDoc(req) {
const email = req.params.email;
const templateid = req.params.templateid;
const signatureType = req.params.signatureType;
const name = req.params.name;
const phone = req.params.phone;
const role = req.params.role;
Expand Down Expand Up @@ -301,8 +305,11 @@ export default async function PublicUserLinkContactToDoc(req) {
const existContact = await contactCls.first({ useMasterKey: true });
if (existContact) {
const template_json = JSON.parse(JSON.stringify(tempRes));
const _template_json = template_json;
_template_json.SignatureType =
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
//update contact in placeholder, signers and update ACl in provide document
const docRes = await createDocumentFromTemplate(template_json, existContact, index);
const docRes = await createDocumentFromTemplate(_template_json, existContact, index);
if (docRes) {
await deductcount(_resSub);
//condition will execute only if sendInOrder will be false for send email to all signers at a time.
Expand All @@ -327,9 +334,12 @@ export default async function PublicUserLinkContactToDoc(req) {
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
};
const template_json = JSON.parse(JSON.stringify(tempRes));
const _template_json = template_json;
_template_json.SignatureType =
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
// if user present on platform create contact on the basis of extended user details
const contactRes = await saveRoleContact(contact);
const docRes = await createDocumentFromTemplate(template_json, contactRes, index);
const docRes = await createDocumentFromTemplate(_template_json, contactRes, index);
if (docRes) {
await deductcount(_resSub);
//condition will execute only if sendInOrder will be false for send email to all signers at a time.
Expand All @@ -354,11 +364,14 @@ export default async function PublicUserLinkContactToDoc(req) {
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
};
const template_json = JSON.parse(JSON.stringify(tempRes));
const _template_json = template_json;
_template_json.SignatureType =
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
// Create new contract on the basis provided contact details by user and userId from _User class
const contactRes = await saveRoleContact(contact);
//update contact in placeholder, signers and update ACl in provide document
const docRes = await createDocumentFromTemplate(
template_json,
_template_json,
contactRes,
index
);
Expand Down Expand Up @@ -391,11 +404,14 @@ export default async function PublicUserLinkContactToDoc(req) {
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
};
const template_json = JSON.parse(JSON.stringify(tempRes));
const _template_json = template_json;
_template_json.SignatureType =
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
// Create new contract on the basis provided contact details by user and userId from _User class
const contactRes = await saveRoleContact(contact);
//update contact in placeholder, signers and update ACl in provide document
const docRes = await createDocumentFromTemplate(
template_json,
_template_json,
contactRes,
index
);
Expand Down
22 changes: 15 additions & 7 deletions apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ export default async function updateSignatureType(request) {
}
const SignatureType = request.params.SignatureType || [];
if (SignatureType.length > 0) {
const isEnabled = SignatureType.some(x => x.enabled === true);
if (isEnabled) {
const enabledSignTypes = SignatureType?.filter(x => x.enabled);
const isDefaultSignTypeOnly =
enabledSignTypes?.length === 1 && enabledSignTypes[0]?.name === 'default';

if (enabledSignTypes.length === 0) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
'At least one signature type should be enabled.'
);
} else if (isDefaultSignTypeOnly) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
'Please enable one more signature type other than default.'
);
} else {
try {
const orgQuery = new Parse.Query('contracts_Users');
orgQuery.equalTo('UserId', {
Expand All @@ -32,11 +45,6 @@ export default async function updateSignatureType(request) {
const msg = err?.message || 'Something went wrong.';
throw new Parse.Error(code, msg);
}
} else {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
'At least one signature type should be enabled.'
);
}
} else {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Please provide signature types.');
Expand Down