From 3ac56c1ea78e33bb041eee4e1ab61cc87cf9af91 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Sat, 8 Mar 2025 13:01:28 -0800 Subject: [PATCH] Made a separate tab component. --- .../NotificationIntegrationModal.jsx | 68 ++----------- .../TabComponent.jsx | 97 +++++++++++++++++++ 2 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 src/Components/NotificationIntegrationModal/TabComponent.jsx diff --git a/src/Components/NotificationIntegrationModal/NotificationIntegrationModal.jsx b/src/Components/NotificationIntegrationModal/NotificationIntegrationModal.jsx index a2c00c882..d8955f18e 100644 --- a/src/Components/NotificationIntegrationModal/NotificationIntegrationModal.jsx +++ b/src/Components/NotificationIntegrationModal/NotificationIntegrationModal.jsx @@ -10,9 +10,8 @@ import { Tab } from "@mui/material"; import { useTheme } from "@emotion/react"; -import TextInput from "../Inputs/TextInput"; -import Checkbox from "../Inputs/Checkbox"; import TabPanel from "./TabPanel"; +import TabComponent from "./TabComponent"; // Configuration for notification tabs const NOTIFICATION_TYPES = [ @@ -205,7 +204,7 @@ const NotificationIntegrationModal = ({ onChange={handleChangeTab} aria-label="Notification tabs" > - {notificationTypes.map((type, index) => ( + {notificationTypes.map((type) => ( ))} @@ -215,62 +214,13 @@ const NotificationIntegrationModal = ({ {notificationTypes.map((type, index) => ( - {type.label} - - {type.description} - - - - handleIntegrationChange(type.id, e.target.checked)} - /> - - - {type.fields.map(field => { - const fieldKey = `${type.id}${field.id.charAt(0).toUpperCase() + field.id.slice(1)}`; - - return ( - - {field.label} - handleInputChange(fieldKey, e.target.value)} - disabled={!integrations[type.id]} - /> - - ); - })} - - - - + ))} diff --git a/src/Components/NotificationIntegrationModal/TabComponent.jsx b/src/Components/NotificationIntegrationModal/TabComponent.jsx new file mode 100644 index 000000000..f9cf6ab53 --- /dev/null +++ b/src/Components/NotificationIntegrationModal/TabComponent.jsx @@ -0,0 +1,97 @@ +import React from "react"; +import { + Typography, + Box, + Button +} from "@mui/material"; +import { useTheme } from "@emotion/react"; +import TextInput from "../../../src/Components/Inputs/TextInput"; +import Checkbox from "../../../src/Components/Inputs/Checkbox"; +const TabComponent = ({ + type, + integrations, + handleIntegrationChange, + handleInputChange, + handleTestNotification +}) => { + const theme = useTheme(); + + // Helper to get the field state key (e.g., slackWebhook, telegramToken) + const getFieldKey = (typeId, fieldId) => { + return `${typeId}${fieldId.charAt(0).toUpperCase() + fieldId.slice(1)}`; + }; + + // Check if all fields have values to enable test button + const areAllFieldsFilled = () => { + return type.fields.every(field => { + const fieldKey = getFieldKey(type.id, field.id); + return integrations[fieldKey]; + }); + }; + + return ( + <> + + {type.label} + + + + {type.description} + + + + handleIntegrationChange(type.id, e.target.checked)} + /> + + + {type.fields.map(field => { + const fieldKey = getFieldKey(type.id, field.id); + + return ( + + + {field.label} + + + handleInputChange(fieldKey, e.target.value)} + disabled={!integrations[type.id]} + /> + + ); + })} + + + + + + ); +}; + +export default TabComponent; \ No newline at end of file