Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Let templates with approvers be bulk sent

Matthew Jackson31a72c3e72cd
diff --git a/src/lib/templates.test.ts b/src/lib/templates.test.ts
index ab8aa53..3ee070e 100644
--- a/src/lib/templates.test.ts
+++ b/src/lib/templates.test.ts
@@ -56,3 +56,27 @@ test("a dropdown with fewer than two choices cannot be sent", () => {
/dropdown/,
);
});
+
+test("approver roles need no Signature field, but someone has to sign", () => {
+ const approver = {
+ id: "role-2",
+ kind: "approver" as const,
+ name: "Approver",
+ };
+
+ assert.equal(
+ describeUnsendableTemplate([role, approver], [signatureField()]),
+ null,
+ );
+ assert.match(
+ describeUnsendableTemplate([approver], [signatureField(approver.id)]) ?? "",
+ /Add at least one signer/,
+ );
+ assert.match(
+ describeUnsendableTemplate(
+ [role, approver],
+ [signatureField(), signatureField(approver.id)],
+ ) ?? "",
+ /approvers have no fields/,
+ );
+});
diff --git a/src/lib/templates.ts b/src/lib/templates.ts
index 9fbea2f..6bcb69d 100644
--- a/src/lib/templates.ts
+++ b/src/lib/templates.ts
@@ -228,8 +228,9 @@ export type TemplateForBulkSend = UseTemplateData & {
};
/**
- * Whether this template can be sent as it stands: every role needs a
- * signature field, and choice fields must be finished. Saved from a draft
+ * Whether this template can be sent as it stands: someone has to sign,
+ * every signer role needs a signature field, an approver role has no
+ * fields, and choice fields must be finished. Saved from a draft
* that was still being prepared, it is kept, but it cannot go out.
*/
export function describeUnsendableTemplate(
@@ -256,8 +257,23 @@ export function describeUnsendableTemplate(
return UNUSABLE_TEMPLATE_MESSAGE;
}
+ if (!roles.some((role) => role.kind !== "approver")) {
+ return "Add at least one signer. Approvers approve or reject, so someone else has to sign.";
+ }
+
+ const approverWithFields = roles.find(
+ (role) =>
+ role.kind === "approver" &&
+ parsed.data.some((field) => field.signerId === role.id),
+ );
+
+ if (approverWithFields) {
+ return `${approverWithFields.name} is an approver, and approvers have no fields. Remove their fields, or make them a signer.`;
+ }
+
const missing = roles.find(
(role) =>
+ role.kind !== "approver" &&
!parsed.data.some(
(field) => field.signerId === role.id && field.type === "signature",
),