add pages

This commit is contained in:
2025-04-22 13:17:17 -03:00
parent 3c36b5f9ad
commit 4b054fb75e
10 changed files with 795 additions and 188 deletions

View File

@@ -1,79 +0,0 @@
import { useForm } from 'react-hook-form'
import { useMutation } from 'node_modules/@tanstack/react-query/build/legacy'
import { queryClient } from '../queryClient'
import axios from 'axios'
import { createElement } from 'react'
import clsx from 'clsx'
interface IFormInput {
name: string
email: string
message: string
}
export function Form() {
const { register, handleSubmit, reset, formState } = useForm<IFormInput>()
const { mutateAsync } = useMutation(
{
mutationFn: async (data: IFormInput) => {
return await axios.post('https://n8n.vps.eduseg.com.br/webhook/a377b3e0-b159-4536-98ab-e13822b60562', data)
},
onSuccess: () => {
reset()
},
},
queryClient,
)
const onSubmit = async (data: IFormInput) => {
await mutateAsync(data)
}
return (
<form onSubmit={handleSubmit(onSubmit)} className="lg:w-6/12 mx-auto flex flex-col gap-2.5">
{formState.isSubmitSuccessful && <p className="bg-green-700 text-white p-3 rounded-lg">OK!</p>}
<Label>
<span className="lg:w-14">Nome</span>
<Input {...register('name')} />
</Label>
<Label>
<span className="lg:w-14">Email</span>
<Input {...register('email')} />
</Label>
<Label className="flex-col !items-start !gap-1">
<span>Mensagem</span>
<Input as="textarea" className="h-26" {...register('message')} />
</Label>
<button type="submit" className="">
Enviar
</button>
</form>
)
}
interface IInput extends React.HTMLAttributes<HTMLElement> {
as?: string
className?: string | undefined
}
export function Input({ as = 'input', className, ...props }: IInput) {
return createElement(as, {
className: clsx(
'bg-white/10 focus:bg-white focus:text-black rounded-xl p-4 w-full focus:outline-none transition duration-150',
className,
),
...props,
})
}
interface ILabel extends React.HTMLAttributes<HTMLElement> {
className?: string | undefined
}
function Label({ children, className }: ILabel) {
return <label className={clsx('flex max-lg:flex-col lg:items-center gap-1 lg:gap-2.5', className)}>{children}</label>
}