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.
|
// We need to invalidate all related entities. We invalidate using `all` keys to ensure that all relevant entities are invalidated.
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: stockLocationsQueryKeys.all,
|
queryKey: stockLocationsQueryKeys.all,
|
||||||
|
refetchType: "all",
|
||||||
})
|
})
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: shippingOptionsQueryKeys.all,
|
queryKey: shippingOptionsQueryKeys.all,
|
||||||
|
|||||||
@@ -166,10 +166,8 @@ export const useCreateStockLocationFulfillmentSet = (
|
|||||||
sdk.admin.stockLocation.createFulfillmentSet(locationId, payload),
|
sdk.admin.stockLocation.createFulfillmentSet(locationId, payload),
|
||||||
onSuccess: async (data, variables, context) => {
|
onSuccess: async (data, variables, context) => {
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: stockLocationsQueryKeys.lists(),
|
queryKey: stockLocationsQueryKeys.all,
|
||||||
})
|
refetchType: "all",
|
||||||
await queryClient.invalidateQueries({
|
|
||||||
queryKey: stockLocationsQueryKeys.details(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
|
|||||||
-1
@@ -1,2 +1 @@
|
|||||||
export { stockLocationLoader as loader } from "./loader"
|
|
||||||
export { LocationCreateServiceZone as Component } from "./location-service-zone-create"
|
export { LocationCreateServiceZone as Component } from "./location-service-zone-create"
|
||||||
|
|||||||
-27
@@ -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))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
+2
-9
@@ -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 { RouteFocusModal } from "../../../components/modals"
|
||||||
import { useStockLocation } from "../../../hooks/api/stock-locations"
|
import { useStockLocation } from "../../../hooks/api/stock-locations"
|
||||||
import { FulfillmentSetType } from "../common/constants"
|
|
||||||
import { CreateServiceZoneForm } from "./components/create-service-zone-form"
|
import { CreateServiceZoneForm } from "./components/create-service-zone-form"
|
||||||
import { stockLocationLoader } from "./loader"
|
import { FulfillmentSetType } from "../common/constants"
|
||||||
|
|
||||||
export function LocationCreateServiceZone() {
|
export function LocationCreateServiceZone() {
|
||||||
const { fset_id, location_id } = useParams()
|
const { fset_id, location_id } = useParams()
|
||||||
const initialData = useLoaderData() as Awaited<
|
|
||||||
ReturnType<typeof stockLocationLoader>
|
|
||||||
>
|
|
||||||
|
|
||||||
const { stock_location, isLoading, isError, error } = useStockLocation(
|
const { stock_location, isLoading, isError, error } = useStockLocation(
|
||||||
location_id!,
|
location_id!,
|
||||||
{
|
{
|
||||||
fields: "*fulfillment_sets",
|
fields: "*fulfillment_sets",
|
||||||
},
|
|
||||||
{
|
|
||||||
initialData,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
-1
@@ -1,2 +1 @@
|
|||||||
export { stockLocationLoader as loader } from "./loader"
|
|
||||||
export { LocationServiceZoneShippingOptionCreate as Component } from "./location-service-zone-shipping-option-create"
|
export { LocationServiceZoneShippingOptionCreate as Component } from "./location-service-zone-shipping-option-create"
|
||||||
|
|||||||
-28
@@ -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))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
+2
-13
@@ -1,31 +1,20 @@
|
|||||||
import {
|
import { json, useParams, useSearchParams } from "react-router-dom"
|
||||||
json,
|
|
||||||
useLoaderData,
|
|
||||||
useParams,
|
|
||||||
useSearchParams,
|
|
||||||
} from "react-router-dom"
|
|
||||||
|
|
||||||
import { RouteFocusModal } from "../../../components/modals"
|
import { RouteFocusModal } from "../../../components/modals"
|
||||||
import { useStockLocation } from "../../../hooks/api/stock-locations"
|
import { useStockLocation } from "../../../hooks/api/stock-locations"
|
||||||
import { CreateShippingOptionsForm } from "./components/create-shipping-options-form"
|
import { CreateShippingOptionsForm } from "./components/create-shipping-options-form"
|
||||||
import { LOC_CREATE_SHIPPING_OPTION_FIELDS } from "./constants"
|
import { LOC_CREATE_SHIPPING_OPTION_FIELDS } from "./constants"
|
||||||
import { stockLocationLoader } from "./loader"
|
|
||||||
|
|
||||||
export function LocationServiceZoneShippingOptionCreate() {
|
export function LocationServiceZoneShippingOptionCreate() {
|
||||||
const { location_id, fset_id, zone_id } = useParams()
|
const { location_id, fset_id, zone_id } = useParams()
|
||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
const isReturn = searchParams.has("is_return")
|
const isReturn = searchParams.has("is_return")
|
||||||
|
|
||||||
const initialData = useLoaderData() as Awaited<
|
|
||||||
ReturnType<typeof stockLocationLoader>
|
|
||||||
>
|
|
||||||
|
|
||||||
const { stock_location, isPending, isError, error } = useStockLocation(
|
const { stock_location, isPending, isError, error } = useStockLocation(
|
||||||
location_id!,
|
location_id!,
|
||||||
{
|
{
|
||||||
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
||||||
},
|
}
|
||||||
{ initialData }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const zone = stock_location?.fulfillment_sets
|
const zone = stock_location?.fulfillment_sets
|
||||||
|
|||||||
Reference in New Issue
Block a user