import { useEffect, useState } from 'react'; import { Trans } from '@lingui/react/macro'; import { match } from 'ts-pattern'; import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@documenso/ui/primitives/alert-dialog'; type RecipientDetectionStep = 'PROMPT' | 'PROCESSING'; export type RecipientDetectionPromptDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; onAccept: () => Promise | void; onSkip: () => void; }; export const RecipientDetectionPromptDialog = ({ open, onOpenChange, onAccept, onSkip, }: RecipientDetectionPromptDialogProps) => { const [currentStep, setCurrentStep] = useState('PROMPT'); useEffect(() => { if (!open) { setCurrentStep('PROMPT'); } }, [open]); const handleStartDetection = (e: React.MouseEvent) => { e.preventDefault(); setCurrentStep('PROCESSING'); Promise.resolve(onAccept()).catch(() => { setCurrentStep('PROMPT'); }); }; const handleSkip = () => { onSkip(); }; return (
{match(currentStep) .with('PROMPT', () => ( <> Auto-detect recipients? Would you like to automatically detect recipients in your document? This can save you time in setting up your document. Skip for now Detect recipients )) .with('PROCESSING', () => (
Analyzing your document Scanning your document to detect recipient names, emails, and signing order.
)) .exhaustive()}
); };