This adds a draft status for Help Center locales so teams can prepare localized content in the dashboard without exposing those locales in the public portal switcher until they are ready to publish. Fixes: https://github.com/chatwoot/chatwoot/issues/10412 Closes: https://github.com/chatwoot/chatwoot/issues/10412 ## Why Teams need a way to work on locale-specific Help Center content ahead of launch. The public portal should only show ready locales, while the admin dashboard should continue to expose every allowed locale for ongoing article and category work. ## What this change does - Adds `draft_locales` to portal config as a subset of `allowed_locales` - Hides drafted locales from the public portal language switchers while keeping direct locale URLs working - Keeps drafted locales fully visible in the admin dashboard for article and category management - Adds locale actions to move an existing locale to draft, publish a drafted locale, and keep the default locale protected from drafting - Adds a status dropdown when creating a locale so new locales can be created as `Published` or `Draft` - Returns each admin locale with a `draft` flag so the locale UI can reflect the public visibility state ## Validation - Seed a portal with multiple locales, draft one locale, and confirm the public portal switcher hides it while `/hc/:slug/:locale` still loads directly - In the admin dashboard, confirm drafted locales still appear in the locale list and remain selectable for articles and categories - Create a new locale with `Draft` status and confirm it stays out of the public switcher until published - Move an existing locale back and forth between `Published` and `Draft` and confirm the public switcher updates accordingly ## Demo https://github.com/user-attachments/assets/ba22dc26-c2e7-463a-b1f5-adf1fda1f9be --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
191 lines
4.7 KiB
JavaScript
191 lines
4.7 KiB
JavaScript
/**
|
|
* Formats a custom domain with https protocol if needed
|
|
* @param {string} customDomain - The custom domain to format
|
|
* @returns {string} Formatted domain with https protocol
|
|
*/
|
|
const formatCustomDomain = customDomain =>
|
|
customDomain.startsWith('https') ? customDomain : `https://${customDomain}`;
|
|
|
|
/**
|
|
* Gets the default base URL from configuration
|
|
* @returns {string} The default base URL
|
|
* @throws {Error} If no valid base URL is found
|
|
*/
|
|
const getDefaultBaseURL = () => {
|
|
const { hostURL, helpCenterURL } = window.chatwootConfig || {};
|
|
const baseURL = helpCenterURL || hostURL || '';
|
|
|
|
if (!baseURL) {
|
|
throw new Error('No valid base URL found in configuration');
|
|
}
|
|
|
|
return baseURL;
|
|
};
|
|
|
|
/**
|
|
* Gets the base URL from configuration or custom domain
|
|
* @param {string} [customDomain] - Optional custom domain for the portal
|
|
* @returns {string} The base URL for the portal
|
|
*/
|
|
const getPortalBaseURL = customDomain =>
|
|
customDomain ? formatCustomDomain(customDomain) : getDefaultBaseURL();
|
|
|
|
/**
|
|
* Builds a portal URL using the provided portal slug and optional custom domain
|
|
* @param {string} portalSlug - The slug identifier for the portal
|
|
* @param {string} [customDomain] - Optional custom domain for the portal
|
|
* @returns {string} The complete portal URL
|
|
* @throws {Error} If portalSlug is not provided or invalid
|
|
*/
|
|
export const buildPortalURL = (portalSlug, customDomain) => {
|
|
const baseURL = getPortalBaseURL(customDomain);
|
|
return `${baseURL}/hc/${portalSlug}`;
|
|
};
|
|
|
|
export const buildPortalArticleURL = (
|
|
portalSlug,
|
|
categorySlug,
|
|
locale,
|
|
articleSlug,
|
|
customDomain
|
|
) => {
|
|
const portalURL = buildPortalURL(portalSlug, customDomain);
|
|
return `${portalURL}/articles/${articleSlug}`;
|
|
};
|
|
|
|
export const getArticleStatus = status => {
|
|
switch (status) {
|
|
case 'draft':
|
|
return 0;
|
|
case 'published':
|
|
return 1;
|
|
case 'archived':
|
|
return 2;
|
|
default:
|
|
return undefined;
|
|
}
|
|
};
|
|
|
|
export const ARTICLE_STATUSES = {
|
|
DRAFT: 'draft',
|
|
PUBLISHED: 'published',
|
|
ARCHIVED: 'archived',
|
|
};
|
|
|
|
export const ARTICLE_MENU_ITEMS = {
|
|
publish: {
|
|
label: 'HELP_CENTER.ARTICLES_PAGE.ARTICLE_CARD.CARD.DROPDOWN_MENU.PUBLISH',
|
|
value: ARTICLE_STATUSES.PUBLISHED,
|
|
action: 'publish',
|
|
icon: 'i-lucide-check',
|
|
},
|
|
draft: {
|
|
label: 'HELP_CENTER.ARTICLES_PAGE.ARTICLE_CARD.CARD.DROPDOWN_MENU.DRAFT',
|
|
value: ARTICLE_STATUSES.DRAFT,
|
|
action: 'draft',
|
|
icon: 'i-lucide-pencil-line',
|
|
},
|
|
archive: {
|
|
label: 'HELP_CENTER.ARTICLES_PAGE.ARTICLE_CARD.CARD.DROPDOWN_MENU.ARCHIVE',
|
|
value: ARTICLE_STATUSES.ARCHIVED,
|
|
action: 'archive',
|
|
icon: 'i-lucide-archive-restore',
|
|
},
|
|
delete: {
|
|
label: 'HELP_CENTER.ARTICLES_PAGE.ARTICLE_CARD.CARD.DROPDOWN_MENU.DELETE',
|
|
value: 'delete',
|
|
action: 'delete',
|
|
icon: 'i-lucide-trash',
|
|
},
|
|
};
|
|
|
|
export const ARTICLE_MENU_OPTIONS = {
|
|
[ARTICLE_STATUSES.ARCHIVED]: ['publish', 'draft'],
|
|
[ARTICLE_STATUSES.DRAFT]: ['publish', 'archive'],
|
|
[ARTICLE_STATUSES.PUBLISHED]: ['draft', 'archive'],
|
|
};
|
|
|
|
export const ARTICLE_TABS = {
|
|
ALL: 'all',
|
|
MINE: 'mine',
|
|
DRAFT: 'draft',
|
|
ARCHIVED: 'archived',
|
|
};
|
|
|
|
export const CATEGORY_ALL = 'all';
|
|
|
|
export const ARTICLE_TABS_OPTIONS = [
|
|
{
|
|
key: 'ALL',
|
|
value: 'all',
|
|
},
|
|
{
|
|
key: 'MINE',
|
|
value: 'mine',
|
|
},
|
|
{
|
|
key: 'DRAFT',
|
|
value: 'draft',
|
|
},
|
|
{
|
|
key: 'ARCHIVED',
|
|
value: 'archived',
|
|
},
|
|
];
|
|
|
|
export const LOCALE_MENU_ITEMS = {
|
|
makeDefault: {
|
|
label: 'HELP_CENTER.LOCALES_PAGE.LOCALE_CARD.DROPDOWN_MENU.MAKE_DEFAULT',
|
|
action: 'change-default',
|
|
value: 'default',
|
|
icon: 'i-lucide-star',
|
|
},
|
|
moveToDraft: {
|
|
label: 'HELP_CENTER.LOCALES_PAGE.LOCALE_CARD.DROPDOWN_MENU.MOVE_TO_DRAFT',
|
|
action: 'move-to-draft',
|
|
value: 'draft',
|
|
icon: 'i-lucide-eye-off',
|
|
},
|
|
publishLocale: {
|
|
label: 'HELP_CENTER.LOCALES_PAGE.LOCALE_CARD.DROPDOWN_MENU.PUBLISH_LOCALE',
|
|
action: 'publish-locale',
|
|
value: 'publish',
|
|
icon: 'i-lucide-eye',
|
|
},
|
|
delete: {
|
|
label: 'HELP_CENTER.LOCALES_PAGE.LOCALE_CARD.DROPDOWN_MENU.DELETE',
|
|
action: 'delete',
|
|
value: 'delete',
|
|
icon: 'i-lucide-trash',
|
|
},
|
|
};
|
|
|
|
const disableLocaleMenuItems = menuItems =>
|
|
menuItems.map(item => ({ ...item, disabled: true }));
|
|
|
|
export const buildLocaleMenuItems = ({ isDefault, isDraft }) => {
|
|
if (isDefault) {
|
|
return disableLocaleMenuItems([
|
|
LOCALE_MENU_ITEMS.makeDefault,
|
|
LOCALE_MENU_ITEMS.moveToDraft,
|
|
LOCALE_MENU_ITEMS.delete,
|
|
]);
|
|
}
|
|
|
|
if (isDraft) {
|
|
return [LOCALE_MENU_ITEMS.publishLocale, LOCALE_MENU_ITEMS.delete];
|
|
}
|
|
|
|
return [
|
|
LOCALE_MENU_ITEMS.makeDefault,
|
|
LOCALE_MENU_ITEMS.moveToDraft,
|
|
LOCALE_MENU_ITEMS.delete,
|
|
];
|
|
};
|
|
|
|
export const ARTICLE_EDITOR_STATUS_OPTIONS = {
|
|
published: ['archive', 'draft'],
|
|
archived: ['draft'],
|
|
draft: ['archive'],
|
|
};
|