import React, { useState, useEffect } from 'react'; import { Settings, Save, Trash2, Key, User, Lock, Plus, X, RefreshCw, Server, Database } from 'lucide-react'; import { useAppContext } from './AppContext'; const ProfilePage = () => { const { activeSpecId, activeSpecName, storedCredentials, saveProfile, addToast, } = useAppContext(); const [profileForm, setProfileForm] = useState({ name: '', email: '', password: '', token: '' }); const [extraKvs, setExtraKvs] = useState([]); const [isSaving, setIsSaving] = useState(false); // Sync stored credentials into local form useEffect(() => { if (!storedCredentials) return; setProfileForm({ name: storedCredentials.name || '', email: storedCredentials.email || storedCredentials.username || '', password: '', // Don't prefill password token: storedCredentials.access_token || storedCredentials.token || '' }); const standardKeys = new Set(['name', 'email', 'username', 'password', 'access_token', 'token', 'refresh_token', 'id_token']); const kvs = Object.entries(storedCredentials) .filter(([k, v]) => !standardKeys.has(k) && k !== '_clear') .map(([k, v]) => ({ key: k, val: String(v) })); setExtraKvs(kvs); }, [storedCredentials]); const handleSave = async () => { if (!activeSpecId) return; setIsSaving(true); try { const payload = { name: profileForm.name, username: profileForm.email, extra: {} }; if (profileForm.password) payload.password = profileForm.password; if (profileForm.token) payload.extra.token = profileForm.token; extraKvs.forEach(kv => { if (kv.key && kv.val) payload.extra[kv.key] = kv.val; }); await saveProfile(payload); } catch (err) { console.error("Save failed", err); addToast('error', err.message || "Failed to save profile."); } finally { setIsSaving(false); } }; if (!activeSpecId) { return (

No Collection Selected

Test user profiles are isolated per collection. Please select an API specification first to manage its credentials.

); } return (
{/* Header */}

Test User Profile

Current Spec: {activeSpecName}
{/* Core Credentials */}

Core Authentication

setProfileForm({...profileForm, name: e.target.value})} placeholder="e.g. John Doe" />
setProfileForm({...profileForm, email: e.target.value})} placeholder="e.g. john.doe@example.com" />
setProfileForm({...profileForm, password: e.target.value})} placeholder="Leave blank to keep current" />
setProfileForm({...profileForm, token: e.target.value})} placeholder="Skip login flow with a manual token" />
{/* Extra Variables */}

Custom Fields & Context

{extraKvs.length === 0 ? (

No custom variables defined. Use these for OTPs, User IDs, or custom test data pointers.

) : (
{extraKvs.map((kv, i) => (
KV
{ const n = [...extraKvs]; n[i].key = e.target.value; setExtraKvs(n); }} /> { const n = [...extraKvs]; n[i].val = e.target.value; setExtraKvs(n); }} />
))}
)}
); }; export default ProfilePage;