fix(dashboard): bust order preview cache to reset fulfilled quantity (#8687)
This commit is contained in:
@@ -74,9 +74,6 @@ export const useCreateClaim = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -103,9 +100,6 @@ export const useCancelClaim = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -135,9 +129,6 @@ export const useDeleteClaim = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -168,9 +159,14 @@ export const useAddClaimItems = (
|
||||
mutationFn: (payload: HttpTypes.AdminAddClaimItems) =>
|
||||
sdk.admin.claim.addItems(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -194,9 +190,14 @@ export const useUpdateClaimItems = (
|
||||
return sdk.admin.claim.updateItem(id, actionId, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -212,9 +213,14 @@ export const useRemoveClaimItem = (
|
||||
mutationFn: (actionId: string) =>
|
||||
sdk.admin.return.removeReturnItem(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -234,9 +240,14 @@ export const useAddClaimInboundItems = (
|
||||
mutationFn: (payload: HttpTypes.AdminAddClaimInboundItems) =>
|
||||
sdk.admin.claim.addInboundItems(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -260,9 +271,14 @@ export const useUpdateClaimInboundItem = (
|
||||
return sdk.admin.claim.updateInboundItem(id, actionId, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -279,10 +295,11 @@ export const useRemoveClaimInboundItem = (
|
||||
sdk.admin.claim.removeInboundItem(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
@@ -304,9 +321,14 @@ export const useAddClaimInboundShipping = (
|
||||
mutationFn: (payload: HttpTypes.AdminClaimAddInboundShipping) =>
|
||||
sdk.admin.claim.addInboundShipping(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -329,9 +351,14 @@ export const useUpdateClaimInboundShipping = (
|
||||
}: HttpTypes.AdminClaimUpdateInboundShipping & { actionId: string }) =>
|
||||
sdk.admin.claim.updateInboundShipping(id, actionId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -347,9 +374,14 @@ export const useDeleteClaimInboundShipping = (
|
||||
mutationFn: (actionId: string) =>
|
||||
sdk.admin.claim.deleteInboundShipping(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -369,9 +401,14 @@ export const useAddClaimOutboundItems = (
|
||||
mutationFn: (payload: HttpTypes.AdminAddClaimOutboundItems) =>
|
||||
sdk.admin.claim.addOutboundItems(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -395,9 +432,14 @@ export const useUpdateClaimOutboundItems = (
|
||||
return sdk.admin.claim.updateOutboundItem(id, actionId, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -413,9 +455,14 @@ export const useRemoveClaimOutboundItem = (
|
||||
mutationFn: (actionId: string) =>
|
||||
sdk.admin.claim.removeOutboundItem(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -435,9 +482,14 @@ export const useAddClaimOutboundShipping = (
|
||||
mutationFn: (payload: HttpTypes.AdminClaimAddOutboundShipping) =>
|
||||
sdk.admin.claim.addOutboundShipping(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -460,9 +512,14 @@ export const useUpdateClaimOutboundShipping = (
|
||||
}: HttpTypes.AdminClaimUpdateOutboundShipping & { actionId: string }) =>
|
||||
sdk.admin.claim.updateOutboundShipping(id, actionId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -478,9 +535,14 @@ export const useDeleteClaimOutboundShipping = (
|
||||
mutationFn: (actionId: string) =>
|
||||
sdk.admin.claim.deleteOutboundShipping(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -507,9 +569,6 @@ export const useClaimConfirmRequest = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -536,9 +595,6 @@ export const useCancelClaimRequest = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
|
||||
@@ -75,10 +75,6 @@ export const useCreateExchange = (
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
@@ -104,9 +100,6 @@ export const useCancelExchange = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -136,9 +129,6 @@ export const useDeleteExchange = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -283,7 +273,7 @@ export const useRemoveExchangeInboundItem = (
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
@@ -509,10 +499,6 @@ export const useExchangeConfirmRequest = (
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
@@ -538,9 +524,6 @@ export const useCancelExchangeRequest = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
|
||||
@@ -2,10 +2,10 @@ import { useMutation, UseMutationOptions } from "@tanstack/react-query"
|
||||
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { client, sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { ordersQueryKeys } from "./orders"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
const FULFILLMENTS_QUERY_KEY = "fulfillments" as const
|
||||
export const fulfillmentsQueryKeys = queryKeysFactory(FULFILLMENTS_QUERY_KEY)
|
||||
|
||||
@@ -9,10 +9,16 @@ import {
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { queryKeysFactory, TQueryKey } from "../../lib/query-key-factory"
|
||||
|
||||
const ORDERS_QUERY_KEY = "orders" as const
|
||||
const _orderKeys = queryKeysFactory(ORDERS_QUERY_KEY)
|
||||
const _orderKeys = queryKeysFactory(ORDERS_QUERY_KEY) as TQueryKey<
|
||||
"orders",
|
||||
any,
|
||||
string
|
||||
> & {
|
||||
preview: (orderId: string) => any
|
||||
}
|
||||
|
||||
_orderKeys.preview = function (id: string) {
|
||||
return [this.detail(id), "preview"]
|
||||
@@ -94,6 +100,10 @@ export const useCreateOrderFulfillment = (
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -151,13 +161,18 @@ export const useCreateOrderShipment = (
|
||||
}
|
||||
|
||||
export const useCancelOrder = (
|
||||
orderId: string,
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (id) => sdk.admin.order.cancel(id),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
|
||||
@@ -12,6 +12,7 @@ export const paymentCollectionQueryKeys = queryKeysFactory(
|
||||
)
|
||||
|
||||
export const useCreatePaymentCollection = (
|
||||
orderId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPaymentCollectionResponse,
|
||||
Error,
|
||||
@@ -22,7 +23,11 @@ export const useCreatePaymentCollection = (
|
||||
mutationFn: (payload) => sdk.admin.paymentCollection.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
@@ -36,6 +41,7 @@ export const useCreatePaymentCollection = (
|
||||
}
|
||||
|
||||
export const useMarkPaymentCollectionAsPaid = (
|
||||
orderId: string,
|
||||
paymentCollectionId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPaymentCollectionResponse,
|
||||
@@ -48,7 +54,11 @@ export const useMarkPaymentCollectionAsPaid = (
|
||||
sdk.admin.paymentCollection.markAsPaid(paymentCollectionId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
@@ -62,6 +72,7 @@ export const useMarkPaymentCollectionAsPaid = (
|
||||
}
|
||||
|
||||
export const useDeletePaymentCollection = (
|
||||
orderId: string,
|
||||
options?: Omit<
|
||||
UseMutationOptions<
|
||||
HttpTypes.AdminDeletePaymentCollectionResponse,
|
||||
@@ -75,7 +86,11 @@ export const useDeletePaymentCollection = (
|
||||
mutationFn: (id: string) => sdk.admin.paymentCollection.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
|
||||
@@ -59,6 +59,7 @@ export const usePayment = (
|
||||
}
|
||||
|
||||
export const useCapturePayment = (
|
||||
orderId: string,
|
||||
paymentId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPaymentResponse,
|
||||
@@ -70,7 +71,11 @@ export const useCapturePayment = (
|
||||
mutationFn: (payload) => sdk.admin.payment.capture(paymentId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
@@ -80,6 +85,7 @@ export const useCapturePayment = (
|
||||
}
|
||||
|
||||
export const useRefundPayment = (
|
||||
orderId: string,
|
||||
paymentId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPaymentResponse,
|
||||
@@ -91,7 +97,11 @@ export const useRefundPayment = (
|
||||
mutationFn: (payload) => sdk.admin.payment.refund(paymentId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.all,
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
useMutation,
|
||||
@@ -5,12 +6,11 @@ import {
|
||||
useQuery,
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { ordersQueryKeys } from "./orders"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { ordersQueryKeys } from "./orders"
|
||||
|
||||
const RETURNS_QUERY_KEY = "returns" as const
|
||||
export const returnsQueryKeys = queryKeysFactory(RETURNS_QUERY_KEY)
|
||||
@@ -72,8 +72,9 @@ export const useInitiateReturn = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
@@ -101,9 +102,6 @@ export const useConfirmReturnRequest = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -132,9 +130,6 @@ export const useCancelReturnRequest = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -166,9 +161,14 @@ export const useAddReturnItem = (
|
||||
mutationFn: (payload: HttpTypes.AdminAddReturnItems) =>
|
||||
sdk.admin.return.addReturnItem(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -192,9 +192,14 @@ export const useUpdateReturnItem = (
|
||||
return sdk.admin.return.updateReturnItem(id, actionId, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -210,9 +215,14 @@ export const useRemoveReturnItem = (
|
||||
mutationFn: (actionId: string) =>
|
||||
sdk.admin.return.removeReturnItem(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -233,9 +243,14 @@ export const useUpdateReturn = (
|
||||
return sdk.admin.return.updateRequest(id, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -255,9 +270,14 @@ export const useAddReturnShipping = (
|
||||
mutationFn: (payload: HttpTypes.AdminAddReturnShipping) =>
|
||||
sdk.admin.return.addReturnShipping(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -280,9 +300,14 @@ export const useUpdateReturnShipping = (
|
||||
}: HttpTypes.AdminAddReturnShipping & { actionId: string }) =>
|
||||
sdk.admin.return.updateReturnShipping(id, actionId, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -298,9 +323,14 @@ export const useDeleteReturnShipping = (
|
||||
mutationFn: (actionId: string) =>
|
||||
sdk.admin.return.deleteReturnShipping(id, actionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -327,13 +357,11 @@ export const useInitiateReceiveReturn = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -353,9 +381,14 @@ export const useAddReceiveItems = (
|
||||
mutationFn: (payload: HttpTypes.AdminReceiveItems) =>
|
||||
sdk.admin.return.receiveItems(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -379,9 +412,14 @@ export const useUpdateReceiveItem = (
|
||||
return sdk.admin.return.updateReceiveItem(id, actionId, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -398,9 +436,14 @@ export const useRemoveReceiveItems = (
|
||||
return sdk.admin.return.removeReceiveItem(id, actionId)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -420,9 +463,14 @@ export const useAddDismissItems = (
|
||||
mutationFn: (payload: HttpTypes.AdminDismissItems) =>
|
||||
sdk.admin.return.dismissItems(id, payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -446,9 +494,14 @@ export const useUpdateDismissItem = (
|
||||
return sdk.admin.return.updateDismissItem(id, actionId, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -465,9 +518,14 @@ export const useRemoveDismissItem = (
|
||||
return sdk.admin.return.removeDismissItem(id, actionId)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -490,9 +548,6 @@ export const useConfirmReturnReceive = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
@@ -521,9 +576,6 @@ export const useCancelReceiveReturn = (
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { QueryKey, UseQueryOptions } from "@tanstack/react-query"
|
||||
|
||||
type TQueryKey<TKey, TListQuery = any, TDetailQuery = string> = {
|
||||
export type TQueryKey<TKey, TListQuery = any, TDetailQuery = string> = {
|
||||
all: readonly [TKey]
|
||||
lists: () => readonly [...TQueryKey<TKey>["all"], "list"]
|
||||
list: (
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
RouteFocusModal,
|
||||
useRouteModal,
|
||||
} from "../../../../../components/modals"
|
||||
import { useFulfillmentProviders } from "../../../../../hooks/api/fulfillment-providers"
|
||||
import { useCreateOrderFulfillment } from "../../../../../hooks/api/orders"
|
||||
import { useStockLocations } from "../../../../../hooks/api/stock-locations"
|
||||
import { getFulfillableQuantity } from "../../../../../lib/order-item"
|
||||
@@ -33,12 +32,8 @@ export function OrderCreateFulfillmentForm({
|
||||
const { mutateAsync: createOrderFulfillment, isPending: isMutating } =
|
||||
useCreateOrderFulfillment(order.id)
|
||||
|
||||
const { fulfillment_providers } = useFulfillmentProviders({
|
||||
region_id: order.region_id,
|
||||
})
|
||||
|
||||
const [fulfillableItems, setFulfillableItems] = useState(() =>
|
||||
order.items.filter((item) => getFulfillableQuantity(item) > 0)
|
||||
(order.items || []).filter((item) => getFulfillableQuantity(item) > 0)
|
||||
)
|
||||
|
||||
const form = useForm<zod.infer<typeof CreateFulfillmentSchema>>({
|
||||
@@ -89,7 +84,9 @@ export function OrderCreateFulfillmentForm({
|
||||
}
|
||||
|
||||
const resetItems = () => {
|
||||
const items = order.items.filter((item) => getFulfillableQuantity(item) > 0)
|
||||
const items = (order.items || []).filter(
|
||||
(item) => getFulfillableQuantity(item) > 0
|
||||
)
|
||||
setFulfillableItems(items)
|
||||
|
||||
items.forEach((i) =>
|
||||
@@ -103,34 +100,35 @@ export function OrderCreateFulfillmentForm({
|
||||
control: form.control,
|
||||
})
|
||||
|
||||
const fulfilledQuantityArray = (order.items || []).map(
|
||||
(item) => item.detail.fulfilled_quantity
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!fulfillableItems.length) {
|
||||
const itemsToFulfill =
|
||||
order?.items?.filter((item) => getFulfillableQuantity(item) > 0) || []
|
||||
|
||||
setFulfillableItems(itemsToFulfill)
|
||||
|
||||
if (itemsToFulfill.length) {
|
||||
form.clearErrors("root")
|
||||
} else {
|
||||
form.setError("root", {
|
||||
type: "manual",
|
||||
message: t("orders.fulfillment.error.noItems"),
|
||||
})
|
||||
}
|
||||
}, [fulfillableItems.length])
|
||||
|
||||
useEffect(() => {
|
||||
const itemsToFulfill = order?.items?.filter(
|
||||
(item) => getFulfillableQuantity(item) > 0
|
||||
const quantityMap = itemsToFulfill.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.id] = getFulfillableQuantity(item as OrderLineItemDTO)
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, number>
|
||||
)
|
||||
|
||||
if (itemsToFulfill?.length) {
|
||||
setFulfillableItems(itemsToFulfill)
|
||||
|
||||
const quantityMap = fulfillableItems.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.id] = getFulfillableQuantity(item as OrderLineItemDTO)
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, number>
|
||||
)
|
||||
|
||||
form.setValue("quantity", quantityMap)
|
||||
}
|
||||
}, [order.items?.length])
|
||||
form.setValue("quantity", quantityMap)
|
||||
}, [...fulfilledQuantityArray])
|
||||
|
||||
return (
|
||||
<RouteFocusModal.Form form={form}>
|
||||
@@ -150,6 +148,7 @@ export function OrderCreateFulfillmentForm({
|
||||
</Button>
|
||||
</div>
|
||||
</RouteFocusModal.Header>
|
||||
|
||||
<RouteFocusModal.Body className="flex h-full w-full flex-col items-center divide-y overflow-y-auto">
|
||||
<div className="flex size-full flex-col items-center overflow-auto p-16">
|
||||
<div className="flex w-full max-w-[736px] flex-col justify-center px-2 pb-2">
|
||||
@@ -197,16 +196,18 @@ export function OrderCreateFulfillmentForm({
|
||||
</Form.Hint>
|
||||
|
||||
<div className="flex flex-col gap-y-1">
|
||||
{fulfillableItems.map((item) => (
|
||||
<OrderCreateFulfillmentItem
|
||||
key={item.id}
|
||||
form={form}
|
||||
item={item}
|
||||
onItemRemove={onItemRemove}
|
||||
locationId={selectedLocationId}
|
||||
currencyCode={order.currency_code}
|
||||
/>
|
||||
))}
|
||||
{fulfillableItems.map((item) => {
|
||||
return (
|
||||
<OrderCreateFulfillmentItem
|
||||
key={item.id}
|
||||
form={form}
|
||||
item={item}
|
||||
onItemRemove={onItemRemove}
|
||||
locationId={selectedLocationId}
|
||||
currencyCode={order.currency_code}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</Form.Item>
|
||||
{form.formState.errors.root && (
|
||||
|
||||
@@ -67,7 +67,7 @@ export const CreateRefundForm = ({
|
||||
form.setValue("amount", normalizedAmount as number)
|
||||
}, [payment])
|
||||
|
||||
const { mutateAsync, isPending } = useRefundPayment(payment?.id!)
|
||||
const { mutateAsync, isPending } = useRefundPayment(order.id, payment?.id!)
|
||||
|
||||
const handleSubmit = form.handleSubmit(async (data) => {
|
||||
await mutateAsync(
|
||||
|
||||
@@ -25,7 +25,7 @@ export const OrderGeneralSection = ({ order }: OrderGeneralSectionProps) => {
|
||||
const { t } = useTranslation()
|
||||
const prompt = usePrompt()
|
||||
|
||||
const { mutateAsync: cancelOrder } = useCancelOrder()
|
||||
const { mutateAsync: cancelOrder } = useCancelOrder(order.id)
|
||||
|
||||
const handleCancel = async () => {
|
||||
const res = await prompt({
|
||||
|
||||
@@ -142,7 +142,7 @@ const Payment = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const prompt = usePrompt()
|
||||
const { mutateAsync } = useCapturePayment(payment.id)
|
||||
const { mutateAsync } = useCapturePayment(order.id, payment.id)
|
||||
|
||||
const handleCapture = async () => {
|
||||
const res = await prompt({
|
||||
|
||||
@@ -111,6 +111,7 @@ export const OrderSummarySection = ({ order }: OrderSummarySectionProps) => {
|
||||
)
|
||||
|
||||
const { mutateAsync: markAsPaid } = useMarkPaymentCollectionAsPaid(
|
||||
order.id,
|
||||
unpaidPaymentCollection?.id!
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user