fix: move refreshBadge into effect, add logout error handling

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 20:16:44 +03:00
parent 735d0a88cb
commit bb8d20a853
2 changed files with 21 additions and 14 deletions
+16 -13
View File
@@ -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>
)}
+5 -1
View File
@@ -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');
};