From 4a8759f627893e613ce8714eb95895f1655aa24f Mon Sep 17 00:00:00 2001 From: headlessdev Date: Thu, 17 Apr 2025 15:25:43 +0200 Subject: [PATCH] Notifications Display & Delete Notifications --- app/dashboard/settings/Settings.tsx | 49 +++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/app/dashboard/settings/Settings.tsx b/app/dashboard/settings/Settings.tsx index 4b2d68b..95ccb21 100644 --- a/app/dashboard/settings/Settings.tsx +++ b/app/dashboard/settings/Settings.tsx @@ -28,7 +28,7 @@ import { AccordionTrigger, } from "@/components/ui/accordion" import { Input } from "@/components/ui/input" -import { useState } from "react"; +import { useEffect, useState } from "react"; import axios from "axios"; import Cookies from "js-cookie"; import { Button } from "@/components/ui/button"; @@ -77,6 +77,8 @@ export default function Settings() { const [telegramChatId, setTelegramChatId] = useState("") const [discordWebhook, setDiscordWebhook] = useState("") + const [notifications, setNotifications] = useState([]) + const changeEmail = async () => { setEmailErrorVisible(false); setEmailSuccess(false); @@ -185,13 +187,30 @@ export default function Settings() { id: id }); if (response.status === 200) { - alert("Notification deleted successfully"); + getNotifications() } } catch (error: any) { alert(error.response.data.error); } } + const getNotifications = async () => { + try { + const response = await axios.post('/api/notifications/get', {}); + if (response.status === 200 && response.data) { + console.log(response.data.notifications) + setNotifications(response.data.notifications); + } + } + catch (error: any) { + alert(error.response.data.error); + } + } + + useEffect(() => { + getNotifications() + }, []) + return ( @@ -449,6 +468,32 @@ export default function Settings() { + +
+ {notifications.length > 0 ? ( + notifications.map((notification) => ( +
+
+

{notification.type}

+
+ +
+ )) + ) : ( +
+ No notifications configured +
+ )} +