Add COD-in-transit summary and received tab to the dashboard
- GET /orders/summary: count and sum of cash-on-delivery for parcels not yet picked up (excludes received, refused, deleted/unknown TTNs, paid COD); shown as a card above the tabs. - New «Полученные» tab: orders with NP received codes (9, 10, 11, 106) move there automatically, regardless of receipt; 106 is now a final status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import type { ReceiptStatus } from '@/features/receipts/types'
|
||||
|
||||
/** Вкладка дашборда (`OrderTab` в backend/app/services/orders.py). */
|
||||
export type OrderTab = 'no_receipt' | 'has_receipt' | 'refused'
|
||||
export type OrderTab = 'no_receipt' | 'has_receipt' | 'received' | 'refused'
|
||||
|
||||
export interface OrderGood {
|
||||
id: string
|
||||
@@ -62,3 +62,9 @@ export interface OrderUpdate {
|
||||
total_amount: string
|
||||
goods: OrderGoodUpdate[]
|
||||
}
|
||||
|
||||
/** Ответ `GET /orders/summary` (`OrdersSummaryOut`). */
|
||||
export interface OrdersSummary {
|
||||
cod_in_transit_count: number
|
||||
cod_in_transit_amount: string
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { getOrders } from '@/api/orders'
|
||||
import { getOrders, getOrdersSummary } from '@/api/orders'
|
||||
import type { OrderTab } from '@/features/orders/types'
|
||||
|
||||
/** Пока чек отправляется в Checkbox — опрашиваем часто, иначе статусы чеков обновляет worker раз в минуту. */
|
||||
const PENDING_POLL_MS = 3_000
|
||||
const RECEIPTS_POLL_MS = 30_000
|
||||
// Статусы NP обновляет worker раз в минуту — чаще сводку опрашивать незачем.
|
||||
const SUMMARY_POLL_MS = 60_000
|
||||
|
||||
export function useOrders(tab: OrderTab) {
|
||||
return useQuery({
|
||||
@@ -17,3 +19,12 @@ export function useOrders(tab: OrderTab) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useOrdersSummary() {
|
||||
return useQuery({
|
||||
// Под ключом ['orders', ...] — чтобы invalidateQueries(['orders']) обновлял и сводку.
|
||||
queryKey: ['orders', 'summary'],
|
||||
queryFn: getOrdersSummary,
|
||||
refetchInterval: SUMMARY_POLL_MS,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user