'use client'; import { useState } from 'react'; import { Loader2, XCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Textarea } from '@/components/ui/textarea'; export type CancelMode = 'delete' | 'keep_remote'; interface CancelDocumentDialogProps { open: boolean; onOpenChange: (next: boolean) => void; /** Label used in the dialog ("Cancel reservation", "Cancel contract", "Cancel EOI"). */ documentLabel: string; /** Fires when the rep confirms. Caller invokes the mutation with the * chosen `cancelMode` (and optional reason). The dialog stays open * until `onOpenChange(false)` is called by the parent - typically on * mutation success/failure. */ onConfirm: (params: { cancelMode: CancelMode; reason: string }) => void; /** When true, disables the confirm action + shows a spinner. */ isSubmitting?: boolean; } /** * Cancel-confirm dialog with an explicit "what to do with Documenso?" * choice. Default `'delete'` mirrors the prior behaviour - DELETE the * upstream envelope to keep the Documenso log uncluttered. `keep_remote` * leaves the envelope intact so admins can later inspect it for audit / * forensics; only the local CRM row flips to `cancelled`. * * Used by the Reservation / Contract / EOI tabs (any signing-doc * surface that exposes a Cancel CTA). Replaces the previous * `useConfirmation()` flow which had no way to surface this choice. */ export function CancelDocumentDialog({ open, onOpenChange, documentLabel, onConfirm, isSubmitting = false, }: CancelDocumentDialogProps) { const [cancelMode, setCancelMode] = useState('delete'); const [reason, setReason] = useState(''); function reset() { setCancelMode('delete'); setReason(''); } return ( { if (!next) reset(); onOpenChange(next); }} > Cancel {documentLabel.toLowerCase()} Signers will no longer be able to sign. Choose how to handle the document on Documenso.
setCancelMode(value as CancelMode)} className="gap-3" >