import { useState } from 'react'; import type { TokenEntry } from '../hooks/useTokens'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '../../components/ui/dialog'; import { Check, Copy, Eye, EyeOff, Pencil, Plus, Trash2, X } from 'lucide-react'; interface TokenManagerDialogProps { open: boolean; onClose: () => void; tokens: TokenEntry[]; activeTokenId: string | null; onSetActive: (id: string) => void; onAdd: (token: string, label: string) => string | null; onRemove: (id: string) => void; onUpdate: (id: string, label: string) => void; } export function TokenManagerDialog({ open, onClose, tokens, activeTokenId, onSetActive, onAdd, onRemove, onUpdate, }: TokenManagerDialogProps) { const [newToken, setNewToken] = useState(''); const [newLabel, setNewLabel] = useState(''); const [addError, setAddError] = useState(''); const [editingId, setEditingId] = useState(null); const [editLabel, setEditLabel] = useState(''); const [visibleTokenId, setVisibleTokenId] = useState(null); const [copiedId, setCopiedId] = useState(null); const handleCopy = (id: string, token: string) => { navigator.clipboard.writeText(token).then(() => { setCopiedId(id); setTimeout(() => setCopiedId(null), 1500); }); }; const handleAdd = () => { const error = onAdd(newToken, newLabel); if (error) { setAddError(error); return; } setNewToken(''); setNewLabel(''); setAddError(''); }; const handleStartEdit = (entry: TokenEntry) => { setEditingId(entry.id); setEditLabel(entry.label); }; const handleSaveEdit = (id: string) => { onUpdate(id, editLabel.trim() || 'Unnamed'); setEditingId(null); }; const handleSwitch = (id: string) => { onSetActive(id); onClose(); }; return ( { if (!o) onClose(); }} > Token Manager Manage API tokens for RCS authentication. {/* Token list */}
{tokens.map(entry => (
{editingId === entry.id ? (
setEditLabel(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') handleSaveEdit(entry.id); if (e.key === 'Escape') setEditingId(null); }} className="flex-1 rounded border border-border bg-surface-1 px-2 py-1 text-sm text-text-primary focus:border-brand focus:outline-none" autoFocus />
) : ( <> )}
))} {tokens.length === 0 && (
No tokens saved yet. Add one below.
)}
{/* Add form */}
Add Token
{ setNewToken(e.target.value); setAddError(''); }} placeholder="API Token" className="w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none font-mono" onKeyDown={e => { if (e.key === 'Enter') handleAdd(); }} />
setNewLabel(e.target.value)} placeholder="Label (optional)" className="flex-1 rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none" onKeyDown={e => { if (e.key === 'Enter') handleAdd(); }} />
{addError &&
{addError}
}
); }