From be7c722ec7970c45c550be1d9cfed2598bb998a9 Mon Sep 17 00:00:00 2001 From: Gabriel Borges Date: Mon, 3 Jun 2024 23:55:18 -0300 Subject: [PATCH] fix(frontend): fix form type --- frontend/src/components/AuthorForm.tsx | 129 +++++++++++-------------- 1 file changed, 54 insertions(+), 75 deletions(-) diff --git a/frontend/src/components/AuthorForm.tsx b/frontend/src/components/AuthorForm.tsx index 1d9edb3..b2161b9 100644 --- a/frontend/src/components/AuthorForm.tsx +++ b/frontend/src/components/AuthorForm.tsx @@ -1,84 +1,63 @@ import React, { useState } from "react"; -import { AuthorCreate } from "types/author"; import Input from "./Form/Input"; import { SubmitHandler, useForm } from "react-hook-form"; -import { yupResolver } from "@hookform/resolvers/yup" +import { yupResolver } from "@hookform/resolvers/yup"; import AuthorSchema from "./Schemas/AuthorSchema"; import Form, { FormMessage } from "./Form/Form"; import ManagementService from "services/managementService"; +import { AuthorFormCreate } from "types/author"; -const managementService = new ManagementService() - +const managementService = new ManagementService(); const AuthorForm: React.FC = () => { - const messageInitialState = { value: "", isError: false } - const [isLoading, setIsLoading] = useState(false) - const [message, setMessage] = useState(messageInitialState) - const { - register, - handleSubmit, - reset, - - formState: { errors }, - } = useForm({ resolver: yupResolver(AuthorSchema) }) - - - - const onSubmit: SubmitHandler = async (data: AuthorCreate) => { - setIsLoading(true) - const author = await managementService.createAuthor(data) - console.log(author, author === undefined) - setMessage({ - value: author ? "Author created with success" : "It wansn't possible to create the author, try again", - isError: author === undefined - }) - setIsLoading(false) - // onReset() - } - - const onReset = () => { - setMessage(messageInitialState) - reset(undefined) - } - - return ( -
- <> - - - - - - - -
- ) -} - -export default AuthorForm + const messageInitialState = { value: "", isError: false }; + const [isLoading, setIsLoading] = useState(false); + const [message, setMessage] = useState(messageInitialState); + const { + register, + handleSubmit, + reset, + + formState: { errors }, + } = useForm({ resolver: yupResolver(AuthorSchema) }); + + const onSubmit: SubmitHandler = async (data: AuthorFormCreate) => { + setIsLoading(true); + const author = await managementService.createAuthor(data); + console.log(author, author === undefined); + setMessage({ + value: author ? "Author created with success" : "It wansn't possible to create the author, try again", + isError: author === undefined, + }); + setIsLoading(false); + // onReset() + }; + + const onReset = () => { + setMessage(messageInitialState); + reset(undefined); + }; + + return ( +
+ <> + + + + + + + + +
+ ); +}; + +export default AuthorForm;