feat: Add custom domain to article URL if custom domain exists for the portal (#11349)

Portals can have custom domains. When inserting or previewing articles,
we consider the frontend URL. This PR fixes article URL generation to
properly include the portal's custom domain.
This commit is contained in:
Muhsin Keloth
2025-04-22 20:54:09 +05:30
committed by GitHub
parent 9c711bab74
commit e3bacd27d8
5 changed files with 109 additions and 10 deletions

View File

@@ -120,6 +120,7 @@ export default {
mounted() {
this.$store.dispatch('agents/get');
this.$store.dispatch('portals/index');
this.initialize();
this.$watch('$store.state.route', () => this.initialize());
this.$watch('chatList.length', () => {

View File

@@ -1,6 +1,7 @@
<script>
import { debounce } from '@chatwoot/utils';
import { useAlert } from 'dashboard/composables';
import { mapGetters } from 'vuex';
import allLocales from 'shared/constants/locales.js';
import SearchHeader from './Header.vue';
@@ -33,6 +34,15 @@ export default {
};
},
computed: {
...mapGetters({
portalBySlug: 'portals/portalBySlug',
}),
portal() {
return this.portalBySlug(this.selectedPortalSlug);
},
portalCustomDomain() {
return this.portal?.custom_domain;
},
articleViewerUrl() {
const article = this.activeArticle(this.activeId);
if (!article) return '';
@@ -47,6 +57,7 @@ export default {
return `${url}`;
},
searchResultsWithUrl() {
return this.searchResults.map(article => ({
...article,
@@ -65,7 +76,8 @@ export default {
this.selectedPortalSlug,
'',
'',
article.slug
article.slug,
this.portalCustomDomain
);
},
localeName(code) {
@@ -111,7 +123,6 @@ export default {
},
onInsert(id) {
const article = this.activeArticle(id || this.activeId);
this.$emit('insert', article);
useAlert(this.$t('HELP_CENTER.ARTICLE_SEARCH.SUCCESS_ARTICLE_INSERTED'));
this.onClose();

View File

@@ -20,17 +20,23 @@ const articleById = useMapGetter('articles/articleById');
const article = computed(() => articleById.value(articleSlug));
const portalBySlug = useMapGetter('portals/portalBySlug');
const portal = computed(() => portalBySlug.value(portalSlug));
const isUpdating = ref(false);
const isSaved = ref(false);
const portalLink = computed(() => {
const articleLink = computed(() => {
const { slug: categorySlug, locale: categoryLocale } = article.value.category;
const { slug: articleSlugValue } = article.value;
const portalCustomDomain = portal.value?.custom_domain;
return buildPortalArticleURL(
portalSlug,
categorySlug,
categoryLocale,
articleSlugValue
articleSlugValue,
portalCustomDomain
);
});
@@ -91,7 +97,7 @@ const fetchArticleDetails = () => {
};
const previewArticle = () => {
window.open(portalLink.value, '_blank');
window.open(articleLink.value, '_blank');
useTrack(PORTALS_EVENTS.PREVIEW_ARTICLE, {
status: article.value?.status,
});