diff --git a/apps/remix/app/components/general/document-signing/document-signing-auth-2fa.tsx b/apps/remix/app/components/general/document-signing/document-signing-auth-2fa.tsx index e0b5ca2b1..be2b8f895 100644 --- a/apps/remix/app/components/general/document-signing/document-signing-auth-2fa.tsx +++ b/apps/remix/app/components/general/document-signing/document-signing-auth-2fa.tsx @@ -4,6 +4,7 @@ import { zodResolver } from '@hookform/resolvers/zod'; import { Trans } from '@lingui/react/macro'; import { RecipientRole } from '@prisma/client'; import { useForm } from 'react-hook-form'; +import { match } from 'ts-pattern'; import { z } from 'zod'; import { AppError } from '@documenso/lib/errors/app-error'; @@ -27,7 +28,6 @@ import { useRequiredDocumentSigningAuthContext } from './document-signing-auth-p export type DocumentSigningAuth2FAProps = { actionTarget?: 'FIELD' | 'DOCUMENT'; - actionVerb?: string; open: boolean; onOpenChange: (value: boolean) => void; onReauthFormSubmit: (values?: TRecipientActionAuth) => Promise | void; @@ -44,7 +44,6 @@ type T2FAAuthFormSchema = z.infer; export const DocumentSigningAuth2FA = ({ actionTarget = 'FIELD', - actionVerb = 'sign', onReauthFormSubmit, open, onOpenChange, @@ -101,14 +100,39 @@ export const DocumentSigningAuth2FA = ({

- {recipient.role === RecipientRole.VIEWER && actionTarget === 'DOCUMENT' ? ( - You need to setup 2FA to mark this document as viewed. - ) : ( - // Todo: Translate - `You need to setup 2FA to ${actionVerb.toLowerCase()} this ${actionTarget.toLowerCase()}.` - )} + {match({ role: recipient.role, actionTarget }) + .with({ role: RecipientRole.SIGNER, actionTarget: 'FIELD' }, () => ( + You need to setup 2FA to sign this field. + )) + .with({ role: RecipientRole.SIGNER, actionTarget: 'DOCUMENT' }, () => ( + You need to setup 2FA to sign this document. + )) + .with({ role: RecipientRole.APPROVER, actionTarget: 'FIELD' }, () => ( + You need to setup 2FA to approve this field. + )) + .with({ role: RecipientRole.APPROVER, actionTarget: 'DOCUMENT' }, () => ( + You need to setup 2FA to approve this document. + )) + .with({ role: RecipientRole.VIEWER, actionTarget: 'FIELD' }, () => ( + You need to setup 2FA to view this field. + )) + .with({ role: RecipientRole.VIEWER, actionTarget: 'DOCUMENT' }, () => ( + You need to setup 2FA to mark this document as viewed. + )) + .with({ role: RecipientRole.CC, actionTarget: 'FIELD' }, () => ( + You need to setup 2FA to view this field. + )) + .with({ role: RecipientRole.CC, actionTarget: 'DOCUMENT' }, () => ( + You need to setup 2FA to view this document. + )) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'FIELD' }, () => ( + You need to setup 2FA to assist with this field. + )) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'DOCUMENT' }, () => ( + You need to setup 2FA to assist with this document. + )) + .exhaustive()}

-

By enabling 2FA, you will be required to enter a code from your authenticator app @@ -138,7 +162,9 @@ export const DocumentSigningAuth2FA = ({ name="token" render={({ field }) => ( - 2FA token + + 2FA token + diff --git a/apps/remix/app/components/general/document-signing/document-signing-auth-account.tsx b/apps/remix/app/components/general/document-signing/document-signing-auth-account.tsx index 3d991d5ee..cd3fc057c 100644 --- a/apps/remix/app/components/general/document-signing/document-signing-auth-account.tsx +++ b/apps/remix/app/components/general/document-signing/document-signing-auth-account.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { Trans, useLingui } from '@lingui/react/macro'; import { RecipientRole } from '@prisma/client'; +import { match } from 'ts-pattern'; import { authClient } from '@documenso/auth/client'; import { Alert, AlertDescription } from '@documenso/ui/primitives/alert'; @@ -13,13 +14,11 @@ import { useRequiredDocumentSigningAuthContext } from './document-signing-auth-p export type DocumentSigningAuthAccountProps = { actionTarget?: 'FIELD' | 'DOCUMENT'; - actionVerb?: string; onOpenChange: (value: boolean) => void; }; export const DocumentSigningAuthAccount = ({ actionTarget = 'FIELD', - actionVerb = 'sign', onOpenChange, }: DocumentSigningAuthAccountProps) => { const { recipient, isDirectTemplate } = useRequiredDocumentSigningAuthContext(); @@ -55,32 +54,110 @@ export const DocumentSigningAuthAccount = ({

- {actionTarget === 'DOCUMENT' && recipient.role === RecipientRole.VIEWER ? ( - - {isDirectTemplate ? ( - To mark this document as viewed, you need to be logged in. - ) : ( - - To mark this document as viewed, you need to be logged in as{' '} - {recipient.email} - - )} - - ) : ( - - {isDirectTemplate ? ( - - To {actionVerb.toLowerCase()} this {actionTarget.toLowerCase()}, you need to be - logged in. - - ) : ( - - To {actionVerb.toLowerCase()} this {actionTarget.toLowerCase()}, you need to be - logged in as {recipient.email} - - )} - - )} + + {match({ role: recipient.role, actionTarget }) + .with({ role: RecipientRole.SIGNER, actionTarget: 'FIELD' }, () => + isDirectTemplate ? ( + To sign this field, you need to be logged in. + ) : ( + + To sign this field, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.SIGNER, actionTarget: 'DOCUMENT' }, () => + isDirectTemplate ? ( + To sign this document, you need to be logged in. + ) : ( + + To sign this document, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.APPROVER, actionTarget: 'FIELD' }, () => + isDirectTemplate ? ( + To approve this field, you need to be logged in. + ) : ( + + To approve this field, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.APPROVER, actionTarget: 'DOCUMENT' }, () => + isDirectTemplate ? ( + To approve this document, you need to be logged in. + ) : ( + + To approve this document, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.VIEWER, actionTarget: 'FIELD' }, () => + isDirectTemplate ? ( + To view this field, you need to be logged in. + ) : ( + + To view this field, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.VIEWER, actionTarget: 'DOCUMENT' }, () => + isDirectTemplate ? ( + To mark this document as viewed, you need to be logged in. + ) : ( + + To mark this document as viewed, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.CC, actionTarget: 'FIELD' }, () => + isDirectTemplate ? ( + To view this field, you need to be logged in. + ) : ( + + To view this field, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.CC, actionTarget: 'DOCUMENT' }, () => + isDirectTemplate ? ( + To view this document, you need to be logged in. + ) : ( + + To view this document, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'FIELD' }, () => + isDirectTemplate ? ( + To assist with this field, you need to be logged in. + ) : ( + + To assist with this field, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'DOCUMENT' }, () => + isDirectTemplate ? ( + To assist with this document, you need to be logged in. + ) : ( + + To assist with this document, you need to be logged in as{' '} + {recipient.email} + + ), + ) + .exhaustive()} + diff --git a/apps/remix/app/components/general/document-signing/document-signing-auth-passkey.tsx b/apps/remix/app/components/general/document-signing/document-signing-auth-passkey.tsx index 9cdb2e28a..0c3fa1201 100644 --- a/apps/remix/app/components/general/document-signing/document-signing-auth-passkey.tsx +++ b/apps/remix/app/components/general/document-signing/document-signing-auth-passkey.tsx @@ -8,6 +8,7 @@ import { RecipientRole } from '@prisma/client'; import { browserSupportsWebAuthn, startAuthentication } from '@simplewebauthn/browser'; import { Loader } from 'lucide-react'; import { useForm } from 'react-hook-form'; +import { match } from 'ts-pattern'; import { z } from 'zod'; import { AppError } from '@documenso/lib/errors/app-error'; @@ -38,7 +39,6 @@ import { useRequiredDocumentSigningAuthContext } from './document-signing-auth-p export type DocumentSigningAuthPasskeyProps = { actionTarget?: 'FIELD' | 'DOCUMENT'; - actionVerb?: string; open: boolean; onOpenChange: (value: boolean) => void; onReauthFormSubmit: (values?: TRecipientActionAuth) => Promise | void; @@ -52,7 +52,6 @@ type TPasskeyAuthFormSchema = z.infer; export const DocumentSigningAuthPasskey = ({ actionTarget = 'FIELD', - actionVerb = 'sign', onReauthFormSubmit, open, onOpenChange, @@ -128,9 +127,62 @@ export const DocumentSigningAuthPasskey = ({
- {/* Todo: Translate */} - Your browser does not support passkeys, which is required to {actionVerb.toLowerCase()}{' '} - this {actionTarget.toLowerCase()}. + {match({ role: recipient.role, actionTarget }) + .with({ role: RecipientRole.SIGNER, actionTarget: 'FIELD' }, () => ( + + Your browser does not support passkeys, which is required to sign this field. + + )) + .with({ role: RecipientRole.SIGNER, actionTarget: 'DOCUMENT' }, () => ( + + Your browser does not support passkeys, which is required to sign this document. + + )) + .with({ role: RecipientRole.APPROVER, actionTarget: 'FIELD' }, () => ( + + Your browser does not support passkeys, which is required to approve this field. + + )) + .with({ role: RecipientRole.APPROVER, actionTarget: 'DOCUMENT' }, () => ( + + Your browser does not support passkeys, which is required to approve this + document. + + )) + .with({ role: RecipientRole.VIEWER, actionTarget: 'FIELD' }, () => ( + + Your browser does not support passkeys, which is required to view this field. + + )) + .with({ role: RecipientRole.VIEWER, actionTarget: 'DOCUMENT' }, () => ( + + Your browser does not support passkeys, which is required to mark this document as + viewed. + + )) + .with({ role: RecipientRole.CC, actionTarget: 'FIELD' }, () => ( + + Your browser does not support passkeys, which is required to view this field. + + )) + .with({ role: RecipientRole.CC, actionTarget: 'DOCUMENT' }, () => ( + + Your browser does not support passkeys, which is required to view this document. + + )) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'FIELD' }, () => ( + + Your browser does not support passkeys, which is required to assist with this + field. + + )) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'DOCUMENT' }, () => ( + + Your browser does not support passkeys, which is required to assist with this + document. + + )) + .exhaustive()} @@ -178,10 +230,38 @@ export const DocumentSigningAuthPasskey = ({
- {/* Todo: Translate */} - {recipient.role === RecipientRole.VIEWER && actionTarget === 'DOCUMENT' - ? 'You need to setup a passkey to mark this document as viewed.' - : `You need to setup a passkey to ${actionVerb.toLowerCase()} this ${actionTarget.toLowerCase()}.`} + {match({ role: recipient.role, actionTarget }) + .with({ role: RecipientRole.SIGNER, actionTarget: 'FIELD' }, () => ( + You need to setup a passkey to sign this field. + )) + .with({ role: RecipientRole.SIGNER, actionTarget: 'DOCUMENT' }, () => ( + You need to setup a passkey to sign this document. + )) + .with({ role: RecipientRole.APPROVER, actionTarget: 'FIELD' }, () => ( + You need to setup a passkey to approve this field. + )) + .with({ role: RecipientRole.APPROVER, actionTarget: 'DOCUMENT' }, () => ( + You need to setup a passkey to approve this document. + )) + .with({ role: RecipientRole.VIEWER, actionTarget: 'FIELD' }, () => ( + You need to setup a passkey to view this field. + )) + .with({ role: RecipientRole.VIEWER, actionTarget: 'DOCUMENT' }, () => ( + You need to setup a passkey to mark this document as viewed. + )) + .with({ role: RecipientRole.CC, actionTarget: 'FIELD' }, () => ( + You need to setup a passkey to view this field. + )) + .with({ role: RecipientRole.CC, actionTarget: 'DOCUMENT' }, () => ( + You need to setup a passkey to view this document. + )) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'FIELD' }, () => ( + You need to setup a passkey to assist with this field. + )) + .with({ role: RecipientRole.ASSISTANT, actionTarget: 'DOCUMENT' }, () => ( + You need to setup a passkey to assist with this document. + )) + .exhaustive()} @@ -213,7 +293,9 @@ export const DocumentSigningAuthPasskey = ({ name="passkeyId" render={({ field }) => ( - Passkey + + Passkey +