diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 3e5a359..9e4e503 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -122,75 +122,21 @@ function LoginForm({ onSwitch }: { onSwitch: () => void }) { // ── Register form ────────────────────────────────────────────────────────────── function RegisterForm({ onSwitch }: { onSwitch: () => void }) { - const [step, setStep] = useState<1 | 2 | 'done'>(1) + const [done, setDone] = useState(false) + const [hotelName, setHotelName] = useState('') + const [address, setAddress] = useState('') + const [contact, setContact] = useState('') + const [email, setEmail] = useState('') + const [phone, setPhone] = useState('') + const [password, setPassword] = useState('') + const [showPass, setShowPass] = useState(false) + const [loading, setLoading] = useState(false) + const [errors, setErrors] = useState>({}) - // Step 1 — Hotel + Legal entity - const [hotelName, setHotelName] = useState('') - const [legalType, setLegalType] = useState('ooo') - const [legalName, setLegalName] = useState('') - const [inn, setInn] = useState('') - const [kpp, setKpp] = useState('') - const [address, setAddress] = useState('') - - // Step 2 — Account - const [firstName, setFirstName] = useState('') - const [lastName, setLastName] = useState('') - const [email, setEmail] = useState('') - const [phone, setPhone] = useState('') - const [password, setPassword] = useState('') - const [confirm, setConfirm] = useState('') - const [showPass, setShowPass] = useState(false) - const [showConfirm, setShowConfirm] = useState(false) - const [loading, setLoading] = useState(false) - const [errors, setErrors] = useState>({}) - - const isIp = legalType === 'ip' - - const validateStep1 = () => { - const e: Record = {} - if (!hotelName.trim()) e.hotelName = 'Введите название отеля' - if (!legalName.trim()) e.legalName = 'Введите наименование юрлица' - if (!inn.trim()) e.inn = 'Введите ИНН' - else if (!/^\d{10,12}$/.test(inn.replace(/\s/g, ''))) - e.inn = 'ИНН — 10 цифр (юрлицо) или 12 (ИП)' - if (!isIp && !kpp.trim()) e.kpp = 'Введите КПП' - setErrors(e) - return Object.keys(e).length === 0 - } - - const validateStep2 = () => { - const e: Record = {} - if (!firstName.trim()) e.firstName = 'Введите имя' - if (!lastName.trim()) e.lastName = 'Введите фамилию' - if (!email.trim()) e.email = 'Введите email' - else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) e.email = 'Некорректный email' - if (password.length < 8) e.password = 'Минимум 8 символов' - if (password !== confirm) e.confirm = 'Пароли не совпадают' - setErrors(e) - return Object.keys(e).length === 0 - } - - const nextStep = () => { - if (validateStep1()) setStep(2) - } - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault() - if (!validateStep2()) return - setLoading(true) - // Simulate API call - await new Promise(r => setTimeout(r, 1200)) - setLoading(false) - setStep('done') - } - - const Field = ({ - label, error, children, hint, - }: { label: string; error?: string; children: React.ReactNode; hint?: string }) => ( + const Field = ({ label, error, children }: { label: string; error?: string; children: React.ReactNode }) => (
{children} - {hint && !error &&

{hint}

} {error && (

{error} @@ -199,21 +145,35 @@ function RegisterForm({ onSwitch }: { onSwitch: () => void }) {

) - if (step === 'done') { + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault() + const err: Record = {} + if (!hotelName.trim()) err.hotelName = 'Введите название отеля' + if (!contact.trim()) err.contact = 'Введите контактное лицо' + if (!email.trim()) err.email = 'Введите email' + else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) err.email = 'Некорректный email' + if (password.length < 8) err.password = 'Минимум 8 символов' + setErrors(err) + if (Object.keys(err).length > 0) return + setLoading(true) + await new Promise(r => setTimeout(r, 1000)) + setLoading(false) + setDone(true) + } + + if (done) { return (
-

- Заявка отправлена! -

+

Заявка отправлена!

Мы получили данные отеля {hotelName}.

На адрес {email} отправлено - письмо с подтверждением. После проверки данных менеджер HotelSync активирует аккаунт в течение одного рабочего дня. + письмо с подтверждением. Менеджер HotelSync активирует аккаунт в течение одного рабочего дня.

- ))} -
- - -
- - setLegalName(e.target.value)} - /> - - -
- - setInn(e.target.value.replace(/\D/g, ''))} - /> - - {!isIp && ( - - setKpp(e.target.value.replace(/\D/g, ''))} - /> - - )} -
- - - setAddress(e.target.value)} - /> - -
- - - - -

- Уже есть аккаунт?{' '} - -

- - )} - - {/* ── Step 2: Account ── */} - {step === 2 && ( - -
- - setFirstName(e.target.value)} - /> - - - setLastName(e.target.value)} - /> - -
- - - setEmail(e.target.value)} - /> - - - - setPhone(e.target.value)} - /> - - - -
- setPassword(e.target.value)} - /> - -
- {password && ( -
- {[ - password.length >= 8, - /[A-Z]/.test(password), - /[0-9]/.test(password), - ].map((ok, i) => ( -
- ))} -
- )} - - - -
- setConfirm(e.target.value)} - /> - -
-
- -

- Нажимая «Создать аккаунт», вы соглашаетесь с{' '} - условиями использования{' '} - и{' '} - политикой конфиденциальности -

- -
- -
- - )} + {password && ( +
+ {[password.length >= 8, /[A-Z]/.test(password), /[0-9]/.test(password)].map((ok, i) => ( +
+ ))} +
+ )} + + + + + +

+ Уже есть аккаунт?{' '} + +

) }