From cc4ef14faa753c468edfa0d9cca5fd9585e7558d Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Tue, 20 Sep 2022 18:23:28 -0700 Subject: [PATCH] chore: Fix link generation logic in help-center (#5470) --- .../public/api/v1/portals_controller.rb | 2 +- .../dashboard/helper/portalHelper.js | 9 ++++-- .../helper/specs/portalHelper.spec.js | 29 +++++++++++++++++++ .../i18n/locale/en/conversation.json | 1 + .../helpcenter/pages/articles/EditArticle.vue | 1 + .../accounts/articles/_article.json.jbuilder | 1 + .../api/v1/portals/_category-block.html.erb | 2 +- .../public/api/v1/portals/_header.html.erb | 2 ++ 8 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 app/javascript/dashboard/helper/specs/portalHelper.spec.js diff --git a/app/controllers/public/api/v1/portals_controller.rb b/app/controllers/public/api/v1/portals_controller.rb index 98c54ca35..da9b23956 100644 --- a/app/controllers/public/api/v1/portals_controller.rb +++ b/app/controllers/public/api/v1/portals_controller.rb @@ -1,7 +1,7 @@ class Public::Api::V1::PortalsController < PublicController before_action :ensure_custom_domain_request, only: [:show] - before_action :redirect_to_portal_with_locale, only: [:show] before_action :portal + before_action :redirect_to_portal_with_locale, only: [:show] layout 'portal' def show; end diff --git a/app/javascript/dashboard/helper/portalHelper.js b/app/javascript/dashboard/helper/portalHelper.js index 71c35f61f..d93aa9275 100644 --- a/app/javascript/dashboard/helper/portalHelper.js +++ b/app/javascript/dashboard/helper/portalHelper.js @@ -4,7 +4,12 @@ export const buildPortalURL = portalSlug => { return `${baseURL}/hc/${portalSlug}`; }; -export const buildPortalArticleURL = (portalSlug, categorySlug, articleId) => { +export const buildPortalArticleURL = ( + portalSlug, + categorySlug, + locale, + articleId +) => { const portalURL = buildPortalURL(portalSlug); - return `${portalURL}/${categorySlug}/${articleId}`; + return `${portalURL}/${locale}/${categorySlug}/${articleId}`; }; diff --git a/app/javascript/dashboard/helper/specs/portalHelper.spec.js b/app/javascript/dashboard/helper/specs/portalHelper.spec.js new file mode 100644 index 000000000..954bdbd58 --- /dev/null +++ b/app/javascript/dashboard/helper/specs/portalHelper.spec.js @@ -0,0 +1,29 @@ +import { buildPortalArticleURL, buildPortalURL } from '../portalHelper'; + +describe('PortalHelper', () => { + describe('buildPortalURL', () => { + it('returns the correct url', () => { + window.chatwootConfig = { + hostURL: 'https://app.chatwoot.com', + helpCenterURL: 'https://help.chatwoot.com', + }; + expect(buildPortalURL('handbook')).toEqual( + 'https://help.chatwoot.com/hc/handbook' + ); + window.chatwootConfig = {}; + }); + }); + + describe('buildPortalArticleURL', () => { + it('returns the correct url', () => { + window.chatwootConfig = { + hostURL: 'https://app.chatwoot.com', + helpCenterURL: 'https://help.chatwoot.com', + }; + expect(buildPortalArticleURL('handbook', 'culture', 'fr', 1)).toEqual( + 'https://help.chatwoot.com/hc/handbook/fr/culture/1' + ); + window.chatwootConfig = {}; + }); + }); +}); diff --git a/app/javascript/dashboard/i18n/locale/en/conversation.json b/app/javascript/dashboard/i18n/locale/en/conversation.json index 39857520f..047e5c351 100644 --- a/app/javascript/dashboard/i18n/locale/en/conversation.json +++ b/app/javascript/dashboard/i18n/locale/en/conversation.json @@ -1,6 +1,7 @@ { "CONVERSATION": { "SELECT_A_CONVERSATION": "Please select a conversation from left pane", + "CSAT_REPLY_MESSAGE": "Please rate the conversation", "404": "Sorry, we cannot find the conversation. Please try again", "SWITCH_VIEW_LAYOUT": "Switch the layout", "DASHBOARD_APP_TAB_MESSAGES": "Messages", 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 bf7468dd1..1dba3a1d4 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/EditArticle.vue @@ -90,6 +90,7 @@ export default { return buildPortalArticleURL( slug, this.article.category.slug, + this.article.category.locale, this.article.id ); }, diff --git a/app/views/api/v1/accounts/articles/_article.json.jbuilder b/app/views/api/v1/accounts/articles/_article.json.jbuilder index e493cc7a2..2428924c5 100644 --- a/app/views/api/v1/accounts/articles/_article.json.jbuilder +++ b/app/views/api/v1/accounts/articles/_article.json.jbuilder @@ -10,6 +10,7 @@ json.category do json.id article.category_id json.name article.category.name json.slug article.category.slug + json.locale article.category.locale end if article.portal.present? diff --git a/app/views/public/api/v1/portals/_category-block.html.erb b/app/views/public/api/v1/portals/_category-block.html.erb index 514a5ce79..de55d5398 100644 --- a/app/views/public/api/v1/portals/_category-block.html.erb +++ b/app/views/public/api/v1/portals/_category-block.html.erb @@ -15,7 +15,7 @@ <% else %> <% category.articles.published.take(5).each do |article| %> -
+ + <% if @portal.config["allowed_locales"].length > 1 %>