You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB
TypeScript

"use client";
import { useActionState } from "react";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
Field,
FieldError,
FieldGroup,
FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { login, type LoginState } from "../actions";
const initialState: LoginState = {};
export function LoginForm() {
const [state, formAction, pending] = useActionState(login, initialState);
return (
<Card>
<CardHeader>
<CardTitle>Masuk</CardTitle>
<CardDescription>Cleo Minimarket back-office</CardDescription>
</CardHeader>
<CardContent>
<form action={formAction}>
<FieldGroup>
<Field>
<FieldLabel htmlFor="username">Username</FieldLabel>
<Input
id="username"
name="username"
autoComplete="username"
defaultValue={state.username}
required
/>
</Field>
<Field>
<FieldLabel htmlFor="password">Password</FieldLabel>
<Input
id="password"
name="password"
type="password"
autoComplete="current-password"
required
/>
</Field>
{state.error && <FieldError>{state.error}</FieldError>}
<Button type="submit" disabled={pending}>
{pending ? "Memproses..." : "Masuk"}
</Button>
</FieldGroup>
</form>
</CardContent>
</Card>
);
}