fix: move refreshBadge into effect, add logout error handling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,15 +16,15 @@ const AdminLayout = () => {
|
||||
const [showNewOrder, setShowNewOrder] = useState(false);
|
||||
const [newCount, setNewCount] = useState(0);
|
||||
|
||||
const refreshBadge = () => {
|
||||
supabase
|
||||
.from('orders')
|
||||
.select('id', { count: 'exact', head: true })
|
||||
.eq('status', 'новая')
|
||||
.then(({ count }) => setNewCount(count || 0));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const refreshBadge = () => {
|
||||
supabase
|
||||
.from('orders')
|
||||
.select('id', { count: 'exact', head: true })
|
||||
.eq('status', 'новая')
|
||||
.then(({ count }) => setNewCount(count || 0));
|
||||
};
|
||||
|
||||
refreshBadge();
|
||||
const channel = supabase
|
||||
.channel('badge-count')
|
||||
@@ -50,11 +50,14 @@ const AdminLayout = () => {
|
||||
{title}
|
||||
</h1>
|
||||
{newCount > 0 && (
|
||||
<span style={{
|
||||
background: '#ef4444', color: '#fff',
|
||||
borderRadius: '50px', padding: '2px 9px',
|
||||
fontSize: '0.72rem', fontWeight: 700,
|
||||
}}>
|
||||
<span
|
||||
aria-label={`${newCount} новых заявок`}
|
||||
style={{
|
||||
background: '#ef4444', color: '#fff',
|
||||
borderRadius: '50px', padding: '2px 9px',
|
||||
fontSize: '0.72rem', fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{newCount} новых
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -14,7 +14,11 @@ const Sidebar = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
try {
|
||||
await logout();
|
||||
} catch (err) {
|
||||
console.error('Logout failed:', err);
|
||||
}
|
||||
navigate('/admin/login');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user