Add customers gold credit menu with request and active tabs.
Gate the submenu on enable_gold_credit and wire settings UI for SuperAdmin and tenant credit options. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -209,7 +209,7 @@ import SettingValueField from './SettingValueField.vue'
|
||||
import SettingCard from './SettingCard.vue'
|
||||
import { refreshAppModeMenu } from '@/router'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import { applyBannerEnabledFromRows, applyTrackingSystemsEnabledFromRows, applyConditionalOrderEnabledFromRows, applyAutomationEnabledFromRows, applyProductFundsEnabledFromRows, applyPriceTriggerEnabledFromRows, applyAppNotificationEnabledFromRows, applyPriceProviderFromRows, applyPriceChannelAccessFromRows, applySupportChatMenuEnabledFromRows, applyGroupSmsFromRows, applyCustomerSpecialPricingFromRows, applyCustomerDirectSmsFromRows, applyCustomerLevelProfitEnabledFromRows, applySuperAdminAccessFlagsFromItems, invalidateSettingsBootstrap, setBannerEnabledFromSettings, setConditionalOrderEnabledFromSettings, setAutomationEnabledFromSettings, setProductFundsEnabledFromSettings, setPriceTriggerEnabledFromSettings, setAppNotificationEnabledFromSettings, setPriceProviderFromSettings, setPriceChannelAccessFromSettings, setStoreModeFromSettings, setTrackingSystemsEnabledFromSettings, setGroupSmsEnabledFromSettings, setCustomerSpecialPricingEnabledFromSettings } from '@/utils/config'
|
||||
import { applyBannerEnabledFromRows, applyTrackingSystemsEnabledFromRows, applyConditionalOrderEnabledFromRows, applyAutomationEnabledFromRows, applyProductFundsEnabledFromRows, applyPriceTriggerEnabledFromRows, applyAppNotificationEnabledFromRows, applyPriceProviderFromRows, applyPriceChannelAccessFromRows, applySupportChatMenuEnabledFromRows, applyGroupSmsFromRows, applyCustomerSpecialPricingFromRows, applyGoldCreditEnabledFromRows, applyCustomerDirectSmsFromRows, applyCustomerLevelProfitEnabledFromRows, applySuperAdminAccessFlagsFromItems, invalidateSettingsBootstrap, setBannerEnabledFromSettings, setConditionalOrderEnabledFromSettings, setAutomationEnabledFromSettings, setProductFundsEnabledFromSettings, setPriceTriggerEnabledFromSettings, setAppNotificationEnabledFromSettings, setPriceProviderFromSettings, setPriceChannelAccessFromSettings, setStoreModeFromSettings, setTrackingSystemsEnabledFromSettings, setGroupSmsEnabledFromSettings, setCustomerSpecialPricingEnabledFromSettings, setGoldCreditEnabledFromSettings } from '@/utils/config'
|
||||
import {
|
||||
EDITABLE_SETTING_GROUPS,
|
||||
SYSTEM_SETTING_GROUPS,
|
||||
@@ -498,13 +498,12 @@ async function pullSuperAdminAndApplyFlags(): Promise<{
|
||||
ok: boolean
|
||||
message?: string
|
||||
count?: number
|
||||
meta?: { channel?: string; origin?: string; domain?: string }
|
||||
items?: Record<string, string>
|
||||
}> {
|
||||
invalidateSettingsBootstrap()
|
||||
const res = await refreshSuperAdminSettings()
|
||||
if (res?.items && typeof res.items === 'object') {
|
||||
applySuperAdminAccessFlagsFromItems(res.items)
|
||||
}
|
||||
// get_settings کامل — فلگ منو و کارتها با مقدار زنده همتراز شوند
|
||||
// get_settings کامل — فلگهای غیرسوپرادمین و قیمت
|
||||
try {
|
||||
const { getConfiguration } = await import('@/api/configuration')
|
||||
const all = await getConfiguration()
|
||||
@@ -513,23 +512,50 @@ async function pullSuperAdminAndApplyFlags(): Promise<{
|
||||
applyPriceProviderFromRows(rows)
|
||||
applyPriceChannelAccessFromRows(rows)
|
||||
} catch {
|
||||
/* فلگ از items میماند */
|
||||
/* در ادامه از items همگام استفاده میشود */
|
||||
}
|
||||
// items پاسخ refresh منبع حقیقت است — آخر اعمال شود تا get_settings کهنه/دامنهٔ اشتباه فلگ را خاموش نکند
|
||||
if (res?.items && typeof res.items === 'object') {
|
||||
applySuperAdminAccessFlagsFromItems(res.items)
|
||||
}
|
||||
return {
|
||||
ok: res?.ok !== false,
|
||||
message: res?.message,
|
||||
count: res?.count
|
||||
count: res?.count,
|
||||
meta: res?.meta,
|
||||
items: res?.items
|
||||
}
|
||||
}
|
||||
|
||||
function syncSuccessMessage(res: {
|
||||
message?: string
|
||||
count?: number
|
||||
meta?: { channel?: string; origin?: string; domain?: string }
|
||||
items?: Record<string, string>
|
||||
}): string {
|
||||
const base = res?.message || `همگام شد (${res?.count ?? 0} کلید دسترسی از سوپرادمین)`
|
||||
const domain = String(res?.meta?.domain || '').trim()
|
||||
const csp = res?.items && typeof res.items === 'object' && !Array.isArray(res.items)
|
||||
? String((res.items as Record<string, string>).customer_special_pricing ?? '')
|
||||
: ''
|
||||
const bits = [base]
|
||||
if (domain) bits.push(`دامنه: ${domain}`)
|
||||
if (csp !== '') bits.push(`قیمت ویژه: ${csp}`)
|
||||
return bits.join(' — ')
|
||||
}
|
||||
|
||||
async function refreshFromSuperAdmin() {
|
||||
if (refreshingSuperAdmin.value) return
|
||||
refreshingSuperAdmin.value = true
|
||||
try {
|
||||
const res = await pullSuperAdminAndApplyFlags()
|
||||
await initConfig()
|
||||
// دوباره items را بعد از initConfig (که ممکن است get_settings ناقص بخواند) اعمال کن
|
||||
if (res?.items && typeof res.items === 'object') {
|
||||
applySuperAdminAccessFlagsFromItems(res.items)
|
||||
}
|
||||
refreshMenuAfterStoreChange()
|
||||
message.success(res?.message || `همگام شد (${res?.count ?? 0} کلید دسترسی از سوپرادمین)`)
|
||||
message.success(syncSuccessMessage(res))
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
const msg = e?.response?.data?.message || e?.message || 'همگامسازی از سوپرادمین ناموفق بود'
|
||||
@@ -546,8 +572,11 @@ async function onRefreshClick() {
|
||||
try {
|
||||
const res = await pullSuperAdminAndApplyFlags()
|
||||
await initConfig()
|
||||
if (res?.items && typeof res.items === 'object') {
|
||||
applySuperAdminAccessFlagsFromItems(res.items)
|
||||
}
|
||||
refreshMenuAfterStoreChange()
|
||||
message.success(res?.message || 'بروزرسانی شد')
|
||||
message.success(syncSuccessMessage(res))
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
const msg = e?.response?.data?.message || e?.message || 'همگامسازی از سوپرادمین ناموفق بود'
|
||||
@@ -580,6 +609,7 @@ async function initConfig() {
|
||||
applySupportChatMenuEnabledFromRows(baseData.value)
|
||||
applyGroupSmsFromRows(baseData.value)
|
||||
applyCustomerSpecialPricingFromRows(baseData.value)
|
||||
applyGoldCreditEnabledFromRows(baseData.value)
|
||||
// صفحهٔ عادی price_provider ندارد (can_edit=0) — همیشه از get_settings کامل بخوان
|
||||
if (
|
||||
!isSystemMode.value ||
|
||||
@@ -587,7 +617,8 @@ async function initConfig() {
|
||||
!baseData.value.some((row) => row.key === 'show_to_users_chat') ||
|
||||
!baseData.value.some((row) => row.key === 'price_channel_access') ||
|
||||
!baseData.value.some((row) => row.key === 'group_sms') ||
|
||||
!baseData.value.some((row) => row.key === 'customer_special_pricing')
|
||||
!baseData.value.some((row) => row.key === 'customer_special_pricing') ||
|
||||
!baseData.value.some((row) => row.key === 'enable_gold_credit')
|
||||
) {
|
||||
try {
|
||||
const { getConfiguration } = await import('@/api/configuration')
|
||||
@@ -598,6 +629,7 @@ async function initConfig() {
|
||||
applyPriceChannelAccessFromRows(rows)
|
||||
applyGroupSmsFromRows(rows)
|
||||
applyCustomerSpecialPricingFromRows(rows)
|
||||
applyGoldCreditEnabledFromRows(rows)
|
||||
} catch {
|
||||
/* کش قبلی میماند */
|
||||
}
|
||||
@@ -677,6 +709,9 @@ function syncMenuFlagsFromSetting(key: string | undefined, value: string) {
|
||||
if (key === 'customer_special_pricing') {
|
||||
setCustomerSpecialPricingEnabledFromSettings(isSwitchOn(value))
|
||||
}
|
||||
if (key === 'enable_gold_credit') {
|
||||
setGoldCreditEnabledFromSettings(isSwitchOn(value))
|
||||
}
|
||||
}
|
||||
|
||||
function onValueChange(row: Const, value: string) {
|
||||
|
||||
Reference in New Issue
Block a user