Spaces:
Paused
Paused
Download frontend/apps/customer/src/components/Sidebar.tsx from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 6.52 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/customer/src/components/Sidebar.tsx
- Command line
-
hf download hf://spaces/TeamError404/nexus/frontend/apps/customer/src/components/Sidebar.tsx
-
curl -L -o Sidebar.tsx https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/customer/src/components/Sidebar.tsx
6.52 kB
| import React, { useState, useEffect } from 'react'; | |
| import { api, NexusLogo } from '@nexus/shared'; | |
| const COLORS = { | |
| brand: "#1E40AF", | |
| brandLight: "#EFF6FF", | |
| brandMid: "#BFDBFE", | |
| gray50: "#F9FAFB", | |
| gray100: "#F3F4F6", | |
| gray200: "#E5E7EB", | |
| gray300: "#D1D5DB", | |
| gray400: "#9CA3AF", | |
| gray500: "#6B7280", | |
| gray600: "#4B5563", | |
| gray700: "#374151", | |
| gray800: "#1F2937", | |
| gray900: "#111827", | |
| }; | |
| interface SidebarProps { | |
| active: "dashboard" | "tickets" | "kb" | "analytics" | "thread" | "workspace"; | |
| setActive: (tab: any) => void; | |
| onNewTicket: () => void; | |
| onSettings: () => void; | |
| user: any; | |
| } | |
| export const Sidebar: React.FC<SidebarProps> = ({ active, setActive, onNewTicket, onSettings, user }) => { | |
| const [workspaces, setWorkspaces] = useState<any[]>([]); | |
| const [currentWs, setCurrentWs] = useState<any>(null); | |
| useEffect(() => { | |
| if (user?.workspace_id) { | |
| fetchWorkspaces(); | |
| } | |
| }, [user?.workspace_id]); | |
| const fetchWorkspaces = async () => { | |
| try { | |
| const resp = await api.get('workspace/list/'); | |
| setWorkspaces(resp.data); | |
| if (user?.workspace_id) { | |
| const activeWs = resp.data.find((w: any) => w.id === user.workspace_id) || resp.data[0]; | |
| setCurrentWs(activeWs); | |
| } | |
| } catch (err) { | |
| console.error("Failed to fetch workspaces:", err); | |
| } | |
| }; | |
| const nav = [ | |
| { id: "dashboard", label: "Dashboard", icon: "⊞" }, | |
| { id: "tickets", label: "My Tickets", icon: "◈" }, | |
| { id: "kb", label: "Knowledge Base", icon: "◉" }, | |
| { id: "workspace", label: "Workspace", icon: "🏢" }, | |
| { id: "analytics", label: "My Analytics", icon: "◫" }, | |
| ]; | |
| const handleWsChange = (wsId: string) => { | |
| const ws = workspaces.find(w => w.id === wsId); | |
| if (ws) { | |
| setCurrentWs(ws); | |
| // In a real app, we'd trigger a global state update or page refresh with the new ID | |
| console.log("Switching context to:", ws.name); | |
| } | |
| }; | |
| return ( | |
| <aside style={{ | |
| width: 240, | |
| background: "#fff", | |
| borderRight: `1px solid ${COLORS.gray200}`, | |
| display: "flex", | |
| flexDirection: "column", | |
| flexShrink: 0, | |
| height: "100vh", | |
| position: "sticky", | |
| top: 0 | |
| }}> | |
| {/* Workspace Switcher Header */} | |
| <div style={{ padding: "16px", borderBottom: `1px solid ${COLORS.gray100}` }}> | |
| <div style={{ marginBottom: 12 }}> | |
| <NexusLogo subtitle="CUSTOMER ECOSYSTEM" /> | |
| </div> | |
| {/* The Actual Switcher */} | |
| <div style={{ position: "relative" }}> | |
| <select | |
| value={currentWs?.id} | |
| onChange={(e) => handleWsChange(e.target.value)} | |
| style={{ | |
| width: "100%", | |
| padding: "8px 12px", | |
| borderRadius: 8, | |
| border: `1px solid ${COLORS.gray200}`, | |
| fontSize: 13, | |
| fontWeight: 600, | |
| color: COLORS.gray700, | |
| background: COLORS.gray50, | |
| cursor: "pointer", | |
| outline: "none" | |
| }} | |
| > | |
| {workspaces.map(ws => ( | |
| <option key={ws.id} value={ws.id}>{ws.name}</option> | |
| ))} | |
| </select> | |
| </div> | |
| </div> | |
| <div style={{ padding: "16px 16px 8px" }}> | |
| <button onClick={onNewTicket} style={{ width: "100%", padding: "10px 14px", background: COLORS.brand, color: "#fff", border: "none", borderRadius: 8, fontSize: 13, fontWeight: 700, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", gap: 8, boxShadow: "0 4px 12px rgba(30, 64, 175, 0.2)" }}> | |
| <span style={{ fontSize: 18, lineHeight: 0.5 }}>+</span> New Ticket | |
| </button> | |
| </div> | |
| <nav style={{ flex: 1, padding: "8px 12px" }}> | |
| {nav.map(item => ( | |
| <button | |
| key={item.id} | |
| onClick={() => setActive(item.id)} | |
| style={{ | |
| width: "100%", | |
| display: "flex", | |
| alignItems: "center", | |
| gap: 12, | |
| padding: "10px 14px", | |
| borderRadius: 10, | |
| border: "none", | |
| cursor: "pointer", | |
| background: active === item.id ? COLORS.brandLight : "transparent", | |
| color: active === item.id ? COLORS.brand : COLORS.gray600, | |
| fontSize: 13, | |
| fontWeight: active === item.id ? 700 : 500, | |
| marginBottom: 4, | |
| transition: "all 0.2s" | |
| }} | |
| > | |
| <span style={{ fontSize: 16, opacity: active === item.id ? 1 : 0.6 }}>{item.icon}</span> | |
| {item.label} | |
| </button> | |
| ))} | |
| </nav> | |
| <div style={{ padding: "16px", borderTop: `1px solid ${COLORS.gray100}`, background: COLORS.gray50 }}> | |
| <div style={{ display: "flex", alignItems: "center", gap: 12, position: "relative" }}> | |
| <div style={{ | |
| width: 36, | |
| height: 36, | |
| borderRadius: "50%", | |
| background: COLORS.brand, | |
| display: "flex", | |
| alignItems: "center", | |
| justifyContent: "center", | |
| fontSize: 12, | |
| fontWeight: 800, | |
| color: "#fff" | |
| }}> | |
| {user?.full_name?.split(' ').map((n: string) => n[0]).join('').toUpperCase() || "CU"} | |
| </div> | |
| <div style={{ minWidth: 0, flex: 1 }}> | |
| <div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray900, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{user?.full_name || 'User'}</div> | |
| <div style={{ fontSize: 11, color: COLORS.gray500, textTransform: "uppercase", fontWeight: 700, letterSpacing: "0.02em" }}>{user?.role?.replace('_', ' ') || 'Customer'}</div> | |
| </div> | |
| <button | |
| onClick={onSettings} | |
| style={{ | |
| background: "none", | |
| border: "none", | |
| padding: 4, | |
| cursor: "pointer", | |
| color: COLORS.gray400, | |
| fontSize: 16, | |
| display: "flex", | |
| alignItems: "center", | |
| justifyContent: "center", | |
| borderRadius: "50%", | |
| transition: "all 0.2s" | |
| }} | |
| onMouseEnter={e => e.currentTarget.style.color = COLORS.brand} | |
| onMouseLeave={e => e.currentTarget.style.color = COLORS.gray400} | |
| > | |
| ⚙️ | |
| </button> | |
| </div> | |
| </div> | |
| </aside> | |
| ); | |
| }; | |