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 DocumentAiStep = 'PROMPT' | 'PROCESSING'; export type DocumentAiPromptDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; onAccept: () => Promise | void; onSkip: () => void; }; export const DocumentAiPromptDialog = ({ open, onOpenChange, onAccept, onSkip, }: DocumentAiPromptDialogProps) => { const [currentStep, setCurrentStep] = useState('PROMPT'); // Reset to first step when dialog closes useEffect(() => { if (!open) { setCurrentStep('PROMPT'); } }, [open]); const handleUseAi = () => { setCurrentStep('PROCESSING'); Promise.resolve(onAccept()).catch(() => { setCurrentStep('PROMPT'); }); }; const handleSkip = () => { onSkip(); }; return (
{match(currentStep) .with('PROMPT', () => ( <> Use AI to prepare your document? Would you like to use AI to automatically add recipients to your document? This can save you time in setting up your document. )) .with('PROCESSING', () => ( <> Analyzing your document Our AI is scanning your document to detect recipient names, emails, and signing order. )) .exhaustive()}
); };