fix(admin-ui): Create fulfillment (#3607)
* fix for create-fulfillment * remove ff check * add changeset * Disable Create fulfillment button if no quantities fulfilled --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Rares Capilnar <rares.capilnar@gmail.com>
This commit is contained in:
9 files changed
+52
-11
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/admin-ui": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(admin-ui): fix bug with create fulfillment and a couple of other minor tweaks
|
||||||
-1
@@ -15,7 +15,6 @@ import clsx from "clsx"
|
|||||||
import { sum } from "lodash"
|
import { sum } from "lodash"
|
||||||
import { useAdminStockLocations } from "medusa-react"
|
import { useAdminStockLocations } from "medusa-react"
|
||||||
import { useFeatureFlag } from "../../../../../providers/feature-flag-provider"
|
import { useFeatureFlag } from "../../../../../providers/feature-flag-provider"
|
||||||
// import { InventoryLevelDTO, StockLocationDTO } from "@medusajs/medusa"
|
|
||||||
|
|
||||||
export type VariantStockFormType = {
|
export type VariantStockFormType = {
|
||||||
manage_inventory?: boolean
|
manage_inventory?: boolean
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ const VariantStockForm = ({ form, locationLevels }: Props) => {
|
|||||||
const { stock_locations: locations, isLoading } = useAdminStockLocations()
|
const { stock_locations: locations, isLoading } = useAdminStockLocations()
|
||||||
|
|
||||||
const locationsMap = useMemo(() => {
|
const locationsMap = useMemo(() => {
|
||||||
if (isLoading) {
|
if (isLoading || !locations) {
|
||||||
return new Map()
|
return new Map()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ export const AllocationLineItem: React.FC<{
|
|||||||
form.setValue(path("line_item_id"), item.id)
|
form.setValue(path("line_item_id"), item.id)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (variant?.inventory) {
|
if (variant?.inventory?.length) {
|
||||||
form.setValue(path("inventory_item_id"), variant.inventory[0].id)
|
form.setValue(path("inventory_item_id"), variant.inventory[0].id)
|
||||||
}
|
}
|
||||||
}, [variant, form, path])
|
}, [variant, form, path])
|
||||||
@@ -232,12 +232,14 @@ export const AllocationLineItem: React.FC<{
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
const { inventory } = variant
|
const { inventory } = variant
|
||||||
const locationInventory = inventory[0].location_levels?.find(
|
const locationInventory = inventory?.[0]?.location_levels?.find(
|
||||||
(inv) => inv.location_id === locationId
|
(inv) => inv.location_id === locationId
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!locationInventory) {
|
if (!locationInventory) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
availableQuantity: locationInventory.available_quantity,
|
availableQuantity: locationInventory.available_quantity,
|
||||||
inStockQuantity: locationInventory.stocked_quantity,
|
inStockQuantity: locationInventory.stocked_quantity,
|
||||||
|
|||||||
@@ -223,6 +223,9 @@ const CreateFulfillmentModal: React.FC<CreateFulfillmentModalProps> = ({
|
|||||||
type="submit"
|
type="submit"
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
onClick={createFulfillment}
|
onClick={createFulfillment}
|
||||||
|
disabled={
|
||||||
|
!Object.values(quantities).some((quantity) => quantity > 0)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Create fulfillment
|
Create fulfillment
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const FulfillmentLine = ({
|
|||||||
handleQuantityUpdate,
|
handleQuantityUpdate,
|
||||||
setErrors,
|
setErrors,
|
||||||
}: {
|
}: {
|
||||||
locationId: string
|
locationId?: string
|
||||||
item: LineItem
|
item: LineItem
|
||||||
quantities: Record<string, number>
|
quantities: Record<string, number>
|
||||||
handleQuantityUpdate: (value: number, id: string) => void
|
handleQuantityUpdate: (value: number, id: string) => void
|
||||||
@@ -79,6 +79,7 @@ const FulfillmentLine = ({
|
|||||||
item.variant_id as string,
|
item.variant_id as string,
|
||||||
{ enabled: isLocationFulfillmentEnabled }
|
{ enabled: isLocationFulfillmentEnabled }
|
||||||
)
|
)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isLocationFulfillmentEnabled) {
|
if (isLocationFulfillmentEnabled) {
|
||||||
refetch()
|
refetch()
|
||||||
@@ -86,6 +87,13 @@ const FulfillmentLine = ({
|
|||||||
}, [isLocationFulfillmentEnabled, refetch])
|
}, [isLocationFulfillmentEnabled, refetch])
|
||||||
|
|
||||||
const { availableQuantity, inStockQuantity } = useMemo(() => {
|
const { availableQuantity, inStockQuantity } = useMemo(() => {
|
||||||
|
if (!isLocationFulfillmentEnabled) {
|
||||||
|
return {
|
||||||
|
availableQuantity: item.variant.inventory_quantity,
|
||||||
|
inStockQuantity: item.variant.inventory_quantity,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isLoading || !locationId || !variant) {
|
if (isLoading || !locationId || !variant) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
@@ -104,7 +112,13 @@ const FulfillmentLine = ({
|
|||||||
availableQuantity: locationInventory.available_quantity,
|
availableQuantity: locationInventory.available_quantity,
|
||||||
inStockQuantity: locationInventory.stocked_quantity,
|
inStockQuantity: locationInventory.stocked_quantity,
|
||||||
}
|
}
|
||||||
}, [variant, locationId, isLoading])
|
}, [
|
||||||
|
isLoading,
|
||||||
|
locationId,
|
||||||
|
variant,
|
||||||
|
item.variant,
|
||||||
|
isLocationFulfillmentEnabled,
|
||||||
|
])
|
||||||
|
|
||||||
const validQuantity =
|
const validQuantity =
|
||||||
!locationId ||
|
!locationId ||
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DisplayTotal, PaymentDetails } from "../templates"
|
import { DisplayTotal, PaymentDetails } from "../templates"
|
||||||
import { Order, ReservationItemDTO } from "@medusajs/medusa"
|
import { Order } from "@medusajs/medusa"
|
||||||
import React, { useContext, useMemo } from "react"
|
import React, { useContext, useMemo } from "react"
|
||||||
|
|
||||||
import { ActionType } from "../../../../components/molecules/actionables"
|
import { ActionType } from "../../../../components/molecules/actionables"
|
||||||
@@ -13,6 +13,7 @@ import StatusIndicator from "../../../../components/fundamentals/status-indicato
|
|||||||
import { sum } from "lodash"
|
import { sum } from "lodash"
|
||||||
import { useFeatureFlag } from "../../../../providers/feature-flag-provider"
|
import { useFeatureFlag } from "../../../../providers/feature-flag-provider"
|
||||||
import useToggleState from "../../../../hooks/use-toggle-state"
|
import useToggleState from "../../../../hooks/use-toggle-state"
|
||||||
|
import { ReservationItemDTO } from "@medusajs/types"
|
||||||
|
|
||||||
type SummaryCardProps = {
|
type SummaryCardProps = {
|
||||||
order: Order
|
order: Order
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ import useClipboard from "../../../hooks/use-clipboard"
|
|||||||
import { useHotkeys } from "react-hotkeys-hook"
|
import { useHotkeys } from "react-hotkeys-hook"
|
||||||
import useImperativeDialog from "../../../hooks/use-imperative-dialog"
|
import useImperativeDialog from "../../../hooks/use-imperative-dialog"
|
||||||
import useNotification from "../../../hooks/use-notification"
|
import useNotification from "../../../hooks/use-notification"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import useToggleState from "../../../hooks/use-toggle-state"
|
import useToggleState from "../../../hooks/use-toggle-state"
|
||||||
import { useFeatureFlag } from "../../../providers/feature-flag-provider"
|
import { useFeatureFlag } from "../../../providers/feature-flag-provider"
|
||||||
|
|
||||||
@@ -154,7 +154,9 @@ const OrderDetails = () => {
|
|||||||
enabled: !!order?.region_id,
|
enabled: !!order?.region_id,
|
||||||
})
|
})
|
||||||
const { isFeatureEnabled } = useFeatureFlag()
|
const { isFeatureEnabled } = useFeatureFlag()
|
||||||
const inventoryEnabled = isFeatureEnabled("inventoryService")
|
const inventoryEnabled = useMemo(() => {
|
||||||
|
return isFeatureEnabled("inventoryService")
|
||||||
|
}, [isFeatureEnabled])
|
||||||
|
|
||||||
const { reservations, refetch: refetchReservations } = useAdminReservations(
|
const { reservations, refetch: refetchReservations } = useAdminReservations(
|
||||||
{
|
{
|
||||||
@@ -541,7 +543,7 @@ const OrderDetails = () => {
|
|||||||
orderToFulfill={order as any}
|
orderToFulfill={order as any}
|
||||||
handleCancel={() => setShowFulfillment(false)}
|
handleCancel={() => setShowFulfillment(false)}
|
||||||
orderId={order.id}
|
orderId={order.id}
|
||||||
onComplete={refetchReservations}
|
onComplete={inventoryEnabled ? refetchReservations : () => {}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showRefund && (
|
{showRefund && (
|
||||||
|
|||||||
@@ -1,7 +1,22 @@
|
|||||||
import { useAdminStockLocations } from "medusa-react"
|
import { useAdminStockLocations } from "medusa-react"
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import { useFeatureFlag } from "../providers/feature-flag-provider"
|
||||||
|
|
||||||
const useStockLocations = () => {
|
const useStockLocations = () => {
|
||||||
const { stock_locations } = useAdminStockLocations()
|
const { isFeatureEnabled } = useFeatureFlag()
|
||||||
|
const isStockLocationsEnabled = isFeatureEnabled("stockLocationService")
|
||||||
|
const { stock_locations, refetch } = useAdminStockLocations(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
enabled: isStockLocationsEnabled,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isStockLocationsEnabled) {
|
||||||
|
void refetch()
|
||||||
|
}
|
||||||
|
}, [isStockLocationsEnabled, refetch])
|
||||||
|
|
||||||
const getLocationNameById = (locationId: string | null) =>
|
const getLocationNameById = (locationId: string | null) =>
|
||||||
stock_locations?.find((stock_location) => stock_location.id === locationId)
|
stock_locations?.find((stock_location) => stock_location.id === locationId)
|
||||||
|
|||||||
Reference in new issue
Block a user