Refactor dashboard notification handling and improve admin broadcast functionality. Ensure only admins can access global notifications, implement draft management for broadcast messages, and add event listeners for real-time updates across dashboard components.
Some checks failed
CI / Bot (Python) (push) Successful in 12s
CI / Dashboard (Next.js) (push) Failing after 9s

This commit is contained in:
TheOnlyMace
2026-07-21 22:30:08 +02:00
parent 18ef29f777
commit 60390009d1
2 changed files with 114 additions and 30 deletions

View File

@@ -69,9 +69,15 @@ export default function DashboardLayout({
if (status === "unauthenticated") {
signIn("discord");
}
// Fetch global notification
if (status !== "authenticated") return;
const fetchNotification = async () => {
// Only admins can read admin config — skip for everyone else
if (!isAdmin(session?.user?.id)) {
setGlobalNotification(null);
return;
}
try {
const config = await api.getAdminConfig();
setGlobalNotification(config.global_notification);
@@ -79,8 +85,15 @@ export default function DashboardLayout({
console.error("Failed to fetch notifications:", err);
}
};
fetchNotification();
}, [status]);
const onBroadcastUpdated = () => {
fetchNotification();
};
window.addEventListener("axiom:broadcast-updated", onBroadcastUpdated);
return () => window.removeEventListener("axiom:broadcast-updated", onBroadcastUpdated);
}, [status, session?.user?.id]);
if (status === "loading" || status === "unauthenticated") {
return (
@@ -367,7 +380,17 @@ export default function DashboardLayout({
<div className="flex items-center justify-between mb-4 border-b border-white/5 pb-2">
<p className="text-[10px] font-black text-slate-500 uppercase tracking-[0.2em]">Broadcast Metrics</p>
<button
onClick={() => setGlobalNotification(null)}
type="button"
onClick={async () => {
setGlobalNotification(null);
if (isAdmin(session?.user?.id)) {
try {
await api.updateAdminConfig({ global_notification: "" });
} catch (err) {
console.error("Failed to clear broadcast:", err);
}
}
}}
className="text-[10px] font-bold text-primary/60 hover:text-primary transition-colors uppercase"
>
Clear