"use client" import {useMutation} from "@tanstack/react-query"; import {Send, ShieldCheck} from "lucide-react"; import {toast} from "sonner"; import {Button} from "@/components/ui/button"; import {NotificationChannel} from "@/db/schema/09_notification-channel"; import {dispatchNotification} from "@/features/notifications/notifications.dispatch"; import {EventPayload} from "@/features/notifications/notifications.types"; import {useIsMobile} from "@/hooks/use-mobile"; import {cn} from "@/lib/utils"; import {StorageChannel} from "@/db/schema/12_storage-channel"; import {ChannelKind} from "@/features/channel/channels-helpers"; import type {StorageInput} from "@/features/storages/storages.types"; import {dispatchStorage} from "@/features/storages/storages.dispatch"; type NotifierTestChannelButtonProps = { channel: NotificationChannel | StorageChannel; organizationId?: string; kind: ChannelKind; } export const ChannelTestButton = ({channel, organizationId, kind}: NotifierTestChannelButtonProps) => { const isMobile = useIsMobile() const mutation = useMutation({ mutationFn: async () => { if (kind === "notification") { const payload: EventPayload = { title: 'Test Channel', message: `We are testing channel ${channel.name}`, level: 'info', }; const result = await dispatchNotification(payload, undefined, channel.id, organizationId); if (result.success) { toast.success(result.message); } else { toast.error("An error occurred while testing the notification channel, check your configuration"); } } else if (kind === "storage") { const input: StorageInput = { action: "ping", }; const result = await dispatchStorage(input, undefined, undefined, channel); if (result.success) { toast.success("Successfully connected to storage channel"); } else { const responseText = result.response ? `(${result.response})` : ""; toast.error(`An error occurred while testing the storage channel, check your configuration ${responseText}`); } } else { toast.error("Not yet supported"); } }, }); return ( ) }