Super Admin can enable it per business; nav and pages stay hidden when off. Co-authored-by: Cursor <cursoragent@cursor.com>
138 lines
4.0 KiB
TypeScript
138 lines
4.0 KiB
TypeScript
/** Optional business-dashboard CMS modules. Always-on areas are not listed. */
|
|
export const BUSINESS_DASHBOARD_MODULE_IDS = [
|
|
'products',
|
|
'store',
|
|
'store_installments',
|
|
'portfolio',
|
|
'blog',
|
|
'warehouse',
|
|
'videos',
|
|
'instructions',
|
|
'workshops',
|
|
'finance',
|
|
'multilanguage_data',
|
|
'roll_call',
|
|
] as const
|
|
|
|
/** Optional customer-dashboard modules. Always-on: home, profile, addresses, orders, favorites. */
|
|
export const CUSTOMER_MODULE_IDS = ['customer_products'] as const
|
|
|
|
/** All optional modules stored in `settings.modules.enabled`. */
|
|
export const BUSINESS_MODULE_IDS = [
|
|
...BUSINESS_DASHBOARD_MODULE_IDS,
|
|
...CUSTOMER_MODULE_IDS,
|
|
] as const
|
|
|
|
export type BusinessDashboardModuleId =
|
|
(typeof BUSINESS_DASHBOARD_MODULE_IDS)[number]
|
|
export type CustomerModuleId = (typeof CUSTOMER_MODULE_IDS)[number]
|
|
export type BusinessModuleId = (typeof BUSINESS_MODULE_IDS)[number]
|
|
|
|
export const BUSINESS_DASHBOARD_MODULE_LABELS: Record<
|
|
BusinessDashboardModuleId,
|
|
string
|
|
> = {
|
|
products: 'Products',
|
|
store: 'Store',
|
|
store_installments: 'Installments & Facilities',
|
|
portfolio: 'Portfolio',
|
|
blog: 'Blog',
|
|
warehouse: 'Warehouse',
|
|
videos: 'Videos',
|
|
instructions: 'Instructions',
|
|
workshops: 'Workshops',
|
|
finance: 'Finance',
|
|
multilanguage_data: 'MultiLanguage Data',
|
|
roll_call: 'Roll Call',
|
|
}
|
|
|
|
export const CUSTOMER_MODULE_LABELS: Record<CustomerModuleId, string> = {
|
|
customer_products: 'Customer products',
|
|
}
|
|
|
|
export const BUSINESS_MODULE_LABELS: Record<BusinessModuleId, string> = {
|
|
...BUSINESS_DASHBOARD_MODULE_LABELS,
|
|
...CUSTOMER_MODULE_LABELS,
|
|
}
|
|
|
|
/** Home dashboard chart slots (super-admin selectable). */
|
|
export const HOME_CHART_IDS = [
|
|
'none',
|
|
'orders_30d',
|
|
'customers_joined_1y',
|
|
'blog_views_30d',
|
|
'products_added_1y',
|
|
'product_views_30d',
|
|
'website_views_30d',
|
|
'portfolio_views_30d',
|
|
] as const
|
|
|
|
export type HomeChartId = (typeof HOME_CHART_IDS)[number]
|
|
|
|
export const HOME_CHART_LABELS: Record<HomeChartId, string> = {
|
|
none: 'No chart',
|
|
orders_30d: 'Orders in past 30 days',
|
|
customers_joined_1y: 'Joined users in last year',
|
|
blog_views_30d: 'Blog visit in last 30 days',
|
|
products_added_1y: 'Added product in last year',
|
|
product_views_30d: 'Product visit in last 30 days',
|
|
website_views_30d: 'Website visit in last 30 days',
|
|
portfolio_views_30d: 'Portfolio visit in last 30 days',
|
|
}
|
|
|
|
/**
|
|
* Existing tenants without saved modules keep every business-dashboard module
|
|
* enabled except opt-in modules. Customer modules stay opt-in.
|
|
*/
|
|
export const DEFAULT_ENABLED_BUSINESS_MODULES: BusinessModuleId[] =
|
|
BUSINESS_DASHBOARD_MODULE_IDS.filter(
|
|
(id) =>
|
|
id !== 'workshops' &&
|
|
id !== 'multilanguage_data' &&
|
|
id !== 'store_installments' &&
|
|
id !== 'roll_call',
|
|
)
|
|
|
|
export const DEFAULT_HOME_CHARTS: [HomeChartId, HomeChartId] = [
|
|
'orders_30d',
|
|
'customers_joined_1y',
|
|
]
|
|
|
|
const MODULE_ID_SET = new Set<string>(BUSINESS_MODULE_IDS)
|
|
const HOME_CHART_ID_SET = new Set<string>(HOME_CHART_IDS)
|
|
|
|
export function isBusinessModuleId(value: unknown): value is BusinessModuleId {
|
|
return typeof value === 'string' && MODULE_ID_SET.has(value)
|
|
}
|
|
|
|
export function isHomeChartId(value: unknown): value is HomeChartId {
|
|
return typeof value === 'string' && HOME_CHART_ID_SET.has(value)
|
|
}
|
|
|
|
export function normalizeEnabledBusinessModules(value: unknown): BusinessModuleId[] {
|
|
if (!Array.isArray(value)) {
|
|
return [...DEFAULT_ENABLED_BUSINESS_MODULES]
|
|
}
|
|
|
|
const selected = new Set<BusinessModuleId>()
|
|
for (const item of value) {
|
|
if (isBusinessModuleId(item)) selected.add(item)
|
|
}
|
|
|
|
return BUSINESS_MODULE_IDS.filter((id) => selected.has(id))
|
|
}
|
|
|
|
export function normalizeHomeCharts(value: unknown): [HomeChartId, HomeChartId] {
|
|
if (!Array.isArray(value)) {
|
|
return [...DEFAULT_HOME_CHARTS]
|
|
}
|
|
|
|
const first = isHomeChartId(value[0]) ? value[0] : DEFAULT_HOME_CHARTS[0]
|
|
const second = isHomeChartId(value[1]) ? value[1] : DEFAULT_HOME_CHARTS[1]
|
|
return [first, second]
|
|
}
|
|
|
|
export function isActiveHomeChart(value: HomeChartId): boolean {
|
|
return value !== 'none'
|
|
}
|