Show negative SMS wallet warning modal on admin page loads.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-08 14:13:51 +03:30
co-authored by Cursor
parent 3ea6b02b47
commit 7e043b24be
5 changed files with 165 additions and 2 deletions
+12 -1
View File
@@ -1,4 +1,5 @@
import { computed, ref } from 'vue'
import { defineStore } from 'pinia'
import { getSmsWalletSummary, type SmsDepositInfo } from '@/api/smsPanel'
import { useUserStore } from '@/store/userStore'
@@ -18,6 +19,8 @@ export const useSmsWalletStore = defineStore('smsWallet', () => {
const deposit = ref<SmsDepositInfo>({ ...EMPTY_DEPOSIT })
const loaded = ref(false)
const loading = ref(false)
/** هشدار موجودی منفی — با هر refresh اگر هنوز منفی باشد دوباره باز می‌شود */
const negativeWarningVisible = ref(false)
/** ویجت فقط وقتی billing/پنل پیامک فعال است نمایش داده می‌شود. */
const visible = computed(() => userStore.smsBillingEnabled)
@@ -25,6 +28,7 @@ export const useSmsWalletStore = defineStore('smsWallet', () => {
async function refresh() {
if (!visible.value) {
loaded.value = false
negativeWarningVisible.value = false
return
}
if (loading.value) return
@@ -36,6 +40,7 @@ export const useSmsWalletStore = defineStore('smsWallet', () => {
isBlocked.value = res.is_blocked
deposit.value = res.deposit ?? { ...EMPTY_DEPOSIT }
loaded.value = true
negativeWarningVisible.value = res.balance < 0
} catch {
// خطای موجودی نباید مزاحم کاربر شود؛ ویجت در صورت نبود داده مخفی می‌ماند
} finally {
@@ -43,6 +48,10 @@ export const useSmsWalletStore = defineStore('smsWallet', () => {
}
}
function dismissNegativeWarning() {
negativeWarningVisible.value = false
}
return {
balance,
isBlocked,
@@ -50,6 +59,8 @@ export const useSmsWalletStore = defineStore('smsWallet', () => {
loaded,
loading,
visible,
refresh
negativeWarningVisible,
refresh,
dismissNegativeWarning
}
})