"use client" import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; import {Info} from "lucide-react"; import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading"; import {useRouter} from "next/navigation"; import {Setting} from "@/db/schema/01_setting"; import { Form, FormField, FormItem, FormLabel, useZodForm } from "@/components/ui/form"; import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select"; import {useMutation} from "@tanstack/react-query"; import {getChannelIcon} from "@/components/wrappers/dashboard/admin/channels/helpers/common"; import {NotificationChannelWith} from "@/db/schema/09_notification-channel"; import { DefaultNotificationSchema, DefaultNotificationType } from "@/components/wrappers/dashboard/admin/settings/notification/settings-notification.schema"; import { updateNotificationSettingsAction } from "@/components/wrappers/dashboard/admin/settings/notification/settings-notification.action"; import {toast} from "sonner"; export type SettingsNotificationSectionProps = { settings: Setting; notificationChannels: NotificationChannelWith[]; }; export const SettingsNotificationSection = ({settings, notificationChannels}: SettingsNotificationSectionProps) => { const router = useRouter(); const form = useZodForm({ schema: DefaultNotificationSchema, defaultValues: { notificationChannelId: settings.defaultNotificationChannelId ?? undefined, } }); const mutation = useMutation({ mutationFn: async (values: DefaultNotificationType) => { const result = await updateNotificationSettingsAction({name: "system", data: values}) const inner = result?.data; if (inner?.success) { toast.success(inner.actionSuccess?.message); router.refresh(); } else { toast.error(inner?.actionError?.message); } } }); return (
Informations The default notification channel will be used to send agent health alert notifications, and will be applied by default if no notification policy is defined at the database or organization level.
{ await mutation.mutateAsync(values); }} >
( Default Notification Provider {notificationChannels.length === 0 ? (
No channel available
) : ( )}
)} />
{notificationChannels.length >0 && ( Confirm )}
); };