Skip to content

Commit 240c776

Browse files
Merge pull request #1427 from OpenSignLabs/validation
2 parents d6129e2 + 508b2e4 commit 240c776

File tree

4 files changed

+73
-31
lines changed

4 files changed

+73
-31
lines changed

apps/OpenSign/src/components/pdf/WidgetNameModal.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ const WidgetNameModal = (props) => {
5757
e.preventDefault();
5858
if (props.handleData) {
5959
if (["signature", "initials"].includes(props.defaultdata?.type)) {
60-
const data = { ...formdata, signatureType };
61-
props.handleData(data, props.defaultdata?.type);
60+
const enabledSignTypes = signatureType?.filter((x) => x.enabled);
61+
const isDefaultSignTypeOnly =
62+
enabledSignTypes?.length === 1 &&
63+
enabledSignTypes[0]?.name === "default";
64+
if (enabledSignTypes.length === 0) {
65+
alert("Please enable at least one signature type");
66+
} else if (isDefaultSignTypeOnly) {
67+
alert("Please enable one more signature type other than default");
68+
} else {
69+
const data = { ...formdata, signatureType };
70+
props.handleData(data, props.defaultdata?.type);
71+
}
6272
} else {
6373
props.handleData(formdata);
6474
}
@@ -287,7 +297,7 @@ const WidgetNameModal = (props) => {
287297
</div>
288298
</div>
289299
)}
290-
{props.defaultdata?.type === "signature" && (
300+
{["signature", "initials"].includes(props.defaultdata?.type) && (
291301
<div className="mb-[0.75rem]">
292302
<label htmlFor="signaturetype" className="text-[14px] mb-[0.7rem]">
293303
{t("allowed-signature-types")}

apps/OpenSign/src/pages/Preferences.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const Preferences = () => {
5555
setIsTopLoader(false);
5656
}
5757
};
58-
console.log("sign", signatureType);
58+
59+
// `handleCheckboxChange` is trigger when user enable/disable checkbox of respective type
5960
const handleCheckboxChange = (index) => {
6061
// Create a copy of the signatureType array
6162
const updatedSignatureType = [...signatureType];
@@ -64,31 +65,38 @@ const Preferences = () => {
6465
// Update the state with the modified array
6566
setSignatureType(updatedSignatureType);
6667
};
68+
69+
// `handleSave` is used save updated value signature type
6770
const handleSave = async () => {
68-
console.log("submit", signatureType);
6971
setIsLoader(true);
70-
const isEnabled = signatureType.some((x) => x.enabled === true);
71-
if (isEnabled) {
72+
const enabledSignTypes = signatureType?.filter((x) => x.enabled);
73+
const isDefaultSignTypeOnly =
74+
enabledSignTypes?.length === 1 && enabledSignTypes[0]?.name === "default";
75+
if (enabledSignTypes.length === 0) {
76+
setIsAlert({
77+
type: "danger",
78+
msg: "Please enable at least one signature type"
79+
});
80+
} else if (isDefaultSignTypeOnly) {
81+
setIsAlert({
82+
type: "danger",
83+
msg: "Please enable one more signature type other than default"
84+
});
85+
} else {
7286
try {
73-
const params = { SignatureType: signatureType };
74-
const updateRes = await Parse.Cloud.run("updatesignaturetype", params);
87+
const updateRes = await Parse.Cloud.run("updatesignaturetype", {
88+
SignatureType: signatureType
89+
});
7590
if (updateRes) {
7691
setIsAlert({ type: "success", msg: "Saved successfully." });
77-
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
7892
}
7993
} catch (err) {
80-
console.log("err while updating signtype", err);
81-
} finally {
82-
setIsLoader(false);
94+
console.log("Error updating signature type", err);
95+
setIsAlert({ type: "danger", msg: err.message });
8396
}
84-
} else {
85-
setIsAlert({
86-
type: "danger",
87-
msg: "Please enable at least one signature type"
88-
});
89-
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
90-
setIsLoader(false);
9197
}
98+
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
99+
setIsLoader(false);
92100
};
93101

94102
return (

apps/OpenSignServer/cloud/parsefunction/PublicUserLinkContactToDoc.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ const createDocumentFromTemplate = async (template, existContact, index) => {
7171
object.set('IsEnableOTP', template?.IsEnableOTP || false);
7272
object.set('IsTourEnabled', template?.IsTourEnabled || false);
7373
object.set('FileAdapterId', template?.FileAdapterId || '');
74+
if (template?.SignatureType?.length > 0) {
75+
object.set('SignatureType', template?.SignatureType);
76+
}
7477
let signers = template?.Signers || [];
7578
const signerobj = {
7679
__type: 'Pointer',
@@ -254,6 +257,7 @@ const deductcount = async _resSub => {
254257
export default async function PublicUserLinkContactToDoc(req) {
255258
const email = req.params.email;
256259
const templateid = req.params.templateid;
260+
const signatureType = req.params.signatureType;
257261
const name = req.params.name;
258262
const phone = req.params.phone;
259263
const role = req.params.role;
@@ -301,8 +305,11 @@ export default async function PublicUserLinkContactToDoc(req) {
301305
const existContact = await contactCls.first({ useMasterKey: true });
302306
if (existContact) {
303307
const template_json = JSON.parse(JSON.stringify(tempRes));
308+
const _template_json = template_json;
309+
_template_json.SignatureType =
310+
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
304311
//update contact in placeholder, signers and update ACl in provide document
305-
const docRes = await createDocumentFromTemplate(template_json, existContact, index);
312+
const docRes = await createDocumentFromTemplate(_template_json, existContact, index);
306313
if (docRes) {
307314
await deductcount(_resSub);
308315
//condition will execute only if sendInOrder will be false for send email to all signers at a time.
@@ -327,9 +334,12 @@ export default async function PublicUserLinkContactToDoc(req) {
327334
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
328335
};
329336
const template_json = JSON.parse(JSON.stringify(tempRes));
337+
const _template_json = template_json;
338+
_template_json.SignatureType =
339+
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
330340
// if user present on platform create contact on the basis of extended user details
331341
const contactRes = await saveRoleContact(contact);
332-
const docRes = await createDocumentFromTemplate(template_json, contactRes, index);
342+
const docRes = await createDocumentFromTemplate(_template_json, contactRes, index);
333343
if (docRes) {
334344
await deductcount(_resSub);
335345
//condition will execute only if sendInOrder will be false for send email to all signers at a time.
@@ -354,11 +364,14 @@ export default async function PublicUserLinkContactToDoc(req) {
354364
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
355365
};
356366
const template_json = JSON.parse(JSON.stringify(tempRes));
367+
const _template_json = template_json;
368+
_template_json.SignatureType =
369+
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
357370
// Create new contract on the basis provided contact details by user and userId from _User class
358371
const contactRes = await saveRoleContact(contact);
359372
//update contact in placeholder, signers and update ACl in provide document
360373
const docRes = await createDocumentFromTemplate(
361-
template_json,
374+
_template_json,
362375
contactRes,
363376
index
364377
);
@@ -391,11 +404,14 @@ export default async function PublicUserLinkContactToDoc(req) {
391404
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
392405
};
393406
const template_json = JSON.parse(JSON.stringify(tempRes));
407+
const _template_json = template_json;
408+
_template_json.SignatureType =
409+
signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;
394410
// Create new contract on the basis provided contact details by user and userId from _User class
395411
const contactRes = await saveRoleContact(contact);
396412
//update contact in placeholder, signers and update ACl in provide document
397413
const docRes = await createDocumentFromTemplate(
398-
template_json,
414+
_template_json,
399415
contactRes,
400416
index
401417
);

apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@ export default async function updateSignatureType(request) {
44
}
55
const SignatureType = request.params.SignatureType || [];
66
if (SignatureType.length > 0) {
7-
const isEnabled = SignatureType.some(x => x.enabled === true);
8-
if (isEnabled) {
7+
const enabledSignTypes = SignatureType?.filter(x => x.enabled);
8+
const isDefaultSignTypeOnly =
9+
enabledSignTypes?.length === 1 && enabledSignTypes[0]?.name === 'default';
10+
11+
if (enabledSignTypes.length === 0) {
12+
throw new Parse.Error(
13+
Parse.Error.INVALID_QUERY,
14+
'At least one signature type should be enabled.'
15+
);
16+
} else if (isDefaultSignTypeOnly) {
17+
throw new Parse.Error(
18+
Parse.Error.INVALID_QUERY,
19+
'Please enable one more signature type other than default.'
20+
);
21+
} else {
922
try {
1023
const orgQuery = new Parse.Query('contracts_Users');
1124
orgQuery.equalTo('UserId', {
@@ -32,11 +45,6 @@ export default async function updateSignatureType(request) {
3245
const msg = err?.message || 'Something went wrong.';
3346
throw new Parse.Error(code, msg);
3447
}
35-
} else {
36-
throw new Parse.Error(
37-
Parse.Error.INVALID_QUERY,
38-
'At least one signature type should be enabled.'
39-
);
4048
}
4149
} else {
4250
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Please provide signature types.');

0 commit comments

Comments
 (0)