126 lines
4 KiB
TypeScript
126 lines
4 KiB
TypeScript
// * Packages.
|
|
import { Head, Link, useForm, usePage } from "@inertiajs/react";
|
|
import { route } from "ziggy-js";
|
|
import { SubmitEvent } from "react";
|
|
import { LoaderCircleIcon, LogInIcon, MoveRightIcon } from "lucide-react";
|
|
// * Components shadcn.
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/components/ui/card";
|
|
// * Other.
|
|
import GuestLayout from "@/back/Layouts/GuestLayout";
|
|
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { AppEnv } from "@/types/global";
|
|
import { toast } from "@/hooks/use-toast";
|
|
import SimpleSwitch from "@/back/Components/Inputs/SimpleSwitch";
|
|
|
|
export default function Login() {
|
|
const appName = (usePage().props.appEnv as AppEnv).name;
|
|
|
|
/** Translations. */
|
|
const transConnected = useTrans("auth.connected");
|
|
const transConnectedDesc = useTrans("auth.connected_desc");
|
|
|
|
/** Form section. */
|
|
const { post, setData, data, processing } = useForm({
|
|
email: null,
|
|
password: null,
|
|
remember: false,
|
|
});
|
|
|
|
const submit = (event: SubmitEvent) => {
|
|
event.preventDefault();
|
|
post(route("back.login.post"), {
|
|
onSuccess: () => {
|
|
toast({
|
|
title: transConnected,
|
|
description: transConnectedDesc,
|
|
});
|
|
},
|
|
});
|
|
};
|
|
|
|
return (
|
|
<GuestLayout>
|
|
<CardHeader>
|
|
<Head title={useTrans("uwil-backend::back.login_title")} />
|
|
<CardTitle>
|
|
<h1 className="text-2xl text-center font-extrabold tracking-tight">
|
|
{useTrans("uwil-backend::back.login_title")}
|
|
</h1>
|
|
</CardTitle>
|
|
<CardDescription
|
|
dangerouslySetInnerHTML={{
|
|
__html: useTrans("auth.description", {
|
|
params: { appName: String(appName) },
|
|
}),
|
|
}}
|
|
/>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form onSubmit={submit} className="space-y-3">
|
|
<SimpleString
|
|
id="email"
|
|
name="email"
|
|
type="email"
|
|
label={useTrans("back.your_field", {
|
|
params: { field: useTrans("validation.attributes.email") },
|
|
})}
|
|
placeholder="ex: john.doe@ldc.fr"
|
|
wordCounter={false}
|
|
required
|
|
setData={setData}
|
|
/>
|
|
<SimpleString
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
label={useTrans("back.your_field", {
|
|
params: { field: useTrans("validation.attributes.password") },
|
|
})}
|
|
placeholder="********"
|
|
wordCounter={false}
|
|
required
|
|
setData={setData}
|
|
/>
|
|
<div className="flex flex-row justify-start items-center space-x-2 space-y-0">
|
|
<SimpleSwitch
|
|
id="remember-switch"
|
|
name="remember"
|
|
checked={data.remember}
|
|
setData={setData}
|
|
/>
|
|
<label
|
|
htmlFor="remember-switch"
|
|
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
>
|
|
{useTrans("auth.remember")}
|
|
</label>
|
|
</div>
|
|
<div className="flex flex-row items-center justify-between gap-y-3">
|
|
<Link
|
|
href={route("back.forgot-password")}
|
|
className="flex justify-center items-center gap-1 rounded-md text-sm text-gray-600 underline hover:text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2"
|
|
>
|
|
{useTrans("auth.forgot_password")}
|
|
<MoveRightIcon size={15} />
|
|
</Link>
|
|
<Button type="submit" disabled={processing}>
|
|
{useTrans("auth.login")}
|
|
{processing ? (
|
|
<LoaderCircleIcon className="animate-spin" />
|
|
) : (
|
|
<LogInIcon />
|
|
)}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</CardContent>
|
|
</GuestLayout>
|
|
);
|
|
}
|