Notification Settings card

This commit is contained in:
headlesdev
2025-05-26 11:30:19 +02:00
parent d045aad2dd
commit 338c1922d0
14 changed files with 121 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ import prisma from "@/app/prisma";
import { z } from "zod/v4"
const schema = z.object({
enabled: z.boolean(),
statusChange: z.boolean(),
latencyLimit: z.number().min(0).max(100),
notificationTextStatus: z.string(),
@@ -13,18 +14,18 @@ const schema = z.object({
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency } = schema.parse(body);
const { enabled, statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency } = schema.parse(body);
const existingNotification = await prisma.applicationMonitoringNotification.findFirst();
if(!existingNotification) {
const notification = await prisma.applicationMonitoringNotification.create({
data: { statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
data: { enabled, statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
});
return NextResponse.json({ notification }, { status: 200 });
} else {
const notification = await prisma.applicationMonitoringNotification.update({
where: { id: existingNotification.id },
data: { statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
data: { enabled, statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
});
return NextResponse.json({ notification }, { status: 200 });
}

View File

@@ -3,6 +3,7 @@ import prisma from "@/app/prisma";
import { z } from "zod/v4"
const schema = z.object({
enabled: z.boolean(),
statusChange: z.boolean(),
cpuLimit: z.number().min(0).max(100),
gpuLimit: z.number().min(0).max(100),
@@ -25,18 +26,18 @@ const schema = z.object({
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature } = schema.parse(body);
const { enabled, statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature } = schema.parse(body);
const existingNotification = await prisma.serverMonitoringNotification.findFirst();
if(!existingNotification) {
const notification = await prisma.serverMonitoringNotification.create({
data: { statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
data: { enabled, statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
});
return NextResponse.json({ notification }, { status: 200 });
} else {
const notification = await prisma.serverMonitoringNotification.update({
where: { id: existingNotification.id },
data: { statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
data: { enabled, statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
});
return NextResponse.json({ notification }, { status: 200 });
}

View File

@@ -5,7 +5,8 @@ import ErrorToast from '@/components/Error';
import SuccessToast from '@/components/Success';
import { ProfileSettings } from '@/components/cards/settings/ProfileSettings';
import { PasswordSettings } from '@/components/cards/settings/PasswordSettings';
import { NotificationSettings } from '@/components/cards/settings/NotificationProviderSettings';
import { NotificationProviderSettings } from '@/components/cards/settings/NotificationProviderSettings';
import { NotificationSettings } from '@/components/cards/settings/NotificationSettings';
import { useState } from 'react';
interface SettingsPageProps {
@@ -59,6 +60,7 @@ export default function SettingsPage({ username, name, email }: SettingsPageProp
<div className="tab-content relative bg-base-100 pl-4 pt-4">
<div className="absolute -top-[3px] left-6 right-0 h-[2px] bg-stone-800"></div>
<div className="flex flex-col gap-4">
<NotificationProviderSettings onError={setError} onSuccess={setSuccess} />
<NotificationSettings onError={setError} onSuccess={setSuccess} />
</div>
</div>