Skip to content

Commit

Permalink
fix handleSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yur1yBubl1k committed Jan 18, 2024
1 parent 2c5b16a commit cd4449a
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/components/NewMovie/NewMovie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,31 @@ export const NewMovie: React.FC<Props> = ({ onAdd }) => {
const [imdbUrl, setImdbUrl] = useState('');
const [imdbId, setimdbId] = useState('');

const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
};

const reset = () => {
setCount(count + 1);
setCount(current => current + 1);
setTitle('');
setDescription('');
setImgUrl('');
setImdbUrl('');
setimdbId('');
};

const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
onAdd({
title,
description,
imgUrl,
imdbUrl,
imdbId,
});
reset();
};

const checkerButton = !title.trim()
|| !imgUrl.trim()
|| !imdbUrl.trim()
|| !imdbId.trim();
|| !imgUrl.trim()
|| !imdbUrl.trim()
|| !imdbId.trim();

return (
<form
Expand Down Expand Up @@ -89,16 +97,6 @@ export const NewMovie: React.FC<Props> = ({ onAdd }) => {
data-cy="submit-button"
className="button is-link"
disabled={checkerButton}
onClick={() => {
onAdd({
title,
description,
imgUrl,
imdbUrl,
imdbId,
});
reset();
}}
>
Add
</button>
Expand Down

0 comments on commit cd4449a

Please sign in to comment.