Fix: Correctly update notification status

- This fix ensures that when the notification status is enabled. Resolves the issue where the status was incorrectly shown as false in PB.
This commit is contained in:
Tola Leng
2025-08-11 17:33:08 +07:00
parent 2ca7c35c69
commit aecf16ba40
2 changed files with 24 additions and 17 deletions
@@ -1,3 +1,4 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -25,7 +26,7 @@ interface EditServerDialogProps {
interface ServerFormData { interface ServerFormData {
name: string; name: string;
check_interval: number; check_interval: number;
retry_attempts: number; max_retries: number;
docker_monitoring: boolean; docker_monitoring: boolean;
notification_enabled: boolean; notification_enabled: boolean;
notification_channels: string[]; // Changed to array for multiple selections notification_channels: string[]; // Changed to array for multiple selections
@@ -49,7 +50,7 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
const [formData, setFormData] = useState<ServerFormData>({ const [formData, setFormData] = useState<ServerFormData>({
name: "", name: "",
check_interval: 60, check_interval: 60,
retry_attempts: 3, max_retries: 3,
docker_monitoring: false, docker_monitoring: false,
notification_enabled: false, notification_enabled: false,
notification_channels: [], // Changed to array notification_channels: [], // Changed to array
@@ -86,9 +87,9 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
setFormData({ setFormData({
name: server.name || "", name: server.name || "",
check_interval: server.check_interval || 60, check_interval: server.check_interval || 60,
retry_attempts: 3, max_retries: server.max_retries || 3,
docker_monitoring: server.docker === "true", docker_monitoring: server.docker === "true",
notification_enabled: notificationChannels.length > 0, notification_enabled: server.notification_status === true,
notification_channels: notificationChannels, notification_channels: notificationChannels,
threshold_id: server.threshold_id || "none", threshold_id: server.threshold_id || "none",
template_id: server.template_id || "none", template_id: server.template_id || "none",
@@ -237,7 +238,9 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
const updateData = { const updateData = {
name: formData.name, name: formData.name,
check_interval: formData.check_interval, check_interval: formData.check_interval,
max_retries: formData.max_retries,
docker: formData.docker_monitoring ? "true" : "false", docker: formData.docker_monitoring ? "true" : "false",
notification_status: formData.notification_enabled,
notification_id: notificationChannelsString, notification_id: notificationChannelsString,
threshold_id: formData.notification_enabled && formData.threshold_id !== "none" ? formData.threshold_id : "", threshold_id: formData.notification_enabled && formData.threshold_id !== "none" ? formData.threshold_id : "",
template_id: formData.notification_enabled && formData.template_id !== "none" ? formData.template_id : "", template_id: formData.notification_enabled && formData.template_id !== "none" ? formData.template_id : "",
@@ -251,7 +254,7 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
try { try {
const updateThresholdData = { const updateThresholdData = {
cpu_threshold: thresholdFormData.cpu_threshold, cpu_threshold: thresholdFormData.cpu_threshold,
ram_threshold_message: thresholdFormData.ram_threshold, // Use the correct field name ram_threshold_message: thresholdFormData.ram_threshold,
disk_threshold: thresholdFormData.disk_threshold, disk_threshold: thresholdFormData.disk_threshold,
network_threshold: thresholdFormData.network_threshold, network_threshold: thresholdFormData.network_threshold,
}; };
@@ -308,9 +311,9 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
setFormData({ setFormData({
name: server.name || "", name: server.name || "",
check_interval: server.check_interval || 60, check_interval: server.check_interval || 60,
retry_attempts: 3, max_retries: server.max_retries || 3,
docker_monitoring: server.docker === "true", docker_monitoring: server.docker === "true",
notification_enabled: notificationChannels.length > 0, notification_enabled: server.notification_status === true,
notification_channels: notificationChannels, notification_channels: notificationChannels,
threshold_id: server.threshold_id || "none", threshold_id: server.threshold_id || "none",
template_id: server.template_id || "none", template_id: server.template_id || "none",
@@ -359,20 +362,20 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
</div> </div>
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="retryAttempts">Retry Attempts</Label> <Label htmlFor="maxRetries">Max Retries</Label>
<Select <Select
value={formData.retry_attempts.toString()} value={formData.max_retries.toString()}
onValueChange={(value) => setFormData(prev => ({ ...prev, retry_attempts: parseInt(value) }))} onValueChange={(value) => setFormData(prev => ({ ...prev, max_retries: parseInt(value) }))}
> >
<SelectTrigger> <SelectTrigger>
<SelectValue placeholder="Select retry attempts" /> <SelectValue placeholder="Select max retries" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="1">1 attempt</SelectItem> <SelectItem value="1">1 retry</SelectItem>
<SelectItem value="2">2 attempts</SelectItem> <SelectItem value="2">2 retries</SelectItem>
<SelectItem value="3">3 attempts</SelectItem> <SelectItem value="3">3 retries</SelectItem>
<SelectItem value="5">5 attempts</SelectItem> <SelectItem value="5">5 retries</SelectItem>
<SelectItem value="10">10 attempts</SelectItem> <SelectItem value="10">10 retries</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>
@@ -669,3 +672,5 @@ export const EditServerDialog: React.FC<EditServerDialogProps> = ({
</Dialog> </Dialog>
); );
}; };
export default EditServerDialog;
+2
View File
@@ -21,6 +21,8 @@ export interface Server {
template_id: string; template_id: string;
threshold_id: string; threshold_id: string;
notification_id: string; notification_id: string;
notification_status: boolean;
max_retries: number;
timestamp: string; timestamp: string;
connection: string; connection: string;
agent_status: string; agent_status: string;