Skip to content

Commit

Permalink
simplify EmailForm
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharqiewicz committed Aug 30, 2024
1 parent 0b083db commit 057cbd7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/components/EmailForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 (
<div className="flex items-center justify-center mt-2 text-white btn-success btn">Successfully saved!</div>
Expand Down Expand Up @@ -52,15 +47,15 @@ export const EmailForm = () => {
)}
</>
);
}
};

return (
<form className="w-full" onSubmit={onSubmit} aria-errormessage={isError ? 'request-error-message' : undefined}>
<p className="font-light text-center text-blue-700">
To receive further assistance and information about our app,
</p>
<p className="font-light text-center text-blue-700">please provide your email address below:</p>
{getFormButtonSection()}
<FormButtonSection />
</form>
);
};

0 comments on commit 057cbd7

Please sign in to comment.