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