feat(ui): desktop piggy/notifications views, support chat fixes, gift card list

This commit is contained in:
2026-09-09 16:57:41 +03:30
parent 5920866a95
commit 0a3a5d7c82
50 changed files with 3242 additions and 1094 deletions
@@ -1,6 +1,10 @@
import { computed, inject, provide, ref, type ComputedRef, type InjectionKey, type Ref } from 'vue'
import { computed, inject, onMounted, provide, ref, type ComputedRef, type InjectionKey, type Ref } from 'vue'
import { loading } from '@/utils'
import { registerCodeGiftCard } from '@/api/giftCard'
import {
fetchMyGiftCards,
registerCodeGiftCard,
type CustomerGiftCardItem,
} from '@/api/giftCard'
import { message } from 'ant-design-vue'
export interface GiftCardPageContext {
@@ -8,6 +12,11 @@ export interface GiftCardPageContext {
disableButton: ComputedRef<boolean>
loading: typeof loading
registerGiftCard: () => Promise<void>
available: Ref<CustomerGiftCardItem[]>
history: Ref<CustomerGiftCardItem[]>
listLoading: Ref<boolean>
loadMyGiftCards: () => Promise<void>
fillCode: (code: string) => void
}
export const GIFT_CARD_PAGE_CONTEXT_KEY: InjectionKey<GiftCardPageContext> =
@@ -17,6 +26,9 @@ export function useGiftCardPage() {
const form = ref<{ code: string }>({
code: '',
})
const available = ref<CustomerGiftCardItem[]>([])
const history = ref<CustomerGiftCardItem[]>([])
const listLoading = ref(false)
const disableButton = computed(() => {
if (!loading.value) {
@@ -25,12 +37,42 @@ export function useGiftCardPage() {
return true
})
async function loadMyGiftCards() {
try {
listLoading.value = true
const res = await fetchMyGiftCards()
available.value = res?.available ?? []
history.value = res?.history ?? []
} catch {
available.value = []
history.value = []
} finally {
listLoading.value = false
}
}
function fillCode(code: string) {
form.value.code = code
}
async function registerGiftCard() {
const code = form.value.code.trim()
if (!code) return
const matched =
available.value.find((item) => item.code === code) ||
history.value.find((item) => item.code === code)
if (matched?.kind === 'discount') {
message.info('کد تخفیف را هنگام ثبت سفارش در سبد خرید وارد کنید')
return
}
try {
loading.value = true
await registerCodeGiftCard(form.value.code)
await registerCodeGiftCard(code)
message.success('کد کارت هدیه با موفقیت ثبت شد')
form.value.code = ''
await loadMyGiftCards()
} catch (e: any) {
message.error(e?.response?.data?.message || 'خطا در ثبت کد کارت هدیه')
} finally {
@@ -38,11 +80,20 @@ export function useGiftCardPage() {
}
}
onMounted(() => {
void loadMyGiftCards()
})
const context: GiftCardPageContext = {
form,
disableButton,
loading,
registerGiftCard,
available,
history,
listLoading,
loadMyGiftCards,
fillCode,
}
provide(GIFT_CARD_PAGE_CONTEXT_KEY, context)