Compare commits
4 Commits
ea8441d4be
...
76c974bcd0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76c974bcd0 | ||
|
|
b2f75562e7 | ||
|
|
750ad525c8 | ||
|
|
4b0d84f2a0 |
@@ -515,18 +515,6 @@ apiRouter.get('/notifications', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
apiRouter.put('/notifications/:id', async (req, res) => {
|
|
||||||
try {
|
|
||||||
await pool.query(
|
|
||||||
'UPDATE notifications SET is_read = true WHERE id = ? AND user_id = ?',
|
|
||||||
[req.params.id, req.user.id]
|
|
||||||
);
|
|
||||||
res.json({ message: 'Notification marked as read' });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ error: error.message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
apiRouter.put('/notifications/read-all', async (req, res) => {
|
apiRouter.put('/notifications/read-all', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
await pool.query(
|
await pool.query(
|
||||||
@@ -539,6 +527,30 @@ apiRouter.put('/notifications/read-all', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apiRouter.put('/notifications/:id', async (req, res) => {
|
||||||
|
try {
|
||||||
|
await pool.query(
|
||||||
|
'UPDATE notifications SET is_read = true WHERE id = ? AND user_id = ?',
|
||||||
|
[req.params.id, req.user.id]
|
||||||
|
);
|
||||||
|
res.json({ message: 'Notification marked as read' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
apiRouter.delete('/notifications/clear-all', async (req, res) => {
|
||||||
|
try {
|
||||||
|
await pool.query(
|
||||||
|
'DELETE FROM notifications WHERE user_id = ?',
|
||||||
|
[req.user.id]
|
||||||
|
);
|
||||||
|
res.json({ message: 'All notifications deleted' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
apiRouter.delete('/notifications/:id', async (req, res) => {
|
apiRouter.delete('/notifications/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
await pool.query(
|
await pool.query(
|
||||||
@@ -551,18 +563,6 @@ apiRouter.delete('/notifications/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
apiRouter.delete('/notifications', async (req, res) => {
|
|
||||||
try {
|
|
||||||
await pool.query(
|
|
||||||
'DELETE FROM notifications WHERE user_id = ?',
|
|
||||||
[req.user.id]
|
|
||||||
);
|
|
||||||
res.json({ message: 'All notifications deleted' });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ error: error.message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- Funnel Routes ---
|
// --- Funnel Routes ---
|
||||||
apiRouter.get('/funnels', async (req, res) => {
|
apiRouter.get('/funnels', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -918,6 +918,25 @@ apiRouter.put('/teams/:id', requireRole(['admin', 'owner', 'super_admin']), asyn
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apiRouter.delete('/teams/:id', requireRole(['admin', 'owner', 'super_admin']), async (req, res) => {
|
||||||
|
try {
|
||||||
|
const [existing] = await pool.query('SELECT tenant_id FROM teams WHERE id = ?', [req.params.id]);
|
||||||
|
if (existing.length === 0) return res.status(404).json({ error: 'Not found' });
|
||||||
|
if (req.user.role !== 'super_admin' && existing[0].tenant_id !== req.user.tenant_id) {
|
||||||
|
return res.status(403).json({ error: 'Acesso negado.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set users team_id to NULL to prevent orphan foreign key issues if constrained
|
||||||
|
await pool.query('UPDATE users SET team_id = NULL WHERE team_id = ?', [req.params.id]);
|
||||||
|
await pool.query('DELETE FROM teams WHERE id = ?', [req.params.id]);
|
||||||
|
|
||||||
|
res.json({ message: 'Team deleted successfully.' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Delete team error:', error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
apiRouter.post('/tenants', requireRole(['super_admin']), async (req, res) => {
|
apiRouter.post('/tenants', requireRole(['super_admin']), async (req, res) => {
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import { NavLink, useLocation, useNavigate } from 'react-router-dom';
|
import { NavLink, useLocation, useNavigate } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
LayoutDashboard, Users, UserCircle, Bell, Search, Menu, X, LogOut,
|
LayoutDashboard, Users, UserCircle, Bell, Search, Menu, X, LogOut,
|
||||||
Hexagon, Settings, Building2, Sun, Moon, Loader2, Layers
|
Hexagon, Settings, Building2, Sun, Moon, Loader2, Layers,
|
||||||
|
ChevronLeft, ChevronRight
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import {
|
import {
|
||||||
getAttendances, getUsers, getUserById, logout, searchGlobal,
|
getAttendances, getUsers, getUserById, logout, searchGlobal,
|
||||||
@@ -10,6 +11,7 @@ import {
|
|||||||
deleteNotification, clearAllNotifications, returnToSuperAdmin
|
deleteNotification, clearAllNotifications, returnToSuperAdmin
|
||||||
} from '../services/dataService';
|
} from '../services/dataService';
|
||||||
import { User } from '../types';
|
import { User } from '../types';
|
||||||
|
import notificationSound from '../src/assets/audio/notification.mp3';
|
||||||
|
|
||||||
const SidebarItem = ({ to, icon: Icon, label, collapsed }: { to: string, icon: any, label: string, collapsed: boolean }) => (
|
const SidebarItem = ({ to, icon: Icon, label, collapsed }: { to: string, icon: any, label: string, collapsed: boolean }) => (
|
||||||
<NavLink
|
<NavLink
|
||||||
@@ -29,11 +31,20 @@ const SidebarItem = ({ to, icon: Icon, label, collapsed }: { to: string, icon: a
|
|||||||
|
|
||||||
export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||||
|
const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(() => {
|
||||||
|
return localStorage.getItem('ctms_sidebar_collapsed') === 'true';
|
||||||
|
});
|
||||||
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'));
|
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'));
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [currentUser, setCurrentUser] = useState<User | null>(null);
|
const [currentUser, setCurrentUser] = useState<User | null>(null);
|
||||||
|
|
||||||
|
const toggleSidebar = () => {
|
||||||
|
const newState = !isSidebarCollapsed;
|
||||||
|
setIsSidebarCollapsed(newState);
|
||||||
|
localStorage.setItem('ctms_sidebar_collapsed', String(newState));
|
||||||
|
};
|
||||||
|
|
||||||
// Search State
|
// Search State
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
const [searchResults, setSearchResults] = useState<{ members: User[], teams: any[], attendances: any[], organizations?: any[] }>({ members: [], teams: [], attendances: [], organizations: [] });
|
const [searchResults, setSearchResults] = useState<{ members: User[], teams: any[], attendances: any[], organizations?: any[] }>({ members: [], teams: [], attendances: [], organizations: [] });
|
||||||
@@ -49,12 +60,6 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
|
|
||||||
// Pre-initialize audio to ensure it's loaded and ready
|
// Pre-initialize audio to ensure it's loaded and ready
|
||||||
const audioRef = React.useRef<HTMLAudioElement | null>(null);
|
const audioRef = React.useRef<HTMLAudioElement | null>(null);
|
||||||
useEffect(() => {
|
|
||||||
// Determine base path correctly whether in prod or dev
|
|
||||||
const basePath = import.meta.env.PROD ? '' : 'http://localhost:3001';
|
|
||||||
audioRef.current = new Audio(`${basePath}/audio/notification.mp3`);
|
|
||||||
audioRef.current.volume = 0.5;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const playNotificationSound = () => {
|
const playNotificationSound = () => {
|
||||||
if (currentUser?.sound_enabled !== false && audioRef.current) {
|
if (currentUser?.sound_enabled !== false && audioRef.current) {
|
||||||
@@ -69,7 +74,6 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
|
|
||||||
const loadNotifications = async () => {
|
const loadNotifications = async () => {
|
||||||
const data = await getNotifications();
|
const data = await getNotifications();
|
||||||
setNotifications(data);
|
|
||||||
|
|
||||||
const newUnreadCount = data.filter((n: any) => !n.is_read).length;
|
const newUnreadCount = data.filter((n: any) => !n.is_read).length;
|
||||||
|
|
||||||
@@ -78,10 +82,24 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
playNotificationSound();
|
playNotificationSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setNotifications(data);
|
||||||
previousUnreadCountRef.current = newUnreadCount;
|
previousUnreadCountRef.current = newUnreadCount;
|
||||||
isInitialLoadRef.current = false;
|
isInitialLoadRef.current = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBellClick = async () => {
|
||||||
|
const willOpen = !showNotifications;
|
||||||
|
setShowNotifications(willOpen);
|
||||||
|
|
||||||
|
if (willOpen && unreadCount > 0) {
|
||||||
|
// Optimistic update
|
||||||
|
setNotifications(prev => prev.map(n => ({ ...n, is_read: true })));
|
||||||
|
previousUnreadCountRef.current = 0;
|
||||||
|
await markAllNotificationsAsRead();
|
||||||
|
loadNotifications();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const delayDebounceFn = setTimeout(async () => {
|
const delayDebounceFn = setTimeout(async () => {
|
||||||
if (searchQuery.length >= 2) {
|
if (searchQuery.length >= 2) {
|
||||||
@@ -167,92 +185,125 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
<div className="flex h-screen bg-zinc-50 dark:bg-dark-bg overflow-hidden transition-colors duration-300">
|
<div className="flex h-screen bg-zinc-50 dark:bg-dark-bg overflow-hidden transition-colors duration-300">
|
||||||
{/* Sidebar */}
|
{/* Sidebar */}
|
||||||
<aside
|
<aside
|
||||||
className={`fixed inset-y-0 left-0 z-50 w-64 bg-white dark:bg-dark-sidebar border-r border-zinc-200 dark:border-dark-border transform transition-transform duration-300 ease-in-out lg:relative lg:translate-x-0 ${
|
className={`fixed inset-y-0 left-0 z-50 bg-white dark:bg-dark-sidebar border-r border-zinc-200 dark:border-dark-border transform transition-all duration-300 ease-in-out lg:relative lg:translate-x-0 ${
|
||||||
isMobileMenuOpen ? 'translate-x-0' : '-translate-x-full'
|
isMobileMenuOpen ? 'translate-x-0' : '-translate-x-full'
|
||||||
}`}
|
} flex flex-col ${isSidebarCollapsed ? 'w-20' : 'w-64'}`}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col h-full">
|
{/* Logo & Toggle */}
|
||||||
{/* Logo */}
|
<div className="flex items-center justify-between px-4 h-20 border-b border-zinc-100 dark:border-dark-border shrink-0">
|
||||||
<div className="flex items-center gap-3 px-6 h-20 border-b border-zinc-100 dark:border-dark-border">
|
<div className={`flex items-center gap-3 overflow-hidden ${isSidebarCollapsed ? 'mx-auto' : ''}`}>
|
||||||
<div className="bg-zinc-900 dark:bg-brand-yellow text-white dark:text-zinc-950 p-2 rounded-lg transition-colors">
|
<div className="bg-zinc-900 dark:bg-brand-yellow text-white dark:text-zinc-950 p-2 rounded-lg transition-colors shrink-0">
|
||||||
<Hexagon size={24} fill="currentColor" />
|
<Hexagon size={24} fill="currentColor" />
|
||||||
</div>
|
</div>
|
||||||
<span className="text-xl font-bold text-zinc-900 dark:text-white tracking-tight">Fasto<span className="text-brand-yellow">.</span></span>
|
{!isSidebarCollapsed && (
|
||||||
<button onClick={() => setIsMobileMenuOpen(false)} className="ml-auto lg:hidden text-zinc-400">
|
<span className="text-xl font-bold text-zinc-900 dark:text-white tracking-tight whitespace-nowrap">Fasto<span className="text-brand-yellow">.</span></span>
|
||||||
<X size={24} />
|
)}
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{!isSidebarCollapsed && (
|
||||||
|
<button
|
||||||
|
onClick={toggleSidebar}
|
||||||
|
className="hidden lg:flex p-1.5 text-zinc-400 hover:bg-zinc-100 dark:hover:bg-dark-border rounded-lg transition-colors shrink-0"
|
||||||
|
title="Recolher Menu"
|
||||||
|
>
|
||||||
|
<ChevronLeft size={18} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button onClick={() => setIsMobileMenuOpen(false)} className="lg:hidden text-zinc-400 hover:text-zinc-900 dark:hover:text-white">
|
||||||
|
<X size={24} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Navigation */}
|
{/* Expand Button when collapsed */}
|
||||||
<nav className="flex-1 px-4 py-6 space-y-2">
|
{isSidebarCollapsed && (
|
||||||
|
<div className="hidden lg:flex justify-center p-2 border-b border-zinc-100 dark:border-dark-border shrink-0">
|
||||||
{/* Standard User Links */}
|
<button
|
||||||
{!isSuperAdmin && (
|
onClick={toggleSidebar}
|
||||||
<>
|
className="p-1.5 text-zinc-400 hover:bg-zinc-100 dark:hover:bg-dark-border rounded-lg transition-colors"
|
||||||
<SidebarItem to="/" icon={LayoutDashboard} label="Dashboard" collapsed={false} />
|
title="Expandir Menu"
|
||||||
{currentUser.role !== 'agent' && (
|
|
||||||
<>
|
|
||||||
<SidebarItem to="/admin/users" icon={Users} label="Membros" collapsed={false} />
|
|
||||||
<SidebarItem to="/admin/teams" icon={Building2} label={currentUser.role === 'manager' ? 'Meu Time' : 'Times'} collapsed={false} />
|
|
||||||
<SidebarItem to="/admin/funnels" icon={Layers} label="Meus Funis" collapsed={false} />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Super Admin Links */}
|
|
||||||
{isSuperAdmin && (
|
|
||||||
<>
|
|
||||||
<div className="pt-2 pb-2 px-4 text-xs font-semibold text-zinc-400 dark:text-dark-muted uppercase tracking-wider">
|
|
||||||
Super Admin
|
|
||||||
</div>
|
|
||||||
<SidebarItem to="/super-admin" icon={Building2} label="Organizações" collapsed={false} />
|
|
||||||
<SidebarItem to="/admin/users" icon={Users} label="Usuários Globais" collapsed={false} />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
{/* User Profile Mini - Now Clickable to Profile */}
|
|
||||||
<div className="p-4 border-t border-zinc-100 dark:border-dark-border space-y-3">
|
|
||||||
{localStorage.getItem('ctms_super_admin_token') && (
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
returnToSuperAdmin();
|
|
||||||
}}
|
|
||||||
className="w-full flex items-center justify-center gap-2 py-2 px-3 bg-zinc-900 dark:bg-brand-yellow text-white dark:text-zinc-950 rounded-lg text-xs font-bold hover:opacity-90 transition-colors"
|
|
||||||
>
|
>
|
||||||
Retornar ao Painel Central
|
<ChevronRight size={18} />
|
||||||
</button>
|
</button>
|
||||||
)}
|
</div>
|
||||||
<div className="flex items-center gap-3 p-2 rounded-lg bg-zinc-50 dark:bg-dark-bg/50 border border-zinc-100 dark:border-dark-border group">
|
)}
|
||||||
<div
|
|
||||||
onClick={() => navigate('/profile')}
|
{/* Navigation */}
|
||||||
className="flex items-center gap-3 flex-1 min-w-0 cursor-pointer hover:opacity-80 transition-opacity"
|
<nav className={`flex-1 py-6 space-y-2 overflow-y-auto overflow-x-hidden ${isSidebarCollapsed ? 'px-2' : 'px-4'}`}>
|
||||||
>
|
|
||||||
<img
|
{/* Standard User Links */}
|
||||||
src={currentUser.avatar_url
|
{!isSuperAdmin && (
|
||||||
? (currentUser.avatar_url.startsWith('http') ? currentUser.avatar_url : `${import.meta.env.PROD ? '' : 'http://localhost:3001'}${currentUser.avatar_url}`)
|
<>
|
||||||
: `https://ui-avatars.com/api/?name=${encodeURIComponent(currentUser.name)}&background=random`}
|
<SidebarItem to="/" icon={LayoutDashboard} label="Dashboard" collapsed={isSidebarCollapsed} />
|
||||||
alt={currentUser.name}
|
{currentUser.role !== 'agent' && (
|
||||||
className="w-10 h-10 rounded-full object-cover border border-zinc-200 dark:border-dark-border"
|
<>
|
||||||
/>
|
<SidebarItem to="/admin/users" icon={Users} label="Membros" collapsed={isSidebarCollapsed} />
|
||||||
|
<SidebarItem to="/admin/teams" icon={Building2} label={currentUser.role === 'manager' ? 'Meu Time' : 'Times'} collapsed={isSidebarCollapsed} />
|
||||||
|
<SidebarItem to="/admin/funnels" icon={Layers} label="Gerenciar Funis" collapsed={isSidebarCollapsed} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Super Admin Links */}
|
||||||
|
{isSuperAdmin && (
|
||||||
|
<>
|
||||||
|
{!isSidebarCollapsed && (
|
||||||
|
<div className="pt-2 pb-2 px-4 text-[10px] font-bold text-zinc-400 dark:text-dark-muted uppercase tracking-widest whitespace-nowrap">
|
||||||
|
Super Admin
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<SidebarItem to="/super-admin" icon={Building2} label="Organizações" collapsed={isSidebarCollapsed} />
|
||||||
|
<SidebarItem to="/admin/users" icon={Users} label="Usuários Globais" collapsed={isSidebarCollapsed} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{/* User Profile Mini - Now Clickable to Profile */}
|
||||||
|
<div className="p-3 border-t border-zinc-100 dark:border-dark-border space-y-3 shrink-0">
|
||||||
|
{localStorage.getItem('ctms_super_admin_token') && (
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
returnToSuperAdmin();
|
||||||
|
}}
|
||||||
|
className={`w-full flex items-center justify-center gap-2 py-2 px-3 bg-zinc-900 dark:bg-brand-yellow text-white dark:text-zinc-950 rounded-lg text-xs font-bold hover:opacity-90 transition-colors ${isSidebarCollapsed ? 'px-0' : ''}`}
|
||||||
|
title="Retornar ao Painel Central"
|
||||||
|
>
|
||||||
|
{isSidebarCollapsed ? <LogOut size={16} /> : 'Retornar ao Painel Central'}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<div className={`flex items-center gap-3 rounded-xl bg-zinc-50 dark:bg-dark-bg/50 border border-zinc-100 dark:border-dark-border group transition-all ${isSidebarCollapsed ? 'justify-center p-2' : 'p-2'}`}>
|
||||||
|
<div
|
||||||
|
onClick={() => navigate('/profile')}
|
||||||
|
className={`flex items-center gap-3 flex-1 min-w-0 cursor-pointer hover:opacity-80 transition-opacity ${isSidebarCollapsed ? 'justify-center' : ''}`}
|
||||||
|
title={isSidebarCollapsed ? currentUser.name : undefined}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={currentUser.avatar_url
|
||||||
|
? (currentUser.avatar_url.startsWith('http') ? currentUser.avatar_url : `${import.meta.env.PROD ? '' : 'http://localhost:3001'}${currentUser.avatar_url}`)
|
||||||
|
: `https://ui-avatars.com/api/?name=${encodeURIComponent(currentUser.name)}&background=random`}
|
||||||
|
alt={currentUser.name}
|
||||||
|
className="w-10 h-10 rounded-full object-cover border border-zinc-200 dark:border-dark-border shrink-0"
|
||||||
|
/>
|
||||||
|
{!isSidebarCollapsed && (
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<p className="text-sm font-semibold text-zinc-900 dark:text-dark-text truncate">{currentUser.name}</p>
|
<p className="text-sm font-semibold text-zinc-900 dark:text-dark-text truncate">{currentUser.name}</p>
|
||||||
<p className="text-xs text-zinc-500 dark:text-dark-muted truncate capitalize">
|
<p className="text-xs text-zinc-500 dark:text-dark-muted truncate capitalize">
|
||||||
{currentUser.role === 'super_admin' ? 'Super Admin' :
|
{currentUser.role === 'super_admin' ? 'Super Admin' :
|
||||||
currentUser.role === 'admin' ? 'Administrador' :
|
currentUser.role === 'admin' ? 'Administrador' :
|
||||||
currentUser.role === 'manager' ? 'Gerente' : 'Agente'}
|
currentUser.role === 'manager' ? 'Gerente' : 'Agente'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
</div>
|
||||||
|
{!isSidebarCollapsed && (
|
||||||
<button
|
<button
|
||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
className="text-zinc-400 hover:text-red-500 transition-colors shrink-0"
|
className="text-zinc-400 hover:text-red-500 transition-colors shrink-0 p-2"
|
||||||
title="Sair"
|
title="Sair"
|
||||||
>
|
>
|
||||||
<LogOut size={18} />
|
<LogOut size={18} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
@@ -424,11 +475,10 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
|
|
||||||
{/* Notifications */}
|
{/* Notifications */}
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowNotifications(!showNotifications)}
|
onClick={handleBellClick}
|
||||||
className="p-2 text-zinc-500 dark:text-dark-muted hover:bg-zinc-100 dark:hover:bg-dark-border rounded-full relative transition-colors"
|
className="p-2 text-zinc-500 dark:text-dark-muted hover:bg-zinc-100 dark:hover:bg-dark-border rounded-full relative transition-colors"
|
||||||
>
|
> <Bell size={20} />
|
||||||
<Bell size={20} />
|
|
||||||
{unreadCount > 0 && (
|
{unreadCount > 0 && (
|
||||||
<span className="absolute top-1.5 right-2 w-2.5 h-2.5 bg-brand-yellow rounded-full border-2 border-white dark:border-dark-header"></span>
|
<span className="absolute top-1.5 right-2 w-2.5 h-2.5 bg-brand-yellow rounded-full border-2 border-white dark:border-dark-header"></span>
|
||||||
)}
|
)}
|
||||||
@@ -487,7 +537,7 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
n.type === 'warning' ? 'text-orange-500' :
|
n.type === 'warning' ? 'text-orange-500' :
|
||||||
n.type === 'error' ? 'text-red-500' : 'text-blue-500'
|
n.type === 'error' ? 'text-red-500' : 'text-blue-500'
|
||||||
}`}>
|
}`}>
|
||||||
{n.type}
|
{n.type === 'success' ? 'SUCESSO' : n.type === 'warning' ? 'AVISO' : n.type === 'error' ? 'ERRO' : 'INFO'}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-[10px] text-zinc-400 dark:text-dark-muted">
|
<span className="text-[10px] text-zinc-400 dark:text-dark-muted">
|
||||||
{new Date(n.created_at).toLocaleDateString()}
|
{new Date(n.created_at).toLocaleDateString()}
|
||||||
@@ -534,11 +584,18 @@ export const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
|
|||||||
|
|
||||||
{/* Overlay for mobile */}
|
{/* Overlay for mobile */}
|
||||||
{isMobileMenuOpen && (
|
{isMobileMenuOpen && (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 bg-zinc-950/50 z-40 lg:hidden"
|
className="fixed inset-0 bg-zinc-950/50 z-40 lg:hidden"
|
||||||
onClick={() => setIsMobileMenuOpen(false)}
|
onClick={() => setIsMobileMenuOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Hidden Audio Player for Notifications */}
|
||||||
|
<audio
|
||||||
|
ref={audioRef}
|
||||||
|
src={notificationSound}
|
||||||
|
preload="auto"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
35
debug.txt
35
debug.txt
@@ -1,12 +1,27 @@
|
|||||||
Look at line 354: `if (req.user.role !== 'super_admin' && rows[0].tenant_id !== req.user.tenant_id) {`
|
Look at `playNotificationSound`:
|
||||||
What if `req.user.tenant_id` is null (which it is for some system admins)?
|
```javascript
|
||||||
But `rows[0].tenant_id` could be something else. That just returns 403.
|
const playNotificationSound = () => {
|
||||||
What if `rows` is empty?
|
if (currentUser?.sound_enabled !== false && audioRef.current) {
|
||||||
Line 353: `if (rows.length === 0) return res.status(404).json({ error: 'Not found' });`
|
// Reset time to 0 to allow rapid replays
|
||||||
What if `req.user` is undefined? (Should be caught by middleware).
|
audioRef.current.currentTime = 0;
|
||||||
|
const playPromise = audioRef.current.play();
|
||||||
|
```
|
||||||
|
Is `currentUser` loaded when `loadNotifications` fires for the first time after `isInitialLoadRef` is false?
|
||||||
|
Yes, `useEffect` calls `fetchCurrentUser()`, which sets `currentUser`.
|
||||||
|
|
||||||
Wait, the user says the error is:
|
Wait. `setInterval` uses a closure over the state!
|
||||||
`https://fasto.blyzer.com.br/api/users/u_71657ec7`
|
```javascript
|
||||||
And it returns `500`.
|
useEffect(() => {
|
||||||
|
fetchCurrentUser();
|
||||||
|
loadNotifications();
|
||||||
|
const interval = setInterval(loadNotifications, 10000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [navigate]);
|
||||||
|
```
|
||||||
|
Oh my god. The `setInterval` callback `loadNotifications` captures the *initial* state variables, including `currentUser`, which is `null` on the first render!
|
||||||
|
If `currentUser` is `null` inside the closure, `currentUser?.sound_enabled !== false` evaluates to `true !== false` which is `true`. So that's not blocking it.
|
||||||
|
BUT `audioRef.current` might not have been rendered yet? No, `audioRef` is a ref, so it mutates in place. The closure always sees the latest `audioRef.current`.
|
||||||
|
|
||||||
Let's log the exact error inside the catch block in the backend.
|
So why does it fail or not play?
|
||||||
|
Is the browser policy blocking it silently without logging?
|
||||||
|
Let's add a robust, standalone Audio approach that doesn't rely on the DOM tag if it fails, or maybe just force a click handler to "unlock" the audio context.
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ export const Funnels: React.FC = () => {
|
|||||||
{/* Sidebar: Funnels List */}
|
{/* Sidebar: Funnels List */}
|
||||||
<div className="w-full md:w-64 shrink-0 space-y-4">
|
<div className="w-full md:w-64 shrink-0 space-y-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<h2 className="text-lg font-bold text-zinc-900 dark:text-zinc-50">Meus Funis</h2>
|
<h2 className="text-lg font-bold text-zinc-900 dark:text-zinc-50">Gerenciar Funis</h2>
|
||||||
<button onClick={() => setIsFunnelModalOpen(true)} className="p-1.5 bg-zinc-100 dark:bg-dark-bg text-zinc-600 dark:text-dark-muted rounded-lg hover:bg-zinc-200 dark:hover:bg-dark-border transition-colors">
|
<button onClick={() => setIsFunnelModalOpen(true)} className="p-1.5 bg-zinc-100 dark:bg-dark-bg text-zinc-600 dark:text-dark-muted rounded-lg hover:bg-zinc-200 dark:hover:bg-dark-border transition-colors">
|
||||||
<Plus size={16} />
|
<Plus size={16} />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect, useMemo } from 'react';
|
import React, { useState, useEffect, useMemo } from 'react';
|
||||||
import { Building2, Users, Plus, Search, Target, ArrowUpRight, Loader2, Edit2, X } from 'lucide-react';
|
import { Building2, Users, Plus, Search, Target, ArrowUpRight, Loader2, Edit2, X, Trash2 } from 'lucide-react';
|
||||||
import { getTeams, getUsers, getAttendances, createTeam, updateTeam, getUserById } from '../services/dataService';
|
import { getTeams, getUsers, getAttendances, createTeam, updateTeam, deleteTeam, getUserById } from '../services/dataService';
|
||||||
import { User, Attendance } from '../types';
|
import { User, Attendance } from '../types';
|
||||||
|
|
||||||
export const Teams: React.FC = () => {
|
export const Teams: React.FC = () => {
|
||||||
@@ -46,13 +46,19 @@ export const Teams: React.FC = () => {
|
|||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
try {
|
try {
|
||||||
const tid = localStorage.getItem('ctms_tenant_id') || '';
|
const tid = localStorage.getItem('ctms_tenant_id') || '';
|
||||||
const success = editingTeam
|
const success = editingTeam
|
||||||
? await updateTeam(editingTeam.id, formData)
|
? await updateTeam(editingTeam.id, formData)
|
||||||
: await createTeam({ ...formData, tenantId: tid });
|
: await createTeam({ ...formData, tenantId: tid });
|
||||||
if (success) { setIsModalOpen(false); loadData(); }
|
if (success) { setIsModalOpen(false); loadData(); }
|
||||||
} catch (err) { alert('Erro ao salvar'); } finally { setIsSaving(false); }
|
} catch (err) { alert('Erro ao salvar'); } finally { setIsSaving(false); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteTeam = async (id: string) => {
|
||||||
|
if (confirm('Tem certeza que deseja excluir este time? Todos os usuários deste time ficarão sem time atribuído.')) {
|
||||||
|
await deleteTeam(id);
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
};
|
||||||
if (loading && teams.length === 0) return <div className="p-12 text-center text-zinc-400 dark:text-dark-muted transition-colors">Carregando...</div>;
|
if (loading && teams.length === 0) return <div className="p-12 text-center text-zinc-400 dark:text-dark-muted transition-colors">Carregando...</div>;
|
||||||
|
|
||||||
const canManage = currentUser?.role === 'admin' || currentUser?.role === 'super_admin';
|
const canManage = currentUser?.role === 'admin' || currentUser?.role === 'super_admin';
|
||||||
@@ -81,7 +87,10 @@ export const Teams: React.FC = () => {
|
|||||||
<div className="flex justify-between mb-6">
|
<div className="flex justify-between mb-6">
|
||||||
<div className="p-3 bg-zinc-50 dark:bg-dark-bg text-zinc-600 dark:text-dark-muted rounded-xl border border-zinc-100 dark:border-dark-border"><Building2 size={24} /></div>
|
<div className="p-3 bg-zinc-50 dark:bg-dark-bg text-zinc-600 dark:text-dark-muted rounded-xl border border-zinc-100 dark:border-dark-border"><Building2 size={24} /></div>
|
||||||
{canManage && (
|
{canManage && (
|
||||||
<button onClick={() => { setEditingTeam(t); setFormData({name:t.name, description:t.description||''}); setIsModalOpen(true); }} className="text-zinc-400 dark:text-dark-muted hover:text-zinc-900 dark:hover:text-dark-text p-2 rounded-lg hover:bg-zinc-50 dark:hover:bg-dark-bg transition-all"><Edit2 size={18} /></button>
|
<div className="flex items-center gap-2">
|
||||||
|
<button onClick={() => { setEditingTeam(t); setFormData({name:t.name, description:t.description||''}); setIsModalOpen(true); }} className="text-zinc-400 dark:text-dark-muted hover:text-zinc-900 dark:hover:text-dark-text p-2 rounded-lg hover:bg-zinc-50 dark:hover:bg-dark-bg transition-all"><Edit2 size={18} /></button>
|
||||||
|
<button onClick={() => handleDeleteTeam(t.id)} className="text-zinc-400 dark:text-dark-muted hover:text-red-600 dark:hover:text-red-500 p-2 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/30 transition-all"><Trash2 size={18} /></button>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<h3 className="text-lg font-bold text-zinc-900 dark:text-zinc-50 mb-1">{t.name}</h3>
|
<h3 className="text-lg font-bold text-zinc-900 dark:text-zinc-50 mb-1">{t.name}</h3>
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
|
||||||
<html><head>
|
|
||||||
<title>404 Not Found</title>
|
|
||||||
</head><body>
|
|
||||||
<h1>Not Found</h1>
|
|
||||||
<p>The requested URL was not found on this server.</p>
|
|
||||||
<p>Additionally, a 404 Not Found
|
|
||||||
error was encountered while trying to use an ErrorDocument to handle the request.</p>
|
|
||||||
</body></html>
|
|
||||||
@@ -71,7 +71,7 @@ export const deleteNotification = async (id: string): Promise<boolean> => {
|
|||||||
|
|
||||||
export const clearAllNotifications = async (): Promise<boolean> => {
|
export const clearAllNotifications = async (): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/notifications`, {
|
const response = await fetch(`${API_URL}/notifications/clear-all`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: getHeaders()
|
headers: getHeaders()
|
||||||
});
|
});
|
||||||
@@ -406,6 +406,19 @@ export const updateTeam = async (id: string, teamData: any): Promise<boolean> =>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteTeam = async (id: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_URL}/teams/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: getHeaders()
|
||||||
|
});
|
||||||
|
return response.ok;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Error (deleteTeam):", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const createTenant = async (tenantData: any): Promise<{ success: boolean; message?: string }> => {
|
export const createTenant = async (tenantData: any): Promise<{ success: boolean; message?: string }> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/tenants`, {
|
const response = await fetch(`${API_URL}/tenants`, {
|
||||||
|
|||||||
BIN
src/assets/audio/notification.mp3
Normal file
BIN
src/assets/audio/notification.mp3
Normal file
Binary file not shown.
Reference in New Issue
Block a user