71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useActionState } from "react";
|
|
import { loginAction, type LoginState } from "./actions";
|
|
|
|
const initialState: LoginState = null;
|
|
|
|
export default function LoginForm({ next }: { next?: string }) {
|
|
const [state, action, pending] = useActionState(loginAction, initialState);
|
|
|
|
return (
|
|
<div className="w-full max-w-md space-y-6">
|
|
<div className="space-y-1">
|
|
<h1 className="text-2xl font-semibold">Log in</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
Sign in to start chatting with your friends.
|
|
</p>
|
|
</div>
|
|
<form action={action} className="space-y-4">
|
|
{next && <input type="hidden" name="next" value={next} />}
|
|
<div className="space-y-2">
|
|
<label htmlFor="email" className="text-sm font-medium">
|
|
Email
|
|
</label>
|
|
<input
|
|
id="email"
|
|
name="email"
|
|
type="email"
|
|
autoComplete="email"
|
|
required
|
|
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:border-neutral-900 focus:outline-none"
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<label htmlFor="password" className="text-sm font-medium">
|
|
Password
|
|
</label>
|
|
<input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:border-neutral-900 focus:outline-none"
|
|
/>
|
|
</div>
|
|
{state?.error ? (
|
|
<p className="text-sm text-red-600">{state.error}</p>
|
|
) : null}
|
|
<button
|
|
type="submit"
|
|
disabled={pending}
|
|
className="w-full rounded-md bg-neutral-900 px-4 py-2 text-sm font-medium text-white shadow-sm transition disabled:cursor-not-allowed disabled:bg-neutral-400"
|
|
>
|
|
{pending ? "Logging in..." : "Log in"}
|
|
</button>
|
|
</form>
|
|
<p className="text-sm text-neutral-600">
|
|
Don't have an account?{" "}
|
|
<Link
|
|
className="font-medium text-neutral-900 hover:underline"
|
|
href="/register"
|
|
>
|
|
Register
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|