ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(notifications): route config notices into the notification center; top banner = urgent only
Juan Denis9de7cc65db17
diff --git a/frontend/src/components/NotificationBell.jsx b/frontend/src/components/NotificationBell.jsxindex 14c1cb3d..f4fa285f 100644--- a/frontend/src/components/NotificationBell.jsx+++ b/frontend/src/components/NotificationBell.jsx@@ -1,6 +1,6 @@import { useState, useRef, useEffect } from 'react';import { useNavigate } from 'react-router-dom';-import { Bell, Check } from 'lucide-react';+import { Bell, Check, X } from 'lucide-react';import { useNotifications } from '../contexts/NotificationsContext';import { timeAgo } from '../utils/timeAgo';@@ -20,7 +20,7 @@ export default function NotificationBell() {const navigate = useNavigate();// The provider is only mounted for authenticated users; render nothing otherwise.- const { items = [], unreadCount = 0, markRead, markAllRead, refresh } = ctx || {};+ const { items = [], unreadCount = 0, markRead, markAllRead, refresh, dismissNotice } = ctx || {};useEffect(() => {if (!open) return undefined;@@ -45,6 +45,12 @@ export default function NotificationBell() {};const onItemClick = (item) => {+ // System notices route to their fix; bus notifications just mark read.+ if (item.kind === 'notice') {+ setOpen(false);+ if (item.action_path) navigate(item.action_path);+ return;+ }if (!item.read && markRead) markRead(item.delivery_id);};@@ -80,23 +86,54 @@ export default function NotificationBell() {<div className="sk-notif__empty">You’re all caught up.</div>) : (items.map((item) => (- <button- key={item.delivery_id}- type="button"- className={`sk-notif__item${item.read ? '' : ' is-unread'}`}- onClick={() => onItemClick(item)}- >- <span- className="sk-notif__dot"- style={{ background: SEVERITY_DOT[item.severity] || SEVERITY_DOT.info }}- aria-hidden="true"- />- <span className="sk-notif__content">- <span className="sk-notif__title">{item.title}</span>- {item.body && <span className="sk-notif__text">{item.body}</span>}- <span className="sk-notif__time">{timeAgo(item.created_at)}</span>- </span>- </button>+ item.kind === 'notice' ? (+ <div key={item.delivery_id} className="sk-notif__item is-notice">+ <button+ type="button"+ className="sk-notif__hit"+ onClick={() => onItemClick(item)}+ >+ <span+ className="sk-notif__dot"+ style={{ background: SEVERITY_DOT[item.severity] || SEVERITY_DOT.info }}+ aria-hidden="true"+ />+ <span className="sk-notif__content">+ <span className="sk-notif__title">{item.title}</span>+ {item.body && <span className="sk-notif__text">{item.body}</span>}+ {item.action_label && (+ <span className="sk-notif__time">{item.action_label} →</span>+ )}+ </span>+ </button>+ <button+ type="button"+ className="sk-notif__dismiss"+ onClick={() => dismissNotice && dismissNotice(item.notice_id)}+ aria-label={`Dismiss ${item.title}`}+ >+ <X size={14} aria-hidden="true" />+ </button>+ </div>+ ) : (+ <button+ key={item.delivery_id}+ type="button"+ className={`sk-notif__item${item.read ? '' : ' is-unread'}`}+ onClick={() => onItemClick(item)}+ >+ <span+ className="sk-notif__dot"+ style={{ background: SEVERITY_DOT[item.severity] || SEVERITY_DOT.info }}+ aria-hidden="true"+ />+ <span className="sk-notif__content">+ <span className="sk-notif__title">{item.title}</span>+ {item.body && <span className="sk-notif__text">{item.body}</span>}+ <span className="sk-notif__time">{timeAgo(item.created_at)}</span>+ </span>+ </button>+ ))))}</div>diff --git a/frontend/src/components/SystemNotices.jsx b/frontend/src/components/SystemNotices.jsxindex 0ea94dec..c06488ad 100644--- a/frontend/src/components/SystemNotices.jsx+++ b/frontend/src/components/SystemNotices.jsx@@ -3,43 +3,29 @@ import { useNavigate } from 'react-router-dom';import { AlertTriangle, Info, X, Settings, ExternalLink } from 'lucide-react';import api from '../services/api';import { Button } from '@/components/ui/button';--const STORAGE_KEY = 'serverkit_dismissed_notices';+import { getDismissedNotices, addDismissedNotice, isUrgentNotice } from '../utils/dismissedNotices';const ICONS = {warning: AlertTriangle,info: Info,error: AlertTriangle,+ critical: AlertTriangle,};-function getDismissed() {- try {- const raw = localStorage.getItem(STORAGE_KEY);- return raw ? JSON.parse(raw) : [];- } catch {- return [];- }-}--function setDismissed(ids) {- try {- localStorage.setItem(STORAGE_KEY, JSON.stringify(ids));- } catch {- // ignore- }-}-+// The top banner is reserved for genuinely urgent notices, and only one at a time —+// everything else lives in the notification center (see NotificationsContext). This+// keeps the dashboard clear instead of stacking every setup hint at the top.export default function SystemNotices() {const navigate = useNavigate();const [notices, setNotices] = useState([]);const [loading, setLoading] = useState(true);- const [dismissed, setDismissedState] = useState(getDismissed);+ const [dismissed, setDismissedState] = useState(getDismissedNotices);const load = useCallback(async () => {try {const data = await api.getSystemNotices();setNotices(data?.notices || []);- } catch (err) {+ } catch {// Non-admin or endpoint error — hide silently.setNotices([]);} finally {@@ -52,9 +38,7 @@ export default function SystemNotices() {}, [load]);const handleDismiss = (id) => {- const next = [...dismissed, id];- setDismissedState(next);- setDismissed(next);+ setDismissedState(addDismissedNotice(id).slice());};const handleAction = (notice) => {@@ -65,54 +49,47 @@ export default function SystemNotices() {}};- if (loading || notices.length === 0) return null;+ if (loading) return null;- const visible = notices.filter((n) => !dismissed.includes(n.id));- if (visible.length === 0) return null;+ // Urgent only, and at most one — the rest are surfaced in the notification bell.+ const notice = notices.find((n) => isUrgentNotice(n) && !dismissed.includes(n.id));+ if (!notice) return null;+ const Icon = ICONS[notice.level] || AlertTriangle;return (<div className="system-notices" role="region" aria-label="System notices">- {visible.map((notice) => {- const Icon = ICONS[notice.level] || Info;- return (- <div- key={notice.id}- className={`system-notice system-notice--${notice.level}`}- role="alert"+ <div className={`system-notice system-notice--${notice.level}`} role="alert">+ <span className="system-notice__icon" aria-hidden="true">+ <Icon size={18} />+ </span>+ <div className="system-notice__body">+ <div className="system-notice__title">{notice.title}</div>+ <div className="system-notice__message">{notice.message}</div>+ </div>+ <div className="system-notice__actions">+ <Button+ variant="ghost"+ size="sm"+ className="system-notice__action"+ onClick={() => handleAction(notice)}+ >+ {notice.action_label || 'Fix'}+ {notice.action_path?.startsWith('http') ? (+ <ExternalLink size={13} />+ ) : (+ <Settings size={13} />+ )}+ </Button>+ <button+ type="button"+ className="system-notice__dismiss"+ onClick={() => handleDismiss(notice.id)}+ aria-label={`Dismiss ${notice.title}`}>- <span className="system-notice__icon" aria-hidden="true">- <Icon size={18} />- </span>- <div className="system-notice__body">- <div className="system-notice__title">{notice.title}</div>- <div className="system-notice__message">{notice.message}</div>- </div>- <div className="system-notice__actions">- <Button- variant="ghost"- size="sm"- className="system-notice__action"- onClick={() => handleAction(notice)}- >- {notice.action_label || 'Fix'}- {notice.action_path?.startsWith('http') ? (- <ExternalLink size={13} />- ) : (- <Settings size={13} />- )}- </Button>- <button- type="button"- className="system-notice__dismiss"- onClick={() => handleDismiss(notice.id)}- aria-label={`Dismiss ${notice.title}`}- >- <X size={16} />- </button>- </div>- </div>- );- })}+ <X size={16} />+ </button>+ </div>+ </div></div>);}diff --git a/frontend/src/contexts/NotificationsContext.jsx b/frontend/src/contexts/NotificationsContext.jsxindex d766d7bd..98b71fe0 100644--- a/frontend/src/contexts/NotificationsContext.jsx+++ b/frontend/src/contexts/NotificationsContext.jsx@@ -2,10 +2,15 @@ import { createContext, useContext, useState, useEffect, useCallback } from 'reaimport api from '../services/api';import socketService from '../services/socket';import { useAuth } from './AuthContext';+import { getDismissedNotices, addDismissedNotice, noticeToItem } from '../utils/dismissedNotices';// Global in-app notification state: the bell's unread badge + recent list, kept// live via the Socket.IO 'notification' push (see services/socket.js). The full// history page paginates independently; this context holds only the recent slice.+//+// It also folds in live "system notices" (admin misconfiguration hints from+// /system/notices) so they surface in the notification center instead of stacking+// as banners at the top of the dashboard — only genuinely urgent ones get a banner.const NotificationsContext = createContext(null);const RECENT_LIMIT = 12;@@ -16,37 +21,47 @@ export function useNotifications() {}export function NotificationsProvider({ children }) {- const { isAuthenticated } = useAuth();+ const { isAuthenticated, isAdmin } = useAuth();const [items, setItems] = useState([]);- const [unreadCount, setUnreadCount] = useState(0);+ const [busUnread, setBusUnread] = useState(0);const [loading, setLoading] = useState(false);const refresh = useCallback(async () => {if (!isAuthenticated) return;setLoading(true);try {- const data = await api.getInbox({ limit: RECENT_LIMIT });- setItems(data.items || []);- setUnreadCount(data.unread_count || 0);+ const [inbox, noticesRes] = await Promise.all([+ api.getInbox({ limit: RECENT_LIMIT }),+ isAdmin+ ? api.getSystemNotices().catch(() => ({ notices: [] }))+ : Promise.resolve({ notices: [] }),+ ]);+ const dismissed = getDismissedNotices();+ const noticeItems = (noticesRes?.notices || [])+ .filter((n) => !dismissed.includes(n.id))+ .map(noticeToItem);+ // Standing config notices sit above the recent bus deliveries.+ setItems([...noticeItems, ...(inbox.items || [])]);+ setBusUnread(inbox.unread_count || 0);} catch {// Non-fatal: the bell just stays at its last known state.} finally {setLoading(false);}- }, [isAuthenticated]);+ }, [isAuthenticated, isAdmin]);useEffect(() => {if (!isAuthenticated) {socketService.disconnect();setItems([]);- setUnreadCount(0);+ setBusUnread(0);return undefined;}refresh();socketService.connect();const off = socketService.on('notification', (n) => {setItems((prev) => [{ ...n, read: false }, ...prev].slice(0, MAX_BUFFERED));- setUnreadCount((count) => count + 1);+ setBusUnread((count) => count + 1);});return off;}, [isAuthenticated, refresh]);@@ -57,15 +72,16 @@ export function NotificationsProvider({ children }) {)));try {const res = await api.markNotificationRead(deliveryId);- if (res && typeof res.unread_count === 'number') setUnreadCount(res.unread_count);+ if (res && typeof res.unread_count === 'number') setBusUnread(res.unread_count);} catch {// ignore — the next refresh reconciles}}, []);const markAllRead = useCallback(async () => {- setItems((prev) => prev.map((it) => ({ ...it, read: true })));- setUnreadCount(0);+ // Notices aren't "read" — they clear when fixed or dismissed, so leave them.+ setItems((prev) => prev.map((it) => (it.kind === 'notice' ? it : { ...it, read: true })));+ setBusUnread(0);try {await api.markAllNotificationsRead();} catch {@@ -73,7 +89,15 @@ export function NotificationsProvider({ children }) {}}, []);- const value = { items, unreadCount, loading, refresh, markRead, markAllRead };+ const dismissNotice = useCallback((noticeId) => {+ addDismissedNotice(noticeId);+ setItems((prev) => prev.filter((it) => it.notice_id !== noticeId));+ }, []);++ const noticeCount = items.reduce((n, it) => (it.kind === 'notice' ? n + 1 : n), 0);+ const unreadCount = busUnread + noticeCount;++ const value = { items, unreadCount, loading, refresh, markRead, markAllRead, dismissNotice };return (<NotificationsContext.Provider value={value}>{children}diff --git a/frontend/src/pages/Notifications.jsx b/frontend/src/pages/Notifications.jsxindex 526109ac..fa62992b 100644--- a/frontend/src/pages/Notifications.jsx+++ b/frontend/src/pages/Notifications.jsx@@ -1,6 +1,6 @@import { useState, useEffect, useCallback } from 'react';import { useNavigate } from 'react-router-dom';-import { Bell, CheckCheck, ScrollText } from 'lucide-react';+import { Bell, CheckCheck, ScrollText, X } from 'lucide-react';import api from '../services/api';import { PageTopbar } from '@/components/ds';import { Button } from '@/components/ui/button';@@ -21,7 +21,7 @@ const PAGE_SIZE = 25;export default function Notifications() {const navigate = useNavigate();const { isAdmin } = useAuth();- const { refresh: refreshBell } = useNotifications() || {};+ const { refresh: refreshBell, items: ctxItems = [], dismissNotice } = useNotifications() || {};const [items, setItems] = useState([]);const [unreadOnly, setUnreadOnly] = useState(false);const [unreadCount, setUnreadCount] = useState(0);@@ -62,6 +62,10 @@ export default function Notifications() {if (refreshBell) refreshBell();};+ // Live system notices (admin config hints) come from the shared context so they+ // surface here too, above the bus history.+ const noticeItems = (ctxItems || []).filter((it) => it.kind === 'notice');+return (<><PageTopbar@@ -104,15 +108,43 @@ export default function Notifications() {</button></div>- {loading && items.length === 0 ? (+ {loading && items.length === 0 && noticeItems.length === 0 ? (<div className="sk-notif-page__state">Loading…</div>- ) : items.length === 0 ? (+ ) : items.length === 0 && noticeItems.length === 0 ? (<div className="sk-notif-page__state"><Bell size={26} aria-hidden="true" /><p>{unreadOnly ? 'No unread notifications.' : 'No notifications yet.'}</p></div>) : (<ul className="sk-notif-page__list">+ {noticeItems.map((item) => (+ <li+ key={item.delivery_id}+ className="sk-notif-row is-unread is-notice"+ onClick={() => item.action_path && navigate(item.action_path)}+ >+ <span+ className="sk-notif-row__dot"+ style={{ background: SEVERITY_DOT[item.severity] || SEVERITY_DOT.info }}+ aria-hidden="true"+ />+ <div className="sk-notif-row__body">+ <div className="sk-notif-row__title">{item.title}</div>+ {item.body && <div className="sk-notif-row__text">{item.body}</div>}+ {item.action_label && (+ <div className="sk-notif-row__action">{item.action_label} →</div>+ )}+ </div>+ <button+ type="button"+ className="sk-notif-row__dismiss"+ onClick={(e) => { e.stopPropagation(); if (dismissNotice) dismissNotice(item.notice_id); }}+ aria-label={`Dismiss ${item.title}`}+ >+ <X size={15} aria-hidden="true" />+ </button>+ </li>+ ))}{items.map((item) => (<likey={item.delivery_id}diff --git a/frontend/src/styles/components/_notification-center.scss b/frontend/src/styles/components/_notification-center.scssindex 556eec5f..799cd67e 100644--- a/frontend/src/styles/components/_notification-center.scss+++ b/frontend/src/styles/components/_notification-center.scss@@ -155,6 +155,38 @@opacity: 0.8;}+ // System-notice rows are a div (clickable hit area + a dismiss button) rather+ // than a single button, so they can carry a "Fix" action and an X to dismiss.+ &__item.is-notice { cursor: default; }++ &__hit {+ display: flex;+ gap: 10px;+ flex: 1;+ min-width: 0;+ padding: 0;+ border: none;+ background: none;+ cursor: pointer;+ text-align: left;+ color: inherit;+ }++ &__dismiss {+ flex: 0 0 auto;+ align-self: flex-start;+ margin-top: 2px;+ padding: 2px;+ border: none;+ background: none;+ border-radius: 6px;+ cursor: pointer;+ color: $text-secondary;+ line-height: 0;++ &:hover { background: $bg-hover; color: $text-primary; }+ }+&__seeall {padding: 11px 14px;border: none;diff --git a/frontend/src/styles/pages/_notification-center.scss b/frontend/src/styles/pages/_notification-center.scssindex 44f8222d..f7ee5768 100644--- a/frontend/src/styles/pages/_notification-center.scss+++ b/frontend/src/styles/pages/_notification-center.scss@@ -105,6 +105,27 @@opacity: 0.8;white-space: nowrap;}++ &__action {+ margin-top: 4px;+ font-size: 12px;+ font-weight: 500;+ color: $accent-primary;+ }++ &__dismiss {+ flex: 0 0 auto;+ align-self: flex-start;+ padding: 2px;+ border: none;+ background: none;+ border-radius: 6px;+ cursor: pointer;+ color: $text-secondary;+ line-height: 0;++ &:hover { background: $bg-hover; color: $text-primary; }+ }}// Admin delivery log (sk-dlog).diff --git a/frontend/src/utils/dismissedNotices.js b/frontend/src/utils/dismissedNotices.jsnew file mode 100644index 00000000..c1302cda--- /dev/null+++ b/frontend/src/utils/dismissedNotices.js@@ -0,0 +1,54 @@+// System notices ("common misconfiguration" hints from GET /system/notices) are+// surfaced in two places — the top banner (SystemNotices) for urgent ones, and the+// notification center (bell + page) for the rest. These helpers keep both surfaces+// in sync: dismissing a notice anywhere persists here and clears it everywhere.++const STORAGE_KEY = 'serverkit_dismissed_notices';++export function getDismissedNotices() {+ try {+ const raw = localStorage.getItem(STORAGE_KEY);+ return raw ? JSON.parse(raw) : [];+ } catch {+ return [];+ }+}++export function addDismissedNotice(id) {+ const ids = getDismissedNotices();+ if (!ids.includes(id)) {+ ids.push(id);+ try {+ localStorage.setItem(STORAGE_KEY, JSON.stringify(ids));+ } catch {+ // ignore — dismissal is best-effort+ }+ }+ return ids;+}++// Only genuinely urgent notices earn a top banner; everything else lives in the+// notification center. Backend can force one with `urgent: true`; otherwise the+// error/critical levels qualify (the setup-hint notices are warning/info).+export function isUrgentNotice(notice) {+ return notice.urgent === true+ || notice.level === 'error'+ || notice.level === 'critical';+}++// Map a /system/notices entry onto the notification-center item shape so it renders+// alongside Notification Bus deliveries in the bell and the Notifications page.+export function noticeToItem(notice) {+ return {+ delivery_id: `notice:${notice.id}`,+ kind: 'notice',+ notice_id: notice.id,+ severity: notice.level === 'error' ? 'critical' : (notice.level || 'info'),+ title: notice.title,+ body: notice.message,+ action_label: notice.action_label,+ action_path: notice.action_path,+ created_at: null,+ read: false,+ };+}