Skip to content

The Open Source DocuSign Alternative.

feat: hide signature ui when theres no signature field (#1676)

Ephraim Duncanba5b7ce480b9
diff --git a/apps/remix/app/components/embed/embed-direct-template-client-page.tsx b/apps/remix/app/components/embed/embed-direct-template-client-page.tsx
index 718f2cb32..2f2a47058 100644
--- a/apps/remix/app/components/embed/embed-direct-template-client-page.tsx
+++ b/apps/remix/app/components/embed/embed-direct-template-client-page.tsx
@@ -415,40 +415,42 @@ export const EmbedDirectTemplateClientPage = ({
/>
</div>
- <div>
- <Label htmlFor="Signature">
- <Trans>Signature</Trans>
- </Label>
-
- <Card className="mt-2" gradient degrees={-120}>
- <CardContent className="p-0">
- <SignaturePad
- className="h-44 w-full"
- disabled={isThrottled || isSubmitting}
- defaultValue={signature ?? undefined}
- onChange={(value) => {
- setSignature(value);
- }}
- onValidityChange={(isValid) => {
- setSignatureValid(isValid);
- }}
- allowTypedSignature={Boolean(
- metadata &&
- 'typedSignatureEnabled' in metadata &&
- metadata.typedSignatureEnabled,
- )}
- />
- </CardContent>
- </Card>
-
- {hasSignatureField && !signatureValid && (
- <div className="text-destructive mt-2 text-sm">
- <Trans>
- Signature is too small. Please provide a more complete signature.
- </Trans>
- </div>
- )}
- </div>
+ {hasSignatureField && (
+ <div>
+ <Label htmlFor="Signature">
+ <Trans>Signature</Trans>
+ </Label>
+
+ <Card className="mt-2" gradient degrees={-120}>
+ <CardContent className="p-0">
+ <SignaturePad
+ className="h-44 w-full"
+ disabled={isThrottled || isSubmitting}
+ defaultValue={signature ?? undefined}
+ onChange={(value) => {
+ setSignature(value);
+ }}
+ onValidityChange={(isValid) => {
+ setSignatureValid(isValid);
+ }}
+ allowTypedSignature={Boolean(
+ metadata &&
+ 'typedSignatureEnabled' in metadata &&
+ metadata.typedSignatureEnabled,
+ )}
+ />
+ </CardContent>
+ </Card>
+
+ {hasSignatureField && !signatureValid && (
+ <div className="text-destructive mt-2 text-sm">
+ <Trans>
+ Signature is too small. Please provide a more complete signature.
+ </Trans>
+ </div>
+ )}
+ </div>
+ )}
</div>
</div>
diff --git a/apps/remix/app/components/embed/embed-document-signing-page.tsx b/apps/remix/app/components/embed/embed-document-signing-page.tsx
index ee8814ef5..05b48fbb1 100644
--- a/apps/remix/app/components/embed/embed-document-signing-page.tsx
+++ b/apps/remix/app/components/embed/embed-document-signing-page.tsx
@@ -418,40 +418,42 @@ export const EmbedSignDocumentClientPage = ({
/>
</div>
- <div>
- <Label htmlFor="Signature">
- <Trans>Signature</Trans>
- </Label>
-
- <Card className="mt-2" gradient degrees={-120}>
- <CardContent className="p-0">
- <SignaturePad
- className="h-44 w-full"
- disabled={isThrottled || isSubmitting}
- defaultValue={signature ?? undefined}
- onChange={(value) => {
- setSignature(value);
- }}
- onValidityChange={(isValid) => {
- setSignatureValid(isValid);
- }}
- allowTypedSignature={Boolean(
- metadata &&
- 'typedSignatureEnabled' in metadata &&
- metadata.typedSignatureEnabled,
- )}
- />
- </CardContent>
- </Card>
-
- {hasSignatureField && !signatureValid && (
- <div className="text-destructive mt-2 text-sm">
- <Trans>
- Signature is too small. Please provide a more complete signature.
- </Trans>
- </div>
- )}
- </div>
+ {hasSignatureField && (
+ <div>
+ <Label htmlFor="Signature">
+ <Trans>Signature</Trans>
+ </Label>
+
+ <Card className="mt-2" gradient degrees={-120}>
+ <CardContent className="p-0">
+ <SignaturePad
+ className="h-44 w-full"
+ disabled={isThrottled || isSubmitting}
+ defaultValue={signature ?? undefined}
+ onChange={(value) => {
+ setSignature(value);
+ }}
+ onValidityChange={(isValid) => {
+ setSignatureValid(isValid);
+ }}
+ allowTypedSignature={Boolean(
+ metadata &&
+ 'typedSignatureEnabled' in metadata &&
+ metadata.typedSignatureEnabled,
+ )}
+ />
+ </CardContent>
+ </Card>
+
+ {hasSignatureField && !signatureValid && (
+ <div className="text-destructive mt-2 text-sm">
+ <Trans>
+ Signature is too small. Please provide a more complete signature.
+ </Trans>
+ </div>
+ )}
+ </div>
+ )}
</>
)}
</div>
diff --git a/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx b/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx
index dbc655a0d..ee0350576 100644
--- a/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx
+++ b/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx
@@ -3,6 +3,7 @@ import { useMemo, useState } from 'react';
import { Trans } from '@lingui/react/macro';
import type { Field } from '@prisma/client';
import { RecipientRole } from '@prisma/client';
+import { match } from 'ts-pattern';
import { fieldsContainUnsignedRequiredField } from '@documenso/lib/utils/advanced-fields-helpers';
import { Button } from '@documenso/ui/primitives/button';
@@ -58,62 +59,88 @@ export const DocumentSigningCompleteDialog = ({
loading={isSubmitting}
disabled={disabled}
>
- {isComplete ? <Trans>Complete</Trans> : <Trans>Next field</Trans>}
+ {match({ isComplete, role })
+ .with({ isComplete: false }, () => <Trans>Next field</Trans>)
+ .with({ isComplete: true, role: RecipientRole.APPROVER }, () => <Trans>Approve</Trans>)
+ .with({ isComplete: true, role: RecipientRole.VIEWER }, () => (
+ <Trans>Mark as viewed</Trans>
+ ))
+ .with({ isComplete: true }, () => <Trans>Complete</Trans>)
+ .exhaustive()}
</Button>
</DialogTrigger>
<DialogContent>
<DialogTitle>
<div className="text-foreground text-xl font-semibold">
- {role === RecipientRole.VIEWER && <Trans>Complete Viewing</Trans>}
- {role === RecipientRole.SIGNER && <Trans>Complete Signing</Trans>}
- {role === RecipientRole.APPROVER && <Trans>Complete Approval</Trans>}
+ {match(role)
+ .with(RecipientRole.VIEWER, () => <Trans>Complete Viewing</Trans>)
+ .with(RecipientRole.SIGNER, () => <Trans>Complete Signing</Trans>)
+ .with(RecipientRole.APPROVER, () => <Trans>Complete Approval</Trans>)
+ .with(RecipientRole.CC, () => <Trans>Complete Viewing</Trans>)
+ .with(RecipientRole.ASSISTANT, () => <Trans>Complete Assisting</Trans>)
+ .exhaustive()}
</div>
</DialogTitle>
<div className="text-muted-foreground max-w-[50ch]">
- {role === RecipientRole.VIEWER && (
- <span>
- <Trans>
- <span className="inline-flex flex-wrap">
- You are about to complete viewing "
- <span className="inline-block max-w-[11rem] truncate align-baseline">
- {documentTitle}
+ {match(role)
+ .with(RecipientRole.VIEWER, () => (
+ <span>
+ <Trans>
+ <span className="inline-flex flex-wrap">
+ You are about to complete viewing "
+ <span className="inline-block max-w-[11rem] truncate align-baseline">
+ {documentTitle}
+ </span>
+ ".
</span>
- ".
- </span>
- <br /> Are you sure?
- </Trans>
- </span>
- )}
- {role === RecipientRole.SIGNER && (
- <span>
- <Trans>
- <span className="inline-flex flex-wrap">
- You are about to complete signing "
- <span className="inline-block max-w-[11rem] truncate align-baseline">
- {documentTitle}
+ <br /> Are you sure?
+ </Trans>
+ </span>
+ ))
+ .with(RecipientRole.SIGNER, () => (
+ <span>
+ <Trans>
+ <span className="inline-flex flex-wrap">
+ You are about to complete signing "
+ <span className="inline-block max-w-[11rem] truncate align-baseline">
+ {documentTitle}
+ </span>
+ ".
</span>
- ".
- </span>
- <br /> Are you sure?
- </Trans>
- </span>
- )}
- {role === RecipientRole.APPROVER && (
- <span>
- <Trans>
- <span className="inline-flex flex-wrap">
- You are about to complete approving{' '}
- <span className="inline-block max-w-[11rem] truncate align-baseline">
- "{documentTitle}"
+ <br /> Are you sure?
+ </Trans>
+ </span>
+ ))
+ .with(RecipientRole.APPROVER, () => (
+ <span>
+ <Trans>
+ <span className="inline-flex flex-wrap">
+ You are about to complete approving{' '}
+ <span className="inline-block max-w-[11rem] truncate align-baseline">
+ "{documentTitle}"
+ </span>
+ .
</span>
- .
- </span>
- <br /> Are you sure?
- </Trans>
- </span>
- )}
+ <br /> Are you sure?
+ </Trans>
+ </span>
+ ))
+ .otherwise(() => (
+ <span>
+ <Trans>
+ <span className="inline-flex flex-wrap">
+ You are about to complete viewing "
+ <span className="inline-block max-w-[11rem] truncate align-baseline">
+ {documentTitle}
+ </span>
+ ".
+ </span>
+ <br /> Are you sure?
+ </Trans>
+ </span>
+ ))}
</div>
<DocumentSigningDisclosure className="mt-4" />
@@ -138,9 +165,13 @@ export const DocumentSigningCompleteDialog = ({
loading={isSubmitting}
onClick={onSignatureComplete}
>
- {role === RecipientRole.VIEWER && <Trans>Mark as Viewed</Trans>}
- {role === RecipientRole.SIGNER && <Trans>Sign</Trans>}
- {role === RecipientRole.APPROVER && <Trans>Approve</Trans>}
+ {match(role)
+ .with(RecipientRole.VIEWER, () => <Trans>Mark as Viewed</Trans>)
+ .with(RecipientRole.SIGNER, () => <Trans>Sign</Trans>)
+ .with(RecipientRole.APPROVER, () => <Trans>Approve</Trans>)
+ .with(RecipientRole.CC, () => <Trans>Mark as Viewed</Trans>)
+ .with(RecipientRole.ASSISTANT, () => <Trans>Complete</Trans>)
+ .exhaustive()}
</Button>
</div>
</DialogFooter>
diff --git a/apps/remix/app/components/general/document-signing/document-signing-form.tsx b/apps/remix/app/components/general/document-signing/document-signing-form.tsx
index ef6847c34..a293afac8 100644
--- a/apps/remix/app/components/general/document-signing/document-signing-form.tsx
+++ b/apps/remix/app/components/general/document-signing/document-signing-form.tsx
@@ -313,7 +313,11 @@ export const DocumentSigningForm = ({
<>
<form onSubmit={handleSubmit(onFormSubmit)}>
<p className="text-muted-foreground mt-2 text-sm">
- <Trans>Please review the document before signing.</Trans>
+ {recipient.role === RecipientRole.APPROVER && !hasSignatureField ? (
+ <Trans>Please review the document before approving.</Trans>
+ ) : (
+ <Trans>Please review the document before signing.</Trans>
+ )}
</p>
<hr className="border-border mb-8 mt-4" />
@@ -337,38 +341,40 @@ export const DocumentSigningForm = ({
/>
</div>
- <div>
- <Label htmlFor="Signature">
- <Trans>Signature</Trans>
- </Label>
-
- <Card className="mt-2" gradient degrees={-120}>
- <CardContent className="p-0">
- <SignaturePad
- className="h-44 w-full"
- disabled={isSubmitting}
- defaultValue={signature ?? undefined}
- onValidityChange={(isValid) => {
- setSignatureValid(isValid);
- }}
- onChange={(value) => {
- if (signatureValid) {
- setSignature(value);
- }
- }}
- allowTypedSignature={document.documentMeta?.typedSignatureEnabled}
- />
- </CardContent>
- </Card>
-
- {hasSignatureField && !signatureValid && (
- <div className="text-destructive mt-2 text-sm">
- <Trans>
- Signature is too small. Please provide a more complete signature.
- </Trans>
- </div>
- )}
- </div>
+ {hasSignatureField && (
+ <div>
+ <Label htmlFor="Signature">
+ <Trans>Signature</Trans>
+ </Label>
+
+ <Card className="mt-2" gradient degrees={-120}>
+ <CardContent className="p-0">
+ <SignaturePad
+ className="h-44 w-full"
+ disabled={isSubmitting}
+ defaultValue={signature ?? undefined}
+ onValidityChange={(isValid) => {
+ setSignatureValid(isValid);
+ }}
+ onChange={(value) => {
+ if (signatureValid) {
+ setSignature(value);
+ }
+ }}
+ allowTypedSignature={document.documentMeta?.typedSignatureEnabled}
+ />
+ </CardContent>
+ </Card>
+
+ {!signatureValid && (
+ <div className="text-destructive mt-2 text-sm">
+ <Trans>
+ Signature is too small. Please provide a more complete signature.
+ </Trans>
+ </div>
+ )}
+ </div>
+ )}
</div>
<div className="flex flex-col gap-4 md:flex-row">
diff --git a/packages/app-tests/e2e/document-flow/stepper-component.spec.ts b/packages/app-tests/e2e/document-flow/stepper-component.spec.ts
index 1dd03aa76..94bb5320f 100644
--- a/packages/app-tests/e2e/document-flow/stepper-component.spec.ts
+++ b/packages/app-tests/e2e/document-flow/stepper-component.spec.ts
@@ -377,7 +377,9 @@ test('[DOCUMENT_FLOW]: should be able to approve a document', async ({ page }) =
await expect(page.locator(`#field-${field.id}`)).toHaveAttribute('data-inserted', 'true');
}
- await page.getByRole('button', { name: 'Complete' }).click();
+ await page
+ .getByRole('button', { name: role === RecipientRole.SIGNER ? 'Complete' : 'Approve' })
+ .click();
await page
.getByRole('button', { name: role === RecipientRole.SIGNER ? 'Sign' : 'Approve' })
.click();
@@ -447,7 +449,7 @@ test('[DOCUMENT_FLOW]: should be able to create, send with redirect url, sign a
const { status } = await getDocumentByToken(token);
expect(status).toBe(DocumentStatus.PENDING);
- await page.getByRole('button', { name: 'Complete' }).click();
+ await page.getByRole('button', { name: 'Approve' }).click();
await expect(page.getByRole('dialog').getByText('Complete Approval').first()).toBeVisible();
await page.getByRole('button', { name: 'Approve' }).click();