add query client
This commit is contained in:
@@ -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")} />
|
||||
|
||||
Reference in New Issue
Block a user