arbret/frontend/app/login/page.tsx
counterweight 7dd13292a0
Phase 5: Translate Auth Pages - login and signup
- Create auth.json translation files for es, en, ca
- Translate login page: title, subtitle, form labels, buttons, footer
- Translate signup page: invite code step and account creation step
- Translate signup/[code] redirect page
- Update IntlProvider to load auth namespace
- Update test expectations to match Spanish translations (default language)
- All frontend and e2e tests passing
2025-12-25 22:14:04 +01:00

101 lines
3 KiB
TypeScript

"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "../auth-context";
import { authFormStyles as styles } from "../styles/auth-form";
import { LanguageSelector } from "../components/LanguageSelector";
import { useTranslation } from "../hooks/useTranslation";
export default function LoginPage() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const { login } = useAuth();
const router = useRouter();
const t = useTranslation("auth");
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
setIsSubmitting(true);
try {
await login(email, password);
router.push("/");
} catch (err) {
setError(err instanceof Error ? err.message : t("login.loginFailed"));
} finally {
setIsSubmitting(false);
}
};
return (
<main style={styles.main}>
<div style={{ position: "absolute", top: "1rem", right: "1rem" }}>
<LanguageSelector />
</div>
<div style={styles.container}>
<div style={styles.card}>
<div style={styles.header}>
<h1 style={styles.title}>{t("login.title")}</h1>
<p style={styles.subtitle}>{t("login.subtitle")}</p>
</div>
<form onSubmit={handleSubmit} style={styles.form}>
{error && <div style={styles.error}>{error}</div>}
<div style={styles.field}>
<label htmlFor="email" style={styles.label}>
{t("login.email")}
</label>
<input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
style={styles.input}
placeholder={t("login.emailPlaceholder")}
required
/>
</div>
<div style={styles.field}>
<label htmlFor="password" style={styles.label}>
{t("login.password")}
</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
style={styles.input}
placeholder={t("login.passwordPlaceholder")}
required
/>
</div>
<button
type="submit"
style={{
...styles.button,
opacity: isSubmitting ? 0.7 : 1,
}}
disabled={isSubmitting}
>
{isSubmitting ? t("login.signingIn") : t("login.signIn")}
</button>
</form>
<p style={styles.footer}>
{t("login.noAccount")}{" "}
<a href="/signup" style={styles.link}>
{t("login.signUp")}
</a>
</p>
</div>
</div>
</main>
);
}