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 []
|
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[]> {
|
async function fetchFromUrl(url: string, timeout = 5000): Promise<SuperAdminSettingRow[]> {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
const timer = window.setTimeout(() => controller.abort(), timeout)
|
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)
|
throw lastError instanceof Error ? lastError : new Error('SuperAdmin program-settings unreachable')
|
||||||
return []
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-8
@@ -332,21 +332,20 @@ async function bootstrapSettingsFromApi(): Promise<void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { getConfiguration } = await import('@/api/configuration')
|
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 { parseMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
|
||||||
const [localRows, saRows] = await Promise.all([
|
const localRows = await getConfiguration().catch(() => [])
|
||||||
getConfiguration().catch(() => []),
|
const saRows = await fetchSuperAdminProgramSettings()
|
||||||
fetchSuperAdminProgramSettings(),
|
|
||||||
])
|
|
||||||
const local = Array.isArray(localRows) ? localRows : []
|
const local = Array.isArray(localRows) ? localRows : []
|
||||||
const merged = [...local]
|
const editable = local.filter((row) => !isLockedCanEdit(row?.can_edit))
|
||||||
for (const item of saRows) {
|
const merged = [...saRows] as typeof local
|
||||||
|
for (const item of editable) {
|
||||||
if (!item?.key) continue
|
if (!item?.key) continue
|
||||||
const index = merged.findIndex((row) => row.key === item.key)
|
const index = merged.findIndex((row) => row.key === item.key)
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
merged[index] = { ...merged[index], ...item }
|
merged[index] = { ...merged[index], ...item }
|
||||||
} else {
|
} else {
|
||||||
merged.push(item as (typeof merged)[number])
|
merged.push(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const list = merged
|
const list = merged
|
||||||
|
|||||||
Reference in New Issue
Block a user