invite link better response

This commit is contained in:
2026-06-17 17:34:21 +03:30
parent abbf7c96bb
commit 5d46b5f046
3 changed files with 47 additions and 8 deletions
@@ -24,8 +24,9 @@
:setting-type="settingType" :setting-type="settingType"
:description="description" :description="description"
:disabled="readonly" :disabled="readonly"
:rows="fieldType === 'longtext' ? 6 : 6" :rows="fieldType === 'longtext' ? 10 : 6"
@update:value="emit('update:value', $event)" @update:value="emit('update:value', $event)"
@blur="emit('blur')"
/> />
</div> </div>
<div v-if="saving" class="setting-card__status"> <div v-if="saving" class="setting-card__status">
@@ -51,6 +52,7 @@ const props = defineProps<{
const emit = defineEmits<{ const emit = defineEmits<{
'update:value': [value: string] 'update:value': [value: string]
blur: []
}>() }>()
const settingKey = computed(() => props.row.key ?? '') const settingKey = computed(() => props.row.key ?? '')
@@ -48,6 +48,7 @@
:rows="rows" :rows="rows"
class="w-full font-mono text-sm" class="w-full font-mono text-sm"
@update:value="emit('update:value', $event)" @update:value="emit('update:value', $event)"
@blur="emit('blur')"
/> />
<a-input <a-input
@@ -56,6 +57,7 @@
:disabled="disabled" :disabled="disabled"
allow-clear allow-clear
@update:value="emit('update:value', $event)" @update:value="emit('update:value', $event)"
@blur="emit('blur')"
/> />
</div> </div>
</template> </template>
@@ -83,7 +85,10 @@ const props = withDefaults(
{ disabled: false, rows: 10 } { disabled: false, rows: 10 }
) )
const emit = defineEmits<{ 'update:value': [value: string] }>() const emit = defineEmits<{
'update:value': [value: string]
blur: []
}>()
const fieldType = computed<SettingFieldType>(() => const fieldType = computed<SettingFieldType>(() =>
resolveSettingFieldType({ resolveSettingFieldType({
+38 -6
View File
@@ -70,6 +70,7 @@
:saving="isSaving(row.id)" :saving="isSaving(row.id)"
:saved-flash="isSavedFlash(row.id)" :saved-flash="isSavedFlash(row.id)"
@update:value="onValueChange(row, $event)" @update:value="onValueChange(row, $event)"
@blur="onFieldBlur(row)"
/> />
</a-col> </a-col>
</a-row> </a-row>
@@ -305,7 +306,7 @@ const SETTING_GROUPS: Array<{
title: 'معرف، پاداش و ثبت‌نام', title: 'معرف، پاداش و ثبت‌نام',
icon: 'vuesax-linear:people', icon: 'vuesax-linear:people',
match: (k) => match: (k) =>
/^(referral_|gift_for|register_referral|register_jibit|has_page_earn_money|jibit_verification|referral_bonus)/.test( /^(referral_|gift_for|register_referral|register_jibit|has_page_earn_money|jibit_verification|referral_bonus|invite_link_text)/.test(
k k
) )
}, },
@@ -460,21 +461,43 @@ async function initConfig() {
} }
} }
function saveDebounceMs(row: Const): number {
const type = resolveSettingFieldType(row)
if (type === 'switch') return 200
if (type === 'longtext') return 3000
if (type === 'text') return 1200
return 800
}
function onValueChange(row: Const, value: string) { function onValueChange(row: Const, value: string) {
if (row.id == null || isReadonly(row)) return if (row.id == null || isReadonly(row)) return
drafts.value[row.id] = value drafts.value[row.id] = value
if (resolveSettingFieldType(row) === 'longtext') {
return
}
scheduleSave(row) scheduleSave(row)
} }
function scheduleSave(row: Const) { function onFieldBlur(row: Const) {
if (row.id == null || isReadonly(row)) return
scheduleSave(row, { flush: true })
}
function scheduleSave(row: Const, options?: { flush?: boolean }) {
const id = row.id! const id = row.id!
const delay = saveDebounceMs(row)
if (!debouncedSave.has(id)) { if (!debouncedSave.has(id)) {
debouncedSave.set( debouncedSave.set(
id, id,
debounce(() => persistRowValue(id), resolveSettingFieldType(row) === 'switch' ? 200 : 600) debounce(() => persistRowValue(id), delay)
) )
} }
debouncedSave.get(id)!() const saveFn = debouncedSave.get(id)!
if (options?.flush) {
saveFn.flush()
} else {
saveFn()
}
} }
async function persistRowValue(id: number) { async function persistRowValue(id: number) {
@@ -496,6 +519,8 @@ async function saveSettingRow(row: Const) {
const value = formatValueForSave(raw, type, row.key) const value = formatValueForSave(raw, type, row.key)
if (value === (row.value ?? '')) return if (value === (row.value ?? '')) return
const draftSnapshot = raw
savingIds.value.add(id) savingIds.value.add(id)
savedFlashIds.value.delete(id) savedFlashIds.value.delete(id)
@@ -511,7 +536,12 @@ async function saveSettingRow(row: Const) {
}) })
row.value = value row.value = value
row.is_active = true row.is_active = true
drafts.value[id] = value const currentDraft = drafts.value[id] ?? ''
if (currentDraft === draftSnapshot) {
drafts.value[id] = value
} else {
scheduleSave(row)
}
if (row.key === 'is_store') { if (row.key === 'is_store') {
setStoreModeFromSettings(isSwitchOn(value)) setStoreModeFromSettings(isSwitchOn(value))
refreshAppModeMenu() refreshAppModeMenu()
@@ -527,7 +557,9 @@ async function saveSettingRow(row: Const) {
) )
} catch (e) { } catch (e) {
console.error(e) console.error(e)
drafts.value[id] = row.value ?? '' if ((drafts.value[id] ?? '') === draftSnapshot) {
drafts.value[id] = row.value ?? ''
}
message.error(`ذخیره «${row.title_fa || row.key}» ناموفق بود`) message.error(`ذخیره «${row.title_fa || row.key}» ناموفق بود`)
} finally { } finally {
savingIds.value.delete(id) savingIds.value.delete(id)