first commit

This commit is contained in:
2026-05-29 10:23:25 +03:00
commit e4b25fe4b7
48 changed files with 9112 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
import { useState, FormEvent } from 'react';
import { Link, Navigate } from 'react-router-dom';
import { useAuth } from '@/hooks/useAuth';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
export default function RegisterPage() {
const { user, register } = useAuth();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [confirm, setConfirm] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
if (user) return <Navigate to="/feed" replace />;
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
setError('');
if (password !== confirm) {
setError('Passwords do not match');
return;
}
setLoading(true);
try {
await register(username, password);
} catch (err: any) {
setError(err.response?.data?.error || 'Registration failed');
} finally {
setLoading(false);
}
};
return (
<div className="flex min-h-screen items-center justify-center p-4">
<div className="w-full max-w-sm animate-fade-in">
<div className="text-center mb-8">
<h1 className="text-2xl font-semibold tracking-tight">Catstagram</h1>
<p className="text-sm text-muted-foreground mt-1">Create your account</p>
</div>
<form onSubmit={handleSubmit} className="space-y-3">
<Input
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Username"
minLength={3}
required
autoFocus
className="h-10 text-sm"
/>
<Input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Password"
minLength={4}
required
className="h-10 text-sm"
/>
<Input
type="password"
value={confirm}
onChange={(e) => setConfirm(e.target.value)}
placeholder="Confirm password"
required
className="h-10 text-sm"
/>
{error && <p className="text-sm text-destructive">{error}</p>}
<Button type="submit" className="w-full h-10" disabled={loading}>
{loading ? 'Creating account...' : 'Create account'}
</Button>
</form>
<p className="mt-6 text-center text-sm text-muted-foreground">
Already have an account?{' '}
<Link to="/login" className="font-medium underline-offset-4 hover:underline">
Sign in
</Link>
</p>
</div>
</div>
);
}