'use client' import { submitWhatsapp } from '@/app/(frontend)/actions/submitWhatsapp' import { CitySelect } from '@/components/CitySelect' import { EmailInput } from '@/components/EmailInput' import { NameInput } from '@/components/NameInput' import { PhoneInput } from '@/components/PhoneInput' import { StateSelect } from '@/components/StateSelect' import { Button } from '@/components/ui/button' import { Field, FieldDescription, FieldGroup } from '@/components/ui/field' import { Textarea } from '@/components/ui/textarea' import { WhatsAppFormInput, whatsAppFormSchema } from '@/lib/schemas/whatsapp-form' import { zodResolver } from '@hookform/resolvers/zod' import { useTransition } from 'react' import { FormProvider, SubmitHandler, useForm } from 'react-hook-form' interface WhatsappFormProps { classname?: string onSubmit: () => void } export const WhatsappForm = ({ classname, onSubmit }: WhatsappFormProps) => { const methods = useForm({ resolver: zodResolver(whatsAppFormSchema), defaultValues: { name: '', email: '', phone: '', state: undefined, city: '', comment: '', }, }) const [isSubmitting, startTransition] = useTransition() const handleSubmit: SubmitHandler = (input) => { startTransition(async () => { try { await submitWhatsapp(input) methods.reset() onSubmit() } catch (e) { console.log(e) methods.setError('root', { message: 'Falha ao enviar assinatura. Tente novamente.', }) } }) } return (