'use client' import { infer as zInfer } from 'zod' import { useState, useTransition } from 'react' import { useForm } from 'react-hook-form' import { useSearchParams } from 'next/navigation' import { zodResolver } from '@hookform/resolvers/zod' import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form' import { Input } from '@/components/ui/input' import { CardWrapper } from '@/components/auth/card-wrapper' import { useI18n } from '@/locales/client' import { Button } from '@/components/ui/button' import FormError from '@/components/form-error' import FormSuccess from '@/components/form-success' import { login } from '@/actions/login' import { LoginSchema } from '@/schemas' import { AUTH_REGISTER_URL } from '@/config/routes' export const LoginForm = () => { const t = useI18n() const searchParams = useSearchParams() const urlError = searchParams.get('error') === 'OAuthAccountNotLinked' ? t('auth.form.error.email_in_use') : '' const [error, setError] = useState('') const [success, setSuccess] = useState('') const [isPending, startTransition] = useTransition() const form = useForm>({ resolver: zodResolver(LoginSchema), defaultValues: { email: '', password: '', }, }) const onSubmit = (values: zInfer) => { setError('') setSuccess('') startTransition(() => { login(values).then((data) => { // @ts-ignore setError(t(data?.error)) // @ts-ignore setSuccess(t(data?.success)) }) }) } return (
( {t('form.label.email')} )}/> {/*Password*/} ( {t('form.label.password')} )}/>
) } //1:30:00