Skip to content

Commit

Permalink
Refactors the handleSubmit function
Browse files Browse the repository at this point in the history
  • Loading branch information
allishultes committed Sep 9, 2019
1 parent a3da609 commit b765718
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/components/FormModal/ItemForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ const ItemForm = (props) => {
const [ title, setTitle ] = useState(props.title);

const handleSubmit = (event) => {
const form = event.currentTarget;
event.preventDefault();
event.stopPropagation();

if (isValidated) {
if (!form.checkValidity()) {
setIsValidated(true);
} else if (form.checkValidity()) {
setIsValidated(true);
const editedProject = {
title: title,
description: description,
id: props.id
};

props.handleSaveForm(editedProject);
} else if (!isValidated) {
setIsValidated(true);
};
}
};

return (
Expand Down Expand Up @@ -80,7 +81,7 @@ ItemForm.propTypes = {
id: PropTypes.number.isRequired,
title: PropTypes.string,
description: PropTypes.string,
showModal: PropTypes.bool.isRequired,
isNewItemModalShow: PropTypes.bool.isRequired,
modalTitle: PropTypes.string.isRequired,
handleSaveForm: PropTypes.func.isRequired,
};
Expand Down

0 comments on commit b765718

Please sign in to comment.