Skip to content

Instantly share code, notes, and snippets.

@bjenkins24
Last active January 13, 2018 17:01
Show Gist options
  • Save bjenkins24/e9706d306c1da751f25ff16011fc8b42 to your computer and use it in GitHub Desktop.
Save bjenkins24/e9706d306c1da751f25ff16011fc8b42 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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment