import { useEffect, useState } from 'react'; import { Plural, Trans } from '@lingui/react/macro'; import { RecipientRole } from '@prisma/client'; import { motion } from 'framer-motion'; import { LucideChevronDown, LucideChevronUp } from 'lucide-react'; import { match } from 'ts-pattern'; import { Button } from '@documenso/ui/primitives/button'; import { useEmbedSigningContext } from '~/components/embed/embed-signing-context'; import { BrandingLogo } from '../branding-logo'; import EnvelopeSignerForm from '../envelope-signing/envelope-signer-form'; import { EnvelopeSignerCompleteDialog } from '../envelope-signing/envelope-signing-complete-dialog'; import { useRequiredEnvelopeSigningContext } from './envelope-signing-provider'; export const DocumentSigningMobileWidget = () => { const [isExpanded, setIsExpanded] = useState(false); const { hidePoweredBy = true } = useEmbedSigningContext() || {}; const { recipientFieldsRemaining, recipient, requiredRecipientFields } = useRequiredEnvelopeSigningContext(); /** * Pre open the widget for assistants to let them know it's there. */ useEffect(() => { if (recipient.role === RecipientRole.ASSISTANT) { setIsExpanded(true); } }, []); return (
{/* Main Header Bar */}
{recipient.role !== RecipientRole.VIEWER && ( )}

{match(recipient.role) .with(RecipientRole.VIEWER, () => View Document) .with(RecipientRole.SIGNER, () => Sign Document) .with(RecipientRole.APPROVER, () => Approve Document) .with(RecipientRole.ASSISTANT, () => Assist Document) .otherwise(() => null)}

{recipientFieldsRemaining.length === 0 ? ( match(recipient.role) .with(RecipientRole.VIEWER, () => ( Please mark as viewed to complete )) .with(RecipientRole.SIGNER, () => ( Please complete the document once reviewed )) .with(RecipientRole.APPROVER, () => ( Please complete the document once reviewed )) .with(RecipientRole.ASSISTANT, () => ( Please complete the document once reviewed )) .otherwise(() => null) ) : ( )}

{/* Progress Bar */} {recipient.role !== RecipientRole.VIEWER && recipient.role !== RecipientRole.ASSISTANT && (
)} {/* Expandable Content */} {isExpanded && (
{!hidePoweredBy && (
Powered by
)}
)}
); };