import { useRouter } from 'next/navigation'; import { trpc as trpcReact } from '@documenso/trpc/react'; import { Button } from '@documenso/ui/primitives/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@documenso/ui/primitives/dialog'; import { useToast } from '@documenso/ui/primitives/use-toast'; type DeleteTemplateDialogProps = { id: number; open: boolean; onOpenChange: (_open: boolean) => void; }; export const DeleteTemplateDialog = ({ id, open, onOpenChange }: DeleteTemplateDialogProps) => { const router = useRouter(); const { toast } = useToast(); const { mutateAsync: deleteTemplate, isLoading } = trpcReact.template.deleteTemplate.useMutation({ onSuccess: () => { router.refresh(); toast({ title: 'Template deleted', description: 'Your template has been successfully deleted.', duration: 5000, }); onOpenChange(false); }, onError: () => { toast({ title: 'Something went wrong', description: 'This template could not be deleted at this time. Please try again.', variant: 'destructive', duration: 7500, }); }, }); return ( !isLoading && onOpenChange(value)}> Do you want to delete this template? Please note that this action is irreversible. Once confirmed, your template will be permanently deleted. ); };