Spaces:
Paused
Paused
File size: 6,515 Bytes
5eb4857 accf280 5eb4857 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | 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>
);
};
|