import { useMemo } from 'react';
import { useLingui } from '@lingui/react';
import { Trans } from '@lingui/react/macro';
import { OrganisationType, RecipientRole } from '@prisma/client';
import { P, match } from 'ts-pattern';
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
import { Button, Section, Text } from '../components';
import { TemplateDocumentImage } from './template-document-image';
export interface TemplateDocumentInviteProps {
inviterName: string;
inviterEmail: string;
documentName: string;
signDocumentLink: string;
assetBaseUrl: string;
role: RecipientRole;
selfSigner: boolean;
teamName?: string;
includeSenderDetails?: boolean;
organisationType?: OrganisationType;
}
export const TemplateDocumentInvite = ({
inviterName,
documentName,
signDocumentLink,
assetBaseUrl,
role,
selfSigner,
teamName,
includeSenderDetails,
organisationType,
}: TemplateDocumentInviteProps) => {
const { _ } = useLingui();
const { actionVerb } = RECIPIENT_ROLES_DESCRIPTION[role];
const rejectDocumentLink = useMemo(() => {
const url = new URL(signDocumentLink);
url.searchParams.set('reject', 'true');
return url.toString();
}, [signDocumentLink]);
return (
<>
{match({ selfSigner, organisationType, includeSenderDetails, teamName })
.with({ selfSigner: true }, () => (
Please {_(actionVerb).toLowerCase()} your document
"{documentName}"
))
.with(
{
organisationType: OrganisationType.ORGANISATION,
includeSenderDetails: true,
teamName: P.string,
},
() => (
{inviterName} on behalf of "{teamName}" has invited you to{' '}
{_(actionVerb).toLowerCase()}
"{documentName}"
),
)
.with({ organisationType: OrganisationType.ORGANISATION, teamName: P.string }, () => (
{teamName} has invited you to {_(actionVerb).toLowerCase()}
"{documentName}"
))
.otherwise(() => (
{inviterName} has invited you to {_(actionVerb).toLowerCase()}
"{documentName}"
))}
{match(role)
.with(RecipientRole.SIGNER, () => Continue by signing the document.)
.with(RecipientRole.VIEWER, () => Continue by viewing the document.)
.with(RecipientRole.APPROVER, () => Continue by approving the document.)
.with(RecipientRole.CC, () => '')
.with(RecipientRole.ASSISTANT, () => (
Continue by assisting with the document.
))
.exhaustive()}
>
);
};
export default TemplateDocumentInvite;