import { useEffect, useState } from 'react'; import { Trans } from '@lingui/react/macro'; import { LoaderIcon } from 'lucide-react'; import { match } from 'ts-pattern'; import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out'; import { Button } from '@documenso/ui/primitives/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@documenso/ui/primitives/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'); // Reset to first step when dialog closes useEffect(() => { if (!open) { setCurrentStep('PROMPT'); } }, [open]); const handleStartDetection = () => { 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. )) .with('PROCESSING', () => ( <> Analyzing your document Scanning your document to detect recipient names, emails, and signing order. )) .exhaustive()}
); };