Spaces:
Runtime error
Runtime error
File size: 11,653 Bytes
098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea ad279fb 098f3ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | import React, { useState } from 'react';
import { AuthService } from '../services/api';
const features = [
{
icon: 'β‘',
title: 'Automated Workflows',
desc: 'Build and run multi-step API test flows without writing boilerplate.',
},
{
icon: 'π',
title: 'Smart Diff & Validation',
desc: 'Instantly compare responses and catch regressions before they ship.',
},
{
icon: 'π',
title: 'Spec-driven Testing',
desc: 'Import OpenAPI specs and generate tests from your existing contracts.',
},
{
icon: 'π€',
title: 'AI Assistant',
desc: 'Ask questions about your APIs and get context-aware suggestions.',
},
];
export default function LoginPage({ onLogin }) {
const [mode, setMode] = useState('login'); // 'login' | 'register'
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [confirm, setConfirm] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const switchMode = (m) => { setMode(m); setError(''); setPassword(''); setConfirm(''); };
const handleSubmit = async (e) => {
e.preventDefault();
setError('');
if (mode === 'register' && password !== confirm) {
setError('Passwords do not match.');
return;
}
setLoading(true);
try {
if (mode === 'register') {
await AuthService.register(username.trim(), password);
} else {
await AuthService.login(username.trim(), password);
}
onLogin();
} catch (err) {
setError(err.message || (mode === 'register' ? 'Registration failed.' : 'Invalid username or password.'));
} finally {
setLoading(false);
}
};
const inputStyle = {
width: '100%',
boxSizing: 'border-box',
padding: '10px 13px',
background: 'var(--bg-3)',
border: '1px solid var(--line-2)',
borderRadius: 8,
color: 'var(--fg-0)',
fontSize: 14,
fontFamily: 'var(--font-mono)',
outline: 'none',
transition: 'border-color 0.15s',
};
return (
<div style={{
minHeight: '100vh',
display: 'flex',
background: 'var(--bg-0)',
fontFamily: 'var(--font-sans)',
}}>
{/* ββ Left: Landing panel βββββββββββββββββββββββββββββββββββ */}
<div style={{
flex: 1,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
padding: '60px 64px',
background: 'var(--bg-1)',
borderRight: '1px solid var(--line-1)',
minWidth: 0,
}}>
{/* Logo / brand */}
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 48 }}>
<div style={{
width: 36,
height: 36,
borderRadius: 9,
background: 'var(--accent)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 18,
fontWeight: 800,
color: 'var(--accent-fg)',
fontFamily: 'var(--font-mono)',
flexShrink: 0,
}}>A</div>
<span style={{
fontSize: 17,
fontWeight: 700,
color: 'var(--fg-0)',
fontFamily: 'var(--font-mono)',
letterSpacing: '-0.3px',
}}>apitest</span>
</div>
{/* Hero headline */}
<h1 style={{
margin: '0 0 16px',
fontSize: 36,
fontWeight: 800,
color: 'var(--fg-0)',
lineHeight: 1.15,
letterSpacing: '-1px',
maxWidth: 480,
}}>
Test your APIs<br/>
<span style={{ color: 'var(--accent)' }}>faster and smarter.</span>
</h1>
<p style={{
margin: '0 0 48px',
fontSize: 15,
color: 'var(--fg-2)',
lineHeight: 1.65,
maxWidth: 400,
}}>
A unified workspace for designing, running, and validating API tests β
powered by AI and driven by your specs.
</p>
{/* Feature list */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
{features.map(f => (
<div key={f.title} style={{ display: 'flex', gap: 16, alignItems: 'flex-start' }}>
<div style={{
width: 36,
height: 36,
borderRadius: 8,
background: 'var(--bg-2)',
border: '1px solid var(--line-2)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 17,
flexShrink: 0,
}}>{f.icon}</div>
<div>
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--fg-0)', marginBottom: 3 }}>
{f.title}
</div>
<div style={{ fontSize: 13, color: 'var(--fg-2)', lineHeight: 1.55 }}>
{f.desc}
</div>
</div>
</div>
))}
</div>
</div>
{/* ββ Right: Login panel ββββββββββββββββββββββββββββββββββββ */}
<div style={{
width: 420,
flexShrink: 0,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
padding: '60px 48px',
background: 'var(--bg-1)',
}}>
<div style={{
width: '100%',
maxWidth: 340,
background: 'var(--bg-2)',
border: '1px solid var(--line-2)',
borderRadius: 16,
padding: '36px 32px',
boxShadow: '0 8px 40px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.07)',
}}>
{/* Mode toggle tabs */}
<div style={{
display: 'flex',
background: 'var(--bg-3)',
borderRadius: 10,
padding: 3,
marginBottom: 28,
}}>
{['login', 'register'].map(m => (
<button
key={m}
type="button"
onClick={() => switchMode(m)}
style={{
flex: 1,
padding: '8px 0',
background: mode === m ? 'var(--bg-2)' : 'transparent',
border: mode === m ? '1px solid var(--line-2)' : '1px solid transparent',
borderRadius: 8,
color: mode === m ? 'var(--fg-0)' : 'var(--fg-2)',
fontSize: 13,
fontWeight: mode === m ? 600 : 400,
fontFamily: 'var(--font-mono)',
cursor: 'pointer',
transition: 'all 0.15s',
}}
>
{m === 'login' ? 'Sign in' : 'Sign up'}
</button>
))}
</div>
<div style={{ marginBottom: 24 }}>
<div style={{
fontSize: 20,
fontWeight: 700,
color: 'var(--fg-0)',
fontFamily: 'var(--font-mono)',
letterSpacing: '-0.5px',
marginBottom: 5,
}}>
{mode === 'login' ? 'Welcome back' : 'Create account'}
</div>
<div style={{ fontSize: 13, color: 'var(--fg-2)' }}>
{mode === 'login'
? 'Enter your credentials to continue.'
: 'Pick a username and password to get started.'}
</div>
</div>
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
<div>
<label style={{ display: 'block', fontSize: 12, fontWeight: 500, color: 'var(--fg-2)', marginBottom: 6 }}>
Username
</label>
<input
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
autoFocus
required
placeholder="your-username"
style={inputStyle}
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--line-2)'}
/>
</div>
<div>
<label style={{ display: 'block', fontSize: 12, fontWeight: 500, color: 'var(--fg-2)', marginBottom: 6 }}>
Password
</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
placeholder="β’β’β’β’β’β’β’β’"
style={inputStyle}
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--line-2)'}
/>
</div>
{mode === 'register' && (
<div>
<label style={{ display: 'block', fontSize: 12, fontWeight: 500, color: 'var(--fg-2)', marginBottom: 6 }}>
Confirm password
</label>
<input
type="password"
value={confirm}
onChange={(e) => setConfirm(e.target.value)}
required
placeholder="β’β’β’β’β’β’β’β’"
style={inputStyle}
onFocus={e => e.target.style.borderColor = 'var(--accent)'}
onBlur={e => e.target.style.borderColor = 'var(--line-2)'}
/>
</div>
)}
{error && (
<div style={{
padding: '9px 13px',
background: 'var(--err-soft)',
border: '1px solid var(--err)',
borderRadius: 8,
color: 'var(--err)',
fontSize: 13,
}}>
{error}
</div>
)}
<button
type="submit"
disabled={loading}
style={{
marginTop: 4,
padding: '11px',
background: 'var(--accent)',
color: 'var(--accent-fg)',
border: 'none',
borderRadius: 8,
fontSize: 14,
fontWeight: 600,
cursor: loading ? 'not-allowed' : 'pointer',
opacity: loading ? 0.7 : 1,
fontFamily: 'var(--font-mono)',
transition: 'opacity 0.15s',
}}
>
{loading
? (mode === 'login' ? 'Signing inβ¦' : 'Creating accountβ¦')
: (mode === 'login' ? 'Sign in β' : 'Create account β')}
</button>
</form>
<div style={{ marginTop: 24, fontSize: 12, color: 'var(--fg-3)', textAlign: 'center' }}>
{mode === 'login' ? "Don't have an account? " : 'Already have an account? '}
<button
type="button"
onClick={() => switchMode(mode === 'login' ? 'register' : 'login')}
style={{
background: 'none', border: 'none', padding: 0,
color: 'var(--accent)', fontSize: 12, cursor: 'pointer', fontWeight: 600,
}}
>
{mode === 'login' ? 'Sign up' : 'Sign in'}
</button>
</div>
</div>
</div>
</div>
);
}
|