2025-11-27 13:48:24 +07:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import styles from '@/app/styles/login.module.scss';
|
2025-12-07 12:53:56 +07:00
|
|
|
import { useActionState } from 'react';
|
2025-11-27 21:33:53 +07:00
|
|
|
import { registration } from '@/app/actions/auth';
|
2025-12-08 13:57:26 +07:00
|
|
|
import PhoneInput from '@/app/ui/inputs/phone-input';
|
2025-12-10 11:42:52 +07:00
|
|
|
import Link from 'next/link';
|
2025-12-10 16:39:13 +07:00
|
|
|
import { useTranslations } from 'next-intl';
|
2025-11-27 13:48:24 +07:00
|
|
|
|
|
|
|
|
export default function RegisterForm() {
|
2025-12-07 12:53:56 +07:00
|
|
|
const [state, formAction, isPending] = useActionState(
|
2025-11-27 13:48:24 +07:00
|
|
|
registration,
|
|
|
|
|
undefined,
|
|
|
|
|
);
|
2025-12-10 16:39:13 +07:00
|
|
|
const t = useTranslations('Login-register-form');
|
2025-11-27 13:48:24 +07:00
|
|
|
|
|
|
|
|
return (
|
2025-11-28 12:38:14 +07:00
|
|
|
<form action={(e) => {
|
|
|
|
|
formAction(e);
|
|
|
|
|
}}>
|
2025-11-27 13:48:24 +07:00
|
|
|
<div className={`${styles['form-group']}`}>
|
|
|
|
|
<label
|
|
|
|
|
className={`${styles['form-label']} ${styles['required']}`}
|
|
|
|
|
>
|
2025-12-10 16:39:13 +07:00
|
|
|
{t('full-name')}
|
2025-11-27 13:48:24 +07:00
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
id="full_name"
|
|
|
|
|
name="full_name"
|
|
|
|
|
className={`${styles['form-input']}`}
|
2025-12-10 16:39:13 +07:00
|
|
|
placeholder={t('name-placeholder')}
|
2025-12-07 12:53:56 +07:00
|
|
|
defaultValue={state?.previousState?.full_name ? state?.previousState?.full_name : ''}
|
|
|
|
|
/>
|
|
|
|
|
{state?.error?.full_name && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{t(state?.error?.full_name)}
|
|
|
|
|
</p>
|
2025-11-28 12:38:14 +07:00
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
|
|
|
|
<div className={`${styles['form-row']}`}>
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
2025-12-10 16:39:13 +07:00
|
|
|
<label className={`${styles['form-label']} ${styles['required']}`}>
|
|
|
|
|
{t('email-adress')}
|
|
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
id="email"
|
|
|
|
|
name="email"
|
|
|
|
|
className={`${styles['form-input']}`}
|
|
|
|
|
placeholder="ivan@example.com"
|
|
|
|
|
defaultValue={state?.previousState?.email ? state?.previousState?.email : ''}
|
|
|
|
|
/>
|
|
|
|
|
{state?.error?.email && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{t(state?.error?.email)}
|
|
|
|
|
</p>
|
2025-11-28 12:38:14 +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']} ${styles['required']}`}>
|
|
|
|
|
{t('phone')}
|
|
|
|
|
</label>
|
2025-12-08 13:57:26 +07:00
|
|
|
<PhoneInput phoneState={state?.previousState?.phone} />
|
|
|
|
|
{state?.error?.phone && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{t(state?.error?.phone)}
|
|
|
|
|
</p>
|
2025-12-08 13:57:26 +07:00
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
|
|
|
|
<label
|
|
|
|
|
className={`${styles['form-label']}`}
|
|
|
|
|
>
|
2025-12-10 16:39:13 +07:00
|
|
|
{t('company')}
|
2025-11-27 13:48:24 +07:00
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
id="company"
|
|
|
|
|
name="company"
|
|
|
|
|
className={`${styles['form-input']}`}
|
2025-12-10 16:39:13 +07:00
|
|
|
placeholder={t('company-placeholder')}
|
2025-12-07 12:53:56 +07:00
|
|
|
defaultValue={state?.previousState?.company ? state?.previousState?.company : ''}
|
|
|
|
|
/>
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
|
|
|
|
<div className={`${styles['form-row']}`}>
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
2025-12-10 16:39:13 +07:00
|
|
|
<label className={`${styles['form-label']} ${styles['required']}`}>
|
|
|
|
|
{t('password')}
|
|
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
id="password" name="password"
|
|
|
|
|
className={`${styles['form-input']}`}
|
2025-12-10 16:39:13 +07:00
|
|
|
placeholder={t('password-placeholder')}
|
2025-12-07 12:53:56 +07:00
|
|
|
defaultValue={state?.previousState?.password ? state?.previousState?.password : ''}
|
|
|
|
|
/>
|
|
|
|
|
{state?.error?.password && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{
|
|
|
|
|
state?.error?.password.split('&').map((e) => {
|
|
|
|
|
return t(e)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</p>
|
2025-11-28 12:38:14 +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']} ${styles['required']}`}>
|
|
|
|
|
{t('confirm-password')}
|
|
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
id="confirm_password"
|
|
|
|
|
name="confirm_password"
|
|
|
|
|
className={`${styles['form-input']}`}
|
2025-12-10 16:39:13 +07:00
|
|
|
placeholder={t('repeat-password')}
|
2025-12-07 12:53:56 +07:00
|
|
|
defaultValue={state?.previousState?.confirm_password ? state?.previousState?.confirm_password : ''}
|
|
|
|
|
/>
|
|
|
|
|
{state?.error?.confirm_password && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{t(state?.error?.confirm_password)}
|
|
|
|
|
</p>
|
2025-11-28 12:38:14 +07:00
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-12-08 13:57:26 +07:00
|
|
|
<div className={`${styles['form-checkbox']}`}>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
id="agree"
|
|
|
|
|
name="agree"
|
|
|
|
|
defaultChecked={state?.previousState?.agree ? true : false}
|
|
|
|
|
/>
|
2025-12-10 16:39:13 +07:00
|
|
|
<label htmlFor="agree">
|
|
|
|
|
{t('i-agree-to')} <Link
|
2025-12-12 11:43:28 +07:00
|
|
|
href="/terms-of-use"
|
2025-12-10 11:42:52 +07:00
|
|
|
target="_blank"
|
2025-12-10 16:39:13 +07:00
|
|
|
>
|
|
|
|
|
{t('terms-of-use')}
|
2025-12-12 11:43:28 +07:00
|
|
|
</Link> {t('and')} <Link
|
|
|
|
|
href="/privacy-policy"
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
{t('privacy-policy')}
|
2025-12-10 11:42:52 +07:00
|
|
|
</Link>
|
|
|
|
|
</label>
|
2025-11-27 13:48:24 +07:00
|
|
|
</div>
|
2025-12-08 13:57:26 +07:00
|
|
|
{state?.error?.agree && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{t(state?.error?.agree)}
|
|
|
|
|
</p>
|
2025-12-08 13:57:26 +07:00
|
|
|
)}
|
|
|
|
|
{state?.error?.server && (
|
2025-12-10 16:39:13 +07:00
|
|
|
<p className="text-sm text-red-500">
|
|
|
|
|
{t(state?.error?.server)}
|
|
|
|
|
</p>
|
2025-12-08 13:57:26 +07:00
|
|
|
)}
|
2025-12-10 16:39:13 +07:00
|
|
|
<button type="submit" className={`${styles['btn']}`}>
|
|
|
|
|
{t('create-an-account')}
|
|
|
|
|
</button>
|
2025-12-08 13:57:26 +07:00
|
|
|
</form >
|
2025-11-27 13:48:24 +07:00
|
|
|
)
|
|
|
|
|
}
|