From d47a0ae4615c54bf5bb6dee5319d64cdff5a8a5d Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Fri, 2 Sep 2022 22:34:07 +0530 Subject: [PATCH] feat: Adds the ability to edit/delete category (#5385) --- .../dashboard/api/helpCenter/categories.js | 7 +- .../dashboard/i18n/locale/en/helpCenter.json | 52 +++++ .../components/HelpCenterLayout.vue | 4 +- .../helpcenter/components/PortalListItem.vue | 8 + .../helpcenter/components/PortalSwitch.vue | 8 + .../dashboard/helpcenter/helpcenter.routes.js | 8 +- .../categories}/AddCategory.vue | 3 +- .../pages/categories/CategoryListItem.vue | 123 +++++++++++ .../pages/categories/EditCategory.vue | 197 +++++++++++++++++- .../pages/categories/ListAllCategories.vue | 193 ++++++++++++++++- .../helpcenter/pages/portals/EditPortal.vue | 21 +- .../modules/helpCenterCategories/actions.js | 16 +- .../modules/helpCenterCategories/getters.js | 7 + .../modules/helpCenterCategories/mutations.js | 2 +- .../specs/actions.spec.js | 49 +++-- .../specs/getters.spec.js | 4 + .../dashboard/store/mutation-types.js | 2 + 17 files changed, 667 insertions(+), 37 deletions(-) rename app/javascript/dashboard/routes/dashboard/helpcenter/{components => pages/categories}/AddCategory.vue (98%) create mode 100644 app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/CategoryListItem.vue diff --git a/app/javascript/dashboard/api/helpCenter/categories.js b/app/javascript/dashboard/api/helpCenter/categories.js index c5cb40cd4..b6eae3f32 100644 --- a/app/javascript/dashboard/api/helpCenter/categories.js +++ b/app/javascript/dashboard/api/helpCenter/categories.js @@ -15,8 +15,11 @@ class CategoriesAPI extends PortalsAPI { return axios.post(`${this.url}/${portalSlug}/categories`, categoryObj); } - update({ portalSlug, categoryObj }) { - return axios.patch(`${this.url}/${portalSlug}/categories`, categoryObj); + update({ portalSlug, categoryId, categoryObj }) { + return axios.patch( + `${this.url}/${portalSlug}/categories/${categoryId}`, + categoryObj + ); } delete({ portalSlug, categoryId }) { diff --git a/app/javascript/dashboard/i18n/locale/en/helpCenter.json b/app/javascript/dashboard/i18n/locale/en/helpCenter.json index d5ab8c8eb..b5dd77749 100644 --- a/app/javascript/dashboard/i18n/locale/en/helpCenter.json +++ b/app/javascript/dashboard/i18n/locale/en/helpCenter.json @@ -139,6 +139,21 @@ "TITLE": "Locales" } }, + "CATEGORIES": { + "TITLE": "Categories in", + "NEW_CATEGORY": "New category", + "TABLE": { + "NAME": "Name", + "DESCRIPTION": "Description", + "LOCALE": "Locale", + "ARTICLE_COUNT": "No. of articles", + "ACTION_BUTTON": { + "EDIT": "Edit category", + "DELETE": "Delete category" + }, + "EMPTY_TEXT": "No categories found" + } + }, "EDIT_BASIC_INFO": { "BUTTON_TEXT": "Update basic settings" } @@ -353,6 +368,43 @@ "SUCCESS_MESSAGE": "Category created successfully", "ERROR_MESSAGE": "Unable to create category" } + }, + "EDIT": { + "TITLE": "Edit a category", + "SUB_TITLE": "Editing a category will update the category in the public facing portal.", + "PORTAL": "Portal", + "LOCALE": "Locale", + "NAME": { + "LABEL": "Name", + "PLACEHOLDER": "Category name", + "HELP_TEXT": "The category name will be used in the public facing portal to categorize articles.", + "ERROR": "Name is required" + }, + "SLUG": { + "LABEL": "Slug", + "PLACEHOLDER": "Category slug for urls", + "HELP_TEXT": "app.chatwoot.com/portal/my-portal/en-US/categories/my-slug", + "ERROR": "Slug is required" + }, + "DESCRIPTION": { + "LABEL": "Description", + "PLACEHOLDER": "Give a short description about the category.", + "ERROR": "Description is required" + }, + "BUTTONS": { + "CREATE": "Update category", + "CANCEL": "Cancel" + }, + "API": { + "SUCCESS_MESSAGE": "Category updated successfully", + "ERROR_MESSAGE": "Unable to update category" + } + }, + "DELETE": { + "API": { + "SUCCESS_MESSAGE": "Category deleted successfully", + "ERROR_MESSAGE": "Unable to delete category" + } } } } diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue index 4f9b30d97..e043adba3 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue @@ -37,6 +37,7 @@ /> { + this.$store.dispatch('categories/index', { + portalSlug: this.portal.slug, + }); + }); + }, async onClickDeletePortal() { const { slug } = this.selectedPortalForDelete; try { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue index d4e80463b..3f815be54 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue @@ -92,8 +92,16 @@ export default { this.selectedLocale = this.locale || this.portal?.meta?.default_locale; }, methods: { + fetchPortalsAndItsCategories() { + this.$store.dispatch('portals/index').then(() => { + this.$store.dispatch('categories/index', { + portalSlug: this.portal.slug, + }); + }); + }, onClick(event, code, portal) { event.preventDefault(); + this.fetchPortalsAndItsCategories(); this.$router.push({ name: 'list_all_locale_articles', params: { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/helpcenter.routes.js b/app/javascript/dashboard/routes/dashboard/helpcenter/helpcenter.routes.js index 8def6be6b..fb0dda331 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/helpcenter.routes.js +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/helpcenter.routes.js @@ -77,6 +77,12 @@ const portalRoutes = [ component: EditPortalCustomization, roles: ['administrator'], }, + { + path: getPortalRoute(':portalSlug/edit/:locale/categories'), + name: 'list_all_locale_categories', + roles: ['administrator', 'agent'], + component: ListAllCategories, + }, ], }, ]; @@ -125,7 +131,7 @@ const articleRoutes = [ const categoryRoutes = [ { path: getPortalRoute(':portalSlug/:locale/categories'), - name: 'list_all_locale_categories', + name: 'all_locale_categories', roles: ['administrator', 'agent'], component: ListAllCategories, }, diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/AddCategory.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/AddCategory.vue similarity index 98% rename from app/javascript/dashboard/routes/dashboard/helpcenter/components/AddCategory.vue rename to app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/AddCategory.vue index c3f053559..0fb6bcd2b 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/AddCategory.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/AddCategory.vue @@ -132,11 +132,12 @@ export default { }, async addCategory() { - const { name, slug, description } = this; + const { name, slug, description, locale } = this; const data = { name, slug, description, + locale, }; this.$v.$touch(); if (this.$v.$invalid) { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/CategoryListItem.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/CategoryListItem.vue new file mode 100644 index 000000000..3a8b7a850 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/CategoryListItem.vue @@ -0,0 +1,123 @@ + + + + + diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/EditCategory.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/EditCategory.vue index ecd03c1b6..ea3bb4aff 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/EditCategory.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/categories/EditCategory.vue @@ -1,3 +1,198 @@