refactor: add restriction foe default signature type

This commit is contained in:
prafull-opensignlabs
2024-11-07 21:51:39 +05:30
parent a11a2444f1
commit 508b2e43d3
4 changed files with 75 additions and 33 deletions
@@ -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);
}
@@ -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")}
+27 -19
View File
@@ -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];
@@ -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) {
try {
const params = { SignatureType: signatureType };
const updateRes = await Parse.Cloud.run("updatesignaturetype", params);
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);
}
} else {
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"
});
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
setIsLoader(false);
} else if (isDefaultSignTypeOnly) {
setIsAlert({
type: "danger",
msg: "Please enable one more signature type other than default"
});
} else {
try {
const updateRes = await Parse.Cloud.run("updatesignaturetype", {
SignatureType: signatureType
});
if (updateRes) {
setIsAlert({ type: "success", msg: "Saved successfully." });
}
} catch (err) {
console.log("Error updating signature type", err);
setIsAlert({ type: "danger", msg: err.message });
}
}
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
setIsLoader(false);
};
return (
@@ -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',
@@ -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;
@@ -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.
@@ -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.
@@ -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
);
@@ -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
);
@@ -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', {
@@ -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.');