updates on the reverse logistics

This commit is contained in:
2026-10-06 17:30:06 +05:30
parent 806f4a2b3f
commit 6e73b59ca9
12 changed files with 1069 additions and 21 deletions

View File

@@ -541,6 +541,43 @@ export const useCancelDelivery = () =>
successMessage: 'Delivery cancelled',
});
/* ── Reverse logistics (RTO) ──────────────────────────────────────────────── */
// Exceptions too: starting a return resolves the parcel's Undeliverable /
// Receiver_Refused exception on the server, and the list must show that at
// once rather than on its next poll.
const RETURN_KEYS = [...BOOKING_KEYS, ['doormile', 'returns'], KEYS.exceptions];
export const useReturns = (params = {}, options) =>
useQuery({
queryKey: ['doormile', 'returns', params],
queryFn: () => api.getReturns(params),
placeholderData: (previous) => previous,
staleTime: 15_000,
...options,
});
export const useInitiateRto = () =>
useDoormileMutation({
mutationFn: ({ consignmentId, reason, note }) => api.initiateRto(consignmentId, { reason, note }),
invalidates: RETURN_KEYS,
successMessage: 'Return to sender started',
});
export const useCancelRto = () =>
useDoormileMutation({
mutationFn: ({ consignmentId, note }) => api.cancelRto(consignmentId, note),
invalidates: RETURN_KEYS,
successMessage: 'Return cancelled — delivery will be re-attempted',
});
export const useCompleteRto = () =>
useDoormileMutation({
mutationFn: ({ consignmentId, note }) => api.completeRto(consignmentId, note),
invalidates: RETURN_KEYS,
successMessage: 'Marked returned to sender',
});
/* ── Consignments ─────────────────────────────────────────────────────────── */
export const useConsignments = (options) =>