Spaces:
Paused
Paused
Download frontend/apps/customer/src/components/WorkspaceView.tsx from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 10.9 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/customer/src/components/WorkspaceView.tsx
- Command line
-
hf download hf://spaces/TeamError404/nexus/frontend/apps/customer/src/components/WorkspaceView.tsx
-
curl -L -o WorkspaceView.tsx https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/customer/src/components/WorkspaceView.tsx
10.9 kB
| import React, { useState } from 'react'; | |
| import { api } from '@nexus/shared'; | |
| const COLORS = { | |
| brand: "#1E40AF", | |
| gray50: "#F9FAFB", | |
| gray100: "#F3F4F6", | |
| gray200: "#E5E7EB", | |
| gray400: "#9CA3AF", | |
| gray600: "#4B5563", | |
| gray700: "#374151", | |
| gray800: "#1F2937", | |
| gray900: "#111827", | |
| success: "#059669", | |
| error: "#DC2626", | |
| }; | |
| 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.gray900, marginBottom: 8 }}>{workspace?.name}</h1> | |
| <p style={{ color: COLORS.gray600, fontSize: 16 }}>Manage your organization's identity, team, and security settings.</p> | |
| </div> | |
| <div style={{ display: "grid", gridTemplateColumns: "1fr 340px", gap: 40, alignItems: "start" }}> | |
| {/* Team Section */} | |
| <div> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}> | |
| <h2 style={{ fontSize: 20, fontWeight: 700, color: COLORS.gray900, margin: 0 }}>Workspace Team</h2> | |
| {isAdmin ? ( | |
| <button | |
| onClick={() => setShowAddForm(true)} | |
| style={{ padding: "10px 20px", background: COLORS.brand, color: "#fff", border: "none", borderRadius: 10, fontSize: 14, fontWeight: 600, cursor: "pointer" }} | |
| > | |
| + Add Member | |
| </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: "#fff", border: `1px solid ${COLORS.gray200}`, borderRadius: 16, overflow: "hidden" }}> | |
| <table style={{ width: "100%", borderCollapse: "collapse", textAlign: "left" }}> | |
| <thead> | |
| <tr style={{ background: COLORS.gray50, borderBottom: `1px solid ${COLORS.gray200}` }}> | |
| <th style={{ padding: "16px 24px", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase" }}>Member</th> | |
| <th style={{ padding: "16px 24px", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase" }}>Role</th> | |
| <th style={{ padding: "16px 24px", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase" }}>Status</th> | |
| <th style={{ padding: "16px 24px", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase" }}></th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {members.map(member => ( | |
| <tr key={member.id} style={{ borderBottom: `1px solid ${COLORS.gray100}` }}> | |
| <td style={{ padding: "20px 24px" }}> | |
| <div style={{ display: "flex", alignItems: "center", gap: 12 }}> | |
| <div style={{ width: 36, height: 36, borderRadius: "50%", background: COLORS.gray100, display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 700, fontSize: 14, color: COLORS.brand }}> | |
| {member.full_name[0].toUpperCase()} | |
| </div> | |
| <div> | |
| <div style={{ fontSize: 14, fontWeight: 600, color: COLORS.gray900 }}>{member.full_name}</div> | |
| <div style={{ fontSize: 12, color: COLORS.gray400 }}>{member.email}</div> | |
| </div> | |
| </div> | |
| </td> | |
| <td style={{ padding: "20px 24px" }}> | |
| <span style={{ fontSize: 12, fontWeight: 600, color: COLORS.gray600, background: COLORS.gray100, padding: "4px 10px", borderRadius: 6 }}> | |
| {member.role.replace('_', ' ').toUpperCase()} | |
| </span> | |
| </td> | |
| <td style={{ padding: "20px 24px" }}> | |
| <div style={{ display: "flex", alignItems: "center", gap: 6 }}> | |
| <div style={{ width: 6, height: 6, borderRadius: "50%", background: COLORS.success }} /> | |
| <span style={{ fontSize: 13, color: COLORS.success }}>Active Member</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: 13, fontWeight: 500, cursor: "pointer" }} | |
| > | |
| Remove Member | |
| </button> | |
| )} | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| {/* Sidebar Creation Form (Fixed right) */} | |
| {showAddForm && ( | |
| <div style={{ background: "#fff", padding: 24, borderRadius: 20, border: `1px solid ${COLORS.gray200}`, boxShadow: "0 10px 40px rgba(0,0,0,0.05)" }}> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 20 }}> | |
| <h3 style={{ fontSize: 16, fontWeight: 700, margin: 0 }}>Add New Member</h3> | |
| <button onClick={() => setShowAddForm(false)} style={{ background: "none", border: "none", fontSize: 20, cursor: "pointer", color: COLORS.gray400 }}>×</button> | |
| </div> | |
| <form onSubmit={handleCreateUser} style={{ display: "flex", flexDirection: "column", gap: 16 }}> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase", marginBottom: 6 }}>Full Name</label> | |
| <input | |
| required | |
| value={form.full_name} | |
| onChange={e => setForm({...form, full_name: e.target.value})} | |
| placeholder="Enter name" | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.gray200}`, fontSize: 14, outline: "none" }} | |
| /> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase", marginBottom: 6 }}>Email</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.gray200}`, fontSize: 14, outline: "none" }} | |
| /> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase", marginBottom: 6 }}>Password</label> | |
| <input | |
| required | |
| type="password" | |
| value={form.password} | |
| onChange={e => setForm({...form, password: e.target.value})} | |
| placeholder="Temporary password" | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.gray200}`, fontSize: 14, outline: "none" }} | |
| /> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase", marginBottom: 6 }}>Role</label> | |
| <select | |
| value={form.role} | |
| onChange={e => setForm({...form, role: e.target.value})} | |
| style={{ width: "100%", padding: "12px", borderRadius: 10, border: `1px solid ${COLORS.gray200}`, fontSize: 14, outline: "none" }} | |
| > | |
| <option value="customer_user">Customer User</option> | |
| <option value="customer_admin">Customer Admin</option> | |
| </select> | |
| </div> | |
| <button | |
| type="submit" | |
| disabled={submitting} | |
| style={{ width: "100%", padding: "14px", background: COLORS.brand, color: "#fff", border: "none", borderRadius: 10, fontWeight: 700, marginTop: 10, cursor: "pointer" }} | |
| > | |
| {submitting ? "Sending Invite..." : "Create User Access"} | |
| </button> | |
| </form> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| }; | |