diff --git a/frontend/src/api/recipe.js b/frontend/src/api/recipe.js index 52cc212f7..f6a08f8c9 100644 --- a/frontend/src/api/recipe.js +++ b/frontend/src/api/recipe.js @@ -88,9 +88,16 @@ export const recipeAPI = { }, async update(data) { - let response = await apiReq.put(recipeURLs.update(data.slug), data); - store.dispatch("patchRecipe", response.data); - return response.data.slug; // ! Temporary until I rewrite to refresh page without additional request + let response = await apiReq.put( + recipeURLs.update(data.slug), + data, + function() { return i18n.t('recipe.recipe-update-failed'); }, + function() { return i18n.t('recipe.recipe-updated'); } + ); + if(response) { + store.dispatch("patchRecipe", response.data); + return response.data.slug; // ! Temporary until I rewrite to refresh page without additional request + } }, async patch(data) { diff --git a/frontend/src/locales/messages/en-US.json b/frontend/src/locales/messages/en-US.json index ad517aff4..9d846a110 100644 --- a/frontend/src/locales/messages/en-US.json +++ b/frontend/src/locales/messages/en-US.json @@ -194,6 +194,8 @@ "recipe-image": "Recipe Image", "recipe-image-updated": "Recipe image updated", "recipe-name": "Recipe Name", + "recipe-update-failed": "Recipe update failed", + "recipe-updated": "Recipe updated", "servings": "Servings", "sodium-content": "Sodium Content", "step-index": "Step: {step}", diff --git a/frontend/src/pages/Recipe/ViewRecipe.vue b/frontend/src/pages/Recipe/ViewRecipe.vue index a56ed9270..6df53d5b1 100644 --- a/frontend/src/pages/Recipe/ViewRecipe.vue +++ b/frontend/src/pages/Recipe/ViewRecipe.vue @@ -180,9 +180,9 @@ export default { return this.$refs.recipeEditor.validateRecipe(); } }, - async saveImage() { + async saveImage(overrideSuccessMsg = false) { if (this.fileObject) { - if (api.recipes.updateImage(this.recipeDetails.slug, this.fileObject)) { + if (api.recipes.updateImage(this.recipeDetails.slug, this.fileObject, overrideSuccessMsg)) { this.imageKey += 1; } } @@ -192,7 +192,7 @@ export default { let slug = await api.recipes.update(this.recipeDetails); if (this.fileObject) { - this.saveImage(); + this.saveImage(true); } this.form = false;