- Add rules_engine.py with quantitative rules for all 8 workout types - Add quality gate retry loop in generate_single_workout() - Expand calibrate_structure_rules to all 120 combinations (8 types × 5 goals × 3 sections) - Wire WeeklySplitPattern DB records into _pick_weekly_split() - Enforce movement patterns from WorkoutStructureRule in exercise selection - Add straight-set strength support (single main lift, 4-6 rounds) - Add modality consistency check for duration-dominant workout types - Add InjuryStep component to onboarding and preferences - Add sibling exercise exclusion in regenerate and preview_day endpoints - Display generator warnings on dashboard - Expand fix_rep_durations, fix_exercise_flags, fix_movement_pattern_typo - Add audit_exercise_data and check_rules_drift management commands - Add Next.js frontend with dashboard, onboarding, preferences, history pages - Add generator app with ML-powered workout generation pipeline - 96 new tests across 7 test modules Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
175 lines
5.9 KiB
TypeScript
175 lines
5.9 KiB
TypeScript
"use client";
|
|
|
|
import { useState, type FormEvent } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useAuth } from "@/lib/auth";
|
|
import { Button } from "@/components/ui/Button";
|
|
import { Spinner } from "@/components/ui/Spinner";
|
|
|
|
export default function LoginPage() {
|
|
const { user, loading: authLoading, login, register } = useAuth();
|
|
const router = useRouter();
|
|
|
|
const [isRegister, setIsRegister] = useState(false);
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [firstName, setFirstName] = useState("");
|
|
const [lastName, setLastName] = useState("");
|
|
const [error, setError] = useState("");
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
// Redirect if already logged in
|
|
if (!authLoading && user) {
|
|
router.replace("/dashboard");
|
|
return null;
|
|
}
|
|
|
|
async function handleSubmit(e: FormEvent) {
|
|
e.preventDefault();
|
|
setError("");
|
|
setLoading(true);
|
|
|
|
try {
|
|
if (isRegister) {
|
|
await register(email, password, firstName, lastName);
|
|
} else {
|
|
await login(email, password);
|
|
}
|
|
router.push("/dashboard");
|
|
} catch (err: unknown) {
|
|
if (err instanceof Error) {
|
|
setError(err.message);
|
|
} else {
|
|
setError("Something went wrong. Please try again.");
|
|
}
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
if (authLoading) {
|
|
return (
|
|
<div className="flex items-center justify-center min-h-screen">
|
|
<Spinner size="lg" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center justify-center min-h-screen px-4">
|
|
<div className="w-full max-w-md">
|
|
<div className="bg-zinc-900 border border-zinc-700/50 rounded-xl p-8">
|
|
{/* Title */}
|
|
<h1 className="text-3xl font-black text-center text-accent tracking-wider mb-8">
|
|
WERKOUT
|
|
</h1>
|
|
|
|
{/* Error */}
|
|
{error && (
|
|
<div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
{/* Form */}
|
|
<form onSubmit={handleSubmit} className="flex flex-col gap-4">
|
|
{isRegister && (
|
|
<div className="flex gap-3">
|
|
<div className="flex-1">
|
|
<label className="block text-sm font-medium text-zinc-400 mb-1.5">
|
|
First Name
|
|
</label>
|
|
<input
|
|
type="text"
|
|
value={firstName}
|
|
onChange={(e) => setFirstName(e.target.value)}
|
|
required
|
|
className="w-full bg-zinc-800 border border-zinc-700 text-zinc-100 rounded-lg px-4 py-2.5 text-sm
|
|
placeholder:text-zinc-500 focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30
|
|
transition-colors duration-150"
|
|
placeholder="First name"
|
|
/>
|
|
</div>
|
|
<div className="flex-1">
|
|
<label className="block text-sm font-medium text-zinc-400 mb-1.5">
|
|
Last Name
|
|
</label>
|
|
<input
|
|
type="text"
|
|
value={lastName}
|
|
onChange={(e) => setLastName(e.target.value)}
|
|
required
|
|
className="w-full bg-zinc-800 border border-zinc-700 text-zinc-100 rounded-lg px-4 py-2.5 text-sm
|
|
placeholder:text-zinc-500 focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30
|
|
transition-colors duration-150"
|
|
placeholder="Last name"
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-zinc-400 mb-1.5">
|
|
Email or Username
|
|
</label>
|
|
<input
|
|
type="text"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
required
|
|
className="w-full bg-zinc-800 border border-zinc-700 text-zinc-100 rounded-lg px-4 py-2.5 text-sm
|
|
placeholder:text-zinc-500 focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30
|
|
transition-colors duration-150"
|
|
placeholder="Email or username"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-zinc-400 mb-1.5">
|
|
Password
|
|
</label>
|
|
<input
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
required
|
|
className="w-full bg-zinc-800 border border-zinc-700 text-zinc-100 rounded-lg px-4 py-2.5 text-sm
|
|
placeholder:text-zinc-500 focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30
|
|
transition-colors duration-150"
|
|
placeholder="Enter password"
|
|
/>
|
|
</div>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="primary"
|
|
size="lg"
|
|
loading={loading}
|
|
className="mt-2 w-full"
|
|
>
|
|
{isRegister ? "Create Account" : "Log In"}
|
|
</Button>
|
|
</form>
|
|
|
|
{/* Toggle */}
|
|
<p className="mt-6 text-center text-sm text-zinc-400">
|
|
{isRegister
|
|
? "Already have an account? "
|
|
: "Don't have an account? "}
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
setIsRegister(!isRegister);
|
|
setError("");
|
|
}}
|
|
className="text-accent hover:underline font-medium"
|
|
>
|
|
{isRegister ? "Log In" : "Register"}
|
|
</button>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|