mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-22 18:06:36 +00:00
Update notification text handling in API and dashboard to support separate application and server notification texts.
This commit is contained in:
parent
49eeab4848
commit
21dd61c597
@ -7,7 +7,7 @@ export async function POST(request: NextRequest) {
|
|||||||
// Check if there are any settings entries
|
// Check if there are any settings entries
|
||||||
const existingSettings = await prisma.settings.findFirst();
|
const existingSettings = await prisma.settings.findFirst();
|
||||||
if (!existingSettings) {
|
if (!existingSettings) {
|
||||||
return NextResponse.json({ "notification_text": "" });
|
return NextResponse.json({ "notification_text_application": "", "notification_text_server": "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// If settings entry exists, fetch it
|
// If settings entry exists, fetch it
|
||||||
@ -15,10 +15,10 @@ export async function POST(request: NextRequest) {
|
|||||||
where: { id: existingSettings.id },
|
where: { id: existingSettings.id },
|
||||||
});
|
});
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
return NextResponse.json({ "notification_text": "" });
|
return NextResponse.json({ "notification_text_application": "", "notification_text_server": "" });
|
||||||
}
|
}
|
||||||
// Return the settings entry
|
// 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) {
|
} catch (error: any) {
|
||||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,14 @@ import { NextResponse, NextRequest } from "next/server";
|
|||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
interface AddRequest {
|
interface AddRequest {
|
||||||
text: string;
|
text_application: string;
|
||||||
|
text_server: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const body: AddRequest = await request.json();
|
const body: AddRequest = await request.json();
|
||||||
const { text } = body;
|
const { text_application, text_server } = body;
|
||||||
|
|
||||||
// Check if there is already a settings entry
|
// Check if there is already a settings entry
|
||||||
const existingSettings = await prisma.settings.findFirst();
|
const existingSettings = await prisma.settings.findFirst();
|
||||||
@ -16,14 +17,15 @@ export async function POST(request: NextRequest) {
|
|||||||
// Update the existing settings entry
|
// Update the existing settings entry
|
||||||
const updatedSettings = await prisma.settings.update({
|
const updatedSettings = await prisma.settings.update({
|
||||||
where: { id: existingSettings.id },
|
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 });
|
return NextResponse.json({ message: "Success", updatedSettings });
|
||||||
}
|
}
|
||||||
// If no settings entry exists, create a new one
|
// If no settings entry exists, create a new one
|
||||||
const settings = await prisma.settings.create({
|
const settings = await prisma.settings.create({
|
||||||
data: {
|
data: {
|
||||||
notification_text: text,
|
notification_text_application: text_application,
|
||||||
|
notification_text_server: text_server,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,8 @@ interface NotificationsResponse {
|
|||||||
notifications: any[]
|
notifications: any[]
|
||||||
}
|
}
|
||||||
interface NotificationResponse {
|
interface NotificationResponse {
|
||||||
notification_text?: string
|
notification_text_application?: string
|
||||||
|
notification_text_server?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Settings() {
|
export default function Settings() {
|
||||||
@ -76,7 +77,8 @@ export default function Settings() {
|
|||||||
|
|
||||||
const [notifications, setNotifications] = useState<any[]>([])
|
const [notifications, setNotifications] = useState<any[]>([])
|
||||||
|
|
||||||
const [notificationText, setNotificationText] = useState<string>("")
|
const [notificationTextApplication, setNotificationTextApplication] = useState<string>("")
|
||||||
|
const [notificationTextServer, setNotificationTextServer] = useState<string>("")
|
||||||
|
|
||||||
const changeEmail = async () => {
|
const changeEmail = async () => {
|
||||||
setEmailErrorVisible(false)
|
setEmailErrorVisible(false)
|
||||||
@ -215,10 +217,15 @@ export default function Settings() {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.post<NotificationResponse>("/api/settings/get_notification_text", {})
|
const response = await axios.post<NotificationResponse>("/api/settings/get_notification_text", {})
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
if (response.data.notification_text) {
|
if (response.data.notification_text_application) {
|
||||||
setNotificationText(response.data.notification_text)
|
setNotificationTextApplication(response.data.notification_text_application)
|
||||||
} else {
|
} 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) {
|
} catch (error: any) {
|
||||||
@ -229,7 +236,8 @@ export default function Settings() {
|
|||||||
const editNotificationText = async () => {
|
const editNotificationText = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post("/api/settings/notification_text", {
|
const response = await axios.post("/api/settings/notification_text", {
|
||||||
text: notificationText,
|
text_application: notificationTextApplication,
|
||||||
|
text_server: notificationTextServer,
|
||||||
})
|
})
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
alert(error.response.data.error)
|
alert(error.response.data.error)
|
||||||
@ -613,12 +621,22 @@ export default function Settings() {
|
|||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="text">Notification Text</Label>
|
<Label htmlFor="text_application">Notification Text for Applications</Label>
|
||||||
<Textarea
|
<Textarea
|
||||||
id="text"
|
id="text_application"
|
||||||
placeholder="Type here..."
|
placeholder="Type here..."
|
||||||
value={notificationText}
|
value={notificationTextApplication}
|
||||||
onChange={(e) => setNotificationText(e.target.value)}
|
onChange={(e) => setNotificationTextApplication(e.target.value)}
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="text_server">Notification Text for Servers</Label>
|
||||||
|
<Textarea
|
||||||
|
id="text_server"
|
||||||
|
placeholder="Type here..."
|
||||||
|
value={notificationTextServer}
|
||||||
|
onChange={(e) => setNotificationTextServer(e.target.value)}
|
||||||
rows={4}
|
rows={4}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -627,13 +645,19 @@ export default function Settings() {
|
|||||||
You can use the following placeholders in the text:
|
You can use the following placeholders in the text:
|
||||||
<ul className="list-disc list-inside space-y-1 pt-2">
|
<ul className="list-disc list-inside space-y-1 pt-2">
|
||||||
<li>
|
<li>
|
||||||
<strong>!name</strong> - Application name
|
<b>Server related:</b>
|
||||||
|
<ul className="list-disc list-inside ml-4 space-y-1 pt-1 text-muted-foreground">
|
||||||
|
<li>!name - The name of the server</li>
|
||||||
|
<li>!status - The current status of the server (online/offline)</li>
|
||||||
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>!url</strong> - Application URL
|
<b>Application related:</b>
|
||||||
</li>
|
<ul className="list-disc list-inside ml-4 space-y-1 pt-1 text-muted-foreground">
|
||||||
<li>
|
<li>!name - The name of the application</li>
|
||||||
<strong>!status</strong> - Application status (online/offline)
|
<li>!url - The URL where the application is hosted</li>
|
||||||
|
<li>!status - The current status of the application (online/offline)</li>
|
||||||
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user