"use client"; import qs from "query-string"; import axios from "axios"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { useModal } from "@/hooks/use-modal-store"; import { Button } from "@/components/ui/button"; export const DeleteChannelModal = () => { const { isOpen, onClose, type, data } = useModal(); const router = useRouter(); const isModalOpen = isOpen && type === "deleteChannel"; const { server, channel } = data; const [isLoading, setIsLoading] = useState(false); const onClick = async () => { try { setIsLoading(true); const url = qs.stringifyUrl({ url: `/api/channels/${channel?.id}`, query: { serverId: server?.id }, }) await axios.delete(url); onClose(); router.refresh(); router.push(`/servers/${server?.id}`); } catch (error) { console.log(error); } finally { setIsLoading(false); onClose(); } } return ( Delete Channel Are you sure you want to do this?
#{channel?.name} will be permenantly deleted.
) }