From d6f0291a27df6ad124d37a08914c1c95a173116b Mon Sep 17 00:00:00 2001 From: Florian Dupret <34862846+sephrat@users.noreply.github.com> Date: Thu, 29 Apr 2021 09:18:45 +0200 Subject: [PATCH] Provide feedback for tags CRUD --- frontend/src/api/category.js | 44 ++++++++++++++----- .../FormHelpers/CategoryTagSelector.vue | 2 +- .../components/Recipe/RecipeEditor/index.vue | 2 +- .../components/Recipe/RecipeViewer/index.vue | 4 +- frontend/src/locales/messages/en-US.json | 10 ++++- .../CategoryTagEditor/RemoveUnused.vue | 2 +- frontend/src/pages/Admin/ToolBox/index.vue | 2 +- 7 files changed, 47 insertions(+), 19 deletions(-) diff --git a/frontend/src/api/category.js b/frontend/src/api/category.js index 633e7c481..ed0e37524 100644 --- a/frontend/src/api/category.js +++ b/frontend/src/api/category.js @@ -84,28 +84,48 @@ export const tagAPI = { return response.data; }, async create(name) { - let response = await apiReq.post(tagURLs.getAll, { name: name }); - store.dispatch("requestTags"); - return response.data; + const response = await apiReq.post( + tagURLs.getAll, + { name: name }, + function() { return i18n.t('tag.tag-creation-failed'); }, + function() { return i18n.t('tag.tag-created'); } + ); + if(response) { + store.dispatch("requestTags"); + return response.data; + } }, async getRecipesInTag(tag) { let response = await apiReq.get(tagURLs.getTag(tag)); return response.data; }, async update(name, newName, overrideRequest = false) { - let response = await apiReq.put(tagURLs.updateTag(name), { name: newName }); + const response = await apiReq.put( + tagURLs.updateTag(name), + { name: newName }, + function() { return i18n.t('tag.tag-update-failed'); }, + function() { return i18n.t('tag.tag-updated'); } + ); - if (!overrideRequest) { - store.dispatch("requestTags"); + if(response) { + if (!overrideRequest) { + store.dispatch("requestTags"); + } + return response.data; } - - return response.data; }, async delete(tag, overrideRequest = false) { - let response = await apiReq.delete(tagURLs.deleteTag(tag)); - if (!overrideRequest) { - store.dispatch("requestTags"); + const response = await apiReq.delete( + tagURLs.deleteTag(tag), + null, + function() { return i18n.t('tag.tag-deletion-failed'); }, + function() { return i18n.t('tag.tag-deleted'); } + ); + if(response) { + if (!overrideRequest) { + store.dispatch("requestTags"); + } + return response.data; } - return response.data; }, }; diff --git a/frontend/src/components/FormHelpers/CategoryTagSelector.vue b/frontend/src/components/FormHelpers/CategoryTagSelector.vue index c31f0a017..526699086 100644 --- a/frontend/src/components/FormHelpers/CategoryTagSelector.vue +++ b/frontend/src/components/FormHelpers/CategoryTagSelector.vue @@ -90,7 +90,7 @@ export default { computed: { inputLabel() { if (!this.showLabel) return null; - return this.tagSelector ? this.$t('recipe.tags') : this.$t('recipe.categories'); + return this.tagSelector ? this.$t('tag.tags') : this.$t('recipe.categories'); }, activeItems() { let ItemObjects = []; diff --git a/frontend/src/components/Recipe/RecipeEditor/index.vue b/frontend/src/components/Recipe/RecipeEditor/index.vue index b8b894d78..cd675c5db 100644 --- a/frontend/src/components/Recipe/RecipeEditor/index.vue +++ b/frontend/src/components/Recipe/RecipeEditor/index.vue @@ -74,7 +74,7 @@ :show-label="false" /> -