diff --git a/client/src/components/AlertModals.jsx b/client/src/components/AlertModals.jsx
index 1998cdb..8968dfe 100644
--- a/client/src/components/AlertModals.jsx
+++ b/client/src/components/AlertModals.jsx
@@ -311,7 +311,12 @@ export const DetectionDetailsModal = ({ detection, onClose }) => {
Detected At:
- {format(new Date(detection.detected_at), 'MMM dd, yyyy HH:mm:ss')}
+
+ {detection.detected_at
+ ? format(new Date(detection.detected_at), 'MMM dd, yyyy HH:mm:ss')
+ : 'Unknown'
+ }
+
Device:
diff --git a/client/src/pages/Alerts.jsx b/client/src/pages/Alerts.jsx
index 7d6cfed..08c0c86 100644
--- a/client/src/pages/Alerts.jsx
+++ b/client/src/pages/Alerts.jsx
@@ -34,11 +34,15 @@ const Alerts = () => {
api.get('/alerts/stats?hours=24')
]);
- setAlertRules(rulesRes.data.data);
- setAlertLogs(logsRes.data.data);
- setAlertStats(statsRes.data.data);
+ setAlertRules(rulesRes.data?.data || []);
+ setAlertLogs(logsRes.data?.data || []);
+ setAlertStats(statsRes.data?.data || null);
} catch (error) {
console.error('Error fetching alert data:', error);
+ // Set default values on error
+ setAlertRules([]);
+ setAlertLogs([]);
+ setAlertStats(null);
} finally {
setLoading(false);
}
@@ -169,7 +173,7 @@ const Alerts = () => {
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
}`}
>
- Alert Logs ({alertLogs.length})
+ Alert Logs ({alertLogs?.length || 0})
@@ -177,7 +181,7 @@ const Alerts = () => {
{/* Alert Rules Tab */}
{activeTab === 'rules' && (
- {alertRules.length === 0 ? (
+ {(alertRules?.length || 0) === 0 ? (
No alert rules
@@ -209,7 +213,7 @@ const Alerts = () => {
- {alertRules.map((rule) => (
+ {(alertRules || []).map((rule) => (
|
@@ -232,7 +236,7 @@ const Alerts = () => {
|
- {rule.alert_channels.map((channel, index) => (
+ {(rule.alert_channels || []).map((channel, index) => (
{
{/* Alert Logs Tab */}
{activeTab === 'logs' && (
- {alertLogs.length === 0 ? (
+ {(alertLogs?.length || 0) === 0 ? (
No alert logs
@@ -320,7 +324,7 @@ const Alerts = () => {
|
- {alertLogs.map((log) => (
+ {(alertLogs || []).map((log) => (
|
|