Spaces:
Paused
Paused
Download frontend/apps/customer/src/components/WorkspaceView.tsx from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 12.5 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/frontend/apps/customer/src/components/WorkspaceView.tsx
- Command line
-
hf download hf://spaces/3SCError404/nexus/frontend/apps/customer/src/components/WorkspaceView.tsx
-
curl -L -o WorkspaceView.tsx https://huggingface.co/spaces/3SCError404/nexus/resolve/main/frontend/apps/customer/src/components/WorkspaceView.tsx
12.5 kB
| import React, { useState } from 'react'; | |
| import { api } from '@nexus/shared'; | |
| const COLORS = { | |
| brand: "var(--neural-accent-indigo)", | |
| border: "var(--border-subtle)", | |
| bg: "var(--bg-dark)", | |
| card: "var(--bg-card)", | |
| text: "var(--text-main)", | |
| muted: "var(--text-muted)", | |
| success: "var(--success)", | |
| error: "var(--error)", | |
| gray200: "var(--border-subtle)", | |
| gray400: "var(--text-muted)", | |
| gray900: "var(--text-main)", | |
| }; | |
| import { useWorkspace, useUsers } from '@nexus/shared'; | |
| export const WorkspaceView: React.FC<{ user: any }> = ({ user }) => { | |
| const { workspace, loading: workspaceLoading } = useWorkspace(); | |
| const { users: members, loading: usersLoading, refresh: refreshUsers, addUser, loaded: usersLoaded } = useUsers(); | |
| // New User Form | |
| const [showAddForm, setShowAddForm] = useState(false); | |
| const [form, setForm] = useState({ email: '', full_name: '', password: '', role: 'customer_user' }); | |
| const [submitting, setSubmitting] = useState(false); | |
| const isAdmin = user.role.includes('admin'); | |
| const isInitialLoading = (workspaceLoading && !workspace) || (usersLoading && !usersLoaded); | |
| const handleCreateUser = async (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| setSubmitting(true); | |
| try { | |
| await addUser(form); | |
| setForm({ email: '', full_name: '', password: '', role: 'customer_user' }); | |
| // Brief delay before closing for better feedback | |
| setTimeout(() => { | |
| setShowAddForm(false); | |
| setSubmitting(false); | |
| }, 500); | |
| } catch (err) { | |
| console.error("Failed to create user:", err); | |
| alert("Error creating user. Check email uniqueness and permissions."); | |
| setSubmitting(false); | |
| } | |
| }; | |
| const removeMember = async (memberId: string) => { | |
| if (!window.confirm("Are you sure you want to remove this member? This action is definitive.")) return; | |
| try { | |
| await api.delete(`/users/${memberId}/`); | |
| refreshUsers(); | |
| } catch (err) { | |
| console.error("Failed to remove member:", err); | |
| alert("Error removing member. Check your administrative permissions."); | |
| } | |
| }; | |
| if (isInitialLoading) return <div style={{ padding: 40, color: COLORS.gray400 }}>Loading workspace intelligence...</div>; | |
| return ( | |
| <div style={{ padding: "40px", maxWidth: 1200, margin: "0 auto" }}> | |
| {/* Workspace Header */} | |
| <div style={{ marginBottom: 48 }}> | |
| <h1 style={{ fontSize: 32, fontWeight: 800, color: COLORS.text, marginBottom: 8, fontFamily: 'var(--font-header)' }}>{workspace?.name}</h1> | |
| <p style={{ color: COLORS.muted, fontSize: 16 }}>Manage your organization's identity, team, and security settings.</p> | |
| </div> | |
| <div style={{ display: "flex", gap: 40, alignItems: "start", flexWrap: "wrap" }}> | |
| {/* Team Section */} | |
| <div style={{ flex: "1 1 600px" }}> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}> | |
| <h2 style={{ fontSize: 20, fontWeight: 700, color: COLORS.text, margin: 0 }}>Workspace Team</h2> | |
| {isAdmin ? ( | |
| <button | |
| onClick={() => setShowAddForm(true)} | |
| style={{ | |
| padding: "10px 24px", | |
| background: "var(--brand-gradient)", | |
| color: "#fff", | |
| border: "none", | |
| borderRadius: 10, | |
| fontSize: 13, | |
| fontWeight: 800, | |
| cursor: "pointer", | |
| textTransform: 'uppercase', | |
| letterSpacing: '0.05em', | |
| boxShadow: '0 8px 16px -4px rgba(109, 40, 217, 0.4)' | |
| }} | |
| > | |
| + Add Intelligence Access | |
| </button> | |
| ) : ( | |
| <button | |
| disabled | |
| style={{ padding: "10px 20px", background: COLORS.gray200, color: COLORS.gray400, border: "none", borderRadius: 10, fontSize: 14, fontWeight: 600, cursor: "not-allowed" }} | |
| > | |
| Contact Admin to Add Users | |
| </button> | |
| )} | |
| </div> | |
| <div style={{ background: COLORS.card, border: `1px solid ${COLORS.border}`, borderRadius: 16, overflow: "hidden", boxShadow: "0 4px 12px rgba(0,0,0,0.1)" }}> | |
| <table style={{ width: "100%", borderCollapse: "collapse", textAlign: "left" }}> | |
| <thead> | |
| <tr style={{ background: "rgba(255,255,255,0.02)", borderBottom: `1px solid ${COLORS.border}` }}> | |
| <th style={{ padding: "16px 24px", fontSize: 10, fontWeight: 800, color: COLORS.muted, textTransform: "uppercase", letterSpacing: '0.1em' }}>Identity</th> | |
| <th style={{ padding: "16px 24px", fontSize: 10, fontWeight: 800, color: COLORS.muted, textTransform: "uppercase", letterSpacing: '0.1em' }}>Access Level</th> | |
| <th style={{ padding: "16px 24px", fontSize: 10, fontWeight: 800, color: COLORS.muted, textTransform: "uppercase", letterSpacing: '0.1em' }}>Operational Status</th> | |
| <th style={{ padding: "16px 24px", fontSize: 10, fontWeight: 800, color: COLORS.muted, textTransform: "uppercase", letterSpacing: '0.1em' }}>Action</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {members.map(member => ( | |
| <tr key={member.id} style={{ borderBottom: `1px solid ${COLORS.border}` }}> | |
| <td style={{ padding: "20px 24px" }}> | |
| <div style={{ display: "flex", alignItems: "center", gap: 12 }}> | |
| <div style={{ width: 36, height: 36, borderRadius: 10, background: "rgba(99, 102, 241, 0.1)", display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 800, fontSize: 14, color: COLORS.brand }}> | |
| {member.full_name[0].toUpperCase()} | |
| </div> | |
| <div> | |
| <div style={{ fontSize: 14, fontWeight: 700, color: COLORS.text }}>{member.full_name}</div> | |
| <div style={{ fontSize: 12, color: COLORS.muted }}>{member.email}</div> | |
| </div> | |
| </div> | |
| </td> | |
| <td style={{ padding: "20px 24px" }}> | |
| <span style={{ fontSize: 11, fontWeight: 800, color: COLORS.brand, background: "rgba(99, 102, 241, 0.1)", padding: "4px 10px", borderRadius: 6, letterSpacing: '0.05em' }}> | |
| {member.role.replace('_', ' ').toUpperCase()} | |
| </span> | |
| </td> | |
| <td style={{ padding: "20px 24px" }}> | |
| <div style={{ display: "flex", alignItems: "center", gap: 8 }}> | |
| <div style={{ width: 8, height: 8, borderRadius: "50%", background: COLORS.success }} /> | |
| <span style={{ fontSize: 12, fontWeight: 600, color: COLORS.success }}>Online</span> | |
| </div> | |
| </td> | |
| <td style={{ padding: "20px 24px", textAlign: "right" }}> | |
| {isAdmin && member.id !== user.id && ( | |
| <button | |
| onClick={() => removeMember(member.id)} | |
| style={{ background: "none", border: "none", color: COLORS.error, fontSize: 12, fontWeight: 700, cursor: "pointer", opacity: 0.7 }} | |
| > | |
| REVOKE ACCESS | |
| </button> | |
| )} | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| {/* Sidebar Creation Form (Fixed right) */} | |
| {showAddForm && ( | |
| <div style={{ flex: "1 1 340px", background: COLORS.card, padding: 24, borderRadius: 20, border: `1px solid ${COLORS.border}`, boxShadow: "0 20px 40px rgba(0,0,0,0.3)" }}> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}> | |
| <h3 style={{ fontSize: 15, fontWeight: 800, margin: 0, textTransform: 'uppercase', letterSpacing: '0.1em' }}>Member Protocol</h3> | |
| <button onClick={() => setShowAddForm(false)} style={{ background: "rgba(255,255,255,0.05)", border: "none", width: 28, height: 28, borderRadius: "50%", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", color: COLORS.text }}>×</button> | |
| </div> | |
| <form onSubmit={handleCreateUser} style={{ display: "flex", flexDirection: "column", gap: 20 }}> | |
| <div> | |
| <label style={{ display: "block", fontSize: 10, fontWeight: 900, color: COLORS.muted, textTransform: "uppercase", marginBottom: 8, letterSpacing: '0.1em' }}>Identity Label</label> | |
| <input | |
| required | |
| value={form.full_name} | |
| onChange={e => setForm({...form, full_name: e.target.value})} | |
| placeholder="e.g. John Doe" | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.border}`, fontSize: 14, outline: "none", background: "rgba(255,255,255,0.03)", color: COLORS.text }} | |
| /> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 10, fontWeight: 900, color: COLORS.muted, textTransform: "uppercase", marginBottom: 8, letterSpacing: '0.1em' }}>Email Secure</label> | |
| <input | |
| required | |
| type="email" | |
| value={form.email} | |
| onChange={e => setForm({...form, email: e.target.value})} | |
| placeholder="name@company.com" | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.border}`, fontSize: 14, outline: "none", background: "rgba(255,255,255,0.03)", color: COLORS.text }} | |
| /> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 10, fontWeight: 900, color: COLORS.muted, textTransform: "uppercase", marginBottom: 8, letterSpacing: '0.1em' }}>Temporary Key</label> | |
| <input | |
| required | |
| type="password" | |
| value={form.password} | |
| onChange={e => setForm({...form, password: e.target.value})} | |
| placeholder="••••••••" | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.border}`, fontSize: 14, outline: "none", background: "rgba(255,255,255,0.03)", color: COLORS.text }} | |
| /> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 10, fontWeight: 900, color: COLORS.muted, textTransform: "uppercase", marginBottom: 8, letterSpacing: '0.1em' }}>Permission Tier</label> | |
| <select | |
| value={form.role} | |
| onChange={e => setForm({...form, role: e.target.value})} | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.border}`, fontSize: 14, outline: "none", background: "rgba(255,255,255,0.03)", color: COLORS.text }} | |
| > | |
| <option value="customer_user">Standard Intelligence Access</option> | |
| <option value="customer_admin">Workspace Administrator</option> | |
| </select> | |
| </div> | |
| <button | |
| type="submit" | |
| disabled={submitting} | |
| style={{ | |
| width: "100%", | |
| padding: "14px", | |
| background: "var(--brand-gradient)", | |
| color: "#fff", | |
| border: "none", | |
| borderRadius: 10, | |
| fontWeight: 800, | |
| marginTop: 10, | |
| cursor: "pointer", | |
| textTransform: 'uppercase', | |
| letterSpacing: '0.1em', | |
| boxShadow: '0 10px 25px -5px rgba(109, 40, 217, 0.3)' | |
| }} | |
| > | |
| {submitting ? "ENCRYPTING..." : "Provision Access"} | |
| </button> | |
| </form> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| }; | |