Skip to content

Instantly share code, notes, and snippets.

@designviacode
Forked from bjenkins24/formValidation.js
Created January 13, 2018 17:01
Show Gist options
  • Save designviacode/f52b92f2613a9209b7aa9e6f0e923682 to your computer and use it in GitHub Desktop.
Save designviacode/f52b92f2613a9209b7aa9e6f0e923682 to your computer and use it in GitHub Desktop.
// Destructuring cleans it up a bit
const { postCatalogues, updateCatalogues } = this.props;
const { catalogueName, activeStatusValidation } = formValidation;
// Bail early
if (catalogueName || activeStatusValidation) return;
// Model the data to avoid a switch - this makes more sense to me - seems more clear - you could even take this out of
// this method completely and include it as a property on the React component, as you may end up with more than add and edit,
// and perhaps it will be needed elsewhere?
const submitActions = {
add: () => {
// I'm not sure where cataologue is defined so you may need to include this as an argument in the add function?
postCatalogues(catalogue);
},
edit: () => {
// Same comment about _id and catalogue as the add function above
updateCatalogues(_id, catalogue);
}
}
submitActions[submitType]();
// Keep it DRY. If you're going to call this.close() on both add and edit, then might as well call it here
this.close();
@designviacode
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment