Improve order detail UX, confirm check actions, and fix notification deep links.
Normalize inbox /orders/:id links, open related admin pages on click, and keep Jalali dates consistent. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { computed, inject, onMounted, provide, reactive, ref, type InjectionKey } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { computed, inject, onMounted, provide, reactive, ref, watch, type InjectionKey } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { companiesApi, mapAdminOrder, ordersApi } from '@/services/api'
|
||||
import { ApiError } from '@/services/http'
|
||||
import type { Company, Order, RawOrderStatus, SettlementMethod } from '@/types'
|
||||
@@ -8,6 +8,7 @@ import { rawStatusLabel } from '@/utils/orderStatus'
|
||||
import { useToast } from '@/composables/useToast'
|
||||
|
||||
export function useOrdersPage() {
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const toast = useToast()
|
||||
|
||||
@@ -54,6 +55,38 @@ export function useOrdersPage() {
|
||||
orderList.value.find((o) => o.id === selectedOrderId.value) ?? null,
|
||||
)
|
||||
|
||||
function findOrderByRef(ref: string): Order | undefined {
|
||||
const key = ref.trim()
|
||||
if (!key) return undefined
|
||||
return orderList.value.find(
|
||||
(o) => o.id === key || o.orderNumber.toUpperCase() === key.toUpperCase(),
|
||||
)
|
||||
}
|
||||
|
||||
async function applyOrderDeepLink() {
|
||||
const orderRef = typeof route.query.order === 'string' ? route.query.order : ''
|
||||
if (!orderRef || !orderList.value.length) return
|
||||
|
||||
const order = findOrderByRef(orderRef)
|
||||
if (!order) {
|
||||
searchQuery.value = orderRef
|
||||
return
|
||||
}
|
||||
|
||||
const focus = typeof route.query.focus === 'string' ? route.query.focus : ''
|
||||
if (focus === 'pricing') {
|
||||
await router.replace(`/orders/${order.id}/pricing`)
|
||||
return
|
||||
}
|
||||
if (focus === 'checks') {
|
||||
await router.replace(`/orders/${order.id}/checks`)
|
||||
return
|
||||
}
|
||||
|
||||
openOrderDetail(order)
|
||||
searchQuery.value = order.orderNumber
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
try {
|
||||
const [ordersData, companiesData] = await Promise.all([
|
||||
@@ -65,6 +98,7 @@ export function useOrdersPage() {
|
||||
if (!form.companyId && companiesData[0]) {
|
||||
form.companyId = companiesData[0].id
|
||||
}
|
||||
await applyOrderDeepLink()
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : 'بارگذاری سفارشها انجام نشد.')
|
||||
}
|
||||
@@ -74,6 +108,13 @@ export function useOrdersPage() {
|
||||
void loadData()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => [route.query.order, route.query.focus] as const,
|
||||
() => {
|
||||
void applyOrderDeepLink()
|
||||
},
|
||||
)
|
||||
|
||||
function selectOrder(order: Order, openDetail = false) {
|
||||
selectedOrderId.value = order.id
|
||||
if (openDetail) {
|
||||
|
||||
Reference in New Issue
Block a user