add query client

This commit is contained in:
2025-03-16 17:21:56 -03:00
parent bfc1114090
commit 12748e7e9c
4 changed files with 328 additions and 2 deletions

View File

@@ -1,4 +1,7 @@
import { useForm } from "react-hook-form";
import { useMutation } from "node_modules/@tanstack/react-query/build/legacy";
import { queryClient } from "../queryClient";
import axios from "axios";
interface IFormInput {
name: string;
@@ -6,14 +9,26 @@ interface IFormInput {
}
export function Form() {
const { register, handleSubmit } = useForm<IFormInput>();
const { register, handleSubmit, reset, formState } = useForm<IFormInput>();
const { mutateAsync } = useMutation(
{
mutationFn: async (data: IFormInput) => {
return await axios.post("https://n8n.sergio.run/webhook/eduseg", data);
},
onSuccess: () => {
reset();
},
},
queryClient,
);
const onSubmit = async (data: IFormInput) => {
console.log(data);
await mutateAsync(data);
};
return (
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-2.5">
{formState.isSubmitting && <>Okey!</>}
<label>
Nome
<Input {...register("name")} />