From 057cbd7c57ac074180adf060aa81b7e554a8ebce Mon Sep 17 00:00:00 2001 From: Kacper Szarkiewicz Date: Fri, 30 Aug 2024 16:56:07 +0200 Subject: [PATCH] simplify EmailForm --- src/components/EmailForm/index.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/components/EmailForm/index.tsx b/src/components/EmailForm/index.tsx index a622f866..1bedf5b5 100644 --- a/src/components/EmailForm/index.tsx +++ b/src/components/EmailForm/index.tsx @@ -3,11 +3,6 @@ import { useForm } from 'react-hook-form'; import { storeUserEmailInBackend } from '../../services/storage/storeUserEmailInBackend'; import { TextInput } from '../../components/TextInput'; -async function saveUserEmail(email: string) { - return await storeUserEmailInBackend({ email }); -} - -// Implement tanstack query export const EmailForm = () => { const { register, handleSubmit } = useForm(); @@ -17,14 +12,14 @@ export const EmailForm = () => { isSuccess, isError, } = useMutation({ - mutationFn: saveUserEmail, + mutationFn: storeUserEmailInBackend, }); const onSubmit = handleSubmit((data) => { - saveUserEmailMutation(data.email); + saveUserEmailMutation({ email: data.email }); }); - function getFormButtonSection() { + const FormButtonSection = () => { if (isSuccess) { return (
Successfully saved!
@@ -52,7 +47,7 @@ export const EmailForm = () => { )} ); - } + }; return (
@@ -60,7 +55,7 @@ export const EmailForm = () => { To receive further assistance and information about our app,

please provide your email address below:

- {getFormButtonSection()} + ); };