From 0cd08065d1784c6374330af12f68a5755dba6702 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 18 Aug 2022 11:45:08 +0530 Subject: [PATCH] feat: Adds the ability to create a new article (#5255) --- .../dashboard/api/helpCenter/articles.js | 10 +++ .../dashboard/i18n/locale/en/helpCenter.json | 3 + .../helpcenter/pages/articles/EditArticle.vue | 3 + .../helpcenter/pages/articles/NewArticle.vue | 68 +++++++++++++++---- .../modules/helpCenterArticles/actions.js | 23 ++++--- .../modules/helpCenterArticles/mutations.js | 18 ++++- .../helpCenterArticles/specs/action.spec.js | 23 ++++--- .../modules/helpCenterPortals/actions.js | 4 +- .../dashboard/store/mutation-types.js | 1 + 9 files changed, 117 insertions(+), 36 deletions(-) diff --git a/app/javascript/dashboard/api/helpCenter/articles.js b/app/javascript/dashboard/api/helpCenter/articles.js index ea6a4f244..8bc960267 100644 --- a/app/javascript/dashboard/api/helpCenter/articles.js +++ b/app/javascript/dashboard/api/helpCenter/articles.js @@ -32,6 +32,16 @@ class ArticlesAPI extends PortalsAPI { articleObj ); } + + createArticle({ portalSlug, articleObj }) { + const { content, title, author_id, category_id } = articleObj; + return axios.post(`${this.url}/${portalSlug}/articles`, { + content, + title, + author_id, + category_id, + }); + } } export default new ArticlesAPI(); diff --git a/app/javascript/dashboard/i18n/locale/en/helpCenter.json b/app/javascript/dashboard/i18n/locale/en/helpCenter.json index 75e0e436f..7f4c7c76d 100644 --- a/app/javascript/dashboard/i18n/locale/en/helpCenter.json +++ b/app/javascript/dashboard/i18n/locale/en/helpCenter.json @@ -183,6 +183,9 @@ "ERROR": "Error while saving article" } }, + "CREATE_ARTICLE": { + "ERROR_MESSAGE": "Something went wrong. Please try again." + }, "SIDEBAR": { "SEARCH": { "PLACEHOLDER": "Search for articles" diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue index f65e24d2e..5b2b5b0f0 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue @@ -51,12 +51,14 @@ export default { isUpdating: false, isSaved: false, showArticleSettings: false, + alertMessage: '', }; }, computed: { ...mapGetters({ isFetching: 'articles/isFetching', articles: 'articles/articles', + selectedPortal: 'portals/getSelectedPortal', }), article() { return this.$store.getters['articles/articleById'](this.articleId); @@ -93,6 +95,7 @@ export default { this.alertMessage = error?.message || this.$t('HELP_CENTER.EDIT_ARTICLE.API.ERROR_MESSAGE'); + this.showAlert(this.alertMessage); } finally { setTimeout(() => { this.isUpdating = false; diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue index 39503efef..1938a724a 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/NewArticle.vue @@ -1,22 +1,27 @@