import React, { useState } from 'react' import { useMutation } from '@apollo/client' import { REGISTER_NEW_CLIENT } from '@/lib/graphql' import type { VerificationResponse } from '@/types/auth' interface UserRegistrationProps { phone: string sessionId: string onSuccess: (data: VerificationResponse) => void onError: (error: string) => void } const UserRegistration: React.FC = ({ phone, sessionId, onSuccess, onError }) => { const [firstName, setFirstName] = useState('') const [lastName, setLastName] = useState('') const [isLoading, setIsLoading] = useState(false) const [registerClient] = useMutation<{ registerNewClient: VerificationResponse }>(REGISTER_NEW_CLIENT) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!firstName.trim()) { onError('Введите имя') return } if (!lastName.trim()) { onError('Введите фамилию') return } setIsLoading(true) try { const fullName = `${firstName.trim()} ${lastName.trim()}` const { data } = await registerClient({ variables: { phone, name: fullName, sessionId } }) if (data?.registerNewClient) { onSuccess(data.registerNewClient) } } catch (error) { onError('Не удалось зарегистрировать пользователя') } finally { setIsLoading(false) } } return (
{/* Имя */}
setFirstName(e.target.value)} placeholder="Иван" className="max-w-[360px] w-full h-[62px] px-6 py-4 text-[18px] leading-[1.4] font-normal font-[Onest,sans-serif] text-neutral-500 bg-white border border-stone-300 rounded focus:outline-none" disabled={isLoading} required />
{/* Фамилия */}
setLastName(e.target.value)} placeholder="Иванов" className="max-w-[360px] w-full h-[62px] px-6 py-4 text-[18px] leading-[1.4] font-normal font-[Onest,sans-serif] text-neutral-500 bg-white border border-stone-300 rounded focus:outline-none" disabled={isLoading} required />
{/* Кнопка */}
) } export default UserRegistration