Fix delivered status grouping and add auto-refresh to order details
This commit is contained in:
+1
-2
@@ -1,4 +1,3 @@
|
||||
# Same-origin in dev (Vite proxies to the real API — avoids CORS)
|
||||
VITE_API_BASE_URL=/server/api
|
||||
VITE_API_BASE_URL=https://parche.montest.ir/server/api
|
||||
# Set true only for offline local OTP (code 1234)
|
||||
VITE_USE_MOCK_AUTH=false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { computed, ref, watch, onMounted } from 'vue'
|
||||
import { computed, ref, watch, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { useOrderStore } from '@/stores/order'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
@@ -27,10 +27,19 @@ export function useOrderList() {
|
||||
const mobilePage = ref(1)
|
||||
const submitSuccessMessage = ref('')
|
||||
|
||||
function onWindowFocus() {
|
||||
void orderStore.hydrate()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
window.addEventListener('focus', onWindowFocus)
|
||||
await Promise.all([orderStore.hydrate(), catalogStore.loadCompanies()])
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('focus', onWindowFocus)
|
||||
})
|
||||
|
||||
watch(
|
||||
() => route.query.submitted,
|
||||
(submitted) => {
|
||||
|
||||
@@ -15,6 +15,9 @@ export const IN_PROGRESS_STATUSES: OrderStatus[] = [
|
||||
'pricing',
|
||||
'check_in_progress',
|
||||
'awaiting_cash_confirmation',
|
||||
'cash_confirmed',
|
||||
'checks_approved',
|
||||
'final_approved',
|
||||
'preparing',
|
||||
'ready_to_ship',
|
||||
'needs_correction',
|
||||
@@ -29,12 +32,7 @@ export const IN_PROGRESS_STATUSES: OrderStatus[] = [
|
||||
|
||||
export const SHIPPED_STATUSES: OrderStatus[] = ['shipped']
|
||||
|
||||
export const DELIVERED_STATUSES: OrderStatus[] = [
|
||||
'delivered',
|
||||
'final_approved',
|
||||
'checks_approved',
|
||||
'cash_confirmed',
|
||||
]
|
||||
export const DELIVERED_STATUSES: OrderStatus[] = ['delivered']
|
||||
|
||||
export const CANCELLED_STATUSES: OrderStatus[] = ['cancelled', 'rejected', 'expired', 'check_rejected']
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useMediaQuery } from '@vueuse/core'
|
||||
import { useOrderStore } from '@/stores/order'
|
||||
@@ -122,21 +122,44 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
async function refreshCurrentOrder() {
|
||||
if (!orderId.value) return
|
||||
try {
|
||||
await orderStore.fetchOrder(orderId.value)
|
||||
} catch {
|
||||
/* keep empty/existing state if fetch fails */
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => orderId.value,
|
||||
async (id) => {
|
||||
if (!id) return
|
||||
if (!orderStore.getOrderById(id)) {
|
||||
try {
|
||||
await orderStore.fetchOrder(id)
|
||||
} catch {
|
||||
/* keep empty state if fetch fails */
|
||||
}
|
||||
}
|
||||
() => {
|
||||
void refreshCurrentOrder()
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
let pollTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
function onWindowFocus() {
|
||||
void refreshCurrentOrder()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('focus', onWindowFocus)
|
||||
pollTimer = setInterval(() => {
|
||||
const s = order.value?.status
|
||||
if (s && !['delivered', 'cancelled', 'rejected', 'expired'].includes(s)) {
|
||||
void refreshCurrentOrder()
|
||||
}
|
||||
}, 15_000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('focus', onWindowFocus)
|
||||
if (pollTimer) clearInterval(pollTimer)
|
||||
})
|
||||
|
||||
const statusHero = computed(() => (order.value ? getStatusHero(order.value.status) : null))
|
||||
const trackingFooterLabel = computed(() =>
|
||||
order.value ? getTrackingFooterLabel(order.value.status) : 'مشاهده جزئیات سفارش',
|
||||
|
||||
Reference in New Issue
Block a user