Got rid of magic numbers in the modal.

This commit is contained in:
Skorpios committed 2025-03-11 19:06:57 -07:00
1 parent f7b247fa9d
commit 798a680fc6
2 files changed
+26 -10

No files matched your search

@@ -17,6 +17,22 @@ import TabPanel from "./TabPanel";
import TabComponent from "./TabComponent"; import TabComponent from "./TabComponent";
import useNotifications from "../Hooks/useNotification"; import useNotifications from "../Hooks/useNotification";
// Define constants for notification types to avoid magic values
const NOTIFICATION_TYPES = {
SLACK: 'slack',
DISCORD: 'discord',
TELEGRAM: 'telegram',
WEBHOOK: 'webhook'
};
// Define constants for field IDs
const FIELD_IDS = {
WEBHOOK: 'webhook',
TOKEN: 'token',
CHAT_ID: 'chatId',
URL: 'url'
};
const NotificationIntegrationModal = ({ const NotificationIntegrationModal = ({
open, open,
onClose, onClose,
@@ -48,12 +64,12 @@ const NotificationIntegrationModal = ({
// Define notification types // Define notification types
const DEFAULT_NOTIFICATION_TYPES = [ const DEFAULT_NOTIFICATION_TYPES = [
{ {
id: 'slack', id: NOTIFICATION_TYPES.SLACK,
label: t('notifications.slack.label'), label: t('notifications.slack.label'),
description: t('notifications.slack.description'), description: t('notifications.slack.description'),
fields: [ fields: [
{ {
id: 'webhook', id: FIELD_IDS.WEBHOOK,
label: t('notifications.slack.webhookLabel'), label: t('notifications.slack.webhookLabel'),
placeholder: t('notifications.slack.webhookPlaceholder'), placeholder: t('notifications.slack.webhookPlaceholder'),
type: 'text' type: 'text'
@@ -61,12 +77,12 @@ const NotificationIntegrationModal = ({
] ]
}, },
{ {
id: 'discord', id: NOTIFICATION_TYPES.DISCORD,
label: t('notifications.discord.label'), label: t('notifications.discord.label'),
description: t('notifications.discord.description'), description: t('notifications.discord.description'),
fields: [ fields: [
{ {
id: 'webhook', id: FIELD_IDS.WEBHOOK,
label: t('notifications.discord.webhookLabel'), label: t('notifications.discord.webhookLabel'),
placeholder: t('notifications.discord.webhookPlaceholder'), placeholder: t('notifications.discord.webhookPlaceholder'),
type: 'text' type: 'text'
@@ -74,18 +90,18 @@ const NotificationIntegrationModal = ({
] ]
}, },
{ {
id: 'telegram', id: NOTIFICATION_TYPES.TELEGRAM,
label: t('notifications.telegram.label'), label: t('notifications.telegram.label'),
description: t('notifications.telegram.description'), description: t('notifications.telegram.description'),
fields: [ fields: [
{ {
id: 'token', id: FIELD_IDS.TOKEN,
label: t('notifications.telegram.tokenLabel'), label: t('notifications.telegram.tokenLabel'),
placeholder: t('notifications.telegram.tokenPlaceholder'), placeholder: t('notifications.telegram.tokenPlaceholder'),
type: 'text' type: 'text'
}, },
{ {
id: 'chatId', id: FIELD_IDS.CHAT_ID,
label: t('notifications.telegram.chatIdLabel'), label: t('notifications.telegram.chatIdLabel'),
placeholder: t('notifications.telegram.chatIdPlaceholder'), placeholder: t('notifications.telegram.chatIdPlaceholder'),
type: 'text' type: 'text'
@@ -93,12 +109,12 @@ const NotificationIntegrationModal = ({
] ]
}, },
{ {
id: 'webhook', id: NOTIFICATION_TYPES.WEBHOOK,
label: t('notifications.webhook.label'), label: t('notifications.webhook.label'),
description: t('notifications.webhook.description'), description: t('notifications.webhook.description'),
fields: [ fields: [
{ {
id: 'url', id: FIELD_IDS.URL,
label: t('notifications.webhook.urlLabel'), label: t('notifications.webhook.urlLabel'),
placeholder: t('notifications.webhook.urlPlaceholder'), placeholder: t('notifications.webhook.urlPlaceholder'),
type: 'text' type: 'text'
@@ -53,7 +53,7 @@ const useNotifications = () => {
case 'webhook': case 'webhook':
payload.webhookUrl = config.url; payload.webhookUrl = config.url;
payload.platform = 'slack'; // Use slack as platform for webhooks payload.platform = 'slack';
if (!payload.webhookUrl) { if (!payload.webhookUrl) {
isValid = false; isValid = false;
errorMessage = t('notifications.webhook.urlRequired', 'Please enter a webhook URL first.'); errorMessage = t('notifications.webhook.urlRequired', 'Please enter a webhook URL first.');