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