From 84b193d99c9446e44767ef2587a504f1b6b5a97e Mon Sep 17 00:00:00 2001 From: Lucas Smith Date: Tue, 28 Jan 2025 15:18:12 +1100 Subject: [PATCH] fix: tidy document invite email render logic (#1597) Updates one of our confusing ternaries to use `ts-pattern` for rendering the conditional blocks making it easy to follow the logic occurring. --- .../template-document-invite.tsx | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/packages/email/template-components/template-document-invite.tsx b/packages/email/template-components/template-document-invite.tsx index 5a5d4157a..d0c0b0afa 100644 --- a/packages/email/template-components/template-document-invite.tsx +++ b/packages/email/template-components/template-document-invite.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import { useLingui } from '@lingui/react'; import { Trans } from '@lingui/react/macro'; -import { match } from 'ts-pattern'; +import { P, match } from 'ts-pattern'; import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles'; import { RecipientRole } from '@documenso/prisma/client'; @@ -40,11 +40,9 @@ export const TemplateDocumentInvite = ({ const rejectDocumentLink = useMemo(() => { const url = new URL(signDocumentLink); - url.searchParams.set('reject', 'true'); - return url.toString(); - }, []); + }, [signDocumentLink]); return ( <> @@ -52,31 +50,32 @@ export const TemplateDocumentInvite = ({
- {selfSigner ? ( - - Please {_(actionVerb).toLowerCase()} your document -
"{documentName}" -
- ) : isTeamInvite ? ( - <> - {includeSenderDetails ? ( - - {inviterName} on behalf of "{teamName}" has invited you to{' '} - {_(actionVerb).toLowerCase()} - - ) : ( - - {teamName} has invited you to {_(actionVerb).toLowerCase()} - - )} -
"{documentName}" - - ) : ( - - {inviterName} has invited you to {_(actionVerb).toLowerCase()} -
"{documentName}" -
- )} + {match({ selfSigner, isTeamInvite, includeSenderDetails, teamName }) + .with({ selfSigner: true }, () => ( + + Please {_(actionVerb).toLowerCase()} your document +
"{documentName}" +
+ )) + .with({ isTeamInvite: true, includeSenderDetails: true, teamName: P.string }, () => ( + + {inviterName} on behalf of "{teamName}" has invited you to{' '} + {_(actionVerb).toLowerCase()} +
"{documentName}" +
+ )) + .with({ isTeamInvite: true, teamName: P.string }, () => ( + + {teamName} has invited you to {_(actionVerb).toLowerCase()} +
"{documentName}" +
+ )) + .otherwise(() => ( + + {inviterName} has invited you to {_(actionVerb).toLowerCase()} +
"{documentName}" +
+ ))}