Amitkasar's picture
deploy: update
ad279fb
Raw History Blame Contribute Delete
11.7 kB
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>
);
}