mirror of
https://git.meshkee.com/Meshkee/dashboards.git
synced 2026-08-11 22:30:58 +04:30
Add business modules column and selectable home charts.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
a48a24e6f2
commit
0a2358b0c2
@@ -0,0 +1,78 @@
|
||||
/** Optional CMS modules a business can have. Always-on areas are not listed. */
|
||||
export const BUSINESS_MODULE_IDS = [
|
||||
'products',
|
||||
'store',
|
||||
'portfolio',
|
||||
'blog',
|
||||
'warehouse',
|
||||
'videos',
|
||||
] as const
|
||||
|
||||
export type BusinessModuleId = (typeof BUSINESS_MODULE_IDS)[number]
|
||||
|
||||
/** Home dashboard chart slots (super-admin selectable). */
|
||||
export const HOME_CHART_IDS = [
|
||||
'none',
|
||||
'orders_30d',
|
||||
'customers_joined_1y',
|
||||
'blog_views_30d',
|
||||
'products_added_1y',
|
||||
] as const
|
||||
|
||||
export type HomeChartId = (typeof HOME_CHART_IDS)[number]
|
||||
|
||||
/** Existing tenants without saved modules keep every module enabled. */
|
||||
export const DEFAULT_ENABLED_BUSINESS_MODULES: BusinessModuleId[] = [
|
||||
...BUSINESS_MODULE_IDS,
|
||||
]
|
||||
|
||||
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 hasBusinessModule(
|
||||
enabledModules: readonly BusinessModuleId[] | null | undefined,
|
||||
moduleId: BusinessModuleId,
|
||||
): boolean {
|
||||
const enabled = normalizeEnabledBusinessModules(enabledModules)
|
||||
return enabled.includes(moduleId)
|
||||
}
|
||||
|
||||
export function isActiveHomeChart(value: HomeChartId): boolean {
|
||||
return value !== 'none'
|
||||
}
|
||||
Reference in New Issue
Block a user