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