diff --git a/Client/src/Pages/Integrations/index.jsx b/Client/src/Pages/Integrations/index.jsx index 376ef6657..75da41a6b 100644 --- a/Client/src/Pages/Integrations/index.jsx +++ b/Client/src/Pages/Integrations/index.jsx @@ -1,20 +1,23 @@ import PropTypes from "prop-types"; -import { Stack, Box, Typography, Grid } from "@mui/material"; +import { Stack, Typography, Grid } from "@mui/material"; import Button from "../../Components/Button"; import { useTheme } from "@emotion/react"; +import Discord from "../../assets/icons/discord-icon.svg?react"; +import Slack from "../../assets/icons/slack-icon.svg?react"; +import Zapier from "../../assets/icons/zapier-icon.svg?react"; import "./index.css"; /** * Integrations component * @param {Object} props - Props for the IntegrationsComponent. - * @param {string} props.url - The URL for the integration image. + * @param {string} props.icon - The icon for the integration image. * @param {string} props.header - The header for the integration. * @param {string} props.info - Information about the integration. * @param {Function} props.onClick - The onClick handler for the integration button. * @returns {JSX.Element} The JSX representation of the IntegrationsComponent. */ -const IntegrationsComponent = ({ url, header, info, onClick }) => { +const IntegrationsComponent = ({ icon, header, info, onClick }) => { const theme = useTheme(); return ( @@ -24,14 +27,10 @@ const IntegrationsComponent = ({ url, header, info, onClick }) => { justifyContent="space-between" gap={theme.gap.large} p={theme.gap.ml} + pl={theme.gap.large} + height="100%" > - + {icon} {header} { level="primary" onClick={onClick} sx={{ alignSelf: "center" }} + disabled={true} /> @@ -56,7 +56,7 @@ const IntegrationsComponent = ({ url, header, info, onClick }) => { // PropTypes for IntegrationsComponent IntegrationsComponent.propTypes = { - url: PropTypes.string.isRequired, + icon: PropTypes.object.isRequired, header: PropTypes.string.isRequired, info: PropTypes.string.isRequired, onClick: PropTypes.func.isRequired, @@ -72,19 +72,34 @@ const Integrations = () => { const integrations = [ { - url: "https://via.placeholder.com/80", + icon: ( + + ), header: "Slack", info: "Connect with Slack and see incidents in a channel", onClick: () => {}, }, { - url: "https://via.placeholder.com/80", + icon: ( + + ), header: "Discord", info: "Connect with Discord and view incidents directly in a channel", onClick: () => {}, }, { - url: "https://via.placeholder.com/80", + icon: ( + + ), header: "Zapier", info: "Send all incidents to Zapier, and then see them everywhere", onClick: () => {}, @@ -102,7 +117,7 @@ const Integrations = () => { {integrations.map((integration, index) => ( + + + + + + + \ No newline at end of file diff --git a/Client/src/assets/icons/slack-icon.svg b/Client/src/assets/icons/slack-icon.svg new file mode 100644 index 000000000..ff256fd4d --- /dev/null +++ b/Client/src/assets/icons/slack-icon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Client/src/assets/icons/zapier-icon.svg b/Client/src/assets/icons/zapier-icon.svg new file mode 100644 index 000000000..6ee0b5eca --- /dev/null +++ b/Client/src/assets/icons/zapier-icon.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 8f7e21453..e05ed0389 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -234,7 +234,23 @@ const editMonitor = async (req, res, next) => { try { const monitorBeforeEdit = await req.db.getMonitorById(req, res); + + // Get notifications from the request body + const notifications = req.body.notifications; + const editedMonitor = await req.db.editMonitor(req, res); + + await req.db.deleteNotificationsByMonitorId(editedMonitor._id); + + if (notifications && notifications.length !== 0) { + await Promise.all( + notifications.map(async (notification) => { + notification.monitorId = editedMonitor._id; + await req.db.createNotification(notification); + }) + ); + } + // Delete the old job(editedMonitor has the same ID as the old monitor) await req.jobQueue.deleteJob(monitorBeforeEdit); // Add the new job back to the queue diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index f82496551..9bca432c2 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -2,6 +2,7 @@ const Monitor = require("../../../models/Monitor"); const Check = require("../../../models/Check"); const PageSpeedCheck = require("../../../models/PageSpeedCheck"); const { errorMessages } = require("../../../utils/messages"); +const Notification = require("../../../models/Notification"); /** * Get all monitors @@ -63,7 +64,8 @@ const getMonitorById = async (req, res) => { createdAt: sortOrder, }) .limit(limit); - const monitorWithChecks = { ...monitor.toObject(), checks }; + const notifications = await Notification.find({ monitorId: monitor._id }); + const monitorWithChecks = { ...monitor.toObject(), checks, notifications }; return monitorWithChecks; } catch (error) { throw error; @@ -119,7 +121,12 @@ const getMonitorsByUserId = async (req, res) => { createdAt: sortOrder, }) .limit(limit); - return { ...monitor.toObject(), checks }; + + // Get notifications + const notifications = await Notification.find({ + monitorId: monitor._id, + }); + return { ...monitor.toObject(), checks, notifications }; }) ); return monitorsWithChecks; @@ -209,6 +216,8 @@ const deleteMonitorsByUserId = async (userId) => { const editMonitor = async (req, res) => { const candidateId = req.params.monitorId; const candidateMonitor = req.body; + candidateMonitor.notifications = undefined; + try { const editedMonitor = await Monitor.findByIdAndUpdate( candidateId,