import { useState } from "react"; import { useTopics } from "../hooks/queries"; import { Edit, Trash2 } from "lucide-react"; import { useDeleteTopic } from "../hooks/mutations"; type PendingDelete = { open: boolean; topic: string; }; export default function StateSection() { const { data, isLoading } = useTopics(); const deleteTopic = useDeleteTopic(); const [pending, setPending] = useState({ open: false, topic: "", }); const handleDelete = (topic: string) => { if (deleteTopic.isPending) return; setPending({ open: true, topic }); }; const handleConfirmDelete = () => { if (!pending.topic || deleteTopic.isPending) return; deleteTopic.mutate( { topic: pending.topic, type: "state-reply" }, { onSuccess: () => setPending({ open: false, topic: "" }), onError: () => setPending({ open: false, topic: "" }), }, ); }; const handleClose = () => { if (deleteTopic.isPending) return; setPending({ open: false, topic: "" }); }; return ( <> {isLoading && Array.from({ length: 3 }).map((_, index) => (
))} {data?.map((item, key) => (

{item.topic}

))} {pending.open && (

Hapus Topic

Yakin ingin menghapus topic "{pending.topic}"?

)} ); }