fix(dashboard): rq cache and pending flag (#9063)
**What** - fix issues from stale data on modal pages --- FIXES CC-137
This commit is contained in:
1 parent
6e46baa2cb
commit
0714315792
11 files changed
+65
-73
No files matched your search
@@ -42,7 +42,6 @@ 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,
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export const useCancelReturn = (
|
|||||||
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ordersQueryKeys.preview(orderId),
|
queryKey: ordersQueryKeys.preview(orderId),
|
||||||
refetchType: "all",
|
refetchType: "all", // We want preview to be updated in the cache immediately
|
||||||
})
|
})
|
||||||
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -163,7 +163,7 @@ export const useCancelReturnRequest = (
|
|||||||
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ordersQueryKeys.preview(orderId),
|
queryKey: ordersQueryKeys.preview(orderId),
|
||||||
refetchType: "all",
|
refetchType: "all", // We want preview to be updated in the cache immediately
|
||||||
})
|
})
|
||||||
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -625,7 +625,7 @@ export const useCancelReceiveReturn = (
|
|||||||
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ordersQueryKeys.preview(orderId),
|
queryKey: ordersQueryKeys.preview(orderId),
|
||||||
refetchType: "all", // For some reason RQ will refetch this but will return stale record from the cache
|
refetchType: "all", // We want preview to be updated in the cache immediately
|
||||||
})
|
})
|
||||||
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ export const useCreateStockLocationFulfillmentSet = (
|
|||||||
onSuccess: async (data, variables, context) => {
|
onSuccess: async (data, variables, context) => {
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: stockLocationsQueryKeys.all,
|
queryKey: stockLocationsQueryKeys.all,
|
||||||
refetchType: "all",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
|
|||||||
+6
-10
@@ -8,25 +8,21 @@ import { FulfillmentSetType } from "../common/constants"
|
|||||||
export function LocationCreateServiceZone() {
|
export function LocationCreateServiceZone() {
|
||||||
const { fset_id, location_id } = useParams()
|
const { fset_id, location_id } = useParams()
|
||||||
|
|
||||||
const { stock_location, isLoading, isError, error } = useStockLocation(
|
const { stock_location, isPending, isFetching, isError, error } =
|
||||||
location_id!,
|
useStockLocation(location_id!, {
|
||||||
{
|
|
||||||
fields: "*fulfillment_sets",
|
fields: "*fulfillment_sets",
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const fulfillmentSet = stock_location?.fulfillment_sets?.find(
|
const fulfillmentSet = stock_location?.fulfillment_sets?.find(
|
||||||
(f) => f.id === fset_id
|
(f) => f.id === fset_id
|
||||||
)
|
)
|
||||||
|
|
||||||
const ready = !isLoading && !!stock_location && !!fulfillmentSet
|
|
||||||
|
|
||||||
const type: FulfillmentSetType =
|
const type: FulfillmentSetType =
|
||||||
fulfillmentSet?.type === FulfillmentSetType.Pickup
|
fulfillmentSet?.type === FulfillmentSetType.Pickup
|
||||||
? FulfillmentSetType.Pickup
|
? FulfillmentSetType.Pickup
|
||||||
: FulfillmentSetType.Shipping
|
: FulfillmentSetType.Shipping
|
||||||
|
|
||||||
if (!isLoading && !fulfillmentSet) {
|
if (!isPending && !isFetching && !fulfillmentSet) {
|
||||||
throw json(
|
throw json(
|
||||||
{ message: `Fulfillment set with ID: ${fset_id} was not found.` },
|
{ message: `Fulfillment set with ID: ${fset_id} was not found.` },
|
||||||
404
|
404
|
||||||
@@ -39,11 +35,11 @@ export function LocationCreateServiceZone() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
||||||
{ready && (
|
{fulfillmentSet && (
|
||||||
<CreateServiceZoneForm
|
<CreateServiceZoneForm
|
||||||
fulfillmentSet={fulfillmentSet}
|
fulfillmentSet={fulfillmentSet}
|
||||||
|
location={stock_location!}
|
||||||
type={type}
|
type={type}
|
||||||
location={stock_location}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</RouteFocusModal>
|
</RouteFocusModal>
|
||||||
|
|||||||
+9
-11
@@ -10,34 +10,32 @@ export const LocationServiceZoneEdit = () => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { location_id, fset_id, zone_id } = useParams()
|
const { location_id, fset_id, zone_id } = useParams()
|
||||||
|
|
||||||
const { stock_location, isPending, isError, error } = useStockLocation(
|
const { stock_location, isPending, isFetching, isError, error } =
|
||||||
location_id!,
|
useStockLocation(location_id!, {
|
||||||
{
|
|
||||||
fields: "*fulfillment_sets.service_zones",
|
fields: "*fulfillment_sets.service_zones",
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const serviceZone = stock_location?.fulfillment_sets
|
const serviceZone = stock_location?.fulfillment_sets
|
||||||
?.find((f) => f.id === fset_id)
|
?.find((f) => f.id === fset_id)
|
||||||
?.service_zones.find((z) => z.id === zone_id)
|
?.service_zones.find((z) => z.id === zone_id)
|
||||||
|
|
||||||
if (isError) {
|
if (!isPending && !isFetching && !serviceZone) {
|
||||||
throw error
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPending && !serviceZone) {
|
|
||||||
throw json(
|
throw json(
|
||||||
{ message: `Service zone with ID ${zone_id} was not found` },
|
{ message: `Service zone with ID ${zone_id} was not found` },
|
||||||
404
|
404
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteDrawer prev={`/settings/locations/${location_id}`}>
|
<RouteDrawer prev={`/settings/locations/${location_id}`}>
|
||||||
<RouteDrawer.Header>
|
<RouteDrawer.Header>
|
||||||
<Heading>{t("stockLocations.serviceZones.edit.header")}</Heading>
|
<Heading>{t("stockLocations.serviceZones.edit.header")}</Heading>
|
||||||
</RouteDrawer.Header>
|
</RouteDrawer.Header>
|
||||||
{!isPending && serviceZone && (
|
{serviceZone && (
|
||||||
<EditServiceZoneForm
|
<EditServiceZoneForm
|
||||||
zone={serviceZone}
|
zone={serviceZone}
|
||||||
fulfillmentSetId={fset_id!}
|
fulfillmentSetId={fset_id!}
|
||||||
|
|||||||
+9
-11
@@ -7,31 +7,29 @@ import { EditServiceZoneAreasForm } from "./components/edit-region-areas-form"
|
|||||||
export const LocationServiceZoneManageAreas = () => {
|
export const LocationServiceZoneManageAreas = () => {
|
||||||
const { location_id, fset_id, zone_id } = useParams()
|
const { location_id, fset_id, zone_id } = useParams()
|
||||||
|
|
||||||
const { stock_location, isPending, isError, error } = useStockLocation(
|
const { stock_location, isPending, isFetching, isError, error } =
|
||||||
location_id!,
|
useStockLocation(location_id!, {
|
||||||
{
|
|
||||||
fields: "*fulfillment_sets.service_zones.geo_zones",
|
fields: "*fulfillment_sets.service_zones.geo_zones",
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const zone = stock_location?.fulfillment_sets
|
const zone = stock_location?.fulfillment_sets
|
||||||
?.find((f) => f.id === fset_id)
|
?.find((f) => f.id === fset_id)
|
||||||
?.service_zones.find((z) => z.id === zone_id)
|
?.service_zones.find((z) => z.id === zone_id)
|
||||||
|
|
||||||
if (isError) {
|
if (!isPending && !isFetching && !zone) {
|
||||||
throw error
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPending && !zone) {
|
|
||||||
throw json(
|
throw json(
|
||||||
{ message: `Service zone with ID ${zone_id} was not found` },
|
{ message: `Service zone with ID ${zone_id} was not found` },
|
||||||
404
|
404
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
||||||
{!isPending && zone && (
|
{zone && (
|
||||||
<EditServiceZoneAreasForm
|
<EditServiceZoneAreasForm
|
||||||
zone={zone}
|
zone={zone}
|
||||||
fulfillmentSetId={fset_id!}
|
fulfillmentSetId={fset_id!}
|
||||||
|
|||||||
+5
-9
@@ -10,18 +10,16 @@ export function LocationServiceZoneShippingOptionCreate() {
|
|||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
const isReturn = searchParams.has("is_return")
|
const isReturn = searchParams.has("is_return")
|
||||||
|
|
||||||
const { stock_location, isPending, isError, error } = useStockLocation(
|
const { stock_location, isPending, isFetching, isError, error } =
|
||||||
location_id!,
|
useStockLocation(location_id!, {
|
||||||
{
|
|
||||||
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
fields: LOC_CREATE_SHIPPING_OPTION_FIELDS,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const zone = stock_location?.fulfillment_sets
|
const zone = stock_location?.fulfillment_sets
|
||||||
?.find((f) => f.id === fset_id)
|
?.find((f) => f.id === fset_id)
|
||||||
?.service_zones?.find((z) => z.id === zone_id)
|
?.service_zones?.find((z) => z.id === zone_id)
|
||||||
|
|
||||||
if (!isPending && !zone) {
|
if (!isPending && !isFetching && !zone) {
|
||||||
throw json(
|
throw json(
|
||||||
{ message: `Service zone with ID ${zone_id} was not found` },
|
{ message: `Service zone with ID ${zone_id} was not found` },
|
||||||
404
|
404
|
||||||
@@ -32,11 +30,9 @@ export function LocationServiceZoneShippingOptionCreate() {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
const ready = !isPending && !!zone
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
||||||
{ready && (
|
{zone && (
|
||||||
<CreateShippingOptionsForm
|
<CreateShippingOptionsForm
|
||||||
zone={zone}
|
zone={zone}
|
||||||
isReturn={isReturn}
|
isReturn={isReturn}
|
||||||
|
|||||||
+10
-9
@@ -11,29 +11,30 @@ export const LocationServiceZoneShippingOptionEdit = () => {
|
|||||||
|
|
||||||
const { location_id, so_id } = useParams()
|
const { location_id, so_id } = useParams()
|
||||||
|
|
||||||
const { shipping_options, isPending, isError, error } = useShippingOptions({
|
const { shipping_options, isPending, isFetching, isError, error } =
|
||||||
id: so_id,
|
useShippingOptions({
|
||||||
})
|
id: so_id,
|
||||||
|
})
|
||||||
|
|
||||||
const shippingOption = shipping_options?.find((so) => so.id === so_id)
|
const shippingOption = shipping_options?.find((so) => so.id === so_id)
|
||||||
|
|
||||||
if (isError) {
|
if (!isPending && !isFetching && !shippingOption) {
|
||||||
throw error
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPending && !shippingOption) {
|
|
||||||
throw json(
|
throw json(
|
||||||
{ message: `Shipping option with ID ${so_id} was not found` },
|
{ message: `Shipping option with ID ${so_id} was not found` },
|
||||||
404
|
404
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteDrawer>
|
<RouteDrawer>
|
||||||
<RouteDrawer.Header>
|
<RouteDrawer.Header>
|
||||||
<Heading>{t("stockLocations.shippingOptions.edit.header")}</Heading>
|
<Heading>{t("stockLocations.shippingOptions.edit.header")}</Heading>
|
||||||
</RouteDrawer.Header>
|
</RouteDrawer.Header>
|
||||||
{!isPending && shippingOption && (
|
{shippingOption && (
|
||||||
<EditShippingOptionForm
|
<EditShippingOptionForm
|
||||||
shippingOption={shippingOption}
|
shippingOption={shippingOption}
|
||||||
locationId={location_id!}
|
locationId={location_id!}
|
||||||
|
|||||||
+11
-6
@@ -7,18 +7,23 @@ import { EditShippingOptionsPricingForm } from "./components/create-shipping-opt
|
|||||||
export function LocationServiceZoneShippingOptionPricing() {
|
export function LocationServiceZoneShippingOptionPricing() {
|
||||||
const { so_id, location_id } = useParams()
|
const { so_id, location_id } = useParams()
|
||||||
|
|
||||||
const { shipping_options, isPending } = useShippingOptions({
|
const { shipping_options, isPending, isFetching, isError, error } =
|
||||||
// TODO: change this when GET option by id endpoint is implemented
|
useShippingOptions({
|
||||||
id: [so_id!],
|
// TODO: change this when GET option by id endpoint is implemented
|
||||||
fields: "*prices,*prices.price_rules",
|
id: [so_id!],
|
||||||
})
|
fields: "*prices,*prices.price_rules",
|
||||||
|
})
|
||||||
|
|
||||||
const shippingOption = shipping_options?.find((so) => so.id === so_id)
|
const shippingOption = shipping_options?.find((so) => so.id === so_id)
|
||||||
|
|
||||||
if (!isPending && !shippingOption) {
|
if (!isPending && !isFetching && !shippingOption) {
|
||||||
throw json(`Shipping option with id: ${so_id} not found`, { status: 404 })
|
throw json(`Shipping option with id: ${so_id} not found`, { status: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
<RouteFocusModal prev={`/settings/locations/${location_id}`}>
|
||||||
{shippingOption && (
|
{shippingOption && (
|
||||||
|
|||||||
+9
-7
@@ -15,23 +15,25 @@ export const ProductVariantEdit = () => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { id, variant_id } = useParams()
|
const { id, variant_id } = useParams()
|
||||||
|
|
||||||
const { product, isLoading, isError, error } = useProduct(id!, undefined, {
|
const { product, isPending, isFetching, isError, error } = useProduct(
|
||||||
initialData,
|
id!,
|
||||||
})
|
undefined,
|
||||||
|
{
|
||||||
|
initialData,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const variant = product?.variants.find(
|
const variant = product?.variants.find(
|
||||||
(v: HttpTypes.AdminProductVariant) => v.id === variant_id
|
(v: HttpTypes.AdminProductVariant) => v.id === variant_id
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isLoading && !variant) {
|
if (!isPending && !isFetching && !variant) {
|
||||||
throw json({
|
throw json({
|
||||||
status: 404,
|
status: 404,
|
||||||
message: `Variant with ID ${variant_id} was not found.`,
|
message: `Variant with ID ${variant_id} was not found.`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const ready = !isLoading && !!product && !!variant
|
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
@@ -41,7 +43,7 @@ export const ProductVariantEdit = () => {
|
|||||||
<RouteDrawer.Header>
|
<RouteDrawer.Header>
|
||||||
<Heading>{t("products.variant.edit.header")}</Heading>
|
<Heading>{t("products.variant.edit.header")}</Heading>
|
||||||
</RouteDrawer.Header>
|
</RouteDrawer.Header>
|
||||||
{ready && (
|
{variant && (
|
||||||
<ProductEditVariantForm
|
<ProductEditVariantForm
|
||||||
product={product}
|
product={product}
|
||||||
variant={variant as unknown as HttpTypes.AdminProductVariant}
|
variant={variant as unknown as HttpTypes.AdminProductVariant}
|
||||||
|
|||||||
+3
-5
@@ -9,13 +9,11 @@ export const ProductEditOption = () => {
|
|||||||
const { id, option_id } = useParams()
|
const { id, option_id } = useParams()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const { product, isLoading, isError, error } = useProduct(id!)
|
const { product, isPending, isFetching, isError, error } = useProduct(id!)
|
||||||
|
|
||||||
const option = product?.options.find((o) => o.id === option_id)
|
const option = product?.options.find((o) => o.id === option_id)
|
||||||
|
|
||||||
const ready = !isLoading && option
|
if (!isPending && !isFetching && !option) {
|
||||||
|
|
||||||
if (!isLoading && !option) {
|
|
||||||
throw json({ message: `An option with ID ${option_id} was not found` }, 404)
|
throw json({ message: `An option with ID ${option_id} was not found` }, 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ export const ProductEditOption = () => {
|
|||||||
<RouteDrawer.Header>
|
<RouteDrawer.Header>
|
||||||
<Heading>{t("products.options.edit.header")}</Heading>
|
<Heading>{t("products.options.edit.header")}</Heading>
|
||||||
</RouteDrawer.Header>
|
</RouteDrawer.Header>
|
||||||
{ready && <CreateProductOptionForm option={option} />}
|
{option && <CreateProductOptionForm option={option} />}
|
||||||
</RouteDrawer>
|
</RouteDrawer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user