From 21dd61c597ec3fe1bcca137feeb6cedd1be776ff Mon Sep 17 00:00:00 2001 From: headlessdev Date: Mon, 21 Apr 2025 13:22:40 +0200 Subject: [PATCH] Update notification text handling in API and dashboard to support separate application and server notification texts. --- .../settings/get_notification_text/route.ts | 6 +-- app/api/settings/notification_text/route.ts | 10 ++-- app/dashboard/settings/Settings.tsx | 54 +++++++++++++------ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/api/settings/get_notification_text/route.ts b/app/api/settings/get_notification_text/route.ts index 65f3a1d..0c210e2 100644 --- a/app/api/settings/get_notification_text/route.ts +++ b/app/api/settings/get_notification_text/route.ts @@ -7,7 +7,7 @@ export async function POST(request: NextRequest) { // Check if there are any settings entries const existingSettings = await prisma.settings.findFirst(); if (!existingSettings) { - return NextResponse.json({ "notification_text": "" }); + return NextResponse.json({ "notification_text_application": "", "notification_text_server": "" }); } // If settings entry exists, fetch it @@ -15,10 +15,10 @@ export async function POST(request: NextRequest) { where: { id: existingSettings.id }, }); if (!settings) { - return NextResponse.json({ "notification_text": "" }); + return NextResponse.json({ "notification_text_application": "", "notification_text_server": "" }); } // Return the settings entry - return NextResponse.json({ "notification_text": settings.notification_text }); + return NextResponse.json({ "notification_text_application": settings.notification_text_application, "notification_text_server": settings.notification_text_server }); } catch (error: any) { return NextResponse.json({ error: error.message }, { status: 500 }); } diff --git a/app/api/settings/notification_text/route.ts b/app/api/settings/notification_text/route.ts index 0a37722..16ae26b 100644 --- a/app/api/settings/notification_text/route.ts +++ b/app/api/settings/notification_text/route.ts @@ -2,13 +2,14 @@ import { NextResponse, NextRequest } from "next/server"; import { prisma } from "@/lib/prisma"; interface AddRequest { - text: string; + text_application: string; + text_server: string; } export async function POST(request: NextRequest) { try { const body: AddRequest = await request.json(); - const { text } = body; + const { text_application, text_server } = body; // Check if there is already a settings entry const existingSettings = await prisma.settings.findFirst(); @@ -16,14 +17,15 @@ export async function POST(request: NextRequest) { // Update the existing settings entry const updatedSettings = await prisma.settings.update({ where: { id: existingSettings.id }, - data: { notification_text: text }, + data: { notification_text_application: text_application, notification_text_server: text_server }, }); return NextResponse.json({ message: "Success", updatedSettings }); } // If no settings entry exists, create a new one const settings = await prisma.settings.create({ data: { - notification_text: text, + notification_text_application: text_application, + notification_text_server: text_server, } }); diff --git a/app/dashboard/settings/Settings.tsx b/app/dashboard/settings/Settings.tsx index e006d2a..3e714e6 100644 --- a/app/dashboard/settings/Settings.tsx +++ b/app/dashboard/settings/Settings.tsx @@ -39,7 +39,8 @@ interface NotificationsResponse { notifications: any[] } interface NotificationResponse { - notification_text?: string + notification_text_application?: string + notification_text_server?: string } export default function Settings() { @@ -76,7 +77,8 @@ export default function Settings() { const [notifications, setNotifications] = useState([]) - const [notificationText, setNotificationText] = useState("") + const [notificationTextApplication, setNotificationTextApplication] = useState("") + const [notificationTextServer, setNotificationTextServer] = useState("") const changeEmail = async () => { setEmailErrorVisible(false) @@ -215,10 +217,15 @@ export default function Settings() { try { const response = await axios.post("/api/settings/get_notification_text", {}) if (response.status === 200) { - if (response.data.notification_text) { - setNotificationText(response.data.notification_text) + if (response.data.notification_text_application) { + setNotificationTextApplication(response.data.notification_text_application) } else { - setNotificationText("The application !name (!url) is now !status.") + setNotificationTextApplication("The application !name (!url) is now !status.") + } + if (response.data.notification_text_server) { + setNotificationTextServer(response.data.notification_text_server) + } else { + setNotificationTextServer("The server !name is now !status.") } } } catch (error: any) { @@ -229,7 +236,8 @@ export default function Settings() { const editNotificationText = async () => { try { const response = await axios.post("/api/settings/notification_text", { - text: notificationText, + text_application: notificationTextApplication, + text_server: notificationTextServer, }) } catch (error: any) { alert(error.response.data.error) @@ -613,12 +621,22 @@ export default function Settings() {
- +