fix(admin): merge SuperAdmin settings over local can_edit locks
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -37,6 +37,11 @@ function parseSettingsPayload(data: unknown): SuperAdminSettingRow[] {
|
||||
return []
|
||||
}
|
||||
|
||||
/** کلید قفلشده در get_settings محلی — باید از سوپرادمین بیاید */
|
||||
export function isLockedCanEdit(canEdit: unknown): boolean {
|
||||
return canEdit === 0 || canEdit === false || canEdit === '0'
|
||||
}
|
||||
|
||||
async function fetchFromUrl(url: string, timeout = 5000): Promise<SuperAdminSettingRow[]> {
|
||||
const controller = new AbortController()
|
||||
const timer = window.setTimeout(() => controller.abort(), timeout)
|
||||
@@ -73,6 +78,5 @@ export async function fetchSuperAdminProgramSettings(): Promise<SuperAdminSettin
|
||||
}
|
||||
}
|
||||
}
|
||||
console.warn('SuperAdmin program-settings failed after retries:', lastError)
|
||||
return []
|
||||
throw lastError instanceof Error ? lastError : new Error('SuperAdmin program-settings unreachable')
|
||||
}
|
||||
|
||||
+7
-8
@@ -332,21 +332,20 @@ async function bootstrapSettingsFromApi(): Promise<void> {
|
||||
|
||||
try {
|
||||
const { getConfiguration } = await import('@/api/configuration')
|
||||
const { fetchSuperAdminProgramSettings } = await import('@/api/superadminSettings')
|
||||
const { fetchSuperAdminProgramSettings, isLockedCanEdit } = await import('@/api/superadminSettings')
|
||||
const { parseMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
|
||||
const [localRows, saRows] = await Promise.all([
|
||||
getConfiguration().catch(() => []),
|
||||
fetchSuperAdminProgramSettings(),
|
||||
])
|
||||
const localRows = await getConfiguration().catch(() => [])
|
||||
const saRows = await fetchSuperAdminProgramSettings()
|
||||
const local = Array.isArray(localRows) ? localRows : []
|
||||
const merged = [...local]
|
||||
for (const item of saRows) {
|
||||
const editable = local.filter((row) => !isLockedCanEdit(row?.can_edit))
|
||||
const merged = [...saRows] as typeof local
|
||||
for (const item of editable) {
|
||||
if (!item?.key) continue
|
||||
const index = merged.findIndex((row) => row.key === item.key)
|
||||
if (index >= 0) {
|
||||
merged[index] = { ...merged[index], ...item }
|
||||
} else {
|
||||
merged.push(item as (typeof merged)[number])
|
||||
merged.push(item)
|
||||
}
|
||||
}
|
||||
const list = merged
|
||||
|
||||
Reference in New Issue
Block a user