fix: normalize Khanegi newTheme ui config for userTheme schema
Map sidebar+bottom→both, products→buyProduct, ensure header.variant. Repair script + get_user normalize so colors apply instead of Zod fallback. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -83,7 +83,7 @@ export class GetUserService {
|
||||
ui_variant: isKhanegi ? uiVariant : undefined,
|
||||
app_ui_config:
|
||||
isKhanegi && uiVariant === 'newTheme'
|
||||
? this.stripKhanegiSaMeta(ui)
|
||||
? this.stripKhanegiSaMeta(this.normalizeKhanegiUiConfig(ui))
|
||||
: undefined,
|
||||
/** Laravel-compatible overlay; Hamkar merges only when present */
|
||||
ui_settings: uiSettings.length ? uiSettings : undefined,
|
||||
@@ -168,6 +168,49 @@ export class GetUserService {
|
||||
return rest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backfillهای قدیمی sidebar+bottom / route=products / بدون header.variant
|
||||
* را با اسکیمای userTheme همتراز میکند تا Zod رد نکند و fallback نشود.
|
||||
*/
|
||||
private normalizeKhanegiUiConfig(ui: Record<string, any> | null) {
|
||||
if (!ui || typeof ui !== 'object') return ui;
|
||||
const next = JSON.parse(JSON.stringify(ui)) as Record<string, any>;
|
||||
this.normalizeKhanegiAppNode(next.app);
|
||||
this.normalizeKhanegiAppNode(next.defaultSnapshot?.app);
|
||||
return next;
|
||||
}
|
||||
|
||||
private normalizeKhanegiAppNode(app: any) {
|
||||
if (!app || typeof app !== 'object') return;
|
||||
|
||||
if (app.startRoute === 'products') app.startRoute = 'buyProduct';
|
||||
|
||||
const header = app.header;
|
||||
if (header && typeof header === 'object' && header.variant !== 'default') {
|
||||
header.variant = 'default';
|
||||
}
|
||||
|
||||
const navigation = app.navigation;
|
||||
if (!navigation || typeof navigation !== 'object') return;
|
||||
|
||||
if (navigation.type === 'sidebar+bottom') navigation.type = 'both';
|
||||
|
||||
const mapItems = (items: unknown) => {
|
||||
if (!Array.isArray(items)) return items;
|
||||
return items.map((item) => {
|
||||
if (!item || typeof item !== 'object') return item;
|
||||
if (item.route === 'products') return { ...item, route: 'buyProduct' };
|
||||
return item;
|
||||
});
|
||||
};
|
||||
|
||||
navigation.sidebar = mapItems(navigation.sidebar);
|
||||
navigation.bottom = mapItems(navigation.bottom);
|
||||
if (navigation.sidebarReferral?.route === 'products') {
|
||||
navigation.sidebarReferral.route = 'buyProduct';
|
||||
}
|
||||
}
|
||||
|
||||
private buildHamkarUiSettings(ui: Record<string, any>): UiSetting[] {
|
||||
const settings = ui?.settings;
|
||||
if (!settings || typeof settings !== 'object') return [];
|
||||
|
||||
Reference in New Issue
Block a user