Adds complete initial codebase for the RJ Bulk Supplies fuel delivery backoffice: - Authentication pages and protected route layouts - Customer, supplier, fuel purchase, and delivery note management - Custom reporting and customer statement sending tools - Full UI component library and Tailwind styling - Server actions, API routes, and PocketBase integration - Development scripts and project configuration updates - Updated README and package metadata
56 lines
2 KiB
TypeScript
56 lines
2 KiB
TypeScript
"use client";
|
|
|
|
import { useActionState, useEffect } from "react";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { loginAction, type LoginResult } from "@/actions/auth";
|
|
import { toast } from "sonner";
|
|
|
|
const initial: LoginResult = { ok: false, error: "" };
|
|
|
|
export function LoginForm() {
|
|
const router = useRouter();
|
|
const [state, formAction, pending] = useActionState(loginAction, initial);
|
|
|
|
useEffect(() => {
|
|
if (!state.ok) {
|
|
toast.error(state.error);
|
|
}
|
|
}, [state]);
|
|
|
|
return (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-2xl">Sign in</CardTitle>
|
|
<CardDescription>Enter your credentials to access RJ Bulk.</CardDescription>
|
|
</CardHeader>
|
|
<form action={formAction}>
|
|
<CardContent className="space-y-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="identity">Username or email</Label>
|
|
<Input id="identity" name="identity" type="text" autoComplete="username" required autoFocus />
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="password">Password</Label>
|
|
<Input id="password" name="password" type="password" autoComplete="current-password" required />
|
|
</div>
|
|
</CardContent>
|
|
<CardFooter className="flex flex-col gap-3">
|
|
<Button type="submit" className="w-full" disabled={pending}>
|
|
{pending ? "Signing in…" : "Sign in"}
|
|
</Button>
|
|
<p className="text-sm text-muted-foreground">
|
|
New here?{" "}
|
|
<Link href="/register" className="text-primary underline-offset-4 hover:underline">
|
|
Create an account
|
|
</Link>
|
|
</p>
|
|
</CardFooter>
|
|
</form>
|
|
</Card>
|
|
);
|
|
}
|