"use client"; import {ButtonWithConfirm} from "@/components/common/button-with-confirm"; import {useMutation} from "@tanstack/react-query"; import {useRouter} from "next/navigation"; import {Trash2} from "lucide-react"; import { removeNotificationChannelAction, } from "@/features/channel/notifications/channel.action"; import {toast} from "sonner"; import {ChannelKind, getChannelTextBasedOnKind} from "@/features/channel/channels-helpers"; import { removeStorageChannelAction } from "@/features/channel/storages/channel.action"; export type DeleteChannelButtonProps = { channelId: string; kind: ChannelKind; organizationId?: string; }; export const DeleteChannelButton = ({channelId, organizationId, kind}: DeleteChannelButtonProps) => { const router = useRouter(); const channelText = getChannelTextBasedOnKind(kind) const mutation = useMutation({ mutationFn: async () => { const result = kind === "notification" ? await removeNotificationChannelAction({ organizationId, notificationChannelId: channelId }) : await removeStorageChannelAction({organizationId, id: channelId}) const inner = result?.data; if (inner?.success) { toast.success(inner.actionSuccess?.message); router.refresh(); } else { toast.error(inner?.actionError?.message); } }, }); return ( , }, confirm: { className: "w-full", text: "Delete", icon: , variant: "destructive", onClick: () => { mutation.mutate(); }, }, cancel: { className: "w-full", text: "Cancel", icon: , variant: "outline", }, }} isPending={mutation.isPending} /> ); };