Skip to content

Instantly share code, notes, and snippets.

@designviacode
Forked from bjenkins24/formValidation.js
Created January 13, 2018 17:01
Show Gist options
  • Select an option

  • Save designviacode/f52b92f2613a9209b7aa9e6f0e923682 to your computer and use it in GitHub Desktop.

Select an option

Save designviacode/f52b92f2613a9209b7aa9e6f0e923682 to your computer and use it in GitHub Desktop.

Revisions

  1. Brian Jenkins revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion formValidation.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // Destructuring cleans it up a bit
    const { catalogueName, activeStatusValidation } = formValidation;
    const { postCatalogues, updateCatalogues } = this.props;
    const { catalogueName, activeStatusValidation } = formValidation;

    // Bail early
    if (catalogueName || activeStatusValidation) return;
  2. Brian Jenkins revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion formValidation.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // Destructuring cleans it up a bit
    const {catalogueName, activeStatusValidation} = formValidation;
    const { catalogueName, activeStatusValidation } = formValidation;
    const { postCatalogues, updateCatalogues } = this.props;

    // Bail early
  3. Brian Jenkins revised this gist Dec 29, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions formValidation.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    // Destructuring cleans it up a bit
    const {catalogueName, activeStatusValidation} = formValidation;
    const { postCatalogues, updateCatalogues } = this.props;

    // Bail early
    if (catalogueName || activeStatusValidation) return;

    @@ -8,11 +11,11 @@ if (catalogueName || activeStatusValidation) return;
    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?
    this.props.postCatalogues(catalogue);
    postCatalogues(catalogue);
    },
    edit: () => {
    // Same comment about _id and catalogue as the add function above
    this.props.updateCatalogues(_id, catalogue);
    updateCatalogues(_id, catalogue);
    }
    }

  4. Brian Jenkins revised this gist Dec 28, 2017. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions formValidation.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    const {catalogueName, activeStatusValidation} = formValidation;
    // Bail early
    if (formValidation.catalogueName !== null && formValidation.activeStatusValidation !== null) {
    return null;
    }
    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,
  5. Brian Jenkins created this gist Dec 28, 2017.
    24 changes: 24 additions & 0 deletions formValidation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    // Bail early
    if (formValidation.catalogueName !== null && formValidation.activeStatusValidation !== null) {
    return null;
    }

    // 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?
    this.props.postCatalogues(catalogue);
    },
    edit: () => {
    // Same comment about _id and catalogue as the add function above
    this.props.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();