78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { login } from "@lib/data/customer"
|
|
import { LOGIN_VIEW } from "@modules/account/templates/login-template"
|
|
import ErrorMessage from "@modules/checkout/components/error-message"
|
|
import { SubmitButton } from "@modules/checkout/components/submit-button"
|
|
import Input from "@modules/common/components/input"
|
|
import { useActionState } from "react"
|
|
|
|
type Props = {
|
|
setCurrentView: (view: LOGIN_VIEW) => void
|
|
}
|
|
|
|
const Login = ({ setCurrentView }: Props) => {
|
|
const [message, formAction] = useActionState(login, null)
|
|
|
|
return (
|
|
<div className="flex w-full max-w-sm flex-col" data-testid="login-page">
|
|
<header className="text-center">
|
|
<p className="eyebrow">Moj račun</p>
|
|
<h1 className="display-heading mt-5 text-4xl sm:text-5xl text-foreground">Prijava</h1>
|
|
<p className="mt-4 text-sm text-muted-foreground">
|
|
Pratite narudžbe, sačuvajte adrese i naručujte brže.
|
|
</p>
|
|
</header>
|
|
|
|
{message?.state === "verification_required" && (
|
|
<div
|
|
className="mt-8 rounded-lg bg-muted p-4 text-center text-sm text-foreground"
|
|
data-testid="login-verification-message"
|
|
>
|
|
Poslali smo link za potvrdu na <strong>{message.email}</strong>. Potvrdite email, pa se prijavite.
|
|
</div>
|
|
)}
|
|
|
|
<form className="mt-10 w-full" action={formAction}>
|
|
<div className="flex w-full flex-col gap-y-3">
|
|
<Input
|
|
label="Email"
|
|
name="email"
|
|
type="email"
|
|
title="Unesite ispravnu email adresu."
|
|
autoComplete="email"
|
|
required
|
|
data-testid="email-input"
|
|
/>
|
|
<Input
|
|
label="Lozinka"
|
|
name="password"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
data-testid="password-input"
|
|
/>
|
|
</div>
|
|
<ErrorMessage
|
|
error={message?.state === "error" ? message.error : null}
|
|
data-testid="login-error-message"
|
|
/>
|
|
<SubmitButton data-testid="sign-in-button" className="mt-6 h-12 w-full">
|
|
Prijava
|
|
</SubmitButton>
|
|
</form>
|
|
|
|
<p className="mt-8 border-t border-border/70 pt-6 text-center text-sm text-muted-foreground">
|
|
Nemate račun?{" "}
|
|
<button
|
|
onClick={() => setCurrentView(LOGIN_VIEW.REGISTER)}
|
|
className="text-primary underline underline-offset-4 hover:opacity-80"
|
|
data-testid="register-button"
|
|
>
|
|
Registrujte se
|
|
</button>
|
|
</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Login
|