diff --git a/src/pages/menuPages/configuration/index.vue b/src/pages/menuPages/configuration/index.vue index 9a2f7a5..f8859ec 100644 --- a/src/pages/menuPages/configuration/index.vue +++ b/src/pages/menuPages/configuration/index.vue @@ -460,15 +460,39 @@ function saveDebounceMs(row: Const): number { return 800 } +function syncMenuFlagsFromSetting(key: string | undefined, value: string) { + if (key === 'price_provider') { + setPriceProviderFromSettings(value) + return + } + if (key === 'banner_enabled') { + setBannerEnabledFromSettings(isSwitchOn(value)) + return + } + if (key === 'tracking_systems_enabled') { + setTrackingSystemsEnabledFromSettings(isSwitchOn(value)) + return + } + if (key === 'enable_conditional_order') { + setConditionalOrderEnabledFromSettings(isSwitchOn(value)) + return + } + if (key === 'has_page_price_trigger') { + setPriceTriggerEnabledFromSettings(isSwitchOn(value)) + return + } + if (key === 'has_page_notification') { + setAppNotificationEnabledFromSettings(isSwitchOn(value)) + } +} + function onValueChange(row: Const, value: string) { if (row.id == null || isReadonly(row)) return drafts.value[row.id] = value - // بلافاصله گروه Montzar را با انتخاب منبع قیمت همگام کن - if (row.key === 'price_provider') { - setPriceProviderFromSettings(value) - } + // منو و UI وابسته را همان لحظه با سوئیچ همگام کن + syncMenuFlagsFromSetting(row.key, value) // longtext هم باید ذخیره شود، فقط با delay بیشتر scheduleSave(row) @@ -552,24 +576,7 @@ async function saveSettingRow(row: Const) { setStoreModeFromSettings(isSwitchOn(value)) refreshMenuAfterStoreChange() } - if (row.key === 'banner_enabled') { - setBannerEnabledFromSettings(isSwitchOn(value)) - } - if (row.key === 'tracking_systems_enabled') { - setTrackingSystemsEnabledFromSettings(isSwitchOn(value)) - } - if (row.key === 'enable_conditional_order') { - setConditionalOrderEnabledFromSettings(isSwitchOn(value)) - } - if (row.key === 'has_page_price_trigger') { - setPriceTriggerEnabledFromSettings(isSwitchOn(value)) - } - if (row.key === 'has_page_notification') { - setAppNotificationEnabledFromSettings(isSwitchOn(value)) - } - if (row.key === 'price_provider') { - setPriceProviderFromSettings(value) - } + syncMenuFlagsFromSetting(row.key, value) savedFlashIds.value.add(id) if (saveTimers.has(id)) clearTimeout(saveTimers.get(id)) saveTimers.set( @@ -584,6 +591,8 @@ async function saveSettingRow(row: Const) { if ((drafts.value[id] ?? '') === draftSnapshot) { drafts.value[id] = row.value ?? '' } + // برگرداندن فلگ منو به مقدار ذخیره‌شده قبلی + syncMenuFlagsFromSetting(row.key, row.value ?? '') message.error(`ذخیره «${row.title_fa || row.key}» ناموفق بود`) } finally { savingIds.value.delete(id) diff --git a/src/utils/config.ts b/src/utils/config.ts index 14c5598..7084449 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -150,42 +150,43 @@ export function setPriceProviderFromSettings(value?: string | null): void { priceProviderSetting.value = (value ?? '').trim().toLowerCase() } +/** فقط وقتی کلید در rows باشد آپدیت می‌شود — پاسخ ناقص (editable/system) فلگ قبلی را پاک نکند */ export function applyBannerEnabledFromRows(rows: Array<{ key?: string; value?: string | null }>) { const row = rows.find((item) => item.key === 'banner_enabled') - setBannerEnabledFromSettings(row ? isSwitchOn(row.value) : false) + if (row) setBannerEnabledFromSettings(isSwitchOn(row.value)) } export function applyTrackingSystemsEnabledFromRows( rows: Array<{ key?: string; value?: string | null }> ) { const row = rows.find((item) => item.key === 'tracking_systems_enabled') - setTrackingSystemsEnabledFromSettings(row ? isSwitchOn(row.value) : false) + if (row) setTrackingSystemsEnabledFromSettings(isSwitchOn(row.value)) } export function applyCustomerDirectSmsFromRows(rows: Array<{ key?: string; value?: string | null }>) { const row = rows.find((item) => item.key === 'customer_direct_sms') - setCustomerDirectSmsEnabledFromSettings(row ? isSwitchOn(row.value) : false) + if (row) setCustomerDirectSmsEnabledFromSettings(isSwitchOn(row.value)) } export function applyConditionalOrderEnabledFromRows( rows: Array<{ key?: string; value?: string | null }> ) { const row = rows.find((item) => item.key === 'enable_conditional_order') - setConditionalOrderEnabledFromSettings(row ? isSwitchOn(row.value) : false) + if (row) setConditionalOrderEnabledFromSettings(isSwitchOn(row.value)) } export function applyPriceTriggerEnabledFromRows( rows: Array<{ key?: string; value?: string | null }> ) { const row = rows.find((item) => item.key === 'has_page_price_trigger') - setPriceTriggerEnabledFromSettings(row ? isSwitchOn(row.value) : false) + if (row) setPriceTriggerEnabledFromSettings(isSwitchOn(row.value)) } export function applyAppNotificationEnabledFromRows( rows: Array<{ key?: string; value?: string | null }> ) { const row = rows.find((item) => item.key === 'has_page_notification') - setAppNotificationEnabledFromSettings(row ? isSwitchOn(row.value) : false) + if (row) setAppNotificationEnabledFromSettings(isSwitchOn(row.value)) } export function applyPriceProviderFromRows(