import { useState } from "react" import { Trash2 } from "lucide-react" import { toast } from "sonner" import { deleteFAQ } from "../../../api/faq.api" import { Button } from "../../../components/ui/button" import { notifyApiError } from "../../../lib/apiErrors" import { Dialog, DialogContent, DialogDescription, DialogTitle, } from "../../../components/ui/dialog" import type { FAQ } from "../../../types/faq.types" type FaqDeleteDialogProps = { faq: FAQ | null open: boolean onOpenChange: (open: boolean) => void onDeleted?: () => void } export function FaqDeleteDialog({ faq, open, onOpenChange, onDeleted, }: FaqDeleteDialogProps) { const [deleting, setDeleting] = useState(false) const handleOpenChange = (next: boolean) => { if (!next && !deleting) onOpenChange(false) } const handleConfirm = async () => { if (!faq) return setDeleting(true) try { const response = await deleteFAQ(faq.id) toast.success(response.message ?? "FAQ deleted successfully") onOpenChange(false) onDeleted?.() } catch (e: unknown) { console.error(e) notifyApiError(e, "Failed to delete FAQ") } finally { setDeleting(false) } } return (
Delete FAQ? This permanently removes the FAQ from the help center.
{faq ? (

{faq.question}

#{faq.id}

) : null}
) }