fix: refreshing inventory locations list (#7828)
This commit is contained in:
+11
-2
@@ -13,6 +13,7 @@ import { useBatchUpdateInventoryLevels } from "../../../../../../hooks/api/inven
|
|||||||
import { useFieldArray, useForm } from "react-hook-form"
|
import { useFieldArray, useForm } from "react-hook-form"
|
||||||
|
|
||||||
import { LocationItem } from "./location-item"
|
import { LocationItem } from "./location-item"
|
||||||
|
import { useEffect, useMemo } from "react"
|
||||||
|
|
||||||
type EditInventoryItemAttributeFormProps = {
|
type EditInventoryItemAttributeFormProps = {
|
||||||
item: AdminInventoryItem
|
item: AdminInventoryItem
|
||||||
@@ -46,8 +47,9 @@ export const ManageLocationsForm = ({
|
|||||||
item,
|
item,
|
||||||
locations,
|
locations,
|
||||||
}: EditInventoryItemAttributeFormProps) => {
|
}: EditInventoryItemAttributeFormProps) => {
|
||||||
const existingLocationLevels = new Set(
|
const existingLocationLevels = useMemo(
|
||||||
item.location_levels?.map((l) => l.location_id) ?? []
|
() => new Set(item.location_levels?.map((l) => l.location_id) ?? []),
|
||||||
|
item.location_levels
|
||||||
)
|
)
|
||||||
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -63,6 +65,13 @@ export const ManageLocationsForm = ({
|
|||||||
name: "locations",
|
name: "locations",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
form.setValue(
|
||||||
|
"locations",
|
||||||
|
getDefaultValues(locations, existingLocationLevels).locations
|
||||||
|
)
|
||||||
|
}, [existingLocationLevels, locations])
|
||||||
|
|
||||||
const { mutateAsync } = useBatchUpdateInventoryLevels(item.id)
|
const { mutateAsync } = useBatchUpdateInventoryLevels(item.id)
|
||||||
|
|
||||||
const handleSubmit = form.handleSubmit(async ({ locations }) => {
|
const handleSubmit = form.handleSubmit(async ({ locations }) => {
|
||||||
|
|||||||
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
import { Heading } from "@medusajs/ui"
|
import { Heading } from "@medusajs/ui"
|
||||||
|
import { useTranslation } from "react-i18next"
|
||||||
|
|
||||||
import { ManageLocationsForm } from "./components/manage-locations-form"
|
import { ManageLocationsForm } from "./components/manage-locations-form"
|
||||||
import { RouteDrawer } from "../../../../../components/route-modal"
|
import { RouteDrawer } from "../../../../../components/route-modal"
|
||||||
import { useInventoryItem } from "../../../../../hooks/api/inventory"
|
import { useInventoryItem } from "../../../../../hooks/api/inventory"
|
||||||
import { useParams } from "react-router-dom"
|
import { useParams } from "react-router-dom"
|
||||||
import { useStockLocations } from "../../../../../hooks/api/stock-locations"
|
import { useStockLocations } from "../../../../../hooks/api/stock-locations"
|
||||||
import { useTranslation } from "react-i18next"
|
|
||||||
|
|
||||||
export const ManageLocationsDrawer = () => {
|
export const ManageLocationsDrawer = () => {
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
|
|||||||
Reference in New Issue
Block a user