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-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,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
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']}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
Полное имя
|
|
|
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
id="full_name"
|
|
|
|
|
|
name="full_name"
|
|
|
|
|
|
className={`${styles['form-input']}`}
|
|
|
|
|
|
placeholder="Иванов Иван Иванович"
|
|
|
|
|
|
defaultValue={state?.previousState?.full_name ? state?.previousState?.full_name : ''}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{state?.error?.full_name && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{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']}`}>
|
|
|
|
|
|
<label className={`${styles['form-label']} ${styles['required']}`}>Email адрес</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 && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{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-08 13:57:26 +07:00
|
|
|
|
<label className={`${styles['form-label']} ${styles['required']}`}>Телефон</label>
|
|
|
|
|
|
<PhoneInput phoneState={state?.previousState?.phone} />
|
|
|
|
|
|
{state?.error?.phone && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{state?.error?.phone}</p>
|
|
|
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
|
|
|
|
|
<label
|
|
|
|
|
|
className={`${styles['form-label']}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
Компания
|
|
|
|
|
|
</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
id="company"
|
|
|
|
|
|
name="company"
|
|
|
|
|
|
className={`${styles['form-input']}`}
|
|
|
|
|
|
placeholder="ООО «Ваша компания»"
|
|
|
|
|
|
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']}`}>
|
|
|
|
|
|
<label className={`${styles['form-label']} ${styles['required']}`}>Пароль</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
|
<input
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
id="password" name="password"
|
|
|
|
|
|
className={`${styles['form-input']}`}
|
|
|
|
|
|
placeholder="Минимум 8 символов"
|
|
|
|
|
|
defaultValue={state?.previousState?.password ? state?.previousState?.password : ''}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{state?.error?.password && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{state?.error?.password}</p>
|
2025-11-28 12:38:14 +07:00
|
|
|
|
)}
|
2025-11-27 13:48:24 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className={`${styles['form-group']}`}>
|
|
|
|
|
|
<label className={`${styles['form-label']} ${styles['required']}`}>Подтвердите пароль</label>
|
2025-12-07 12:53:56 +07:00
|
|
|
|
<input
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
id="confirm_password"
|
|
|
|
|
|
name="confirm_password"
|
|
|
|
|
|
className={`${styles['form-input']}`}
|
|
|
|
|
|
placeholder="Повторите пароль"
|
|
|
|
|
|
defaultValue={state?.previousState?.confirm_password ? state?.previousState?.confirm_password : ''}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{state?.error?.confirm_password && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{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}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<label htmlFor="agree">Я соглашаюсь с <a href="/" >условиями использования и политикой конфиденциальности</a></label>
|
2025-11-27 13:48:24 +07:00
|
|
|
|
</div>
|
2025-12-08 13:57:26 +07:00
|
|
|
|
{state?.error?.agree && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{state?.error?.agree}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{state?.error?.server && (
|
|
|
|
|
|
<p className="text-sm text-red-500">{state?.error?.server}</p>
|
|
|
|
|
|
)}
|
2025-12-09 18:08:58 +07:00
|
|
|
|
<button type="submit" className={`${styles['btn']}`}>Создать аккаунт</button>
|
2025-12-08 13:57:26 +07:00
|
|
|
|
</form >
|
2025-11-27 13:48:24 +07:00
|
|
|
|
)
|
|
|
|
|
|
}
|