feat: Add admin access denial alert to Dashboard with timeout handling
This commit is contained in:
1 parent
430a928df6
commit
bd694b30a6
2 files changed
+34
-8
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { Check, Brain } from 'lucide-react'
|
||||
import {
|
||||
LineChart, Line, XAxis, YAxis, Tooltip,
|
||||
@@ -252,8 +252,11 @@ function ComboChart({ weights, nutrition }) {
|
||||
// ── Main Dashboard ────────────────────────────────────────────────────────────
|
||||
export default function Dashboard() {
|
||||
const nav = useNavigate()
|
||||
const location = useLocation()
|
||||
const { activeProfile } = useProfile()
|
||||
|
||||
const [adminDeniedHint, setAdminDeniedHint] = useState(false)
|
||||
|
||||
const [stats, setStats] = useState(null)
|
||||
const [weights, setWeights] = useState([])
|
||||
const [calipers, setCalipers] = useState([])
|
||||
@@ -299,6 +302,14 @@ export default function Dashboard() {
|
||||
|
||||
useEffect(()=>{ load() },[])
|
||||
|
||||
useEffect(() => {
|
||||
if (!location.state?.adminDenied) return
|
||||
setAdminDeniedHint(true)
|
||||
nav('.', { replace: true, state: null })
|
||||
const clear = window.setTimeout(() => setAdminDeniedHint(false), 8000)
|
||||
return () => window.clearTimeout(clear)
|
||||
}, [location.state, nav])
|
||||
|
||||
if (loading) return <div className="empty-state"><div className="spinner"/></div>
|
||||
|
||||
const latestCal = calipers[0]
|
||||
@@ -349,6 +360,24 @@ export default function Dashboard() {
|
||||
|
||||
return (
|
||||
<div className="dashboard-page">
|
||||
{adminDeniedHint && (
|
||||
<div
|
||||
role="alert"
|
||||
style={{
|
||||
marginBottom: 14,
|
||||
padding: '12px 14px',
|
||||
borderRadius: 10,
|
||||
background: '#FCEBEB',
|
||||
border: '1px solid #D85A3033',
|
||||
fontSize: 13,
|
||||
color: '#D85A30',
|
||||
lineHeight: 1.5,
|
||||
}}
|
||||
>
|
||||
<strong>Kein Admin-Zugriff.</strong> Dieser Bereich ist nur für Konten mit Administrator-Rolle.
|
||||
Du wurdest zur Übersicht weitergeleitet.
|
||||
</div>
|
||||
)}
|
||||
{/* Header greeting */}
|
||||
<div className="dashboard-greeting">
|
||||
<h1 style={{fontSize:22,fontWeight:800,margin:0,color:'var(--text1)'}}>
|
||||
|
||||
Reference in new issue
Block a user