79 lines
2.9 KiB
TypeScript
79 lines
2.9 KiB
TypeScript
"use client";
|
|
|
|
import { useActionState } from "react";
|
|
import { useFormStatus } from "react-dom";
|
|
import Link from "next/link";
|
|
import { login } from "@/app/actions/auth";
|
|
|
|
function SubmitButton() {
|
|
const { pending } = useFormStatus();
|
|
return (
|
|
<button
|
|
type="submit"
|
|
disabled={pending}
|
|
className="w-full bg-accent text-accent-on font-bold py-3 rounded-xl border-b-4 border-accent-active hover:bg-accent-hover active:translate-y-0.5 active:border-b-0 transition-all disabled:opacity-50 cursor-pointer"
|
|
>
|
|
{pending ? "Logging in..." : "Log in"}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
export default function LoginPage() {
|
|
const [state, formAction] = useActionState(login, undefined);
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-bg px-4">
|
|
<div className="w-full max-w-md">
|
|
<div className="text-center mb-8">
|
|
<div className="w-14 h-14 rounded-2xl bg-accent flex items-center justify-center mx-auto mb-4 shadow-[0_4px_0_0_var(--accent-active)]">
|
|
<span className="text-accent-on font-bold text-xl">OL</span>
|
|
</div>
|
|
<h1 className="font-display text-2xl font-bold text-fg">Order Loop</h1>
|
|
</div>
|
|
|
|
<div className="bg-surface border-2 border-border rounded-2xl p-6 shadow-card">
|
|
<h2 className="font-display text-xl font-bold text-fg mb-6">Welcome back</h2>
|
|
|
|
{state?.message && (
|
|
<div className="mb-4 p-3 rounded-xl bg-danger/10 border border-danger/20 text-danger text-sm font-medium">
|
|
{state.message}
|
|
</div>
|
|
)}
|
|
|
|
<form action={formAction} className="space-y-4">
|
|
<div>
|
|
<label htmlFor="email" className="block text-sm font-medium text-fg mb-1">Email</label>
|
|
<input
|
|
id="email"
|
|
name="email"
|
|
type="email"
|
|
required
|
|
className="w-full border-2 border-border rounded-xl px-4 py-2.5 text-sm bg-bg text-fg focus:outline-none focus:border-accent"
|
|
placeholder="admin@example.com"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="password" className="block text-sm font-medium text-fg mb-1">Password</label>
|
|
<input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
required
|
|
className="w-full border-2 border-border rounded-xl px-4 py-2.5 text-sm bg-bg text-fg focus:outline-none focus:border-accent"
|
|
placeholder="Enter password"
|
|
/>
|
|
</div>
|
|
<SubmitButton />
|
|
</form>
|
|
|
|
<div className="mt-4 text-center">
|
|
<Link href="/forgot-password" className="text-sm text-accent hover:text-accent-hover">
|
|
Forgot your password?
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|