'use client'; import { usePathname, useRouter } from 'next/navigation'; import { useForm } from 'react-hook-form'; import AppLink from './AppLink'; import Button from './Button'; import Input from './Input'; export default function UserAuthForm() { return ( <> ); } type FormData = { pseudo: string; email: string; passwd: string; firstname: string; lastname: string; description: string; sgroup: string; avatar: string; }; function AuthForm() { const { register, handleSubmit, formState: { errors }, setError } = useForm({ defaultValues: { pseudo: '', email: '', passwd: '', firstname: '', lastname: '', description: '', sgroup: '', avatar: '' } }); const router = useRouter(); const pathname = usePathname()!; const isSignIn = pathname.includes('sign-in'); async function onSubmit(data: FormData) { const response = await fetch( `${process.env.NEXT_PUBLIC_API_URL}/${isSignIn ? 'login' : 'register'}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...data }) } ); const status = response.status; const json = await response.json(); console.log(json, status); if (status === 200) { router.push('/dashboard'); } } return (
{!isSignIn && ( <> // {translations.noAccountAssociated}{' '} // // {translations.signUpQuestion} // // // ) : ( // errors.email.message // )) } {...register('email')} /> // {translations.noAccountAssociated}{' '} // // {translations.signUpQuestion} // // // ) : ( // errors.email.message // )) } {...register('lastname')} /> // {translations.noAccountAssociated}{' '} // // {translations.signUpQuestion} // // // ) : ( // errors.email.message // )) } {...register('firstname')} /> )} {/* {!isSignIn && (

En cliquant sur continuer, vous acceptez les{' '} Politique de confidentialité .

)} */}

{isSignIn ? "Vous n'avez pas de compte?" : 'Vous possédez un compte?'}{' '} {isSignIn ? "S'inscrire maintenant" : 'Se connecter'}

); }