'use client' import { useState } from 'react' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { Button } from 'components/ui/button' import { registerSchema, type RegisterForm as RegisterFormType } from 'lib/validations/auth' export function RegisterForm() { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) const { register, handleSubmit, formState: { errors } } = useForm({ resolver: zodResolver(registerSchema) }) const onSubmit = async (data: RegisterFormType) => { try { setLoading(true) setError(null) const response = await fetch('/api/auth/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) const result = await response.json() if (!response.ok) { setError(result.error || 'Registrace se nezdařila') return } setSuccess(true) } catch { setError('Došlo k neočekávané chybě') } finally { setLoading(false) } } if (success) { return (

Registrace úspěšná!

Zkontrolujte svůj email a klikněte na ověřovací odkaz.

) } return (
{error ? (
{error}
) : null}
Jméno
{errors.fname?.message}
Příjmení
{errors.sname?.message}
E-mail
{errors.email?.message}
Heslo
{errors.password?.message}
Heslo znovu
{errors.confirmPassword?.message}
Pohlaví
{error ?
{error}
: null}
) }