Skip to content

Commit

Permalink
fix(dashboard): bust order preview cache to reset fulfilled quantity (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Aug 21, 2024
1 parent 1e07ab1 commit 0da9445
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 102 deletions.
90 changes: 73 additions & 17 deletions packages/admin-next/dashboard/src/hooks/api/claims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export const useCreateClaim = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand All @@ -103,9 +100,6 @@ export const useCancelClaim = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand Down Expand Up @@ -135,9 +129,6 @@ export const useDeleteClaim = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -507,9 +569,6 @@ export const useClaimConfirmRequest = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand All @@ -536,9 +595,6 @@ export const useCancelClaimRequest = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand Down
19 changes: 1 addition & 18 deletions packages/admin-next/dashboard/src/hooks/api/exchanges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ export const useCreateExchange = (
queryKey: ordersQueryKeys.details(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
})
Expand All @@ -104,9 +100,6 @@ export const useCancelExchange = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand Down Expand Up @@ -136,9 +129,6 @@ export const useDeleteExchange = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand Down Expand Up @@ -283,7 +273,7 @@ export const useRemoveExchangeInboundItem = (
queryKey: ordersQueryKeys.preview(orderId),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.all,
queryKey: ordersQueryKeys.details(),
})

options?.onSuccess?.(data, variables, context)
Expand Down Expand Up @@ -509,10 +499,6 @@ export const useExchangeConfirmRequest = (
queryKey: ordersQueryKeys.details(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
})
Expand All @@ -538,9 +524,6 @@ export const useCancelExchangeRequest = (
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.lists(),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 18 additions & 3 deletions packages/admin-next/dashboard/src/hooks/api/orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -94,6 +100,10 @@ export const useCreateOrderFulfillment = (
queryKey: ordersQueryKeys.preview(orderId),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.preview(orderId),
})

options?.onSuccess?.(data, variables, context)
},
...options,
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 0da9445

Please sign in to comment.