Files
boursecu_admin/src/store/smsWalletStore.ts
T

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-07-07 20:27:51 +03:30
import { computed, ref } from 'vue'
import { getSmsWalletSummary, type SmsDepositInfo } from '@/api/smsPanel'
import { useUserStore } from '@/store/userStore'
const EMPTY_DEPOSIT: SmsDepositInfo = {
card_number: '',
sheba: '',
account_holder: '',
note: ''
}
/** وضعیت کیف پول پیامک برای نمایش «اعتبار پیامک» در هدر (همه ادمین‌ها). */
export const useSmsWalletStore = defineStore('smsWallet', () => {
const userStore = useUserStore()
const balance = ref(0)
const isBlocked = ref(false)
const deposit = ref<SmsDepositInfo>({ ...EMPTY_DEPOSIT })
const loaded = ref(false)
const loading = ref(false)
/** ویجت فقط وقتی billing/پنل پیامک فعال است نمایش داده می‌شود. */
const visible = computed(() => userStore.smsBillingEnabled)
async function refresh() {
if (!visible.value) {
loaded.value = false
return
}
if (loading.value) return
loading.value = true
try {
const res = await getSmsWalletSummary()
balance.value = res.balance
isBlocked.value = res.is_blocked
deposit.value = res.deposit ?? { ...EMPTY_DEPOSIT }
loaded.value = true
} catch {
// خطای موجودی نباید مزاحم کاربر شود؛ ویجت در صورت نبود داده مخفی می‌ماند
} finally {
loading.value = false
}
}
return {
balance,
isBlocked,
deposit,
loaded,
loading,
visible,
refresh
}
})