Download studio/src/components/AccessManagementModal.jsx from shak3008/DiffWeave: direct link, hf CLI and curl.
- Browser
- Download file 36.3 kB
-
https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/components/AccessManagementModal.jsx
- Command line
-
hf download hf://spaces/shak3008/DiffWeave/studio/src/components/AccessManagementModal.jsx
-
curl -L -o AccessManagementModal.jsx https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/components/AccessManagementModal.jsx
36.3 kB
| import React, { useState, useEffect } from 'react'; | |
| import { | |
| Lock, | |
| Globe, | |
| Users, | |
| UserPlus, | |
| Shield, | |
| Trash2, | |
| CheckCircle2, | |
| Copy, | |
| Key, | |
| X, | |
| RefreshCw, | |
| AlertCircle, | |
| Heart, | |
| UserCheck, | |
| UserX, | |
| Clock, | |
| Sparkles, | |
| Send | |
| } from 'lucide-react'; | |
| import { api } from '../api/client'; | |
| export default function AccessManagementModal({ workspace, isOpen, onClose, onWorkspaceUpdated }) { | |
| const [accessData, setAccessData] = useState(null); | |
| const [loading, setLoading] = useState(true); | |
| const [visibility, setVisibility] = useState(workspace?.visibility || 'private'); | |
| const [savingVis, setSavingVis] = useState(false); | |
| const [activeTab, setActiveTab] = useState('members'); // 'members' | 'followers' | 'requests' | |
| // Invite state | |
| const [inviteEmail, setInviteEmail] = useState(''); | |
| const [inviteRole, setInviteRole] = useState('EDITOR'); | |
| const [inviting, setInviting] = useState(false); | |
| const [errorMsg, setErrorMsg] = useState(''); | |
| const [successMsg, setSuccessMsg] = useState(''); | |
| // Follow / Collab Request state | |
| const [actionLoading, setActionLoading] = useState(false); | |
| const [requestNote, setRequestNote] = useState(''); | |
| // Scoped Token state | |
| const [generatedToken, setGeneratedToken] = useState(''); | |
| const [copiedToken, setCopiedToken] = useState(false); | |
| useEffect(() => { | |
| if (isOpen && workspace?.id) { | |
| loadAccess(); | |
| } | |
| }, [isOpen, workspace?.id]); | |
| const loadAccess = async () => { | |
| setLoading(true); | |
| setErrorMsg(''); | |
| try { | |
| const data = await api.getWorkspaceAccess(workspace.id); | |
| setAccessData(data); | |
| setVisibility(data.visibility || 'private'); | |
| if (data.pending_requests?.length > 0 && data.is_owner && activeTab === 'members') { | |
| // highlight requests tab if pending items exist for owner | |
| } | |
| } catch (err) { | |
| setErrorMsg(`Could not load access data: ${err.message}`); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| const handleVisibilityChange = async (newVis) => { | |
| if (newVis === visibility) return; | |
| setSavingVis(true); | |
| setErrorMsg(''); | |
| setSuccessMsg(''); | |
| try { | |
| await api.updateWorkspaceVisibility(workspace.id, newVis); | |
| setVisibility(newVis); | |
| setSuccessMsg(`Workspace is now ${newVis.toUpperCase()}.`); | |
| if (onWorkspaceUpdated) { | |
| onWorkspaceUpdated({ ...workspace, visibility: newVis }); | |
| } | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Failed to update visibility: ${err.message}`); | |
| } finally { | |
| setSavingVis(false); | |
| } | |
| }; | |
| const handleInvite = async (e) => { | |
| e.preventDefault(); | |
| if (!inviteEmail.trim()) return; | |
| setInviting(true); | |
| setErrorMsg(''); | |
| setSuccessMsg(''); | |
| try { | |
| await api.addWorkspaceMember(workspace.id, inviteEmail.trim(), inviteRole); | |
| setInviteEmail(''); | |
| setSuccessMsg(`Collaborator added successfully.`); | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Could not add collaborator: ${err.message}`); | |
| } finally { | |
| setInviting(false); | |
| } | |
| }; | |
| const handleRemoveMember = async (memberId) => { | |
| try { | |
| await api.removeWorkspaceMember(workspace.id, memberId); | |
| setSuccessMsg('Collaborator removed.'); | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Failed to remove: ${err.message}`); | |
| } | |
| }; | |
| const handleUpdateRole = async (memberId, newRole) => { | |
| try { | |
| await api.updateWorkspaceMemberRole(workspace.id, memberId, newRole); | |
| setSuccessMsg(`Role updated to ${newRole}.`); | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Failed to update role: ${err.message}`); | |
| } | |
| }; | |
| // Follow / Unfollow | |
| const handleToggleFollow = async () => { | |
| setActionLoading(true); | |
| setErrorMsg(''); | |
| setSuccessMsg(''); | |
| try { | |
| if (accessData?.user_membership?.is_follower) { | |
| await api.unfollowWorkspace(workspace.id); | |
| setSuccessMsg('You unfollowed this workspace.'); | |
| } else { | |
| await api.followWorkspace(workspace.id); | |
| setSuccessMsg('You are now following this workspace.'); | |
| } | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Could not update follow status: ${err.message}`); | |
| } finally { | |
| setActionLoading(false); | |
| } | |
| }; | |
| // Request Access / Collaboration on Private Workspace | |
| const handleRequestCollab = async (e) => { | |
| e?.preventDefault(); | |
| setActionLoading(true); | |
| setErrorMsg(''); | |
| setSuccessMsg(''); | |
| try { | |
| const res = await api.requestWorkspaceCollab(workspace.id, 'REQUESTED_COLLAB', requestNote); | |
| setSuccessMsg(res.message || 'Collaboration request submitted to workspace owner.'); | |
| setRequestNote(''); | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Failed to submit request: ${err.message}`); | |
| } finally { | |
| setActionLoading(false); | |
| } | |
| }; | |
| // Owner Approve Request | |
| const handleApproveRequest = async (memberId, assignedRole = 'EDITOR') => { | |
| setActionLoading(true); | |
| setErrorMsg(''); | |
| setSuccessMsg(''); | |
| try { | |
| await api.respondWorkspaceRequest(workspace.id, memberId, 'APPROVE', assignedRole); | |
| setSuccessMsg('Access request approved! Collaborator is now active.'); | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Could not approve request: ${err.message}`); | |
| } finally { | |
| setActionLoading(false); | |
| } | |
| }; | |
| // Owner Reject Request | |
| const handleRejectRequest = async (memberId) => { | |
| setActionLoading(true); | |
| setErrorMsg(''); | |
| setSuccessMsg(''); | |
| try { | |
| await api.respondWorkspaceRequest(workspace.id, memberId, 'REJECT'); | |
| setSuccessMsg('Access request dismissed.'); | |
| await loadAccess(); | |
| } catch (err) { | |
| setErrorMsg(`Could not reject request: ${err.message}`); | |
| } finally { | |
| setActionLoading(false); | |
| } | |
| }; | |
| const handleGenerateToken = () => { | |
| const token = `dw_ws_${workspace.id.replace(/-/g, '').slice(0, 12)}_${Math.random().toString(36).substring(2, 10)}`; | |
| setGeneratedToken(token); | |
| setCopiedToken(false); | |
| }; | |
| const handleCopyToken = () => { | |
| if (!generatedToken) return; | |
| navigator.clipboard.writeText(generatedToken); | |
| setCopiedToken(true); | |
| setTimeout(() => setCopiedToken(false), 2500); | |
| }; | |
| if (!isOpen) return null; | |
| const isOwner = Boolean(accessData?.is_owner); | |
| const userMembership = accessData?.user_membership || {}; | |
| const pendingCount = (accessData?.pending_requests || []).length; | |
| const followersCount = accessData?.followers_count || (accessData?.followers || []).length; | |
| const membersCount = (accessData?.members || []).length + 1; | |
| return ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm p-4 overflow-y-auto"> | |
| <div className="bg-[#0C101A] border border-slate-700/80 rounded-2xl w-full max-w-2xl shadow-2xl overflow-hidden my-8 flex flex-col max-h-[85vh]"> | |
| {/* Header */} | |
| <div className="px-6 py-4 border-b border-slate-800 flex items-center justify-between bg-[#0F1422] shrink-0"> | |
| <div className="flex items-center space-x-3"> | |
| <div className="w-9 h-9 rounded-xl bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center text-emerald-400"> | |
| <Users className="w-5 h-5" /> | |
| </div> | |
| <div> | |
| <h3 className="text-sm font-bold text-white flex items-center space-x-2"> | |
| <span>Workspace Access & Collaborators</span> | |
| <span className="text-[10px] px-2 py-0.5 rounded-full font-mono bg-slate-800 text-slate-300 border border-slate-700"> | |
| {workspace?.name} | |
| </span> | |
| </h3> | |
| <p className="text-[11px] text-slate-400"> | |
| Manage members, followers, pending collaboration requests, and visibility. | |
| </p> | |
| </div> | |
| </div> | |
| <button | |
| onClick={onClose} | |
| className="p-1 rounded-lg text-slate-400 hover:text-white hover:bg-slate-800 transition" | |
| > | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| {/* Alerts */} | |
| {errorMsg && ( | |
| <div className="mx-6 mt-3 p-3 rounded-xl bg-rose-950/40 border border-rose-500/30 text-rose-300 text-xs flex items-center space-x-2 shrink-0"> | |
| <AlertCircle className="w-4 h-4 text-rose-400 shrink-0" /> | |
| <span>{errorMsg}</span> | |
| </div> | |
| )} | |
| {successMsg && ( | |
| <div className="mx-6 mt-3 p-3 rounded-xl bg-emerald-950/40 border border-emerald-500/30 text-emerald-300 text-xs flex items-center space-x-2 shrink-0"> | |
| <CheckCircle2 className="w-4 h-4 text-emerald-400 shrink-0" /> | |
| <span>{successMsg}</span> | |
| </div> | |
| )} | |
| {/* Sub-Header Actions: Follower status & Collab request button */} | |
| <div className="px-6 py-3 bg-[#080B12] border-b border-slate-800/80 flex flex-wrap items-center justify-between gap-3 text-xs shrink-0"> | |
| <div className="flex items-center space-x-2"> | |
| <span className="text-slate-400">Your Status:</span> | |
| <span className={`px-2 py-0.5 rounded text-[10px] font-bold font-mono ${ | |
| userMembership.is_owner | |
| ? 'bg-emerald-500/10 text-emerald-400 border border-emerald-500/30' | |
| : userMembership.is_member | |
| ? 'bg-sky-500/10 text-sky-400 border border-sky-500/30' | |
| : userMembership.request_pending | |
| ? 'bg-amber-500/10 text-amber-400 border border-amber-500/30' | |
| : 'bg-slate-800 text-slate-400' | |
| }`}> | |
| {userMembership.role || 'VIEWER'} | |
| </span> | |
| {userMembership.is_follower && ( | |
| <span className="px-2 py-0.5 rounded text-[10px] font-bold font-mono bg-pink-500/10 text-pink-400 border border-pink-500/30 flex items-center space-x-1"> | |
| <Heart className="w-2.5 h-2.5 fill-pink-400" /> | |
| <span>FOLLOWING</span> | |
| </span> | |
| )} | |
| </div> | |
| <div className="flex items-center space-x-2"> | |
| {/* Follow / Unfollow Button */} | |
| <button | |
| type="button" | |
| onClick={handleToggleFollow} | |
| disabled={actionLoading} | |
| className={`px-3 py-1.5 rounded-xl text-xs font-semibold transition flex items-center space-x-1.5 ${ | |
| userMembership.is_follower | |
| ? 'bg-pink-500/10 hover:bg-pink-500/20 text-pink-300 border border-pink-500/30' | |
| : 'bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700' | |
| }`} | |
| > | |
| <Heart className={`w-3.5 h-3.5 ${userMembership.is_follower ? 'fill-pink-400 text-pink-400' : 'text-slate-400'}`} /> | |
| <span>{userMembership.is_follower ? 'Unfollow' : 'Follow Workspace'}</span> | |
| <span className="px-1.5 py-0.2 bg-black/40 rounded-full text-[10px] ml-1"> | |
| {followersCount} | |
| </span> | |
| </button> | |
| {/* Request Collab button if private and not a member */} | |
| {!userMembership.is_member && visibility === 'private' && ( | |
| <button | |
| type="button" | |
| onClick={handleRequestCollab} | |
| disabled={actionLoading || userMembership.request_pending} | |
| className={`px-3 py-1.5 rounded-xl text-xs font-semibold transition flex items-center space-x-1.5 ${ | |
| userMembership.request_pending | |
| ? 'bg-amber-500/10 text-amber-300 border border-amber-500/30 cursor-default' | |
| : 'bg-emerald-600 hover:bg-emerald-500 text-white' | |
| }`} | |
| > | |
| <Send className="w-3.5 h-3.5" /> | |
| <span>{userMembership.request_pending ? 'Request Pending...' : 'Request Collaboration'}</span> | |
| </button> | |
| )} | |
| </div> | |
| </div> | |
| {/* Tab Controls */} | |
| <div className="flex border-b border-slate-800 bg-[#0C101A] px-6 pt-2 shrink-0"> | |
| <button | |
| type="button" | |
| onClick={() => setActiveTab('members')} | |
| className={`pb-2.5 px-3 text-xs font-semibold border-b-2 transition flex items-center space-x-1.5 ${ | |
| activeTab === 'members' | |
| ? 'border-emerald-400 text-white' | |
| : 'border-transparent text-slate-400 hover:text-slate-200' | |
| }`} | |
| > | |
| <Users className="w-3.5 h-3.5" /> | |
| <span>Active Members</span> | |
| <span className="text-[10px] px-1.5 py-0.2 rounded-full bg-slate-800 font-mono text-slate-300"> | |
| {membersCount} | |
| </span> | |
| </button> | |
| <button | |
| type="button" | |
| onClick={() => setActiveTab('followers')} | |
| className={`pb-2.5 px-3 text-xs font-semibold border-b-2 transition flex items-center space-x-1.5 ${ | |
| activeTab === 'followers' | |
| ? 'border-pink-400 text-white' | |
| : 'border-transparent text-slate-400 hover:text-slate-200' | |
| }`} | |
| > | |
| <Heart className="w-3.5 h-3.5" /> | |
| <span>Followers</span> | |
| <span className="text-[10px] px-1.5 py-0.2 rounded-full bg-slate-800 font-mono text-slate-300"> | |
| {followersCount} | |
| </span> | |
| </button> | |
| {isOwner && ( | |
| <button | |
| type="button" | |
| onClick={() => setActiveTab('requests')} | |
| className={`pb-2.5 px-3 text-xs font-semibold border-b-2 transition flex items-center space-x-1.5 ${ | |
| activeTab === 'requests' | |
| ? 'border-amber-400 text-white' | |
| : 'border-transparent text-slate-400 hover:text-slate-200' | |
| }`} | |
| > | |
| <Clock className="w-3.5 h-3.5 text-amber-400" /> | |
| <span>Pending Requests</span> | |
| {pendingCount > 0 && ( | |
| <span className="text-[10px] px-1.5 py-0.2 rounded-full bg-amber-500/20 text-amber-300 font-mono font-bold animate-pulse"> | |
| {pendingCount} | |
| </span> | |
| )} | |
| </button> | |
| )} | |
| <button | |
| type="button" | |
| onClick={() => setActiveTab('visibility')} | |
| className={`pb-2.5 px-3 text-xs font-semibold border-b-2 transition flex items-center space-x-1.5 ${ | |
| activeTab === 'visibility' | |
| ? 'border-sky-400 text-white' | |
| : 'border-transparent text-slate-400 hover:text-slate-200' | |
| }`} | |
| > | |
| <Shield className="w-3.5 h-3.5" /> | |
| <span>Visibility & API</span> | |
| </button> | |
| </div> | |
| {/* Tab Contents */} | |
| <div className="p-6 space-y-6 overflow-y-auto flex-1"> | |
| {/* TAB 1: ACTIVE MEMBERS */} | |
| {activeTab === 'members' && ( | |
| <div className="space-y-6"> | |
| {/* Invite Collaborators (Owner/Admin) */} | |
| {isOwner && ( | |
| <div className="space-y-3"> | |
| <label className="text-xs font-bold uppercase tracking-wider text-slate-300 font-mono block"> | |
| Invite Collaborator | |
| </label> | |
| <form onSubmit={handleInvite} className="flex flex-col sm:flex-row gap-2"> | |
| <input | |
| type="email" | |
| placeholder="teammate@company.com" | |
| value={inviteEmail} | |
| onChange={(e) => setInviteEmail(e.target.value)} | |
| required | |
| className="flex-1 bg-[#121726] border border-slate-800 rounded-xl px-3.5 py-2 text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:ring-1 focus:ring-emerald-500" | |
| /> | |
| <select | |
| value={inviteRole} | |
| onChange={(e) => setInviteRole(e.target.value)} | |
| className="bg-[#121726] border border-slate-800 rounded-xl px-3 py-2 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-emerald-500" | |
| > | |
| <option value="ADMIN">Admin (Full Control)</option> | |
| <option value="EDITOR">Editor (Stage & Review PRs)</option> | |
| <option value="VIEWER">Viewer (Read-Only)</option> | |
| </select> | |
| <button | |
| type="submit" | |
| disabled={inviting || !inviteEmail.trim()} | |
| className="px-4 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-semibold text-xs transition flex items-center justify-center space-x-1.5 disabled:opacity-50 shrink-0" | |
| > | |
| <UserPlus className="w-3.5 h-3.5" /> | |
| <span>{inviting ? 'Inviting...' : 'Add Member'}</span> | |
| </button> | |
| </form> | |
| </div> | |
| )} | |
| {/* Members List */} | |
| <div className="space-y-3"> | |
| <div className="flex items-center justify-between"> | |
| <label className="text-xs font-bold uppercase tracking-wider text-slate-300 font-mono"> | |
| Workspace Collaborators ({membersCount}) | |
| </label> | |
| <button | |
| type="button" | |
| onClick={loadAccess} | |
| className="text-[11px] text-slate-400 hover:text-white flex items-center space-x-1" | |
| > | |
| <RefreshCw className={`w-3 h-3 ${loading ? 'animate-spin' : ''}`} /> | |
| <span>Refresh</span> | |
| </button> | |
| </div> | |
| <div className="divide-y divide-slate-800/80 rounded-xl border border-slate-800 bg-[#121726] overflow-hidden text-xs"> | |
| {/* Workspace Owner */} | |
| <div className="p-3.5 flex items-center justify-between"> | |
| <div className="flex items-center space-x-3"> | |
| <div className="w-8 h-8 rounded-full bg-emerald-500/20 text-emerald-400 font-bold flex items-center justify-center text-xs border border-emerald-500/30"> | |
| {(accessData?.owner?.username || 'O')[0].toUpperCase()} | |
| </div> | |
| <div> | |
| <div className="flex items-center space-x-2"> | |
| <span className="font-semibold text-white block"> | |
| {accessData?.owner?.username || 'Workspace Owner'} | |
| </span> | |
| <span className="text-[10px] font-mono font-bold px-2 py-0.2 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20"> | |
| OWNER | |
| </span> | |
| </div> | |
| <span className="text-[11px] text-slate-400 font-mono"> | |
| {accessData?.owner?.email || 'owner@diffweave.io'} | |
| </span> | |
| </div> | |
| </div> | |
| <span className="text-[10px] text-slate-500 font-mono">Creator</span> | |
| </div> | |
| {/* Collaborators */} | |
| {(accessData?.members || []).map((m) => ( | |
| <div key={m.id} className="p-3.5 flex items-center justify-between"> | |
| <div className="flex items-center space-x-3 min-w-0"> | |
| <div className="w-8 h-8 rounded-full bg-slate-800 text-slate-300 font-bold flex items-center justify-center text-xs shrink-0"> | |
| {(m.username || m.email)[0].toUpperCase()} | |
| </div> | |
| <div className="min-w-0"> | |
| <span className="font-semibold text-slate-200 block truncate"> | |
| {m.username || m.email} | |
| </span> | |
| <span className="text-[10px] text-slate-400 font-mono block truncate"> | |
| {m.email} • Joined {m.created_at ? new Date(m.created_at).toLocaleDateString() : 'recently'} | |
| </span> | |
| </div> | |
| </div> | |
| <div className="flex items-center space-x-2 shrink-0"> | |
| {isOwner ? ( | |
| <> | |
| <select | |
| value={m.role} | |
| onChange={(e) => handleUpdateRole(m.id, e.target.value)} | |
| className="bg-[#0C101A] border border-slate-700 rounded-lg px-2 py-1 text-[11px] text-slate-200" | |
| > | |
| <option value="ADMIN">Admin</option> | |
| <option value="EDITOR">Editor</option> | |
| <option value="VIEWER">Viewer</option> | |
| </select> | |
| <button | |
| onClick={() => handleRemoveMember(m.id)} | |
| className="p-1 rounded text-slate-500 hover:text-rose-400 transition" | |
| title="Remove Collaborator" | |
| > | |
| <Trash2 className="w-3.5 h-3.5" /> | |
| </button> | |
| </> | |
| ) : ( | |
| <span className="text-[10px] font-mono px-2 py-0.5 rounded bg-slate-800 text-slate-300"> | |
| {m.role} | |
| </span> | |
| )} | |
| </div> | |
| </div> | |
| ))} | |
| {(accessData?.members || []).length === 0 && ( | |
| <div className="p-4 text-center text-slate-500 text-xs"> | |
| No additional collaborators added yet. Invite teammates above to collaborate on this workspace. | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {/* TAB 2: FOLLOWERS */} | |
| {activeTab === 'followers' && ( | |
| <div className="space-y-4"> | |
| <div className="flex items-center justify-between"> | |
| <div> | |
| <h4 className="text-xs font-bold uppercase tracking-wider text-slate-300 font-mono"> | |
| Workspace Followers ({followersCount}) | |
| </h4> | |
| <p className="text-[11px] text-slate-400"> | |
| Users who follow this workspace to receive live Knowledge updates and PR activity. | |
| </p> | |
| </div> | |
| <button | |
| type="button" | |
| onClick={loadAccess} | |
| className="text-[11px] text-slate-400 hover:text-white flex items-center space-x-1" | |
| > | |
| <RefreshCw className={`w-3 h-3 ${loading ? 'animate-spin' : ''}`} /> | |
| <span>Refresh</span> | |
| </button> | |
| </div> | |
| {(accessData?.followers || []).length === 0 ? ( | |
| <div className="p-8 text-center rounded-xl border border-dashed border-slate-800 bg-[#121726] space-y-2"> | |
| <Heart className="w-8 h-8 text-slate-600 mx-auto" /> | |
| <p className="text-xs text-slate-300 font-medium">No followers yet.</p> | |
| <p className="text-[11px] text-slate-500 max-w-sm mx-auto"> | |
| When teammates or community members follow this workspace, they will appear here. Click the "Follow" button above to follow this workspace yourself! | |
| </p> | |
| </div> | |
| ) : ( | |
| <div className="divide-y divide-slate-800/80 rounded-xl border border-slate-800 bg-[#121726] overflow-hidden text-xs"> | |
| {accessData.followers.map((f) => ( | |
| <div key={f.id} className="p-3.5 flex items-center justify-between"> | |
| <div className="flex items-center space-x-3"> | |
| <div className="w-8 h-8 rounded-full bg-pink-500/10 border border-pink-500/30 text-pink-400 font-bold flex items-center justify-center text-xs"> | |
| {(f.username || f.email)[0].toUpperCase()} | |
| </div> | |
| <div> | |
| <span className="font-semibold text-slate-200 block">{f.username || f.email}</span> | |
| <span className="text-[10px] text-slate-400 font-mono"> | |
| {f.email} • Following since {f.created_at ? new Date(f.created_at).toLocaleDateString() : 'recently'} | |
| </span> | |
| </div> | |
| </div> | |
| <span className="px-2 py-0.5 rounded text-[10px] font-mono font-bold bg-pink-500/10 text-pink-400 border border-pink-500/20 flex items-center space-x-1"> | |
| <Heart className="w-3 h-3 fill-pink-400" /> | |
| <span>FOLLOWER</span> | |
| </span> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {/* TAB 3: PENDING ACCESS & COLLAB REQUESTS (OWNER ONLY) */} | |
| {activeTab === 'requests' && isOwner && ( | |
| <div className="space-y-4"> | |
| <div className="flex items-center justify-between"> | |
| <div> | |
| <h4 className="text-xs font-bold uppercase tracking-wider text-slate-300 font-mono"> | |
| Pending Collaboration & Follow Requests ({pendingCount}) | |
| </h4> | |
| <p className="text-[11px] text-slate-400"> | |
| Review incoming access requests from teammates. Approve to grant access or dismiss. | |
| </p> | |
| </div> | |
| <button | |
| type="button" | |
| onClick={loadAccess} | |
| className="text-[11px] text-slate-400 hover:text-white flex items-center space-x-1" | |
| > | |
| <RefreshCw className={`w-3 h-3 ${loading ? 'animate-spin' : ''}`} /> | |
| <span>Refresh</span> | |
| </button> | |
| </div> | |
| {pendingCount === 0 ? ( | |
| <div className="p-8 text-center rounded-xl border border-dashed border-slate-800 bg-[#121726] space-y-2"> | |
| <UserCheck className="w-8 h-8 text-emerald-500/60 mx-auto" /> | |
| <p className="text-xs text-slate-300 font-medium">All caught up!</p> | |
| <p className="text-[11px] text-slate-500"> | |
| No pending collaboration requests waiting for review. | |
| </p> | |
| </div> | |
| ) : ( | |
| <div className="divide-y divide-slate-800/80 rounded-xl border border-slate-800 bg-[#121726] overflow-hidden text-xs"> | |
| {accessData.pending_requests.map((req) => ( | |
| <div key={req.id} className="p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3"> | |
| <div className="flex items-start space-x-3"> | |
| <div className="w-8 h-8 rounded-full bg-amber-500/10 border border-amber-500/30 text-amber-400 font-bold flex items-center justify-center text-xs shrink-0 mt-0.5"> | |
| {(req.username || req.email)[0].toUpperCase()} | |
| </div> | |
| <div> | |
| <div className="flex items-center space-x-2"> | |
| <span className="font-semibold text-white">{req.username || req.email}</span> | |
| <span className="px-1.5 py-0.2 rounded text-[9px] font-bold font-mono bg-amber-500/10 text-amber-400 border border-amber-500/20"> | |
| REQUESTED {req.role === 'REQUESTED_FOLLOW' ? 'FOLLOW' : 'COLLAB'} | |
| </span> | |
| </div> | |
| <p className="text-[11px] text-slate-400 font-mono mt-0.5">{req.email}</p> | |
| <p className="text-[10px] text-slate-500 mt-0.5"> | |
| Requested on {req.created_at ? new Date(req.created_at).toLocaleDateString() : 'today'} | |
| </p> | |
| </div> | |
| </div> | |
| {/* Approval / Rejection Actions */} | |
| <div className="flex items-center space-x-2 shrink-0 self-end sm:self-center"> | |
| <button | |
| type="button" | |
| onClick={() => handleApproveRequest(req.id, req.role === 'REQUESTED_FOLLOW' ? 'FOLLOWER' : 'EDITOR')} | |
| disabled={actionLoading} | |
| className="px-3 py-1.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 text-white font-semibold text-xs transition flex items-center space-x-1.5" | |
| > | |
| <UserCheck className="w-3.5 h-3.5" /> | |
| <span>Approve</span> | |
| </button> | |
| <button | |
| type="button" | |
| onClick={() => handleRejectRequest(req.id)} | |
| disabled={actionLoading} | |
| className="px-3 py-1.5 rounded-lg bg-rose-950/40 hover:bg-rose-900/60 border border-rose-500/30 text-rose-300 font-semibold text-xs transition flex items-center space-x-1.5" | |
| > | |
| <UserX className="w-3.5 h-3.5" /> | |
| <span>Reject</span> | |
| </button> | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {/* TAB 4: VISIBILITY & SCOPED TOKENS */} | |
| {activeTab === 'visibility' && ( | |
| <div className="space-y-6"> | |
| {/* Visibility Controls */} | |
| <div className="space-y-3"> | |
| <label className="text-xs font-bold uppercase tracking-wider text-slate-300 font-mono block"> | |
| Workspace Visibility | |
| </label> | |
| <div className="grid grid-cols-1 sm:grid-cols-2 gap-3"> | |
| <button | |
| type="button" | |
| onClick={() => isOwner && handleVisibilityChange('private')} | |
| disabled={!isOwner || savingVis} | |
| className={`p-3.5 rounded-xl border text-left transition flex items-start space-x-3 ${ | |
| visibility === 'private' | |
| ? 'border-amber-500 bg-amber-500/10 shadow-sm shadow-amber-500/10' | |
| : 'border-slate-800 bg-[#121726] hover:border-slate-700 text-slate-400' | |
| } ${!isOwner ? 'cursor-not-allowed opacity-80' : ''}`} | |
| > | |
| <Lock className={`w-4 h-4 mt-0.5 shrink-0 ${visibility === 'private' ? 'text-amber-400' : 'text-slate-500'}`} /> | |
| <div> | |
| <div className="flex items-center space-x-2"> | |
| <span className="font-bold text-xs text-white">Private</span> | |
| {visibility === 'private' && ( | |
| <span className="text-[9px] px-1.5 py-0.2 rounded bg-amber-500/20 text-amber-300 font-mono font-bold"> | |
| ACTIVE | |
| </span> | |
| )} | |
| </div> | |
| <p className="text-[11px] text-slate-400 mt-0.5 leading-snug"> | |
| Strictly locked. Non-members must submit a follow or collaboration request to the owner. | |
| </p> | |
| </div> | |
| </button> | |
| <button | |
| type="button" | |
| onClick={() => isOwner && handleVisibilityChange('public')} | |
| disabled={!isOwner || savingVis} | |
| className={`p-3.5 rounded-xl border text-left transition flex items-start space-x-3 ${ | |
| visibility === 'public' | |
| ? 'border-sky-500 bg-sky-500/10 shadow-sm shadow-sky-500/10' | |
| : 'border-slate-800 bg-[#121726] hover:border-slate-700 text-slate-400' | |
| } ${!isOwner ? 'cursor-not-allowed opacity-80' : ''}`} | |
| > | |
| <Globe className={`w-4 h-4 mt-0.5 shrink-0 ${visibility === 'public' ? 'text-sky-400' : 'text-slate-500'}`} /> | |
| <div> | |
| <div className="flex items-center space-x-2"> | |
| <span className="font-bold text-xs text-white">Public</span> | |
| {visibility === 'public' && ( | |
| <span className="text-[9px] px-1.5 py-0.2 rounded bg-sky-500/20 text-sky-300 font-mono font-bold"> | |
| ACTIVE | |
| </span> | |
| )} | |
| </div> | |
| <p className="text-[11px] text-slate-400 mt-0.5 leading-snug"> | |
| Open to the world. Any authenticated user can follow and submit proposals. | |
| </p> | |
| </div> | |
| </button> | |
| </div> | |
| {!isOwner && ( | |
| <p className="text-[10px] text-slate-500 italic"> | |
| Note: Only the workspace owner can toggle public/private visibility. | |
| </p> | |
| )} | |
| </div> | |
| {/* Scoped API Access Tokens */} | |
| <div className="space-y-3 pt-4 border-t border-slate-800"> | |
| <div className="flex items-center justify-between"> | |
| <div> | |
| <label className="text-xs font-bold uppercase tracking-wider text-slate-300 font-mono flex items-center space-x-1.5"> | |
| <Key className="w-3.5 h-3.5 text-amber-400" /> | |
| <span>Scoped Access Token (MCP & CLI)</span> | |
| </label> | |
| <p className="text-[11px] text-slate-400"> | |
| Generate a dedicated workspace token for Claude, Cursor, or terminal CI pipelines. | |
| </p> | |
| </div> | |
| <button | |
| type="button" | |
| onClick={handleGenerateToken} | |
| className="px-3 py-1.5 rounded-lg bg-[#141B2D] hover:bg-[#1E2740] border border-slate-700 text-slate-200 text-xs font-semibold transition shrink-0" | |
| > | |
| + Generate Token | |
| </button> | |
| </div> | |
| {generatedToken && ( | |
| <div className="p-3 rounded-xl bg-[#141B2D] border border-slate-700/80 flex items-center justify-between gap-2"> | |
| <span className="text-xs font-mono text-emerald-300 truncate"> | |
| {generatedToken} | |
| </span> | |
| <button | |
| type="button" | |
| onClick={handleCopyToken} | |
| className="px-2.5 py-1 rounded bg-slate-800 hover:bg-slate-700 text-slate-200 text-xs font-semibold flex items-center space-x-1 shrink-0" | |
| > | |
| <Copy className="w-3 h-3" /> | |
| <span>{copiedToken ? 'Copied!' : 'Copy'}</span> | |
| </button> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| {/* Footer */} | |
| <div className="px-6 py-3.5 border-t border-slate-800 bg-[#0F1422] flex items-center justify-end shrink-0"> | |
| <button | |
| onClick={onClose} | |
| className="px-4 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 text-slate-200 text-xs font-semibold transition" | |
| > | |
| Done | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |