import { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '@/lib/auth-context'; type ShortcutMap = { [key: string]: () => void; }; export const useKeyboardShortcuts = () => { const navigate = useNavigate(); const { userData } = useAuth(); // Check if user is client role or not logged in const isClientRole = !userData || userData?.roleName?.toLowerCase() === "client"; useEffect(() => { // Don't set up shortcuts for client role users if (isClientRole) { return; } const shortcuts: ShortcutMap = { // Alt+T for Tasks 'alt+t': () => navigate('/tasks'), // Alt+F for Features 'alt+f': () => navigate('/issues'), // Alt+D for Dashboard 'alt+d': () => navigate('/'), // Alt+S for Settings 'alt+s': () => navigate('/settings'), // Alt+B for Bugs 'alt+b': () => navigate('/bugs'), // Alt+P for Projects 'alt+p': () => navigate('/projects'), // Alt+E for Employee 'alt+e': () => navigate('/employee'), }; const handleKeyDown = (event: KeyboardEvent) => { // Check if Alt key is pressed if (event.altKey) { const key = event.key.toLowerCase(); const shortcutKey = `alt+${key}`; if (shortcuts[shortcutKey]) { event.preventDefault(); shortcuts[shortcutKey](); } } }; window.addEventListener('keydown', handleKeyDown); return () => { window.removeEventListener('keydown', handleKeyDown); }; }, [navigate, isClientRole, userData]); }; export default useKeyboardShortcuts;