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.

## Related Issue

N/A

## Changes Made

- Swapped ternary for `ts-pattern`

## Testing Performed

- Manually created a bunch of documents in configurations matching those
required to exhaust the `match` conditions.
This commit is contained in:
Lucas Smith
2025-01-28 15:18:12 +11:00
committed by GitHub
parent c6fb101a99
commit 70a3ac0525

View File

@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { Trans } from '@lingui/macro'; import { Trans } from '@lingui/macro';
import { useLingui } from '@lingui/react'; import { useLingui } from '@lingui/react';
import { match } from 'ts-pattern'; import { P, match } from 'ts-pattern';
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles'; import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
import { RecipientRole } from '@documenso/prisma/client'; import { RecipientRole } from '@documenso/prisma/client';
@ -40,11 +40,9 @@ export const TemplateDocumentInvite = ({
const rejectDocumentLink = useMemo(() => { const rejectDocumentLink = useMemo(() => {
const url = new URL(signDocumentLink); const url = new URL(signDocumentLink);
url.searchParams.set('reject', 'true'); url.searchParams.set('reject', 'true');
return url.toString(); return url.toString();
}, []); }, [signDocumentLink]);
return ( return (
<> <>
@ -52,31 +50,32 @@ export const TemplateDocumentInvite = ({
<Section> <Section>
<Text className="text-primary mx-auto mb-0 max-w-[80%] text-center text-lg font-semibold"> <Text className="text-primary mx-auto mb-0 max-w-[80%] text-center text-lg font-semibold">
{selfSigner ? ( {match({ selfSigner, isTeamInvite, includeSenderDetails, teamName })
<Trans> .with({ selfSigner: true }, () => (
Please {_(actionVerb).toLowerCase()} your document <Trans>
<br />"{documentName}" Please {_(actionVerb).toLowerCase()} your document
</Trans> <br />"{documentName}"
) : isTeamInvite ? ( </Trans>
<> ))
{includeSenderDetails ? ( .with({ isTeamInvite: true, includeSenderDetails: true, teamName: P.string }, () => (
<Trans> <Trans>
{inviterName} on behalf of "{teamName}" has invited you to{' '} {inviterName} on behalf of "{teamName}" has invited you to{' '}
{_(actionVerb).toLowerCase()} {_(actionVerb).toLowerCase()}
</Trans> <br />"{documentName}"
) : ( </Trans>
<Trans> ))
{teamName} has invited you to {_(actionVerb).toLowerCase()} .with({ isTeamInvite: true, teamName: P.string }, () => (
</Trans> <Trans>
)} {teamName} has invited you to {_(actionVerb).toLowerCase()}
<br />"{documentName}" <br />"{documentName}"
</> </Trans>
) : ( ))
<Trans> .otherwise(() => (
{inviterName} has invited you to {_(actionVerb).toLowerCase()} <Trans>
<br />"{documentName}" {inviterName} has invited you to {_(actionVerb).toLowerCase()}
</Trans> <br />"{documentName}"
)} </Trans>
))}
</Text> </Text>
<Text className="my-1 text-center text-base text-slate-400"> <Text className="my-1 text-center text-base text-slate-400">