fix(dashboard): stock location hook cache invalidation (#8049)
This commit is contained in:
@@ -42,6 +42,7 @@ export const useDeleteFulfillmentSet = (
|
||||
// We need to invalidate all related entities. We invalidate using `all` keys to ensure that all relevant entities are invalidated.
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
refetchType: "all",
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: shippingOptionsQueryKeys.all,
|
||||
|
||||
@@ -166,10 +166,8 @@ export const useCreateStockLocationFulfillmentSet = (
|
||||
sdk.admin.stockLocation.createFulfillmentSet(locationId, payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
refetchType: "all",
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export { stockLocationLoader as loader } from "./loader"
|
||||
export { LocationCreateServiceZone as Component } from "./location-service-zone-create"
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
|
||||
import { stockLocationsQueryKeys } from "../../../hooks/api/stock-locations"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
|
||||
const fulfillmentSetCreateQuery = (id: string) => ({
|
||||
queryKey: stockLocationsQueryKeys.detail(id, {
|
||||
fields: "*fulfillment_sets",
|
||||
}),
|
||||
queryFn: async () =>
|
||||
sdk.admin.stockLocation.retrieve(id, {
|
||||
fields: "*fulfillment_sets",
|
||||
}),
|
||||
})
|
||||
|
||||
export const stockLocationLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const id = params.location_id
|
||||
const query = fulfillmentSetCreateQuery(id!)
|
||||
|
||||
return (
|
||||
queryClient.getQueryData<HttpTypes.AdminStockLocationResponse>(
|
||||
query.queryKey
|
||||
) ?? (await queryClient.fetchQuery(query))
|
||||
)
|
||||
}
|
||||
@@ -1,24 +1,17 @@
|
||||
import { json, useLoaderData, useParams } from "react-router-dom"
|
||||
import { json, useParams } from "react-router-dom"
|
||||
|
||||
import { RouteFocusModal } from "../../../components/modals"
|
||||
import { useStockLocation } from "../../../hooks/api/stock-locations"
|
||||
import { FulfillmentSetType } from "../common/constants"
|
||||
import { CreateServiceZoneForm } from "./components/create-service-zone-form"
|
||||
import { stockLocationLoader } from "./loader"
|
||||
import { FulfillmentSetType } from "../common/constants"
|
||||
|
||||
export function LocationCreateServiceZone() {
|
||||
const { fset_id, location_id } = useParams()
|
||||
const initialData = useLoaderData() as Awaited<
|
||||
ReturnType<typeof stockLocationLoader>
|
||||
>
|
||||
|
||||
const { stock_location, isLoading, isError, error } = useStockLocation(
|
||||
location_id!,
|
||||
{
|
||||
fields: "*fulfillment_sets",
|
||||
},
|
||||
{
|
||||
initialData,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export { stockLocationLoader as loader } from "./loader"
|
||||
export { LocationServiceZoneShippingOptionCreate as Component } from "./location-service-zone-shipping-option-create"
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { stockLocationsQueryKeys } from "../../../hooks/api/stock-locations"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
import { LOC_CREATE_SHIPPING_OPTION_FIELDS } from "./constants"
|
||||
|
||||
const fulfillmentSetCreateQuery = (id: string) => ({
|
||||
queryKey: stockLocationsQueryKeys.detail(id, {
|
||||
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
||||
}),
|
||||
queryFn: async () =>
|
||||
sdk.admin.stockLocation.retrieve(id, {
|
||||
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
||||
}),
|
||||
})
|
||||
|
||||
export const stockLocationLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const id = params.location_id
|
||||
const query = fulfillmentSetCreateQuery(id!)
|
||||
|
||||
return (
|
||||
queryClient.getQueryData<HttpTypes.AdminStockLocationResponse>(
|
||||
query.queryKey
|
||||
) ?? (await queryClient.fetchQuery(query))
|
||||
)
|
||||
}
|
||||
@@ -1,31 +1,20 @@
|
||||
import {
|
||||
json,
|
||||
useLoaderData,
|
||||
useParams,
|
||||
useSearchParams,
|
||||
} from "react-router-dom"
|
||||
import { json, useParams, useSearchParams } from "react-router-dom"
|
||||
|
||||
import { RouteFocusModal } from "../../../components/modals"
|
||||
import { useStockLocation } from "../../../hooks/api/stock-locations"
|
||||
import { CreateShippingOptionsForm } from "./components/create-shipping-options-form"
|
||||
import { LOC_CREATE_SHIPPING_OPTION_FIELDS } from "./constants"
|
||||
import { stockLocationLoader } from "./loader"
|
||||
|
||||
export function LocationServiceZoneShippingOptionCreate() {
|
||||
const { location_id, fset_id, zone_id } = useParams()
|
||||
const [searchParams] = useSearchParams()
|
||||
const isReturn = searchParams.has("is_return")
|
||||
|
||||
const initialData = useLoaderData() as Awaited<
|
||||
ReturnType<typeof stockLocationLoader>
|
||||
>
|
||||
|
||||
const { stock_location, isPending, isError, error } = useStockLocation(
|
||||
location_id!,
|
||||
{
|
||||
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
||||
},
|
||||
{ initialData }
|
||||
}
|
||||
)
|
||||
|
||||
const zone = stock_location?.fulfillment_sets
|
||||
|
||||
Reference in New Issue
Block a user