Commit 0a9b4fcd authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Make the login and sign-up states visually distinguishable

Both modes shared one subtle heading line and a bottom text-link toggle,
so it was hard to tell at a glance which one you were in. Replaced the
toggle with a segmented Log in/Sign up tab control (same pill pattern
Social.tsx already uses), gave each mode its own heading+tagline, and
added a confirm-password field that only exists in sign-up - the two
states now differ in layout and content, not just a word or two.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent f078ae95
Pipeline #1261 failed with stages
...@@ -87,7 +87,7 @@ describe('Login', () => { ...@@ -87,7 +87,7 @@ describe('Login', () => {
expect(await screen.findByText('Business page')).toBeInTheDocument() expect(await screen.findByText('Business page')).toBeInTheDocument()
}) })
it('toggles to register mode and creates an account', async () => { it('switches to sign-up mode via the tab and creates an account', async () => {
const register = vi.spyOn(authApi, 'register').mockResolvedValue({ const register = vi.spyOn(authApi, 'register').mockResolvedValue({
access_token: 'real-access', access_token: 'real-access',
refresh_token: 'real-refresh', refresh_token: 'real-refresh',
...@@ -96,11 +96,12 @@ describe('Login', () => { ...@@ -96,11 +96,12 @@ describe('Login', () => {
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 2, username: 'newuser', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } } }) vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 2, username: 'newuser', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } } })
renderLogin() renderLogin()
await userEvent.click(screen.getByRole('button', { name: "Don't have an account? Register" })) await userEvent.click(screen.getByRole('button', { name: 'Sign up' }))
expect(screen.getByRole('button', { name: 'Create account' })).toBeInTheDocument() expect(screen.getByRole('button', { name: 'Create account' })).toBeInTheDocument()
await userEvent.type(screen.getByLabelText('Username'), 'newuser') await userEvent.type(screen.getByLabelText('Username'), 'newuser')
await userEvent.type(screen.getByLabelText('Password'), 'correcthorse') await userEvent.type(screen.getByLabelText('Password'), 'correcthorse')
await userEvent.type(screen.getByLabelText('Confirm password'), 'correcthorse')
await userEvent.click(screen.getByRole('button', { name: 'Create account' })) await userEvent.click(screen.getByRole('button', { name: 'Create account' }))
await waitFor(() => expect(register).toHaveBeenCalledWith('newuser', 'correcthorse')) await waitFor(() => expect(register).toHaveBeenCalledWith('newuser', 'correcthorse'))
...@@ -111,19 +112,45 @@ describe('Login', () => { ...@@ -111,19 +112,45 @@ describe('Login', () => {
vi.spyOn(authApi, 'register').mockRejectedValue(new ApiError(409, 'Username already taken', null)) vi.spyOn(authApi, 'register').mockRejectedValue(new ApiError(409, 'Username already taken', null))
renderLogin() renderLogin()
await userEvent.click(screen.getByRole('button', { name: "Don't have an account? Register" })) await userEvent.click(screen.getByRole('button', { name: 'Sign up' }))
await userEvent.type(screen.getByLabelText('Username'), 'dupeuser') await userEvent.type(screen.getByLabelText('Username'), 'dupeuser')
await userEvent.type(screen.getByLabelText('Password'), 'correcthorse') await userEvent.type(screen.getByLabelText('Password'), 'correcthorse')
await userEvent.type(screen.getByLabelText('Confirm password'), 'correcthorse')
await userEvent.click(screen.getByRole('button', { name: 'Create account' })) await userEvent.click(screen.getByRole('button', { name: 'Create account' }))
expect(await screen.findByText('Username already taken')).toBeInTheDocument() expect(await screen.findByText('Username already taken')).toBeInTheDocument()
expect(screen.queryByText('Home page')).not.toBeInTheDocument() expect(screen.queryByText('Home page')).not.toBeInTheDocument()
}) })
it('lets you toggle back from register to sign-in', async () => { it('lets you switch back from sign-up to sign-in via the tabs', async () => {
renderLogin() renderLogin()
await userEvent.click(screen.getByRole('button', { name: "Don't have an account? Register" })) await userEvent.click(screen.getByRole('button', { name: 'Sign up' }))
await userEvent.click(screen.getByRole('button', { name: 'Already have an account? Sign in' })) await userEvent.click(screen.getByRole('button', { name: 'Log in' }))
expect(screen.getByRole('button', { name: 'Sign in' })).toBeInTheDocument() expect(screen.getByRole('button', { name: 'Sign in' })).toBeInTheDocument()
expect(screen.queryByLabelText('Confirm password')).not.toBeInTheDocument()
})
it('blocks submit and shows an error when the confirm-password field does not match', async () => {
const register = vi.spyOn(authApi, 'register')
renderLogin()
await userEvent.click(screen.getByRole('button', { name: 'Sign up' }))
await userEvent.type(screen.getByLabelText('Username'), 'newuser')
await userEvent.type(screen.getByLabelText('Password'), 'correcthorse')
await userEvent.type(screen.getByLabelText('Confirm password'), 'wrongconfirm')
expect(screen.getByRole('button', { name: 'Create account' })).toBeDisabled()
expect(await screen.findByText("Passwords don't match")).toBeInTheDocument()
expect(register).not.toHaveBeenCalled()
})
it('clears the confirm-password field when switching back to sign-up after switching away', async () => {
renderLogin()
await userEvent.click(screen.getByRole('button', { name: 'Sign up' }))
await userEvent.type(screen.getByLabelText('Confirm password'), 'leftover')
await userEvent.click(screen.getByRole('button', { name: 'Log in' }))
await userEvent.click(screen.getByRole('button', { name: 'Sign up' }))
expect(screen.getByLabelText('Confirm password')).toHaveValue('')
}) })
}) })
...@@ -17,12 +17,19 @@ export function Login() { ...@@ -17,12 +17,19 @@ export function Login() {
const [mode, setMode] = useState<Mode>('login') const [mode, setMode] = useState<Mode>('login')
const [username, setUsername] = useState('') const [username, setUsername] = useState('')
const [password, setPassword] = useState('') const [password, setPassword] = useState('')
const [confirmPassword, setConfirmPassword] = useState('')
const [busy, setBusy] = useState(false) const [busy, setBusy] = useState(false)
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const passwordsMismatched = mode === 'register' && confirmPassword.length > 0 && password !== confirmPassword
async function handleSubmit(e: React.FormEvent) { async function handleSubmit(e: React.FormEvent) {
e.preventDefault() e.preventDefault()
if (!username.trim() || !password) return if (!username.trim() || !password) return
if (mode === 'register' && password !== confirmPassword) {
setError("Passwords don't match")
return
}
setBusy(true) setBusy(true)
setError(null) setError(null)
try { try {
...@@ -44,8 +51,9 @@ export function Login() { ...@@ -44,8 +51,9 @@ export function Login() {
} }
} }
function toggleMode() { function switchMode(next: Mode) {
setMode((m) => (m === 'login' ? 'register' : 'login')) setMode(next)
setConfirmPassword('')
setError(null) setError(null)
} }
...@@ -82,9 +90,41 @@ export function Login() { ...@@ -82,9 +90,41 @@ export function Login() {
the inputs floating bare on it - backdrop-blur keeps the drifting blobs visible the inputs floating bare on it - backdrop-blur keeps the drifting blobs visible
but softened through it, same "glass over glow" idea as the blobs themselves. */} but softened through it, same "glass over glow" idea as the blobs themselves. */}
<div className="rounded-3xl border border-outline-variant/60 bg-surface-container/70 p-6 shadow-xl shadow-black/10 backdrop-blur-xl"> <div className="rounded-3xl border border-outline-variant/60 bg-surface-container/70 p-6 shadow-xl shadow-black/10 backdrop-blur-xl">
<p className="mb-4 text-center text-sm font-medium text-on-surface-variant"> {/* Segmented sign-in/sign-up switcher, same pill-tab pattern as Social.tsx's own
{mode === 'login' ? 'Sign in to your account' : 'Create an account'} tab row - a single filled/outlined pair reads as "which mode am I in" far more
</p> clearly at a glance than the old bottom text-link toggle did, which is exactly
what made the two modes hard to tell apart. */}
<div className="mb-5 flex rounded-full border border-outline-variant bg-surface-container p-1">
<button
type="button"
onClick={() => switchMode('login')}
className={`flex-1 rounded-full px-4 py-2 text-sm font-medium transition-colors duration-150 ${
mode === 'login' ? 'bg-primary text-on-primary' : 'text-on-surface-variant hover:text-on-surface'
}`}
>
Log in
</button>
<button
type="button"
onClick={() => switchMode('register')}
className={`flex-1 rounded-full px-4 py-2 text-sm font-medium transition-colors duration-150 ${
mode === 'register' ? 'bg-primary text-on-primary' : 'text-on-surface-variant hover:text-on-surface'
}`}
>
Sign up
</button>
</div>
{/* Keyed by mode so switching genuinely remounts this block and replays the fade,
same idiom as TelegramLink's step transitions - a plain conditional swap here
produced an instant flash instead. */}
<div key={mode} className="mb-4 animate-content-enter text-center">
<p className="text-lg font-semibold text-on-surface">{mode === 'login' ? 'Welcome back' : 'Create your account'}</p>
<p className="mt-1 text-sm text-on-surface-variant">
{mode === 'login' ? 'Sign in to pick up where you left off.' : 'Start tagging, discovering, and remixing your music.'}
</p>
</div>
<form onSubmit={handleSubmit} className="space-y-3"> <form onSubmit={handleSubmit} className="space-y-3">
<Input <Input
type="text" type="text"
...@@ -103,21 +143,27 @@ export function Login() { ...@@ -103,21 +143,27 @@ export function Login() {
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
aria-label="Password" aria-label="Password"
/> />
{mode === 'register' && (
<Input
type="password"
autoComplete="new-password"
placeholder="Confirm password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
aria-label="Confirm password"
/>
)}
{passwordsMismatched && <p className="text-sm text-error">Passwords don't match</p>}
{error && <p className="text-sm text-error">{error}</p>} {error && <p className="text-sm text-error">{error}</p>}
<Button type="submit" disabled={busy || !username.trim() || !password} className="w-full"> <Button
type="submit"
disabled={busy || !username.trim() || !password || passwordsMismatched}
className="w-full"
>
{busy ? (mode === 'login' ? 'Signing in…' : 'Creating account…') : mode === 'login' ? 'Sign in' : 'Create account'} {busy ? (mode === 'login' ? 'Signing in…' : 'Creating account…') : mode === 'login' ? 'Sign in' : 'Create account'}
</Button> </Button>
</form> </form>
</div> </div>
<button
type="button"
onClick={toggleMode}
className="mt-5 w-full text-center text-sm text-on-surface-variant transition-colors hover:text-on-surface"
>
{mode === 'login' ? "Don't have an account? " : 'Already have an account? '}
<span className="font-medium text-primary">{mode === 'login' ? 'Register' : 'Sign in'}</span>
</button>
</div> </div>
</div> </div>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment