import { useState } from "react"; import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Stack, Typography, Box, Tabs, Tab, Divider } from "@mui/material"; import { useTheme } from "@emotion/react"; import TextInput from "../../../../../../src/Components/Inputs/TextInput"; import Checkbox from "../../../../../../src/Components/Inputs/Checkbox"; // Tab Panel component function TabPanel({ children, value, index, ...other }) { return ( ); } const NotificationIntegrationModal = ({ open, onClose, monitor, setMonitor }) => { const theme = useTheme(); const [tabValue, setTabValue] = useState(0); const [integrations, setIntegrations] = useState({ slack: monitor?.notifications?.some(n => n.type === "slack") || false, slackWebhook: monitor?.notifications?.find(n => n.type === "slack")?.webhook || "", discord: monitor?.notifications?.some(n => n.type === "discord") || false, discordWebhook: monitor?.notifications?.find(n => n.type === "discord")?.webhook || "", telegram: monitor?.notifications?.some(n => n.type === "telegram") || false, telegramToken: monitor?.notifications?.find(n => n.type === "telegram")?.token || "", telegramChatId: monitor?.notifications?.find(n => n.type === "telegram")?.chatId || "", webhook: monitor?.notifications?.some(n => n.type === "webhook") || false, webhookUrl: monitor?.notifications?.find(n => n.type === "webhook")?.url || "", }); const testNotificationButtonStyle = { textDecoration: 'underline', color: '#344054', textTransform: 'none', padding: '0 !important', margin: 0, fontSize: '0.9rem', fontWeight: 'normal', backgroundColor: 'transparent !important', '&:hover': { backgroundColor: 'transparent !important', textDecoration: 'underline' }, '&.Mui-disabled': { backgroundColor: 'transparent !important' }, minWidth: '0 !important', boxShadow: 'none !important', border: 'none !important' }; const handleChangeTab = (event, newValue) => { setTabValue(newValue); }; const handleIntegrationChange = (type, checked) => { setIntegrations(prev => ({ ...prev, [type]: checked })); }; const handleInputChange = (type, value) => { setIntegrations(prev => ({ ...prev, [type]: value })); }; const handleTestNotification = (type) => { console.log(`Testing ${type} notification`); // Here you would implement the actual test notification functionality }; const handleSave = () => { // Create notifications array based on selected integrations const notifications = [...(monitor?.notifications || [])]; // Filter out existing integrations that will be updated const existingTypes = ["slack", "discord", "telegram", "webhook"]; const filteredNotifications = notifications.filter( notification => !existingTypes.includes(notification.type) ); // Add selected integrations if (integrations.slack) { filteredNotifications.push({ type: "slack", webhook: integrations.slackWebhook }); } if (integrations.discord) { filteredNotifications.push({ type: "discord", webhook: integrations.discordWebhook }); } if (integrations.telegram) { filteredNotifications.push({ type: "telegram", token: integrations.telegramToken, chatId: integrations.telegramChatId }); } if (integrations.webhook) { filteredNotifications.push({ type: "webhook", url: integrations.webhookUrl }); } // Update monitor with new notifications setMonitor(prev => ({ ...prev, notifications: filteredNotifications })); onClose(); }; return ( {/* Left sidebar with tabs */} Add or edit notifications {/* Right side content */} {/* Slack Tab */} Slack To enable Slack notifications, create a Slack app and enable incoming webhooks. After that, simply provide the webhook URL here. handleIntegrationChange('slack', e.target.checked)} /> Webhook URL handleInputChange('slackWebhook', e.target.value)} disabled={!integrations.slack} /> {/* Discord Tab */} Discord To send data to a Discord channel from Checkmate via Discord notifications using webhooks, you can use Discord's incoming Webhooks feature. handleIntegrationChange('discord', e.target.checked)} /> Discord Webhook URL handleInputChange('discordWebhook', e.target.value)} disabled={!integrations.discord} /> {/* Telegram Tab */} Telegram To enable Telegram notifications, create a Telegram bot using BotFather, an official bot for creating and managing Telegram bots. Then, get the API token and chat ID and write them down here. handleIntegrationChange('telegram', e.target.checked)} /> Your bot token handleInputChange('telegramToken', e.target.value)} disabled={!integrations.telegram} /> Your Chat ID handleInputChange('telegramChatId', e.target.value)} disabled={!integrations.telegram} /> {/* Webhooks Tab */} Webhooks You can set up a custom webhook to receive notifications when incidents occur. handleIntegrationChange('webhook', e.target.checked)} /> Webhook URL handleInputChange('webhookUrl', e.target.value)} disabled={!integrations.webhook} /> ); }; export default NotificationIntegrationModal;