2025-11-27 13:48:24 +07:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import styles from '@/app/styles/login.module.scss'
|
2025-12-15 12:42:50 +07:00
|
|
|
import { useActionState, useState } from 'react';
|
2025-11-27 21:33:53 +07:00
|
|
|
import { authorization } from '@/app/actions/auth';
|
2025-12-10 16:39:13 +07:00
|
|
|
import { useTranslations } from 'next-intl';
|
2025-12-15 12:42:50 +07:00
|
|
|
import { IconEye } from '@/app/ui/icons/icons';
|
2025-11-27 13:48:24 +07:00
|
|
|
|
|
|
|
|
export default function LoginForm() {
|
2025-12-07 12:53:56 +07:00
|
|
|
const [state, formAction, isPending] = useActionState(
|
2025-11-27 21:33:53 +07:00
|
|
|
authorization,
|
2025-11-27 13:48:24 +07:00
|
|
|
undefined,
|
|
|
|
|
);
|
2025-12-10 16:39:13 +07:00
|
|
|
const t = useTranslations('Login-register-form');
|
2025-11-27 13:48:24 +07:00
|
|
|
|
2025-12-15 12:42:50 +07:00
|
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
|
|
|
|
|
|
|
|
function handleMouseDown() {
|
|
|
|
|
setShowPassword(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleMouseUp() {
|
|
|
|
|
setShowPassword(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleMouseOut() {
|
|
|
|
|
setShowPassword(false);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 13:48:24 +07:00
|
|
|
return (
|
|
|
|
|
<form action={formAction}>
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
2025-12-10 16:39:13 +07:00
|
|
|
<label className={`${styles['form-label']}`}>
|
|
|
|
|
{t('email-adress')}
|
|
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
<input
|
|
|
|
|
type="readOnly"
|
|
|
|
|
id="email"
|
|
|
|
|
name="email"
|
|
|
|
|
className={`${styles['form-input']}`}
|
2025-12-10 16:39:13 +07:00
|
|
|
placeholder={t('enter-email')}
|
2025-12-07 12:53:56 +07:00
|
|
|
defaultValue={state?.previousState?.email ? state?.previousState?.email : ''}
|
|
|
|
|
/>
|
|
|
|
|
{state?.error?.email && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className={`${styles['form-error']}`}>
|
|
|
|
|
{t(state?.error?.email)}
|
|
|
|
|
</p>
|
2025-12-07 12:53:56 +07:00
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
2025-12-10 16:39:13 +07:00
|
|
|
<label className={`${styles['form-label']}`}>
|
|
|
|
|
{t('password')}
|
|
|
|
|
</label>
|
2025-12-15 12:42:50 +07:00
|
|
|
<div className={`${styles['password-wrapper']}`}>
|
|
|
|
|
<input
|
|
|
|
|
type={showPassword ? "text" : "password"}
|
|
|
|
|
id="password"
|
|
|
|
|
name="password"
|
|
|
|
|
className={`${styles['form-input']}`}
|
|
|
|
|
placeholder={t('enter-password')}
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
onMouseDown={handleMouseDown}
|
|
|
|
|
onMouseUp={handleMouseUp}
|
|
|
|
|
onMouseOut={handleMouseOut}
|
|
|
|
|
type="button"
|
|
|
|
|
className={`show-password-button ${showPassword ? 'show' : ''}`}
|
|
|
|
|
>
|
|
|
|
|
<IconEye />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-12-07 12:53:56 +07:00
|
|
|
{state?.error?.password && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className={`${styles['form-error']}`}>
|
|
|
|
|
{t(state?.error?.password)}
|
|
|
|
|
</p>
|
2025-12-07 12:53:56 +07:00
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
2025-12-07 12:53:56 +07:00
|
|
|
{state?.error.server && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className={`${styles['form-error']}`}>
|
|
|
|
|
{t(state?.error.server)}
|
|
|
|
|
</p>
|
2025-11-27 13:48:24 +07:00
|
|
|
)}
|
|
|
|
|
<div className={`${styles['form-options']}`}>
|
|
|
|
|
<div className={`${styles['form-checkbox']}`}>
|
|
|
|
|
<input type="checkbox" id="remember" name="remember" />
|
2025-12-10 16:39:13 +07:00
|
|
|
<label>
|
|
|
|
|
{t('remember-me')}
|
|
|
|
|
</label>
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
2025-12-10 16:39:13 +07:00
|
|
|
<a href="forgot-password" className={`${styles['forgot-password']}`} >
|
|
|
|
|
{t('forgot-password')}?
|
|
|
|
|
</a>
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
2025-12-10 16:39:13 +07:00
|
|
|
<button type="submit" className={`${styles['btn']}`}>
|
|
|
|
|
{t('sign-in')}
|
|
|
|
|
</button>
|
2025-11-27 13:48:24 +07:00
|
|
|
</form>
|
|
|
|
|
)
|
|
|
|
|
}
|