2026-07-17 00:52:17 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
|
import { ChatWindow } from '@/components/ai/ChatWindow';
|
2026-07-17 22:24:26 +02:00
|
|
|
import { ResizablePanel } from '@/components/ui/ResizablePanel';
|
2026-07-18 17:48:09 +02:00
|
|
|
import { SuggestionList } from '@/components/ai/SuggestionSidebar';
|
2026-07-17 00:52:17 +02:00
|
|
|
import { createSession, fetchSessions } from '@/api/ai';
|
|
|
|
|
import { useUIStore } from '@/store/uiStore';
|
2026-07-21 22:38:45 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2026-07-21 23:11:17 +02:00
|
|
|
import { useUsers, useGroups } from '@/api/hooks';
|
|
|
|
|
import { Avatar } from '@/components/ui/Avatar';
|
2026-07-23 03:21:05 +02:00
|
|
|
import { Bell, Bot, ChevronLeft, ChevronRight, Lightbulb, MessageSquare, Users, X } from 'lucide-react';
|
2026-07-21 22:38:45 +02:00
|
|
|
|
|
|
|
|
const robotIcon = (className: string) => (
|
2026-07-23 03:21:05 +02:00
|
|
|
<Bot className={className} aria-hidden="true" strokeWidth={2} />
|
2026-07-21 22:38:45 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const bellIcon = (className: string) => (
|
2026-07-23 03:21:05 +02:00
|
|
|
<Bell className={className} aria-hidden="true" strokeWidth={2} />
|
2026-07-21 22:38:45 +02:00
|
|
|
);
|
|
|
|
|
|
2026-07-21 22:50:45 +02:00
|
|
|
const bulbIcon = (className: string) => (
|
2026-07-23 03:21:05 +02:00
|
|
|
<Lightbulb className={className} aria-hidden="true" strokeWidth={2} />
|
2026-07-21 22:50:45 +02:00
|
|
|
);
|
|
|
|
|
|
2026-07-21 23:11:17 +02:00
|
|
|
const teamIcon = (className: string) => (
|
2026-07-23 03:21:05 +02:00
|
|
|
<Users className={className} aria-hidden="true" strokeWidth={2} />
|
2026-07-21 23:11:17 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const chatBubbleIcon = (className: string) => (
|
2026-07-23 03:21:05 +02:00
|
|
|
<MessageSquare className={className} aria-hidden="true" strokeWidth={2} />
|
2026-07-21 23:11:17 +02:00
|
|
|
);
|
|
|
|
|
|
2026-07-21 22:38:45 +02:00
|
|
|
const chevronRightIcon = (
|
2026-07-23 03:21:05 +02:00
|
|
|
<ChevronRight className="w-4 h-4" aria-hidden="true" strokeWidth={2} />
|
2026-07-21 22:38:45 +02:00
|
|
|
);
|
2026-07-17 00:52:17 +02:00
|
|
|
|
2026-07-21 22:50:45 +02:00
|
|
|
interface TabDef {
|
2026-07-21 23:11:17 +02:00
|
|
|
key: 'proactive' | 'chat' | 'notifications' | 'team' | 'chatroom';
|
2026-07-21 22:50:45 +02:00
|
|
|
label: string;
|
|
|
|
|
icon: (cls: string) => React.ReactNode;
|
|
|
|
|
testId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 23:11:17 +02:00
|
|
|
function TeamPanel() {
|
|
|
|
|
const { data: usersData, isLoading: usersLoading } = useUsers();
|
|
|
|
|
const { data: groupsData, isLoading: groupsLoading } = useGroups();
|
|
|
|
|
const users: any[] = usersData?.items || [];
|
|
|
|
|
const groups: any[] = groupsData?.items || [];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col h-full overflow-y-auto p-3 gap-3" data-testid="team-panel">
|
|
|
|
|
<div>
|
|
|
|
|
<h3 className="text-xs font-semibold text-secondary-500 uppercase tracking-wide mb-2">Mitarbeiter</h3>
|
|
|
|
|
{usersLoading ? (
|
|
|
|
|
<p className="text-sm text-secondary-400">Laden...</p>
|
|
|
|
|
) : users.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-secondary-400">Keine Mitarbeiter</p>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
{users.map((u) => (
|
|
|
|
|
<div key={u.id} className="flex items-center gap-2 px-2 py-1.5 rounded-lg hover:bg-secondary-50 transition-colors">
|
|
|
|
|
<div className="relative flex-shrink-0">
|
|
|
|
|
<Avatar name={u.name} size="sm" />
|
|
|
|
|
<span className="absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full border-2 border-white bg-secondary-300" aria-label="offline" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<p className="text-sm font-medium text-secondary-700 truncate">{u.name}</p>
|
|
|
|
|
<p className="text-xs text-secondary-400 truncate">{u.email}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-xs text-secondary-400">{u.role}</span>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<h3 className="text-xs font-semibold text-secondary-500 uppercase tracking-wide mb-2">Gruppen</h3>
|
|
|
|
|
{groupsLoading ? (
|
|
|
|
|
<p className="text-sm text-secondary-400">Laden...</p>
|
|
|
|
|
) : groups.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-secondary-400">Keine Gruppen</p>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
{groups.map((g) => (
|
|
|
|
|
<div key={g.id} className="flex items-center gap-2 px-2 py-1.5 rounded-lg hover:bg-secondary-50 transition-colors">
|
|
|
|
|
<div className="w-8 h-8 rounded-full bg-secondary-200 flex items-center justify-center flex-shrink-0">
|
2026-07-23 03:21:05 +02:00
|
|
|
<Users className="w-4 h-4 text-secondary-500" aria-hidden="true" strokeWidth={2} />
|
2026-07-21 23:11:17 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<p className="text-sm font-medium text-secondary-700 truncate">{g.name}</p>
|
|
|
|
|
{g.description && <p className="text-xs text-secondary-400 truncate">{g.description}</p>}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ChatPanel() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col h-full" data-testid="chat-panel">
|
|
|
|
|
<div className="flex-1 overflow-y-auto p-3">
|
|
|
|
|
<p className="text-sm text-secondary-400 text-center py-8">Chat-Sidebar - Coming Soon</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 00:52:17 +02:00
|
|
|
export function AISidebar() {
|
2026-07-21 22:38:45 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { aiSidebarCollapsed, toggleAISidebar, aiSidebarTab, setAISidebarTab, notifications, removeNotification } = useUIStore();
|
2026-07-17 00:52:17 +02:00
|
|
|
const [sessionId, setSessionId] = useState<string | null>(null);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
(async () => {
|
|
|
|
|
try {
|
|
|
|
|
const sessions = await fetchSessions(true);
|
|
|
|
|
if (sessions.length > 0) {
|
|
|
|
|
setSessionId(sessions[0].id);
|
|
|
|
|
} else {
|
|
|
|
|
const session = await createSession({ is_sidebar: true, title: 'Sidebar Chat' });
|
|
|
|
|
setSessionId(session.id);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('AISidebar init error:', e);
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-07-21 22:50:45 +02:00
|
|
|
const tabs: TabDef[] = [
|
|
|
|
|
{ key: 'chat', label: 'KI Chat', icon: robotIcon, testId: 'ai-sidebar-tab-chat' },
|
2026-07-21 23:01:21 +02:00
|
|
|
{ key: 'proactive', label: 'Live KI', icon: bulbIcon, testId: 'ai-sidebar-tab-proactive' },
|
2026-07-21 22:50:45 +02:00
|
|
|
{ key: 'notifications', label: t('topbar.notifications'), icon: bellIcon, testId: 'ai-sidebar-tab-notifications' },
|
2026-07-21 23:11:17 +02:00
|
|
|
{ key: 'team', label: 'Team', icon: teamIcon, testId: 'ai-sidebar-tab-team' },
|
|
|
|
|
{ key: 'chatroom', label: 'Chat', icon: chatBubbleIcon, testId: 'ai-sidebar-tab-chatroom' },
|
2026-07-21 22:50:45 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const activeTab = tabs.find((tab) => tab.key === aiSidebarTab) || tabs[0];
|
|
|
|
|
|
2026-07-18 01:51:01 +02:00
|
|
|
// Collapsed: narrow icon strip (desktop only, hidden on mobile)
|
2026-07-18 00:53:00 +02:00
|
|
|
if (aiSidebarCollapsed) {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
2026-07-21 22:38:45 +02:00
|
|
|
className="hidden md:flex flex-shrink-0 w-12 flex-col items-center border-l border-secondary-200 bg-white py-3 gap-2"
|
2026-07-18 00:53:00 +02:00
|
|
|
data-testid="ai-sidebar-collapsed"
|
|
|
|
|
>
|
2026-07-21 22:50:45 +02:00
|
|
|
{tabs.map((tab) => (
|
|
|
|
|
<button
|
|
|
|
|
key={tab.key}
|
|
|
|
|
onClick={() => { setAISidebarTab(tab.key); toggleAISidebar(); }}
|
|
|
|
|
className="p-2 rounded-md hover:bg-secondary-100 min-h-touch min-w-touch flex items-center justify-center focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 relative"
|
|
|
|
|
aria-label={tab.label}
|
|
|
|
|
title={tab.label}
|
|
|
|
|
data-testid={tab.testId}
|
|
|
|
|
>
|
|
|
|
|
{tab.icon('w-5 h-5 text-secondary-600')}
|
|
|
|
|
{tab.key === 'notifications' && notifications.length > 0 && (
|
|
|
|
|
<span className="absolute -top-0.5 -right-0.5 w-4 h-4 bg-danger-500 text-white text-[10px] font-bold rounded-full flex items-center justify-center">
|
|
|
|
|
{notifications.length}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
2026-07-18 00:53:00 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 17:48:09 +02:00
|
|
|
const renderTabContent = () => {
|
|
|
|
|
if (aiSidebarTab === 'proactive') {
|
|
|
|
|
return <SuggestionList />;
|
|
|
|
|
}
|
2026-07-21 22:38:45 +02:00
|
|
|
if (aiSidebarTab === 'notifications') {
|
|
|
|
|
return (
|
2026-07-21 23:01:21 +02:00
|
|
|
<div className="flex flex-col h-full overflow-y-auto p-3 gap-2" data-testid="notification-list">
|
|
|
|
|
{notifications.length === 0 && (
|
|
|
|
|
<p className="text-sm text-secondary-400 text-center py-4">Keine Benachrichtigungen</p>
|
|
|
|
|
)}
|
|
|
|
|
{notifications.map((msg, i) => (
|
|
|
|
|
<div key={i} className="flex items-start justify-between gap-2 px-3 py-2 rounded-lg border border-secondary-200 bg-secondary-50 hover:border-secondary-300 hover:bg-secondary-100 transition-colors text-sm text-secondary-700 group">
|
|
|
|
|
<span className="flex-1 leading-snug">{msg}</span>
|
|
|
|
|
<button
|
|
|
|
|
className="p-1 rounded text-secondary-300 hover:text-danger-600 hover:bg-danger-50 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0 mt-0.5"
|
|
|
|
|
aria-label="Benachrichtigung löschen"
|
|
|
|
|
onClick={() => removeNotification(i)}
|
|
|
|
|
>
|
2026-07-23 03:21:05 +02:00
|
|
|
<X className="w-3.5 h-3.5" aria-hidden="true" strokeWidth={2} />
|
2026-07-21 23:01:21 +02:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2026-07-21 22:38:45 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-07-21 23:11:17 +02:00
|
|
|
if (aiSidebarTab === 'team') {
|
|
|
|
|
return <TeamPanel />;
|
|
|
|
|
}
|
|
|
|
|
if (aiSidebarTab === 'chatroom') {
|
|
|
|
|
return <ChatPanel />;
|
|
|
|
|
}
|
2026-07-18 17:48:09 +02:00
|
|
|
// chat tab
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-center h-full text-sm text-secondary-400">Laden...</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (sessionId) {
|
|
|
|
|
return <ChatWindow sessionId={sessionId} compact className="h-full" />;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-center h-full text-sm text-red-500">
|
|
|
|
|
Session konnte nicht erstellt werden
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-21 22:50:45 +02:00
|
|
|
const iconStrip = (
|
2026-07-21 23:01:21 +02:00
|
|
|
<div className="flex items-center gap-1 px-2 h-[58px] border-b border-secondary-200" role="tablist">
|
2026-07-21 22:50:45 +02:00
|
|
|
{tabs.map((tab) => (
|
|
|
|
|
<button
|
|
|
|
|
key={tab.key}
|
|
|
|
|
onClick={() => setAISidebarTab(tab.key)}
|
|
|
|
|
className={`p-2 rounded-md min-h-touch min-w-touch flex items-center justify-center transition-colors relative ${
|
|
|
|
|
aiSidebarTab === tab.key
|
|
|
|
|
? 'bg-primary-100 text-primary-600'
|
|
|
|
|
: 'text-secondary-500 hover:bg-secondary-100 hover:text-secondary-700'
|
|
|
|
|
}`}
|
|
|
|
|
role="tab"
|
|
|
|
|
aria-selected={aiSidebarTab === tab.key}
|
|
|
|
|
aria-label={tab.label}
|
|
|
|
|
data-testid={tab.testId}
|
|
|
|
|
>
|
|
|
|
|
{tab.icon('w-5 h-5')}
|
|
|
|
|
{tab.key === 'notifications' && notifications.length > 0 && (
|
|
|
|
|
<span className="absolute -top-0.5 -right-0.5 w-4 h-4 bg-danger-500 text-white text-[10px] font-bold rounded-full flex items-center justify-center">
|
|
|
|
|
{notifications.length}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
<div className="flex-1" />
|
2026-07-21 22:38:45 +02:00
|
|
|
<button
|
2026-07-21 22:50:45 +02:00
|
|
|
onClick={toggleAISidebar}
|
|
|
|
|
className="p-1.5 rounded-md text-secondary-400 hover:text-secondary-600 hover:bg-secondary-100 min-h-touch min-w-touch flex items-center justify-center"
|
|
|
|
|
title="Einklappen"
|
|
|
|
|
aria-label="KI Assistent einklappen"
|
2026-07-21 22:38:45 +02:00
|
|
|
>
|
2026-07-21 22:50:45 +02:00
|
|
|
{chevronRightIcon}
|
2026-07-21 22:38:45 +02:00
|
|
|
</button>
|
2026-07-18 17:48:09 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2026-07-18 01:51:01 +02:00
|
|
|
// Expanded: Mobile = full width overlay, Desktop = resizable panel
|
2026-07-17 00:52:17 +02:00
|
|
|
return (
|
2026-07-18 01:51:01 +02:00
|
|
|
<>
|
|
|
|
|
{/* Mobile: full width overlay with back button */}
|
|
|
|
|
<div
|
|
|
|
|
className="md:hidden fixed inset-0 z-50 bg-white flex flex-col"
|
|
|
|
|
data-testid="ai-sidebar-mobile"
|
|
|
|
|
>
|
|
|
|
|
<div className="h-14 flex items-center gap-2 px-3 border-b border-secondary-200">
|
2026-07-17 22:24:26 +02:00
|
|
|
<button
|
2026-07-18 00:53:00 +02:00
|
|
|
onClick={toggleAISidebar}
|
2026-07-18 01:51:01 +02:00
|
|
|
className="inline-flex items-center gap-1 px-2 py-1 rounded text-sm text-secondary-700 hover:bg-secondary-100 min-h-touch"
|
|
|
|
|
aria-label="Zurück"
|
|
|
|
|
data-testid="ai-sidebar-back"
|
2026-07-17 22:24:26 +02:00
|
|
|
>
|
2026-07-23 03:21:05 +02:00
|
|
|
<ChevronLeft className="w-5 h-5" aria-hidden="true" strokeWidth={2} />
|
2026-07-18 01:51:01 +02:00
|
|
|
<span className="text-sm font-medium">Zurück</span>
|
2026-07-17 22:24:26 +02:00
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-07-21 22:50:45 +02:00
|
|
|
{iconStrip}
|
|
|
|
|
<div className="px-3 py-2 border-b border-secondary-200">
|
|
|
|
|
<span className="text-sm font-medium text-secondary-700">{activeTab.label}</span>
|
|
|
|
|
</div>
|
2026-07-17 22:24:26 +02:00
|
|
|
<div className="flex-1 overflow-hidden">
|
2026-07-18 17:48:09 +02:00
|
|
|
{renderTabContent()}
|
2026-07-17 22:24:26 +02:00
|
|
|
</div>
|
2026-07-17 00:52:17 +02:00
|
|
|
</div>
|
2026-07-18 01:51:01 +02:00
|
|
|
|
|
|
|
|
{/* Desktop: resizable panel */}
|
|
|
|
|
<ResizablePanel
|
|
|
|
|
initialWidth={320}
|
|
|
|
|
minWidth={240}
|
|
|
|
|
maxWidth={600}
|
2026-07-19 23:16:22 +02:00
|
|
|
handleSide="left"
|
2026-07-18 01:51:01 +02:00
|
|
|
className="hidden md:flex border-l border-secondary-200 bg-white"
|
|
|
|
|
data-testid="ai-sidebar-pane"
|
|
|
|
|
>
|
|
|
|
|
<div className="h-full flex flex-col">
|
2026-07-21 22:50:45 +02:00
|
|
|
{iconStrip}
|
|
|
|
|
<div className="px-3 py-2 border-b border-secondary-200">
|
|
|
|
|
<span className="text-sm font-medium text-secondary-700">{activeTab.label}</span>
|
2026-07-18 01:51:01 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="flex-1 overflow-hidden">
|
2026-07-18 17:48:09 +02:00
|
|
|
{renderTabContent()}
|
2026-07-18 01:51:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</ResizablePanel>
|
|
|
|
|
</>
|
2026-07-17 00:52:17 +02:00
|
|
|
);
|
|
|
|
|
}
|