"use client"; import { useState } from "react"; import useNotification from "@/hooks/useNotifications"; import { Bell, Text, BellRing, Braces } from "lucide-react"; interface AddNotificationProps { onNotificationAdded?: () => void; onError?: (message: string) => void; onSuccess?: (message: string) => void; } export default function AddNotification({ onNotificationAdded, onError, onSuccess }: AddNotificationProps) { const [name, setName] = useState(""); const [type, setType] = useState("Select a type"); const [telegramBotToken, setTelegramBotToken] = useState(""); const [telegramChatId, setTelegramChatId] = useState(""); const [nftyUrl, setNftyUrl] = useState(""); const [ntfyToken, setNftyToken] = useState(""); const [smtpHost, setSmtpHost] = useState(""); const [smtpPort, setSmtpPort] = useState(""); const [smtpUsername, setSmtpUsername] = useState(""); const [smtpPassword, setSmtpPassword] = useState(""); const [smtpFrom, setSmtpFrom] = useState(""); const [smtpTo, setSmtpTo] = useState(""); const [smtpSecure, setSmtpSecure] = useState(false); const { addNotification } = useNotification(); const clearForm = () => { setName("") setType("Select a type") setTelegramBotToken("") setTelegramChatId("") setNftyUrl("") setNftyToken("") setSmtpHost("") setSmtpPort("") setSmtpUsername("") setSmtpPassword("") setSmtpFrom("") setSmtpTo("") setSmtpSecure(false) } const addNotificationHandler = async () => { let config = ""; if (type === "TELEGRAM") { config = `{ "token": "${telegramBotToken}", "chat_id": "${telegramChatId}" }`; } else if (type === "NTFY") { config = `{ "url": "${nftyUrl}", "token": "${ntfyToken}" }`; } else if (type === "SMTP") { config = `{ "host": "${smtpHost}", "port": "${smtpPort}", "username": "${smtpUsername}", "password": "${smtpPassword}", "from": "${smtpFrom}", "to": "${smtpTo}", "secure": "${smtpSecure}" }`; } const response = addNotification(name, type, config); if (typeof response === "string") { onError && onError(response) clearForm(); return } try { const successMessage = await response if (onSuccess && successMessage) { onSuccess('Notification Provider added successfully') onNotificationAdded && onNotificationAdded() } } catch (apiError: any) { onError && onError(apiError) } finally { clearForm(); } } return (