From 7c2dc9ae845026e4d48e9b2e76bd43b41060e77f Mon Sep 17 00:00:00 2001 From: Ryan Noelk Date: Thu, 30 Aug 2018 10:47:12 +0200 Subject: [PATCH] Fix/recipe creation refresh (#17) * adding menus * adding a menu item for menus * adding react-big-calender * adding basic redux hooks * adding a recipe event * adding modal and datetime picker * adding more responsive menu * saving * adding some basic updates * fixing reducer to save correctly * fixing reducer to save correctly * making creatin/editing and delting easier * adding react app that handles selects * adding proper select box * saving some calander changes * cleaning up datetime object handling and display * create a seperate redux call for creating recipes * fixing agenda style and adding history to the calander * adding support for all day button * fixing bug with times * updating menus * adding a menu selector * adding selector for filtering by menu * Adding Menu management * doing some clean up and adding translations * clean up on containers * update the URL when you create or delete a menu * fixing bugs * remvoing fixed todos * adding ability to copy menus * fixing issues with dates * adding a menu list * commenting out the menu list for now * adding a basic status bar * adding comment * abstracting the modals and adding validation * adding proper descriptions to the validators * adding text to the menu status * cleaning up the menu header * adding better css for alert messages and fixing small bug with menu item dates * fixing merge conflicks * merge conflict fixes * adding recipe slug to the menu * fixing lint errors * putting some finishing touches on the menu composer * updating tests * adding menu items to the homepage * fixing menu item support * removing unused components * adding menu items to the home page * adding complete button to the homepage * adding simple add menu button to the recipe page * updating lock file * fixing tests * adding proper styling for add to menu button * bug fixes * bug fixes --- .../__snapshots__/Ingredients.test.js.snap | 89 +++++++++++++++++++ modules/locale/en.json | 2 +- .../recipe_form/actions/RecipeFormActions.js | 6 +- .../recipe_form/reducers/RecipeFormReducer.js | 16 +++- package.json | 2 +- yarn.lock | 50 +++++------ 6 files changed, 133 insertions(+), 32 deletions(-) create mode 100644 modules/list/tests/__snapshots__/Ingredients.test.js.snap diff --git a/modules/list/tests/__snapshots__/Ingredients.test.js.snap b/modules/list/tests/__snapshots__/Ingredients.test.js.snap new file mode 100644 index 00000000..0d33daf9 --- /dev/null +++ b/modules/list/tests/__snapshots__/Ingredients.test.js.snap @@ -0,0 +1,89 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MyLists component test 1`] = ` +
+ +
+`; + +exports[`MyLists component test w/ no lists 1`] = ` +
+ +
+`; diff --git a/modules/locale/en.json b/modules/locale/en.json index 8829a4dc..d58485bf 100644 --- a/modules/locale/en.json +++ b/modules/locale/en.json @@ -59,7 +59,7 @@ "select_widget.header": "Please select a {label}", "widget_error.title": "Form error!", "widget_error.message": "Please confirm that all the data is there.", - "nav.menu": "Menu (Beta)", + "nav.menu": "Menu", "nav.randomRecipe": "Random", "list.new-input-placeholder": "What else do you need?", "list.error.message": "Something went wrong!", diff --git a/modules/recipe_form/actions/RecipeFormActions.js b/modules/recipe_form/actions/RecipeFormActions.js index 69c6f180..3c4b3a16 100644 --- a/modules/recipe_form/actions/RecipeFormActions.js +++ b/modules/recipe_form/actions/RecipeFormActions.js @@ -103,7 +103,8 @@ export const save = (data, event) => { dispatch({ type: RecipeFormConstants.RECIPE_FORM_SUBMIT, oldRecipeId: data.id, - newRecipeId: res.body.id + newRecipeId: res.body.id, + slug: res.body.slug }); dispatch({ type: StatusConstants.RECIPE_FROM_STATUS_DISPLAY, @@ -124,7 +125,8 @@ export const save = (data, event) => { dispatch({ type: RecipeFormConstants.RECIPE_FORM_SUBMIT, oldRecipeId: data.id, - newRecipeId: res.body.id + newRecipeId: res.body.id, + slug: res.body.slug }); dispatch({ type: StatusConstants.RECIPE_FROM_STATUS_DISPLAY, diff --git a/modules/recipe_form/reducers/RecipeFormReducer.js b/modules/recipe_form/reducers/RecipeFormReducer.js index e5fb00f6..465e2c66 100644 --- a/modules/recipe_form/reducers/RecipeFormReducer.js +++ b/modules/recipe_form/reducers/RecipeFormReducer.js @@ -3,7 +3,19 @@ import RecipeFormConstants from '../constants/RecipeFormConstants' function form(state = [], action) { switch (action.type) { case RecipeFormConstants.RECIPE_FORM_INIT: - return [...state, { ...action.data, errors: [] }]; + let newRecipe = true; + const recipes = state.map(recipe => { + if (recipe.slug === action.data.slug) { + newRecipe = false; + return { ...recipe, ...action.data, errors: [] }; + } + return recipe; + }); + + if (newRecipe) { + return [...state, { ...action.data, errors: [] }]; + } + return [ ...recipes ]; case RecipeFormConstants.RECIPE_FORM_UPDATE: return state.map(recipe => { if (recipe.slug === action.recipeSlug) { @@ -27,7 +39,7 @@ function form(state = [], action) { if (action.newRecipeId !== action.oldRecipeId) { return state.map(recipe => { if (recipe.id === action.oldRecipeId) { - return {...recipe, id: action.newRecipeId }; + return {...recipe, id: action.newRecipeId, slug: action.slug }; } return recipe; }); diff --git a/package.json b/package.json index a0dc5cf6..195c3808 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "react-spinkit": "2.1.2", "redux": "^3.7.2", "redux-thunk": "^2.2.0", - "superagent": "^2.3.0", + "superagent": "^3.8.3", "superagent-defaults": "^0.1.14" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index b07f7c15..d2e1c151 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1646,7 +1646,7 @@ colors@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63" -combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.6: +combined-stream@1.0.6, combined-stream@~1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818" dependencies: @@ -1756,7 +1756,7 @@ cookie@0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" -cookiejar@^2.0.6: +cookiejar@^2.1.0: version "2.1.2" resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.2.tgz#dd8a235530752f988f9a0844f3fc589e3111125c" @@ -2980,15 +2980,7 @@ forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" -form-data@1.0.0-rc4: - version "1.0.0-rc4" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-1.0.0-rc4.tgz#05ac6bc22227b43e4461f488161554699d4f8b5e" - dependencies: - async "^1.5.2" - combined-stream "^1.0.5" - mime-types "^2.1.10" - -form-data@~2.3.2: +form-data@^2.3.1, form-data@~2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.2.tgz#4970498be604c20c005d4f5c23aecd21d6b49099" dependencies: @@ -2996,7 +2988,7 @@ form-data@~2.3.2: combined-stream "1.0.6" mime-types "^2.1.12" -formidable@^1.0.17: +formidable@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.2.1.tgz#70fb7ca0290ee6ff961090415f4b3df3d2082659" @@ -4736,7 +4728,13 @@ miller-rabin@^4.0.0: version "1.36.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.36.0.tgz#5020478db3c7fe93aad7bbcc4dcf869c43363397" -mime-types@^2.1.10, mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.18, mime-types@~2.1.19: +mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.18: + version "2.1.18" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8" + dependencies: + mime-db "~1.33.0" + +mime-types@~2.1.19: version "2.1.20" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.20.tgz#930cb719d571e903738520f8470911548ca2cc19" dependencies: @@ -4746,7 +4744,7 @@ mime@1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6" -mime@^1.3.4, mime@^1.4.1, mime@^1.5.0: +mime@^1.4.1, mime@^1.5.0: version "1.6.0" resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" @@ -5857,7 +5855,7 @@ qs@6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" -qs@^6.1.0, qs@~6.5.2: +qs@^6.5.1, qs@~6.5.2: version "6.5.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" @@ -6213,7 +6211,7 @@ readable-stream@1.0: isarray "0.0.1" string_decoder "~0.10.x" -readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.2.2, readable-stream@^2.2.9, readable-stream@^2.3.3, readable-stream@^2.3.6: +readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.2.2, readable-stream@^2.2.9, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6: version "2.3.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" dependencies: @@ -7022,20 +7020,20 @@ superagent-defaults@^0.1.14: dependencies: emitter-component "~1.0.1" -superagent@^2.3.0: - version "2.3.0" - resolved "http://registry.npmjs.org/superagent/-/superagent-2.3.0.tgz#703529a0714e57e123959ddefbce193b2e50d115" +superagent@^3.8.3: + version "3.8.3" + resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.8.3.tgz#460ea0dbdb7d5b11bc4f78deba565f86a178e128" dependencies: component-emitter "^1.2.0" - cookiejar "^2.0.6" - debug "^2.2.0" + cookiejar "^2.1.0" + debug "^3.1.0" extend "^3.0.0" - form-data "1.0.0-rc4" - formidable "^1.0.17" + form-data "^2.3.1" + formidable "^1.2.0" methods "^1.1.1" - mime "^1.3.4" - qs "^6.1.0" - readable-stream "^2.0.5" + mime "^1.4.1" + qs "^6.5.1" + readable-stream "^2.3.5" supports-color@^2.0.0: version "2.0.0"