Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

feat(admin): align inventory panel with Figma (MER-139) (#1329)

Viktor Holik97623c00f4b2
diff --git a/claude-progress.md b/claude-progress.md
index c27cc1bba..1ecdcd280 100644
--- a/claude-progress.md
+++ b/claude-progress.md
@@ -14,6 +14,62 @@ session detail aggressively. The per-spec source of truth lives in
`bun run test:integration:http -- <pattern>`
- **Current blocker**: none
+## Session — Admin Inventory (MER-139), branch `feat/admin-inventory`
+
+Spec + audit: `docs/specs/spec-3-admin-inventory/`. Implemented (type-clean; deps built; lint
+warnings pre-existing only): **D-01** remove admin create-inventory-item flow; **D-04** drop
+"Details" suffix; **D-06** Edit Attributes `InlineTip`; **D-12** Manage-Qty warning `InlineTip`;
+**D-13** Edit Details flip (Title required / SKU optional); **D-15** toast copy → Figma verbatim +
+subtitle; **D-18** Create Reservation warning `InlineTip`. Added all prompt/warning i18n keys and
+regenerated the `$schema.json` inventory block (inventory subtree 66/66 parity).
+
+Also done: **D-16** delete item + delete level prompts (verbatim copy, `{{location}}` interp);
+**D-17** reservation delete two cases (discriminator `reservation.line_item_id` → unfulfilled-order
+"Got it" info prompt vs deletable confirm); **D-19** bulk "Edit stock levels" pre-confirm prompt;
+**D-14** adjust-qty empty-quantity message. Schema parity 67/67.
+
+Also done (frontend, build-clean): **D-02** Product + Store columns + reorder (In stock before
+Reserved); list now requests `+variants.product.title,+seller.name`. **D-03** filters =
+SKU/Store/Location/Height/Width/MID code/Material (dropped Length/Weight/Requires-shipping) +
+default sort `title` ascending (**G3b**); `seller_id` flows through the query. **D-14** reservation
+required-field messages (schema moved to `buildCreateReservationSchema(t)`). Fixed a pre-existing
+`AdminInventoryItemParams`→`AdminInventoryItemsParams` typo.
+
+All touched files type-clean (`tsc --noEmit`); remaining tsc errors are pre-existing
+(`@custom-types/*` alias cascade + untouched `inventory-metadata`/`inventory-stock-form`).
+
+**Backend-remaining (needs running API — NOT verifiable in this worktree per project constraints):**
+- Admin `inventory-items` route override in `packages/core` so the **Store filter** (`seller_id`
+ param) is accepted and the **Store column** seller-link is guaranteed to resolve. (Store column
+ may already resolve via global links in `fields`; the `seller_id` filter needs the override.)
+- **D-05** Associated-offers sidebar (needs offer reverse-link on the inventory detail contract).
+- **D-07** bulk store-ownership gate; **D-08** vendor notifications (subscribers); **D-09/D-10**
+ admin location scoping to the item's store.
+- **D-11** locations `…` right-align — uses canonical `columnHelper.action`; live visual check.
+See `docs/specs/spec-3-admin-inventory/blueprint.md` for the route-override plan.
+
+## Integration test (spin up to verify)
+
+`integration-tests/http/inventory/admin/inventory.spec.ts` — type-clean (only jest-global noise
+under standalone tsc, same as every spec). Run later with:
+`bun run test:integration:http -- inventory/admin/inventory`. It seeds a seller + offer-backed
+inventory item (stock location → shipping → product → offer) and asserts:
+1. **Store column** — `GET /admin/inventory-items?fields=+seller.name` resolves the seller link
+ (should PASS; validates D-02 Store column).
+2. **Product via offer** — offer inventory links to the *offer, not the variant* (memory
+ `offer-inventory-not-on-variant`), so `inventory_item.variants` is EMPTY; the product is
+ reached through the offer. Test asserts `item.offer?.product?.title`.
+3. **seller_id filter** — specifies D-03 backend; expected RED until the core route override lands.
+
+⚠️ **Finding to action:** because offer inventory has no variant link, the current frontend Product
+column (`variants?.[0]?.product?.title` in `use-inventory-table-columns.tsx`) will show `-` for
+offer items. The list must reach Product through the offer instead. Test #2 confirms the exact
+offer field/alias to use (verify `offer` vs `offers` when the suite runs), then update the column +
+the list `fields` request accordingly.
+
+Verify: `bun install` done; built `@mercurjs/types|client|dashboard-shared`; `tsc --noEmit`
+touched-files clean (remaining errors are pre-existing `@custom-types/*` alias + workspace drift).
+
## Session — Vendor Campaigns Figma Sync (branch `feat/vendor-campaigns-figma-sync`)
Spec: `docs/specs/spec-1-vendor-campaigns/` (brief / blueprint / assert / deltas).
diff --git a/integration-tests/http/inventory/admin/inventory.spec.ts b/integration-tests/http/inventory/admin/inventory.spec.ts
new file mode 100644
index 000000000..d2e758103
--- /dev/null
+++ b/integration-tests/http/inventory/admin/inventory.spec.ts
@@ -0,0 +1,270 @@
+import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
+import {
+ ISalesChannelModuleService,
+ MedusaContainer,
+} from "@medusajs/framework/types"
+import { Modules } from "@medusajs/framework/utils"
+import { MercurModules, SellerStatus } from "@mercurjs/types"
+
+import {
+ adminHeaders,
+ createAdminUser,
+} from "../../../helpers/create-admin-user"
+import { createSellerUser } from "../../../helpers/create-seller-user"
+import { createVendorProduct } from "../../../helpers/create-product"
+
+jest.setTimeout(60000)
+
+/**
+ * Admin Inventory (MER-139, spec-3-admin-inventory).
+ *
+ * The admin inventory list adds two marketplace columns to Medusa's native
+ * table — **Store** (the seller that owns the item) and **Product** (the
+ * product title). Both come from the mercur links, requested off the native
+ * `GET /admin/inventory-items` route via `fields`:
+ * - Store → `+seller.name` (inventory_item ↔ seller link)
+ * - Product → `+offers.product_variant.product.title` (item → offer → variant → product)
+ *
+ * IMPORTANT (memory `offer-inventory-not-on-variant`, decision D1): seller
+ * inventory is created through an **offer** and links to the *offer*, not the
+ * variant — so `inventory_item.variants` is empty. The Product column reaches
+ * the title through the offer (`offers.product.title`), inventory-side alias
+ * `offers`.
+ *
+ * `seller_id` filtering (the list's "Store" filter) is NOT in the native
+ * validator, so the last test specifies the behavior the core route override
+ * (delta D-03, backend) still has to deliver — it is expected red until then.
+ */
+const approveSeller = async (container: MedusaContainer, sellerId: string) => {
+ const sellerModule = container.resolve(MercurModules.SELLER) as {
+ updateSellers: (data: { id: string; status: SellerStatus }) => Promise<unknown>
+ }
+ await sellerModule.updateSellers({ id: sellerId, status: SellerStatus.OPEN })
+}
+
+medusaIntegrationTestRunner({
+ testSuite: ({ getContainer, api, dbConnection }) => {
+ describe("Admin - Inventory (marketplace columns)", () => {
+ let container: MedusaContainer
+ let counter = 0
+
+ beforeEach(async () => {
+ container = getContainer()
+ await createAdminUser(dbConnection, adminHeaders, container)
+ })
+
+ /**
+ * Seed a seller that owns one offer-backed inventory item, mirroring the
+ * production chain: seller → stock location + fulfillment + shipping
+ * profile → product → offer (with an inventory item + stock level).
+ * Returns the seller and the inventory item's sku.
+ */
+ const seedSellerInventory = async (opts: {
+ email: string
+ name: string
+ productTitle: string
+ offerSku: string
+ stocked?: number
+ }) => {
+ const { seller, headers } = await createSellerUser(container, {
+ email: opts.email,
+ name: opts.name,
+ })
+ const sellerId = (seller as { id: string }).id
+ await approveSeller(container, sellerId)
+
+ const tag = `_${++counter}_${Date.now()}`
+
+ const salesChannel = await container
+ .resolve<ISalesChannelModuleService>(Modules.SALES_CHANNEL)
+ .createSalesChannels({ name: `SC${tag}` })
+
+ const stockLocation = (
+ await api.post(
+ `/vendor/stock-locations`,
+ { name: `WH${tag}` },
+ headers
+ )
+ ).data.stock_location
+
+ await api.post(
+ `/vendor/stock-locations/${stockLocation.id}/fulfillment-sets`,
+ { name: `FS${tag}`, type: "shipping" },
+ headers
+ )
+ const fulfillmentSet = (
+ await api.get(
+ `/vendor/stock-locations/${stockLocation.id}?fields=*fulfillment_sets`,
+ headers
+ )
+ ).data.stock_location.fulfillment_sets[0]
+
+ const serviceZone = (
+ await api.post(
+ `/vendor/fulfillment-sets/${fulfillmentSet.id}/service-zones`,
+ {
+ name: `SZ${tag}`,
+ geo_zones: [{ type: "country", country_code: "us" }],
+ },
+ headers
+ )
+ ).data.fulfillment_set.service_zones.find(
+ (z: { name: string }) => z.name === `SZ${tag}`
+ )
+
+ const shippingProfile = (
+ await api.post(
+ `/vendor/shipping-profiles`,
+ { name: `SP${tag}`, type: "default" },
+ headers
+ )
+ ).data.shipping_profile
+
+ await api.post(
+ `/vendor/stock-locations/${stockLocation.id}/fulfillment-providers`,
+ { add: ["manual_manual"] },
+ headers
+ )
+ await api.post(
+ `/vendor/stock-locations/${stockLocation.id}/sales-channels`,
+ { add: [salesChannel.id] },
+ headers
+ )
+ await api.post(
+ `/vendor/shipping-options`,
+ {
+ name: `Ship${tag}`,
+ service_zone_id: serviceZone.id,
+ shipping_profile_id: shippingProfile.id,
+ provider_id: "manual_manual",
+ price_type: "flat",
+ type: { label: "Standard", description: "Standard", code: "standard" },
+ prices: [{ currency_code: "usd", amount: 500 }],
+ rules: [
+ { attribute: "enabled_in_store", value: "true", operator: "eq" },
+ ],
+ },
+ headers
+ )
+
+ const product = await createVendorProduct(api, headers, {
+ title: opts.productTitle,
+ sku: `V${tag}`,
+ })
+ await api.post(
+ `/vendor/sales-channels/${salesChannel.id}/products`,
+ { add: [product.id] },
+ headers
+ )
+
+ await api.post(
+ `/vendor/offers`,
+ {
+ sku: opts.offerSku,
+ variant_id: product.variants[0].id,
+ shipping_profile_id: shippingProfile.id,
+ inventory_items: [
+ {
+ title: opts.productTitle,
+ required_quantity: 1,
+ stock_levels: [
+ {
+ location_id: stockLocation.id,
+ stocked_quantity: opts.stocked ?? 100,
+ },
+ ],
+ },
+ ],
+ prices: [{ amount: 1000, currency_code: "usd" }],
+ },
+ headers
+ )
+
+ return { sellerId, sellerName: opts.name, offerSku: opts.offerSku }
+ }
+
+ const listItemForSeller = async (sellerId: string) => {
+ const res = await api.get(
+ `/admin/inventory-items?fields=id,sku,*seller,offers.id,offers.sku,offers.product_variant.title,offers.product_variant.product.title`,
+ adminHeaders
+ )
+ expect(res.status).toEqual(200)
+ return (res.data.inventory_items as Array<{ seller?: { id: string } }>).find(
+ (i) => i.seller?.id === sellerId
+ )
+ }
+
+ it("resolves the Store (seller) column via the seller link", async () => {
+ const { sellerId, sellerName } = await seedSellerInventory({
+ email: "[email protected]",
+ name: "Store One",
+ productTitle: "Tennis Dress",
+ offerSku: "OF-STORE-1",
+ })
+
+ const item = (await listItemForSeller(sellerId)) as
+ | { seller?: { id: string; name: string } }
+ | undefined
+
+ expect(item).toBeDefined()
+ expect(item!.seller!.name).toEqual(sellerName)
+ })
+
+ it("resolves the Product column via the offer's variant product", async () => {
+ const { sellerId } = await seedSellerInventory({
+ email: "[email protected]",
+ name: "Store Two",
+ productTitle: "A-Line Dress",
+ offerSku: "OF-STORE-2",
+ })
+
+ const item = (await listItemForSeller(sellerId)) as
+ | {
+ offers?: Array<{
+ product_variant?: { product?: { title?: string } }
+ }>
+ }
+ | undefined
+
+ expect(item).toBeDefined()
+ // Product column reads offers[0].product_variant.product.title
+ expect(
+ item!.offers?.[0]?.product_variant?.product?.title
+ ).toEqual("A-Line Dress")
+ })
+
+ // Specifies delta D-03 (backend). The list "Store" filter sends
+ // `seller_id`, which the native validator drops today. When the core
+ // admin `inventory-items` route override lands, this must scope the list
+ // to the given seller. Expected RED until then — that red is the signal.
+ it("filters the list by seller_id (Store filter)", async () => {
+ const a = await seedSellerInventory({
+ email: "[email protected]",
+ name: "Store A",
+ productTitle: "Prod A",
+ offerSku: "OF-A",
+ })
+ await seedSellerInventory({
+ email: "[email protected]",
+ name: "Store B",
+ productTitle: "Prod B",
+ offerSku: "OF-B",
+ })
+
+ const res = await api.get(
+ `/admin/inventory-items?seller_id=${a.sellerId}&fields=id,sku,*seller`,
+ adminHeaders
+ )
+ expect(res.status).toEqual(200)
+
+ const sellerIds = new Set(
+ (res.data.inventory_items as Array<{ seller?: { id: string } }>).map(
+ (i) => i.seller?.id
+ )
+ )
+ expect(sellerIds.has(a.sellerId)).toBe(true)
+ expect(sellerIds.size).toBe(1)
+ })
+ })
+ },
+})
diff --git a/packages/admin/src/extension-targets.d.ts b/packages/admin/src/extension-targets.d.ts
index a8dce84ca..0e405b506 100644
--- a/packages/admin/src/extension-targets.d.ts
+++ b/packages/admin/src/extension-targets.d.ts
@@ -220,8 +220,8 @@ declare module "@mercurjs/dashboard-sdk" {
displayFieldIds: "customers" | "name" | "owner"
}
"inventory_item": {
- formZones: "create" | "edit"
- formTabs: { "create": "availability" | "details" }
+ formZones: "edit"
+ formTabs: Record<string, string>
displayZones: "attributes" | "general" | "locations" | "reservations" | "variants"
displayFieldIds: "available_quantity" | "reserved_quantity" | "sku" | "stocked_quantity" | "title"
}
diff --git a/packages/admin/src/get-route-map.tsx b/packages/admin/src/get-route-map.tsx
index c11fe7b76..25f705899 100644
--- a/packages/admin/src/get-route-map.tsx
+++ b/packages/admin/src/get-route-map.tsx
@@ -1087,11 +1087,6 @@ export function getRouteMap({
path: "",
lazy: () => import("./pages/inventory/inventory-list"),
children: [
- {
- path: "create",
- lazy: () =>
- import("./pages/inventory/inventory-create"),
- },
{
path: "stock",
lazy: () => import("./pages/inventory/inventory-stock"),
diff --git a/packages/admin/src/i18n/translations/$schema.json b/packages/admin/src/i18n/translations/$schema.json
index fb5ac6f8b..189aa5f9e 100644
--- a/packages/admin/src/i18n/translations/$schema.json
+++ b/packages/admin/src/i18n/translations/$schema.json
@@ -220,12 +220,12 @@
"general": {
"type": "object",
"properties": {
- "unknownError": {
- "type": "string"
- },
- "notAvailable": {
- "type": "string"
- },
+ "unknownError": {
+ "type": "string"
+ },
+ "notAvailable": {
+ "type": "string"
+ },
"ascending": {
"type": "string"
},
@@ -603,18 +603,18 @@
"validation": {
"type": "object",
"properties": {
- "requiredField": {
- "type": "string"
- },
- "valueRequired": {
- "type": "string"
- },
- "currencyCodeNotFound": {
- "type": "string"
- },
- "shippingOptionIdMissing": {
- "type": "string"
- },
+ "requiredField": {
+ "type": "string"
+ },
+ "valueRequired": {
+ "type": "string"
+ },
+ "currencyCodeNotFound": {
+ "type": "string"
+ },
+ "shippingOptionIdMissing": {
+ "type": "string"
+ },
"mustBeInt": {
"type": "string"
},
@@ -3595,23 +3595,11 @@
},
"required": [
"titleRequired"
- ],
- "additionalProperties": false
+ ]
},
"editCollection": {
"type": "string"
},
- "validation": {
- "type": "object",
- "properties": {
- "titleRequired": {
- "type": "string"
- }
- },
- "required": [
- "titleRequired"
- ]
- },
"handleTooltip": {
"type": "string"
},
@@ -4438,6 +4426,12 @@
"subtitle": {
"type": "string"
},
+ "store": {
+ "type": "string"
+ },
+ "associatedOffers": {
+ "type": "string"
+ },
"reserved": {
"type": "string"
},
@@ -4468,6 +4462,50 @@
"levelDeleted": {
"type": "string"
},
+ "attributes": {
+ "type": "object",
+ "properties": {
+ "tip": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "tip"
+ ],
+ "additionalProperties": false
+ },
+ "item": {
+ "type": "object",
+ "properties": {
+ "deleteTitle": {
+ "type": "string"
+ },
+ "deleteDescription": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "deleteTitle",
+ "deleteDescription"
+ ],
+ "additionalProperties": false
+ },
+ "level": {
+ "type": "object",
+ "properties": {
+ "deleteTitle": {
+ "type": "string"
+ },
+ "deleteDescription": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "deleteTitle",
+ "deleteDescription"
+ ],
+ "additionalProperties": false
+ },
"create": {
"type": "object",
"properties": {
@@ -4492,6 +4530,9 @@
"requiresShippingHint": {
"type": "string"
},
+ "descriptionPlaceholder": {
+ "type": "string"
+ },
"successToast": {
"type": "string"
}
@@ -4504,6 +4545,7 @@
"attributes",
"requiresShipping",
"requiresShippingHint",
+ "descriptionPlaceholder",
"successToast"
],
"additionalProperties": false
@@ -4562,6 +4604,21 @@
"deleteSuccessToast": {
"type": "string"
},
+ "deleteTitle": {
+ "type": "string"
+ },
+ "deleteDescription": {
+ "type": "string"
+ },
+ "deleteBlockedDescription": {
+ "type": "string"
+ },
+ "gotIt": {
+ "type": "string"
+ },
+ "storeLocationWarning": {
+ "type": "string"
+ },
"errors": {
"type": "object",
"properties": {
@@ -4573,12 +4630,20 @@
},
"idRequired": {
"type": "string"
+ },
+ "selectLocation": {
+ "type": "string"
+ },
+ "enterQuantity": {
+ "type": "string"
}
},
"required": [
"noAvaliableQuantity",
"quantityOutOfRange",
- "idRequired"
+ "idRequired",
+ "selectLocation",
+ "enterQuantity"
],
"additionalProperties": false
}
@@ -4601,6 +4666,11 @@
"successToast",
"updateSuccessToast",
"deleteSuccessToast",
+ "deleteTitle",
+ "deleteDescription",
+ "deleteBlockedDescription",
+ "gotIt",
+ "storeLocationWarning",
"errors"
],
"additionalProperties": false
@@ -4637,12 +4707,16 @@
},
"updateItem": {
"type": "string"
+ },
+ "deleteItem": {
+ "type": "string"
}
},
"required": [
"updateLocations",
"updateLevel",
- "updateItem"
+ "updateItem",
+ "deleteItem"
],
"additionalProperties": false
},
@@ -4670,8 +4744,20 @@
"disabledToggleTooltip": {
"type": "string"
},
+ "foreignStoreTooltip": {
+ "type": "string"
+ },
"successToast": {
"type": "string"
+ },
+ "confirmTitle": {
+ "type": "string"
+ },
+ "confirmDescription": {
+ "type": "string"
+ },
+ "editQuantityWarning": {
+ "type": "string"
}
},
"required": [
@@ -4682,7 +4768,11 @@
"disablePrompt_one",
"disablePrompt_other",
"disabledToggleTooltip",
- "successToast"
+ "foreignStoreTooltip",
+ "successToast",
+ "confirmTitle",
+ "confirmDescription",
+ "editQuantityWarning"
],
"additionalProperties": false
}
@@ -4690,6 +4780,8 @@
"required": [
"domain",
"subtitle",
+ "store",
+ "associatedOffers",
"reserved",
"available",
"locationLevels",
@@ -4700,6 +4792,9 @@
"editItemDetails",
"quantityAcrossLocations",
"levelDeleted",
+ "attributes",
+ "item",
+ "level",
"create",
"reservation",
"adjustInventory",
@@ -9606,66 +9701,66 @@
"promotions": {
"type": "object",
"properties": {
- "templates": {
- "type": "object",
- "properties": {
- "amountOffProducts": {
- "type": "object",
- "properties": {
- "title": {
- "type": "string"
- },
- "description": {
- "type": "string"
- }
+ "templates": {
+ "type": "object",
+ "properties": {
+ "amountOffProducts": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
}
- },
- "amountOffOrder": {
- "type": "object",
- "properties": {
- "title": {
- "type": "string"
- },
- "description": {
- "type": "string"
- }
+ }
+ },
+ "amountOffOrder": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
}
- },
- "percentageOffProduct": {
- "type": "object",
- "properties": {
- "title": {
- "type": "string"
- },
- "description": {
- "type": "string"
- }
+ }
+ },
+ "percentageOffProduct": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
}
- },
- "percentageOffOrder": {
- "type": "object",
- "properties": {
- "title": {
- "type": "string"
- },
- "description": {
- "type": "string"
- }
+ }
+ },
+ "percentageOffOrder": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
}
- },
- "buyGet": {
- "type": "object",
- "properties": {
- "title": {
- "type": "string"
- },
- "description": {
- "type": "string"
- }
+ }
+ },
+ "buyGet": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
}
}
}
- },
+ }
+ },
"list": {
"type": "object",
"properties": {
@@ -14944,32 +15039,32 @@
"views": {
"type": "object",
"properties": {
- "toasts": {
- "type": "object",
- "properties": {
- "created": {
- "type": "string"
- },
- "createFailed": {
- "type": "string"
- },
- "updateActiveFailed": {
- "type": "string"
- },
- "updated": {
- "type": "string"
- },
- "updateFailed": {
- "type": "string"
- },
- "deleted": {
- "type": "string"
- },
- "deleteFailed": {
- "type": "string"
- }
+ "toasts": {
+ "type": "object",
+ "properties": {
+ "created": {
+ "type": "string"
+ },
+ "createFailed": {
+ "type": "string"
+ },
+ "updateActiveFailed": {
+ "type": "string"
+ },
+ "updated": {
+ "type": "string"
+ },
+ "updateFailed": {
+ "type": "string"
+ },
+ "deleted": {
+ "type": "string"
+ },
+ "deleteFailed": {
+ "type": "string"
}
- },
+ }
+ },
"save": {
"type": "string"
},
@@ -15289,20 +15384,20 @@
"commissions": {
"type": "object",
"properties": {
- "rulesTable": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "attribute": {
- "type": "string"
- },
- "fee": {
- "type": "string"
- }
+ "rulesTable": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "attribute": {
+ "type": "string"
+ },
+ "fee": {
+ "type": "string"
}
- },
+ }
+ },
"domain": {
"type": "string"
},
diff --git a/packages/admin/src/i18n/translations/en.json b/packages/admin/src/i18n/translations/en.json
index e508cc821..1709b84c3 100644
--- a/packages/admin/src/i18n/translations/en.json
+++ b/packages/admin/src/i18n/translations/en.json
@@ -1084,7 +1084,9 @@
},
"inventory": {
"domain": "Inventory",
- "subtitle": "Manage your inventory items",
+ "subtitle": "Manage inventory items.",
+ "store": "Store",
+ "associatedOffers": "Associated offers",
"reserved": "Reserved",
"available": "Available",
"locationLevels": "Locations",
@@ -1094,7 +1096,18 @@
"deleteWarning": "You are about to delete an inventory item. This action cannot be undone.",
"editItemDetails": "Edit item details",
"quantityAcrossLocations": "{{quantity}} across {{locations}} locations",
- "levelDeleted": "Inventory level deleted successfully.",
+ "levelDeleted": "Inventory level was successfully deleted.",
+ "attributes": {
+ "tip": "These are default values used to describe the item. They are not managed in Settings → Product Attributes."
+ },
+ "item": {
+ "deleteTitle": "Delete inventory item",
+ "deleteDescription": "You are about to delete an inventory item. This may affect Store inventory records. Before proceeding, make sure the Vendor has confirmed this change to avoid inconsistencies."
+ },
+ "level": {
+ "deleteTitle": "Delete inventory level",
+ "deleteDescription": "You're about to delete inventory level from {{location}}. This will delete stock and reservations for this location and can't be undone. Before proceeding, make sure the Vendor has confirmed this change to avoid inconsistencies."
+ },
"create": {
"title": "Create Inventory Item",
"details": "Details",
@@ -1124,10 +1137,17 @@
"successToast": "Reservation was successfully created.",
"updateSuccessToast": "Reservation was successfully updated.",
"deleteSuccessToast": "Reservation was successfully deleted.",
+ "deleteTitle": "Delete reservation",
+ "deleteDescription": "You are about to delete a reservation. This may affect Store inventory records. Before proceeding, make sure the Vendor has confirmed this change to avoid inconsistencies.",
+ "deleteBlockedDescription": "This reservation cannot be deleted because it's linked to an unfulfilled order.",
+ "gotIt": "Got it",
+ "storeLocationWarning": "You're creating a reservation at a Store location. Please confirm it with the Vendor to avoid data inconsistencies.",
"errors": {
- "noAvaliableQuantity": "Stock location doesn't have available quantity.",
+ "noAvaliableQuantity": "Stock location doesn't have available quantity",
"quantityOutOfRange": "Minimum quantity is 1 and maximum quantity is {{max}}",
- "idRequired": "Inventory item ID is required"
+ "idRequired": "Inventory item ID is required",
+ "selectLocation": "Please select a location",
+ "enterQuantity": "Please enter a quantity"
}
},
"adjustInventory": {
@@ -1136,9 +1156,10 @@
}
},
"toast": {
- "updateLocations": "Locations updated successfully.",
- "updateLevel": "Inventory level updated successfully.",
- "updateItem": "Inventory item updated successfully."
+ "updateLocations": "Locations were successfully updated.",
+ "updateLevel": "Inventory level was successfully updated.",
+ "updateItem": "Inventory item was successfully updated.",
+ "deleteItem": "Inventory item was successfully deleted."
},
"stock": {
"title": "Update inventory levels",
@@ -1148,7 +1169,11 @@
"disablePrompt_one": "You are about to disable {{count}} location level. This action cannot be undone.",
"disablePrompt_other": "You are about to disable {{count}} location levels. This action cannot be undone.",
"disabledToggleTooltip": "Cannot disable: clear incoming and/or reserved quantity before disabling.",
- "successToast": "Inventory levels updated successfully."
+ "foreignStoreTooltip": "You can't enable stock for this item at this location because it belongs to another Store.",
+ "successToast": "Stock levels were successfully updated.",
+ "confirmTitle": "Edit stock levels",
+ "confirmDescription": "You are about to edit stock levels in Stores locations. Before making changes to stock levels, please confirm them with the Vendors to avoid data inconsistencies or misunderstandings.",
+ "editQuantityWarning": "You are editing Store location quantity. Before making changes to stock levels, please confirm them with the Vendor to avoid data inconsistencies or misunderstandings."
}
},
"giftCards": {
diff --git a/packages/admin/src/pages/inventory/index.ts b/packages/admin/src/pages/inventory/index.ts
index 133c66bca..5cb944984 100644
--- a/packages/admin/src/pages/inventory/index.ts
+++ b/packages/admin/src/pages/inventory/index.ts
@@ -1,3 +1,2 @@
export { InventoryListPage } from "./inventory-list/inventory-list"
export { InventoryDetailPage } from "./inventory-detail/inventory-detail"
-export { InventoryCreatePage, CreateInventoryItemSchema } from "./inventory-create/inventory-create"
diff --git a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/index.ts b/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/index.ts
deleted file mode 100644
index 2322ccaff..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./inventory-create-form.tsx"
diff --git a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-availability-form.tsx b/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-availability-form.tsx
deleted file mode 100644
index b0947ae08..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-availability-form.tsx
+++ /dev/null
@@ -1,84 +0,0 @@
-import { HttpTypes } from "@medusajs/types"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-
-import {
- DataGrid,
- createDataGridHelper,
-} from "../../../../../components/data-grid"
-import { useRouteModal } from "../../../../../components/modals"
-import { useTabbedForm } from "../../../../../components/tabbed-form/tabbed-form"
-import { defineTabMeta } from "../../../../../components/tabbed-form/types"
-import { CreateInventoryItemSchema } from "./schema"
-
-type InventoryAvailabilityFormProps = {
- locations: HttpTypes.AdminStockLocation[]
-}
-
-const Root = ({ locations }: InventoryAvailabilityFormProps) => {
- const form = useTabbedForm<CreateInventoryItemSchema>()
- const { setCloseOnEscape } = useRouteModal()
-
- const columns = useColumns()
-
- return (
- <div className="size-full" data-testid="inventory-create-form-availability">
- <DataGrid
- columns={columns}
- data={locations}
- state={form}
- onEditingChange={(editing) => setCloseOnEscape(!editing)}
- />
- </div>
- )
-}
-
-const columnHelper = createDataGridHelper<
- HttpTypes.AdminStockLocation,
- CreateInventoryItemSchema
->()
-
-const useColumns = () => {
- const { t } = useTranslation()
-
- return useMemo(
- () => [
- columnHelper.column({
- id: "location",
- header: () => (
- <div className="flex size-full items-center overflow-hidden">
- <span className="truncate">{t("locations.domain")}</span>
- </div>
- ),
- cell: (context) => {
- return (
- <DataGrid.ReadonlyCell context={context}>
- {context.row.original.name}
- </DataGrid.ReadonlyCell>
- )
- },
- disableHiding: true,
- }),
- columnHelper.column({
- id: "in-stock",
- name: t("fields.inStock"),
- header: t("fields.inStock"),
- field: (context) => `locations.${context.row.original.id}`,
- type: "number",
- cell: (context) => {
- return <DataGrid.NumberCell placeholder="0" context={context} />
- },
- disableHiding: true,
- }),
- ],
- [t]
- )
-}
-
-Root._tabMeta = defineTabMeta<CreateInventoryItemSchema>({
- id: "availability",
- labelKey: "inventory.create.availability",
- validationFields: ["locations"],
-})
-
-export const InventoryAvailabilityForm = Root
diff --git a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-create-details-tab.tsx b/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-create-details-tab.tsx
deleted file mode 100644
index 9a1da09a4..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-create-details-tab.tsx
+++ /dev/null
@@ -1,207 +0,0 @@
-import {
- Divider,
- Heading,
- Input,
- Textarea,
-} from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-
-import { Form } from "../../../../../components/common/form"
-import { SwitchBox } from "../../../../../components/common/switch-box"
-import { CountrySelect } from "../../../../../components/inputs/country-select"
-import { useTabbedForm } from "../../../../../components/tabbed-form/tabbed-form"
-import { defineTabMeta } from "../../../../../components/tabbed-form/types"
-import { CreateInventoryItemSchema } from "./schema"
-
-const Root = () => {
- const { t } = useTranslation()
- const form = useTabbedForm<CreateInventoryItemSchema>()
-
- return (
- <div className="flex flex-1 flex-col items-center overflow-y-auto px-3">
- <div className="mx-auto flex w-full max-w-[720px] flex-col gap-y-8 px-px py-16" data-testid="inventory-create-form-content">
- <div className="flex flex-col gap-y-8">
- <div data-testid="inventory-create-form-header">
- <Heading data-testid="inventory-create-form-heading">{t("inventory.create.title")}</Heading>
- </div>
- <div className="flex flex-col gap-y-6">
- <div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
- <Form.Field
- control={form.control}
- name="title"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-title-item">
- <Form.Label data-testid="inventory-create-form-title-label">{t("fields.title")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-title-control">
- <Input {...field} placeholder={t("fields.title")} data-testid="inventory-create-form-title-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-title-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="sku"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-sku-item">
- <Form.Label data-testid="inventory-create-form-sku-label">{t("fields.sku")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-sku-control">
- <Input {...field} placeholder="sku-123" data-testid="inventory-create-form-sku-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-sku-error" />
- </Form.Item>
- )}
- />
- </div>
- <Form.Field
- control={form.control}
- name="description"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-description-item">
- <Form.Label optional data-testid="inventory-create-form-description-label">
- {t("products.fields.description.label")}
- </Form.Label>
- <Form.Control data-testid="inventory-create-form-description-control">
- <Textarea {...field} placeholder={t("inventory.create.descriptionPlaceholder")} data-testid="inventory-create-form-description-textarea" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-description-error" />
- </Form.Item>
- )}
- />
- </div>
- <SwitchBox
- control={form.control}
- name="requires_shipping"
- label={t("inventory.create.requiresShipping")}
- description={t("inventory.create.requiresShippingHint")}
- data-testid="inventory-create-form-requires-shipping"
- />
- </div>
-
- <Divider />
-
- <div className="flex flex-col gap-y-6">
- <Heading level="h2">{t("inventory.create.attributes")}</Heading>
- <div className="grid grid-cols-1 gap-x-4 gap-y-4 lg:grid-cols-2 lg:gap-y-8">
- <Form.Field
- control={form.control}
- name="width"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-width-item">
- <Form.Label optional data-testid="inventory-create-form-width-label">{t("products.fields.width.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-width-control">
- <Input {...field} type="number" min={0} placeholder="100" data-testid="inventory-create-form-width-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-width-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="length"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-length-item">
- <Form.Label optional data-testid="inventory-create-form-length-label">{t("products.fields.length.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-length-control">
- <Input {...field} type="number" min={0} placeholder="100" data-testid="inventory-create-form-length-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-length-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="height"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-height-item">
- <Form.Label optional data-testid="inventory-create-form-height-label">{t("products.fields.height.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-height-control">
- <Input {...field} type="number" min={0} placeholder="100" data-testid="inventory-create-form-height-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-height-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="weight"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-weight-item">
- <Form.Label optional data-testid="inventory-create-form-weight-label">{t("products.fields.weight.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-weight-control">
- <Input {...field} type="number" min={0} placeholder="100" data-testid="inventory-create-form-weight-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-weight-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="mid_code"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-mid-code-item">
- <Form.Label optional data-testid="inventory-create-form-mid-code-label">{t("products.fields.mid_code.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-mid-code-control">
- <Input {...field} data-testid="inventory-create-form-mid-code-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-mid-code-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="hs_code"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-hs-code-item">
- <Form.Label optional data-testid="inventory-create-form-hs-code-label">{t("products.fields.hs_code.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-hs-code-control">
- <Input {...field} data-testid="inventory-create-form-hs-code-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-hs-code-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="origin_country"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-origin-country-item">
- <Form.Label optional data-testid="inventory-create-form-origin-country-label">{t("products.fields.countryOrigin.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-origin-country-control">
- <CountrySelect {...field} data-testid="inventory-create-form-origin-country-select" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-origin-country-error" />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="material"
- render={({ field }) => (
- <Form.Item data-testid="inventory-create-form-material-item">
- <Form.Label optional data-testid="inventory-create-form-material-label">{t("products.fields.material.label")}</Form.Label>
- <Form.Control data-testid="inventory-create-form-material-control">
- <Input {...field} data-testid="inventory-create-form-material-input" />
- </Form.Control>
- <Form.ErrorMessage data-testid="inventory-create-form-material-error" />
- </Form.Item>
- )}
- />
- </div>
- </div>
- </div>
- </div>
- )
-}
-
-Root._tabMeta = defineTabMeta<CreateInventoryItemSchema>({
- id: "details",
- labelKey: "inventory.create.details",
- validationFields: [
- "title", "sku", "description", "hs_code", "weight", "length",
- "height", "width", "origin_country", "mid_code", "material",
- "requires_shipping", "thumbnail",
- ],
-})
-
-export const InventoryCreateDetailsTab = Root
diff --git a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-create-form.tsx b/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-create-form.tsx
deleted file mode 100644
index ed4180877..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/inventory-create-form.tsx
+++ /dev/null
@@ -1,139 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { toast } from "@medusajs/ui"
-import { Children, ReactNode, useMemo } from "react"
-import { DeepPartial, useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import { z } from "zod"
-
-import { HttpTypes } from "@medusajs/types"
-import { useRouteModal } from "../../../../../components/modals"
-import { TabbedForm } from "../../../../../components/tabbed-form/tabbed-form"
-import {
- inventoryItemsQueryKeys,
- useCreateInventoryItem,
-} from "../../../../../hooks/api/inventory"
-import { sdk } from "../../../../../lib/client"
-import {
- transformNullableFormData,
- transformNullableFormNumber,
- transformNullableFormNumbers,
-} from "../../../../../lib/form-helpers"
-import { queryClient } from "../../../../../lib/query-client"
-import { InventoryAvailabilityForm } from "./inventory-availability-form"
-import { InventoryCreateDetailsTab } from "./inventory-create-details-tab"
-import { CreateInventoryItemSchema } from "./schema"
-
-export type CreateInventoryItemSchemaType = z.infer<typeof CreateInventoryItemSchema>
-
-type InventoryCreateFormProps = {
- locations: HttpTypes.AdminStockLocation[]
- children?: ReactNode
- schema?: typeof CreateInventoryItemSchema
- defaultValues?: DeepPartial<CreateInventoryItemSchemaType>
-}
-
-export function InventoryCreateForm({
- locations,
- children,
- schema,
- defaultValues: extraDefaults,
-}: InventoryCreateFormProps) {
- const { t } = useTranslation()
- const { handleSuccess } = useRouteModal()
-
- const form = useForm<CreateInventoryItemSchemaType>({
- defaultValues: {
- title: "",
- sku: "",
- hs_code: "",
- weight: "",
- length: "",
- height: "",
- width: "",
- origin_country: "",
- mid_code: "",
- material: "",
- description: "",
- requires_shipping: true,
- thumbnail: "",
- locations: Object.fromEntries(
- locations.map((location) => [location.id, ""])
- ),
- ...extraDefaults,
- } as CreateInventoryItemSchemaType,
- resolver: zodResolver(schema ?? CreateInventoryItemSchema),
- })
-
- const { mutateAsync: createInventoryItem, isPending: isLoading } =
- useCreateInventoryItem()
-
- const handleSubmit = form.handleSubmit(async (data) => {
- const { locations: formLocations, weight, length, height, width, ...payload } = data
-
- const cleanData = transformNullableFormData(payload, false)
- const cleanNumbers = transformNullableFormNumbers(
- { weight, length, height, width },
- false
- )
-
- const { inventory_item } = await createInventoryItem(
- {
- ...cleanData,
- ...cleanNumbers,
- },
- {
- onError: (e) => {
- toast.error(e.message)
- return
- },
- }
- )
-
- // @ts-expect-error — Mercur SDK extension
- await sdk.admin.inventoryItem.batchUpdateLevels(inventory_item.id, {
- create: Object.entries(formLocations ?? {})
- .filter(([_, quantiy]) => !!quantiy)
- .map(([location_id, stocked_quantity]) => ({
- location_id,
- stocked_quantity: transformNullableFormNumber(
- stocked_quantity,
- false
- ),
- })),
- })
- .then(async () => {
- await queryClient.invalidateQueries({
- queryKey: inventoryItemsQueryKeys.lists(),
- })
- })
- .catch((e: Error) => {
- toast.error(e.message)
- })
- .finally(() => {
- handleSuccess()
- toast.success(t("inventory.create.successToast"))
- })
- })
-
- const defaultTabs = useMemo(
- () => [
- <InventoryCreateDetailsTab key="details" />,
- <InventoryAvailabilityForm key="availability" locations={locations} />,
- ],
- [locations]
- )
-
- const hasCustomChildren = Children.count(children) > 0
-
- return (
- <TabbedForm
- model="inventory_item"
- zone="create"
- form={form}
- onSubmit={handleSubmit}
- isLoading={isLoading}
- >
- {hasCustomChildren ? children : defaultTabs}
- </TabbedForm>
- )
-}
diff --git a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/schema.ts b/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/schema.ts
deleted file mode 100644
index 60f8e7a86..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/components/inventory-create-form/schema.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { z } from "zod"
-import { optionalInt } from "../../../../../lib/validation"
-
-export const CreateInventoryItemSchema = z.object({
- title: z.string().min(1),
- description: z.string().optional(),
- sku: z.string().optional(),
- hs_code: z.string().optional(),
- weight: optionalInt,
- length: optionalInt,
- height: optionalInt,
- width: optionalInt,
- origin_country: z.string().optional(),
- mid_code: z.string().optional(),
- material: z.string().optional(),
- requires_shipping: z.boolean().optional(),
- thumbnail: z.string().optional(),
- locations: z.record(z.string(), optionalInt).optional(),
-})
-
-export type CreateInventoryItemSchema = z.infer<
- typeof CreateInventoryItemSchema
->
diff --git a/packages/admin/src/pages/inventory/inventory-create/index.ts b/packages/admin/src/pages/inventory/inventory-create/index.ts
deleted file mode 100644
index 237a809ef..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { InventoryCreate as Component } from "./inventory-create"
diff --git a/packages/admin/src/pages/inventory/inventory-create/inventory-create.tsx b/packages/admin/src/pages/inventory/inventory-create/inventory-create.tsx
deleted file mode 100644
index 99ababb11..000000000
--- a/packages/admin/src/pages/inventory/inventory-create/inventory-create.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { Children, ReactNode } from "react"
-
-import { RouteFocusModal } from "../../../components/modals"
-import { TabbedForm } from "../../../components/tabbed-form/tabbed-form"
-import { useStockLocations } from "../../../hooks/api"
-import {
- InventoryCreateForm,
- CreateInventoryItemSchemaType,
-} from "./components/inventory-create-form"
-import { InventoryCreateDetailsTab } from "./components/inventory-create-form/inventory-create-details-tab"
-import { InventoryAvailabilityForm } from "./components/inventory-create-form/inventory-availability-form"
-import { CreateInventoryItemSchema } from "./components/inventory-create-form/schema"
-
-const Root = ({ children }: { children?: ReactNode }) => {
- const { isPending, stock_locations, isError, error } = useStockLocations({
- limit: 9999,
- fields: "id,name",
- })
-
- const ready = !isPending && !!stock_locations
-
- if (isError) {
- throw error
- }
-
- return (
- <RouteFocusModal>
- {ready && (
- Children.count(children) > 0 ? (
- children
- ) : (
- <InventoryCreateForm locations={stock_locations} />
- )
- )}
- </RouteFocusModal>
- )
-}
-
-export const InventoryCreatePage = Object.assign(Root, {
- Form: InventoryCreateForm,
- DetailsTab: InventoryCreateDetailsTab,
- AvailabilityTab: InventoryAvailabilityForm,
- Tab: TabbedForm.Tab,
-})
-
-export type { CreateInventoryItemSchemaType }
-export { CreateInventoryItemSchema }
-
-// Keep backward-compatible named export for route `Component`
-export const InventoryCreate = Root
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx
index 8bbb46ec7..79f7b77c2 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx
@@ -1,5 +1,5 @@
import type { HttpTypes } from "@medusajs/types";
-import { Button, Input, Text, toast } from "@medusajs/ui";
+import { Button, InlineTip, Input, Text, toast } from "@medusajs/ui";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm, useWatch } from "react-hook-form";
@@ -59,9 +59,8 @@ export const AdjustInventoryForm = ({
if (quantity === null) {
ctx.addIssue({
- code: z.ZodIssueCode.invalid_type,
- expected: "number",
- received: "undefined",
+ code: z.ZodIssueCode.custom,
+ message: t("validation.requiredField"),
path: ["stocked_quantity"],
});
@@ -176,6 +175,9 @@ export const AdjustInventoryForm = ({
);
}}
/>
+ <InlineTip variant="warning" label={t("general.warning")}>
+ {t("inventory.stock.editQuantityWarning")}
+ </InlineTip>
</RouteDrawer.Body>
<RouteDrawer.Footer data-testid="inventory-adjust-inventory-form-footer">
<div className="flex items-center justify-end gap-x-2" data-testid="inventory-adjust-inventory-form-footer-actions">
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx
index 104c8307a..4c8e50d9c 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx
@@ -1,6 +1,6 @@
import type * as zod from "zod"
-import { Button, Input, toast } from "@medusajs/ui"
+import { Button, InlineTip, Input, toast } from "@medusajs/ui"
import { zodResolver } from "@hookform/resolvers/zod"
// import { InventoryTypes } from "@medusajs/types"
@@ -72,6 +72,9 @@ export const EditInventoryItemAttributesForm = ({
data-testid="inventory-edit-item-attributes-keybound-form"
>
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-4 overflow-auto" data-testid="inventory-edit-item-attributes-form-body">
+ <InlineTip label={t("general.tip")}>
+ {t("inventory.attributes.tip")}
+ </InlineTip>
<Form.Field
control={form.control}
name="height"
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx
index 4fb2ba810..ae295268d 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx
@@ -17,14 +17,9 @@ type EditInventoryItemFormProps = {
item: HttpTypes.AdminInventoryItem
}
-const EditInventoryItemSchema = z.object({
- title: z.string().optional(),
- sku: z.string().min(1),
-})
-
const getDefaultValues = (item: HttpTypes.AdminInventoryItem) => {
return {
- title: item.title ?? undefined,
+ title: item.title ?? "",
sku: item.sku ?? undefined,
}
}
@@ -33,6 +28,11 @@ export const EditInventoryItemForm = ({ item }: EditInventoryItemFormProps) => {
const { t } = useTranslation()
const { handleSuccess } = useRouteModal()
+ const EditInventoryItemSchema = z.object({
+ title: z.string().min(1, t("validation.requiredField")),
+ sku: z.string().optional(),
+ })
+
const form = useExtendableForm({
schema: EditInventoryItemSchema,
model: "inventory_item",
@@ -84,7 +84,7 @@ export const EditInventoryItemForm = ({ item }: EditInventoryItemFormProps) => {
render={({ field }) => {
return (
<Form.Item data-testid="inventory-edit-item-form-sku-item">
- <Form.Label data-testid="inventory-edit-item-form-sku-label">{t("fields.sku")}</Form.Label>
+ <Form.Label optional data-testid="inventory-edit-item-form-sku-label">{t("fields.sku")}</Form.Label>
<Form.Control data-testid="inventory-edit-item-form-sku-control">
<div data-testid="inventory-edit-item-form-sku-input-wrapper">
<Input {...field} data-testid="inventory-edit-item-form-sku-input" />
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-general-section.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-general-section.tsx
index 82f488bbb..307a57f24 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-general-section.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-general-section.tsx
@@ -36,7 +36,7 @@ export const InventoryItemGeneralSection = ({
data={inventoryItem}
>
<Heading data-testid="inventory-item-general-title">
- {inventoryItem.title ?? inventoryItem.sku} {t("fields.details")}
+ {inventoryItem.title ?? inventoryItem.sku}
</Heading>
</DisplayField>
<ActionMenu
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-offers/associated-offers-section.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-offers/associated-offers-section.tsx
new file mode 100644
index 000000000..136c4f7e4
--- /dev/null
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/inventory-item-offers/associated-offers-section.tsx
@@ -0,0 +1,53 @@
+import { Container, Heading } from "@medusajs/ui"
+import { OfferDTO } from "@mercurjs/types"
+import { useTranslation } from "react-i18next"
+
+import { SidebarLink } from "@components/common/sidebar-link/sidebar-link"
+import { Thumbnail } from "@components/common/thumbnail"
+
+type AssociatedOffersSectionProps = {
+ offers?: OfferDTO[] | null
+}
+
+export const AssociatedOffersSection = ({
+ offers,
+}: AssociatedOffersSectionProps) => {
+ const { t } = useTranslation()
+
+ if (!offers?.length) {
+ return null
+ }
+
+ return (
+ <Container className="p-0" data-testid="inventory-item-offers-section">
+ <div className="flex items-center justify-between px-6 py-4">
+ <Heading level="h2" data-testid="inventory-item-offers-title">
+ {t("inventory.associatedOffers")}
+ </Heading>
+ </div>
+ {offers.map((offer) => {
+ const variantTitle = offer.product_variant?.title
+ const productTitle = offer.product_variant?.product?.title
+ const label = variantTitle || offer.sku
+ const description = [variantTitle, productTitle]
+ .filter(Boolean)
+ .join(" · ")
+
+ return (
+ <SidebarLink
+ key={offer.id}
+ to={`/offers/${offer.product_id}/variants/${offer.id}`}
+ labelKey={label}
+ descriptionKey={description}
+ icon={
+ <Thumbnail
+ src={offer.product_variant?.product?.thumbnail ?? null}
+ />
+ }
+ dataTestid={`inventory-associated-offer-${offer.id}`}
+ />
+ )
+ })}
+ </Container>
+ )
+}
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx
index 1855e96aa..654d7b513 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx
@@ -13,6 +13,7 @@ import { useNavigate } from "react-router-dom";
import type { ExtendedInventoryItemLevel } from "@custom-types/inventory";
+import { ActionMenu } from "@components/common/action-menu";
import { PlaceholderCell } from "@components/table/table-cells/common/placeholder-cell";
import {
@@ -33,9 +34,15 @@ export const useLocationListTableColumns =
const prompt = usePrompt();
const handleDelete = async (level: ExtendedInventoryItemLevel) => {
+ const locationName = level.stock_locations
+ ?.map((location) => location.name)
+ .join(", ");
+
const res = await prompt({
- title: t("general.areYouSure"),
- description: t("inventory.deleteWarning"),
+ title: t("inventory.level.deleteTitle"),
+ description: t("inventory.level.deleteDescription", {
+ location: locationName || t("fields.location"),
+ }),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
});
@@ -142,30 +149,39 @@ export const useLocationListTableColumns =
);
},
}),
- columnHelper.action({
- actions: (ctx) => {
- const level = ctx.row.original;
- return [
- [
- {
- icon: <PencilSquare />,
- label: t("actions.edit"),
-
- onClick: () => {
- navigate(`locations/${level.location_id}`);
+ columnHelper.display({
+ id: "actions",
+ cell: ({ row }) => {
+ const level = row.original;
+ return (
+ <ActionMenu
+ groups={[
+ {
+ actions: [
+ {
+ icon: <PencilSquare />,
+ label: t("actions.edit"),
+ onClick: () => {
+ navigate(`locations/${level.location_id}`);
+ },
+ },
+ ],
+ },
+ {
+ actions: [
+ {
+ icon: <Trash />,
+ label: t("actions.delete"),
+ onClick: () => handleDelete(level),
+ disabled:
+ level.reserved_quantity > 0 ||
+ level.stocked_quantity > 0,
+ },
+ ],
},
- },
- ],
- [
- {
- icon: <Trash />,
- label: t("actions.delete"),
- onClick: () => handleDelete(level),
- disabled:
- level.reserved_quantity > 0 || level.stocked_quantity > 0,
- },
- ],
- ];
+ ]}
+ />
+ );
},
}),
],
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx
index b2eb19f7c..395ac80cf 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx
@@ -18,10 +18,12 @@ import { useStockLocations } from "../../../../../../hooks/api/stock-locations"
type EditInventoryItemAttributeFormProps = {
item: AdminInventoryItem
locations: AdminStockLocation[]
+ sellerId?: string
}
export const ManageLocationsForm = ({
item,
+ sellerId,
}: EditInventoryItemAttributeFormProps) => {
const existingLocationLevels = useMemo(
() => new Set(item.location_levels?.map((l) => l.location_id) ?? []),
@@ -136,24 +138,31 @@ export const ManageLocationsForm = ({
HttpTypes.AdminStockLocation,
HttpTypes.AdminStockLocationListParams
>
- queryKey={["stock-locations", searchQuery]}
+ queryKey={["stock-locations", searchQuery, sellerId ?? "all"]}
queryFn={async (params) => {
+ // Only the item's store may stock it — scope to that seller's
+ // warehouses via the admin stock-locations `seller_id` filter.
const response = await sdk.admin.stockLocations.query({
limit: params.limit,
offset: params.offset,
+ ...(sellerId && { seller_id: sellerId }),
...(searchQuery && { q: searchQuery }),
+ } as HttpTypes.AdminStockLocationListParams & {
+ seller_id?: string
})
return response
}}
responseKey="stock_locations"
renderItem={(location) => (
- <LocationItem
- selected={selectedLocationIds.has(location.id)}
- location={location}
- onSelect={(selected) =>
- handleLocationSelect(location.id, selected)
- }
- />
+ <div className="pb-2 last:pb-0">
+ <LocationItem
+ selected={selectedLocationIds.has(location.id)}
+ location={location}
+ onSelect={(selected) =>
+ handleLocationSelect(location.id, selected)
+ }
+ />
+ </div>
)}
renderEmpty={() => (
<div className="flex items-center justify-center py-8" data-testid="inventory-manage-locations-form-empty-state">
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/manage-locations-drawer.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/manage-locations-drawer.tsx
index 556163109..b003a316b 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/manage-locations-drawer.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/manage-locations/manage-locations-drawer.tsx
@@ -16,7 +16,9 @@ export const ManageLocationsDrawer = () => {
isPending: isLoading,
isError,
error,
- } = useInventoryItem(id!)
+ } = useInventoryItem(id!, {
+ fields: "id,sku,title,*location_levels,offers.seller_id",
+ })
const { stock_locations, isLoading: loadingLocations } = useStockLocations()
@@ -27,13 +29,21 @@ export const ManageLocationsDrawer = () => {
throw error
}
+ const sellerId = (
+ inventoryItem as { offers?: { seller_id: string }[] } | undefined
+ )?.offers?.[0]?.seller_id
+
return (
<RouteDrawer data-testid="inventory-manage-locations-drawer">
<RouteDrawer.Header data-testid="inventory-manage-locations-drawer-header">
<Heading data-testid="inventory-manage-locations-drawer-title">{t("inventory.manageLocations")}</Heading>
</RouteDrawer.Header>
{ready && (
- <ManageLocationsForm item={inventoryItem} locations={stock_locations} />
+ <ManageLocationsForm
+ item={inventoryItem}
+ locations={stock_locations}
+ sellerId={sellerId}
+ />
)}
</RouteDrawer>
)
diff --git a/packages/admin/src/pages/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx b/packages/admin/src/pages/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx
index aff5f1c9d..31f67f057 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx
@@ -16,9 +16,20 @@ export const ReservationActions = ({
const { mutateAsync } = useDeleteReservationItem(reservation.id)
const handleDelete = async () => {
+ if (reservation.line_item_id) {
+ await prompt({
+ title: t("inventory.reservation.deleteTitle"),
+ description: t("inventory.reservation.deleteBlockedDescription"),
+ confirmText: t("inventory.reservation.gotIt"),
+ cancelText: t("actions.cancel"),
+ })
+
+ return
+ }
+
const res = await prompt({
- title: t("general.areYouSure"),
- description: t("inventory.deleteWarning"),
+ title: t("inventory.reservation.deleteTitle"),
+ description: t("inventory.reservation.deleteDescription"),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
})
diff --git a/packages/admin/src/pages/inventory/inventory-detail/constants.ts b/packages/admin/src/pages/inventory/inventory-detail/constants.ts
index 5e4988ae0..4da1dd317 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/constants.ts
+++ b/packages/admin/src/pages/inventory/inventory-detail/constants.ts
@@ -1,2 +1,2 @@
export const INVENTORY_DETAIL_FIELDS =
- "*variants,*variants.product,*variants.options"
+ "*variants,*variants.product,*variants.options,+offers.id,+offers.sku,+offers.seller_id,+offers.product_id,+offers.product_variant.title,+offers.product_variant.product.title,+offers.product_variant.product.thumbnail"
diff --git a/packages/admin/src/pages/inventory/inventory-detail/inventory-detail.tsx b/packages/admin/src/pages/inventory/inventory-detail/inventory-detail.tsx
index 6263231e6..1b603085d 100644
--- a/packages/admin/src/pages/inventory/inventory-detail/inventory-detail.tsx
+++ b/packages/admin/src/pages/inventory/inventory-detail/inventory-detail.tsx
@@ -11,7 +11,7 @@ import { InventoryItemAttributeSection } from "./components/inventory-item-attri
import { InventoryItemGeneralSection } from "./components/inventory-item-general-section"
import { InventoryItemLocationLevelsSection } from "./components/inventory-item-location-levels"
import { InventoryItemReservationsSection } from "./components/inventory-item-reservations"
-import { InventoryItemVariantsSection } from "./components/inventory-item-variants/variants-section"
+import { AssociatedOffersSection } from "./components/inventory-item-offers/associated-offers-section"
import { INVENTORY_DETAIL_FIELDS } from "./constants"
import type { inventoryItemLoader } from "./loader"
@@ -67,12 +67,7 @@ const Root = ({ children }: { children?: ReactNode }) => {
</TwoColumnPage.Main>
<TwoColumnPage.Sidebar data-testid="inventory-detail-sidebar">
<WidgetZone id="inventory.detail.side" data={inventory_item}>
- {inventory_item.variants &&
- inventory_item.variants?.length > 0 && (
- <InventoryItemVariantsSection
- variants={inventory_item.variants}
- />
- )}
+ <AssociatedOffersSection offers={inventory_item.offers} />
<InventoryItemAttributeSection inventoryItem={inventory_item} />
</WidgetZone>
</TwoColumnPage.Sidebar>
@@ -86,6 +81,6 @@ export const InventoryDetailPage = Object.assign(Root, {
MainGeneralSection: InventoryItemGeneralSection,
MainLocationLevelsSection: InventoryItemLocationLevelsSection,
MainReservationsSection: InventoryItemReservationsSection,
- SidebarVariantsSection: InventoryItemVariantsSection,
+ SidebarOffersSection: AssociatedOffersSection,
SidebarAttributeSection: InventoryItemAttributeSection,
})
diff --git a/packages/admin/src/pages/inventory/inventory-list/components/inventory-actions.tsx b/packages/admin/src/pages/inventory/inventory-list/components/inventory-actions.tsx
index c911c9859..86a639b04 100644
--- a/packages/admin/src/pages/inventory/inventory-list/components/inventory-actions.tsx
+++ b/packages/admin/src/pages/inventory/inventory-list/components/inventory-actions.tsx
@@ -3,7 +3,7 @@ import { PencilSquare, Trash } from "@medusajs/icons"
import { ActionMenu } from "../../../../components/common/action-menu"
import { InventoryItemDTO } from "@medusajs/types"
import { useDeleteInventoryItem } from "../../../../hooks/api/inventory"
-import { usePrompt } from "@medusajs/ui"
+import { toast, usePrompt } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
export const InventoryActions = ({ item }: { item: InventoryItemDTO }) => {
@@ -13,8 +13,8 @@ export const InventoryActions = ({ item }: { item: InventoryItemDTO }) => {
const handleDelete = async () => {
const res = await prompt({
- title: t("general.areYouSure"),
- description: t("inventory.deleteWarning"),
+ title: t("inventory.item.deleteTitle"),
+ description: t("inventory.item.deleteDescription"),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
})
@@ -23,7 +23,10 @@ export const InventoryActions = ({ item }: { item: InventoryItemDTO }) => {
return
}
- await mutateAsync()
+ await mutateAsync(undefined, {
+ onSuccess: () => toast.success(t("inventory.toast.deleteItem")),
+ onError: (e) => toast.error(e.message),
+ })
}
return (
diff --git a/packages/admin/src/pages/inventory/inventory-list/components/inventory-list-table.tsx b/packages/admin/src/pages/inventory/inventory-list/components/inventory-list-table.tsx
index 7170fd362..f19e26e4f 100644
--- a/packages/admin/src/pages/inventory/inventory-list/components/inventory-list-table.tsx
+++ b/packages/admin/src/pages/inventory/inventory-list/components/inventory-list-table.tsx
@@ -1,11 +1,11 @@
import { InventoryTypes, ProductVariantDTO } from "@medusajs/types"
-import { Button, Container, Heading, Text } from "@medusajs/ui"
+import { Container, Heading, Text } from "@medusajs/ui"
import { ColumnDef, RowSelectionState } from "@tanstack/react-table"
import { useExtendableTable, useLinkQuery } from "@mercurjs/dashboard-shared"
import { Children, ReactNode, useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
-import { Link, useNavigate } from "react-router-dom"
+import { useNavigate } from "react-router-dom"
import { _DataTable } from "../../../../components/table/data-table"
import { useInventoryItems } from "../../../../hooks/api/inventory"
import { useDataTable } from "../../../../hooks/use-data-table"
@@ -38,21 +38,12 @@ export const InventoryListTitle = () => {
)
}
-export const InventoryListCreateButton = () => {
- const { t } = useTranslation()
- return (
- <Button size="small" variant="secondary" asChild data-testid="inventory-create-button">
- <Link to="create" data-testid="inventory-create-link">{t("actions.create")}</Link>
- </Button>
- )
-}
-
export const InventoryListActions = ({ children }: { children?: ReactNode }) => {
- return (
- <div className="flex items-center gap-x-2">
- {Children.count(children) > 0 ? children : <InventoryListCreateButton />}
- </div>
- )
+ if (Children.count(children) === 0) {
+ return null
+ }
+
+ return <div className="flex items-center gap-x-2">{children}</div>
}
export const InventoryListHeader = ({ children }: { children?: ReactNode }) => {
@@ -91,7 +82,10 @@ export const InventoryListDataTable = () => {
error,
} = useInventoryItems({
...searchParams,
- ...useLinkQuery("inventory_item"),
+ ...useLinkQuery(
+ "inventory_item",
+ "+offers.product_variant.product.title,+seller.name"
+ ),
})
const baseFilters = useInventoryTableFilters()
@@ -150,6 +144,7 @@ export const InventoryListDataTable = () => {
{ key: "stocked_quantity", label: t("fields.inStock") },
{ key: "reserved_quantity", label: t("inventory.reserved") },
]}
+ defaultOrder="title"
navigateTo={(row) => `${row.id}`}
commands={[
{
diff --git a/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-columns.tsx b/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-columns.tsx
index 1583e45b4..8d196b442 100644
--- a/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-columns.tsx
+++ b/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-columns.tsx
@@ -1,4 +1,5 @@
import { InventoryTypes, ProductVariantDTO } from "@medusajs/types"
+import { OfferDTO, SellerDTO } from "@mercurjs/types"
import { Checkbox } from "@medusajs/ui"
import { createColumnHelper } from "@tanstack/react-table"
@@ -12,6 +13,8 @@ import { InventoryActions } from "./inventory-actions"
*/
interface ExtendedInventoryItem extends InventoryTypes.InventoryItemDTO {
variants?: ProductVariantDTO[] | null
+ offers?: OfferDTO[] | null
+ seller?: SellerDTO | null
stocked_quantity?: number
reserved_quantity?: number
}
@@ -103,16 +106,18 @@ export const useInventoryTableColumns = () => {
)
},
}),
- columnHelper.accessor("reserved_quantity", {
+ columnHelper.display({
+ id: "product",
header: () => (
- <div className="flex h-full w-full items-center" data-testid="inventory-table-header-reserved-quantity">
- <span data-testid="inventory-table-header-reserved-quantity-text">{t("inventory.reserved")}</span>
+ <div className="flex h-full w-full items-center" data-testid="inventory-table-header-product">
+ <span data-testid="inventory-table-header-product-text">{t("fields.product")}</span>
</div>
),
- cell: ({ getValue, row }) => {
- const quantity = getValue()
+ cell: ({ row }) => {
+ const productTitle =
+ row.original.offers?.[0]?.product_variant?.product?.title
- if (Number.isNaN(quantity)) {
+ if (!productTitle) {
return <PlaceholderCell />
}
@@ -120,9 +125,35 @@ export const useInventoryTableColumns = () => {
<div className="flex size-full items-center overflow-hidden">
<span
className="truncate"
- data-testid={`inventory-table-cell-${row.id}-reserved_quantity-value`}
+ data-testid={`inventory-table-cell-${row.id}-product-value`}
>
- {quantity}
+ {productTitle}
+ </span>
+ </div>
+ )
+ },
+ }),
+ columnHelper.display({
+ id: "store",
+ header: () => (
+ <div className="flex h-full w-full items-center" data-testid="inventory-table-header-store">
+ <span data-testid="inventory-table-header-store-text">{t("inventory.store")}</span>
+ </div>
+ ),
+ cell: ({ row }) => {
+ const store = row.original.seller?.name
+
+ if (!store) {
+ return <PlaceholderCell />
+ }
+
+ return (
+ <div className="flex size-full items-center overflow-hidden">
+ <span
+ className="truncate"
+ data-testid={`inventory-table-cell-${row.id}-store-value`}
+ >
+ {store}
</span>
</div>
)
@@ -153,6 +184,31 @@ export const useInventoryTableColumns = () => {
)
},
}),
+ columnHelper.accessor("reserved_quantity", {
+ header: () => (
+ <div className="flex h-full w-full items-center" data-testid="inventory-table-header-reserved-quantity">
+ <span data-testid="inventory-table-header-reserved-quantity-text">{t("inventory.reserved")}</span>
+ </div>
+ ),
+ cell: ({ getValue, row }) => {
+ const quantity = getValue()
+
+ if (Number.isNaN(quantity)) {
+ return <PlaceholderCell />
+ }
+
+ return (
+ <div className="flex size-full items-center overflow-hidden">
+ <span
+ className="truncate"
+ data-testid={`inventory-table-cell-${row.id}-reserved_quantity-value`}
+ >
+ {quantity}
+ </span>
+ </div>
+ )
+ },
+ }),
columnHelper.display({
id: "actions",
header: () => (
diff --git a/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-filters.tsx b/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-filters.tsx
index e2be67e1b..9c3b5856b 100644
--- a/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-filters.tsx
+++ b/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-filters.tsx
@@ -1,4 +1,5 @@
import { Filter } from "../../../../components/table/data-table"
+import { useSellers } from "../../../../hooks/api/sellers"
import { useStockLocations } from "../../../../hooks/api/stock-locations"
import { useTranslation } from "react-i18next"
@@ -7,11 +8,31 @@ export const useInventoryTableFilters = () => {
const { stock_locations } = useStockLocations({
limit: 1000,
})
+ const { sellers } = useSellers({ limit: 1000 })
const filters: Filter[] = []
+ filters.push({
+ type: "string",
+ key: "sku",
+ label: t("fields.sku"),
+ })
+
+ if (sellers) {
+ filters.push({
+ type: "select",
+ options: sellers.map((s) => ({
+ label: s.name,
+ value: s.id,
+ })),
+ key: "seller_id",
+ searchable: true,
+ label: t("inventory.store"),
+ })
+ }
+
if (stock_locations) {
- const stockLocationFilter: Filter = {
+ filters.push({
type: "select",
options: stock_locations.map((s) => ({
label: s.name,
@@ -20,29 +41,9 @@ export const useInventoryTableFilters = () => {
key: "location_id",
searchable: true,
label: t("fields.location"),
- }
-
- filters.push(stockLocationFilter)
+ })
}
- filters.push({
- type: "string",
- key: "material",
- label: t("fields.material"),
- })
-
- filters.push({
- type: "string",
- key: "sku",
- label: t("fields.sku"),
- })
-
- filters.push({
- type: "string",
- key: "mid_code",
- label: t("fields.midCode"),
- })
-
filters.push({
type: "number",
key: "height",
@@ -56,26 +57,15 @@ export const useInventoryTableFilters = () => {
})
filters.push({
- type: "number",
- key: "length",
- label: t("fields.length"),
- })
-
- filters.push({
- type: "number",
- key: "weight",
- label: t("fields.weight"),
+ type: "string",
+ key: "mid_code",
+ label: t("fields.midCode"),
})
filters.push({
- type: "select",
- options: [
- { label: t("fields.true"), value: "true" },
- { label: t("fields.false"), value: "false" },
- ],
- key: "requires_shipping",
- multiple: false,
- label: t("fields.requiresShipping"),
+ type: "string",
+ key: "material",
+ label: t("fields.material"),
})
return filters
diff --git a/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-query.tsx b/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-query.tsx
index acf886a72..9721d3d59 100644
--- a/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-query.tsx
+++ b/packages/admin/src/pages/inventory/inventory-list/components/use-inventory-table-query.tsx
@@ -13,53 +13,39 @@ export const useInventoryTableQuery = ({
[
"id",
"location_id",
+ "seller_id",
"q",
"order",
- "requires_shipping",
"offset",
"sku",
- "origin_country",
"material",
"mid_code",
"hs_code",
- "order",
- "weight",
"width",
- "length",
"height",
],
prefix
)
- const {
- offset,
- weight,
- width,
- length,
- height,
- requires_shipping,
- ...params
- } = raw
+ const { offset, width, height, ...params } = raw
- const searchParams: HttpTypes.AdminInventoryItemParams = {
+ const searchParams: HttpTypes.AdminInventoryItemsParams & {
+ seller_id?: string[]
+ } = {
limit: pageSize,
offset: offset ? parseInt(offset) : undefined,
- weight: weight ? JSON.parse(weight) : undefined,
width: width ? JSON.parse(width) : undefined,
- length: length ? JSON.parse(length) : undefined,
height: height ? JSON.parse(height) : undefined,
- requires_shipping: requires_shipping
- ? JSON.parse(requires_shipping)
- : undefined,
q: params.q,
sku: params.sku,
- order: params.order,
+ order: params.order || "title",
mid_code: params.mid_code,
hs_code: params.hs_code,
material: params.material,
location_levels: {
location_id: params.location_id || [],
},
+ seller_id: params.seller_id ? params.seller_id.split(",") : undefined,
id: params.id ? params.id.split(",") : undefined,
}
diff --git a/packages/admin/src/pages/inventory/inventory-list/inventory-list.tsx b/packages/admin/src/pages/inventory/inventory-list/inventory-list.tsx
index 0613203ae..02c85be9b 100644
--- a/packages/admin/src/pages/inventory/inventory-list/inventory-list.tsx
+++ b/packages/admin/src/pages/inventory/inventory-list/inventory-list.tsx
@@ -8,7 +8,6 @@ import {
InventoryListHeader,
InventoryListTitle,
InventoryListActions,
- InventoryListCreateButton,
InventoryListDataTable,
} from "./components/inventory-list-table"
@@ -29,6 +28,5 @@ export const InventoryListPage = Object.assign(Root, {
Header: InventoryListHeader,
HeaderTitle: InventoryListTitle,
HeaderActions: InventoryListActions,
- HeaderCreateButton: InventoryListCreateButton,
DataTable: InventoryListDataTable,
})
diff --git a/packages/admin/src/pages/inventory/inventory-stock/components/inventory-stock-form/inventory-stock-form.tsx b/packages/admin/src/pages/inventory/inventory-stock/components/inventory-stock-form/inventory-stock-form.tsx
index 37ce62803..d8ad87e53 100644
--- a/packages/admin/src/pages/inventory/inventory-stock/components/inventory-stock-form/inventory-stock-form.tsx
+++ b/packages/admin/src/pages/inventory/inventory-stock/components/inventory-stock-form/inventory-stock-form.tsx
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod"
import { HttpTypes } from "@medusajs/types"
-import { Button, toast } from "@medusajs/ui"
+import { Button, toast, usePrompt } from "@medusajs/ui"
import { useRef } from "react"
import { DefaultValues, useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
@@ -30,6 +30,7 @@ export const InventoryStockForm = ({
}: InventoryStockFormProps) => {
const { t } = useTranslation()
const { setCloseOnEscape, handleSuccess } = useRouteModal()
+ const prompt = usePrompt()
const initialValues = useRef(getDefaultValues(items, locations))
@@ -89,6 +90,17 @@ export const InventoryStockForm = ({
}
}
+ const confirmed = await prompt({
+ title: t("inventory.stock.confirmTitle"),
+ description: t("inventory.stock.confirmDescription"),
+ confirmText: t("actions.continue"),
+ cancelText: t("actions.cancel"),
+ })
+
+ if (!confirmed) {
+ return
+ }
+
await mutateAsync(payload, {
onSuccess: () => {
toast.success(t("inventory.stock.successToast"))
diff --git a/packages/admin/src/pages/inventory/inventory-stock/inventory-stock.tsx b/packages/admin/src/pages/inventory/inventory-stock/inventory-stock.tsx
index 4abc69310..0e18dee58 100644
--- a/packages/admin/src/pages/inventory/inventory-stock/inventory-stock.tsx
+++ b/packages/admin/src/pages/inventory/inventory-stock/inventory-stock.tsx
@@ -1,3 +1,4 @@
+import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next"
import { useSearchParams } from "react-router-dom"
import { RouteFocusModal } from "../../../components/modals"
@@ -13,6 +14,7 @@ export const InventoryStock = () => {
const { inventory_items, isPending, isError, error } = useInventoryItems({
id: inventoryItemIds,
+ fields: "id,sku,title,*location_levels,offers.seller_id",
})
const {
@@ -22,7 +24,7 @@ export const InventoryStock = () => {
error: errorStockLocations,
} = useStockLocations({
limit: 9999,
- fields: "id,name",
+ fields: "id,name,seller.id",
})
const ready =
@@ -39,6 +41,19 @@ export const InventoryStock = () => {
throw errorStockLocations
}
+ // Scope the location columns to the warehouses owned by the sellers behind
+ // the selected items' offers — a store can only stock at its own locations.
+ const sellerIds = new Set(
+ ((inventory_items ?? []) as Array<{ offers?: { seller_id: string }[] }>)
+ .flatMap((item) => item.offers ?? [])
+ .map((offer) => offer.seller_id)
+ )
+ const scopedLocations = (
+ (stock_locations ?? []) as Array<
+ HttpTypes.AdminStockLocation & { seller?: { id: string } }
+ >
+ ).filter((loc) => !!loc.seller?.id && sellerIds.has(loc.seller.id))
+
return (
<RouteFocusModal>
<RouteFocusModal.Title asChild>
@@ -48,10 +63,7 @@ export const InventoryStock = () => {
<span className="sr-only">{t("inventory.stock.description")}</span>
</RouteFocusModal.Description>
{ready && (
- <InventoryStockForm
- items={inventory_items}
- locations={stock_locations}
- />
+ <InventoryStockForm items={inventory_items} locations={scopedLocations} />
)}
</RouteFocusModal>
)
diff --git a/packages/admin/src/pages/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx b/packages/admin/src/pages/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx
index 1b688e1c8..240e3bcba 100644
--- a/packages/admin/src/pages/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx
+++ b/packages/admin/src/pages/reservations/reservation-create/components/reservation-create-from/reservation-create-from.tsx
@@ -1,6 +1,6 @@
import * as zod from "zod"
-import { Button, Heading, Input, Text, Textarea, toast } from "@medusajs/ui"
+import { Button, Heading, InlineTip, Input, Text, Textarea, toast } from "@medusajs/ui"
import {
RouteFocusModal,
useRouteModal,
@@ -18,13 +18,6 @@ import { useInventoryItems } from "../../../../../hooks/api/inventory"
import { useCreateReservationItem } from "../../../../../hooks/api/reservations"
import { useStockLocations } from "../../../../../hooks/api/stock-locations"
-export const CreateReservationSchema = zod.object({
- inventory_item_id: zod.string().min(1),
- location_id: zod.string().min(1),
- quantity: zod.number().min(1),
- description: zod.string().optional(),
-})
-
const AttributeGridRow = ({
title,
value,
@@ -44,6 +37,20 @@ const AttributeGridRow = ({
)
}
+const buildCreateReservationSchema = (t: (key: string) => string) =>
+ zod.object({
+ inventory_item_id: zod
+ .string()
+ .min(1, t("inventory.reservation.errors.idRequired")),
+ location_id: zod
+ .string()
+ .min(1, t("inventory.reservation.errors.selectLocation")),
+ quantity: zod
+ .number()
+ .min(1, t("inventory.reservation.errors.enterQuantity")),
+ description: zod.string().optional(),
+ })
+
export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
const { t } = useTranslation()
const { handleSuccess } = useRouteModal()
@@ -51,6 +58,8 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
null
)
+ const CreateReservationSchema = buildCreateReservationSchema(t)
+
const form = useForm<zod.infer<typeof CreateReservationSchema>>({
defaultValues: {
inventory_item_id: props.inventoryItemId ?? undefined,
@@ -61,10 +70,28 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
resolver: zodResolver(CreateReservationSchema),
})
- const { inventory_items } = useInventoryItems({
+ const { inventory_items: searchedItems } = useInventoryItems({
q: inventorySearch,
})
+ // The preselected item (from `?item_id=`) may not be in the search results,
+ // so fetch it explicitly and merge it into the options so it stays selected.
+ const { inventory_items: presetItems } = useInventoryItems(
+ {
+ id: props.inventoryItemId ? [props.inventoryItemId] : undefined,
+ fields: "id,sku,title,*location_levels",
+ },
+ { enabled: !!props.inventoryItemId }
+ )
+
+ const inventory_items = React.useMemo(() => {
+ const byId = new Map<string, NonNullable<typeof searchedItems>[number]>()
+ ;[...(presetItems ?? []), ...(searchedItems ?? [])].forEach((it) =>
+ byId.set(it.id, it)
+ )
+ return Array.from(byId.values())
+ }, [presetItems, searchedItems])
+
const inventoryItemId = form.watch("inventory_item_id")
const selectedInventoryItem = inventory_items?.find(
(it) => it.id === inventoryItemId
@@ -172,6 +199,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
)}
/>
</Form.Control>
+ <Form.ErrorMessage />
</Form.Item>
)
}}
@@ -200,6 +228,7 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
)}
/>
</Form.Control>
+ <Form.ErrorMessage />
</Form.Item>
)
}}
@@ -286,6 +315,9 @@ export const ReservationCreateForm = (props: { inventoryItemId?: string }) => {
)
}}
/>
+ <InlineTip variant="warning" label={t("general.warning")}>
+ {t("inventory.reservation.storeLocationWarning")}
+ </InlineTip>
</div>
</RouteFocusModal.Body>
<RouteFocusModal.Footer>
diff --git a/packages/core/src/api/admin/inventory-items/middlewares.ts b/packages/core/src/api/admin/inventory-items/middlewares.ts
new file mode 100644
index 000000000..88ac4c7f2
--- /dev/null
+++ b/packages/core/src/api/admin/inventory-items/middlewares.ts
@@ -0,0 +1,67 @@
+import {
+ AuthenticatedMedusaRequest,
+ maybeApplyLinkFilter,
+ MedusaNextFunction,
+ MedusaResponse,
+ MiddlewareRoute,
+} from "@medusajs/framework/http"
+import { validateAndTransformQuery } from "@medusajs/framework"
+import { z } from "zod"
+import { AdminGetInventoryItemsParams } from "@medusajs/medusa/api/admin/inventory-items/validators"
+import { listTransformQueryConfig } from "@medusajs/medusa/api/admin/inventory-items/query-config"
+
+import { ORIGINAL_MIDDLEWARES } from "../../../utils/disable-medusa-middlewares"
+
+const LIST_MATCHER = "/admin/inventory-items"
+
+const capturedBase = (ORIGINAL_MIDDLEWARES[
+ "dist/api/admin/inventory-items/middlewares.js"
+] ?? []) as MiddlewareRoute[]
+
+const baseWithoutListGet = capturedBase.filter((route) => {
+ if (route.matcher !== LIST_MATCHER) return true
+ const methods = Array.isArray(route.method)
+ ? route.method
+ : route.method
+ ? [route.method]
+ : []
+ return !methods.includes("GET")
+})
+
+const AdminGetInventoryItemsParamsWithSeller =
+ AdminGetInventoryItemsParams.merge(
+ z.object({
+ seller_id: z.union([z.string(), z.array(z.string())]).optional(),
+ })
+ )
+
+const maybeApplySellerInventoryFilter = (
+ req: AuthenticatedMedusaRequest,
+ res: MedusaResponse,
+ next: MedusaNextFunction
+) => {
+ if (!req.filterableFields.seller_id) {
+ return next()
+ }
+
+ return maybeApplyLinkFilter({
+ entryPoint: "inventory_item_seller",
+ resourceId: "inventory_item_id",
+ filterableField: "seller_id",
+ })(req, res, next)
+}
+
+export const adminInventoryItemsMiddlewares: MiddlewareRoute[] = [
+ ...baseWithoutListGet,
+ {
+ method: ["GET"],
+ matcher: LIST_MATCHER,
+ middlewares: [
+ validateAndTransformQuery(
+ AdminGetInventoryItemsParamsWithSeller,
+ listTransformQueryConfig
+ ),
+ maybeApplySellerInventoryFilter,
+ ],
+ },
+]
diff --git a/packages/core/src/api/admin/middlewares.ts b/packages/core/src/api/admin/middlewares.ts
index c94574bf2..145ae68ce 100644
--- a/packages/core/src/api/admin/middlewares.ts
+++ b/packages/core/src/api/admin/middlewares.ts
@@ -20,6 +20,7 @@ import { adminProductCategoriesMiddlewares } from "./product-categories/middlewa
import { adminProductAttributesMiddlewares } from "./product-attributes/middlewares"
import { adminProductChangesMiddlewares } from "./product-changes/middlewares"
import { adminStockLocationsMiddlewares } from "./stock-locations/middlewares"
+import { adminInventoryItemsMiddlewares } from "./inventory-items/middlewares"
import { adminShippingOptionsMiddlewares } from "./shipping-options/middlewares"
import { adminShippingProfilesMiddlewares } from "./shipping-profiles/middlewares"
import { adminReviewsMiddlewares } from "./reviews/middlewares"
@@ -51,6 +52,7 @@ export const adminMiddlewares: MiddlewareRoute[] = [
...adminProductAttributesMiddlewares,
...adminProductChangesMiddlewares,
...adminStockLocationsMiddlewares,
+ ...adminInventoryItemsMiddlewares,
...adminShippingOptionsMiddlewares,
...adminShippingProfilesMiddlewares,
...adminReviewsMiddlewares,
diff --git a/packages/core/src/utils/disable-medusa-middlewares.ts b/packages/core/src/utils/disable-medusa-middlewares.ts
index 79fa0f715..9fe5d263b 100644
--- a/packages/core/src/utils/disable-medusa-middlewares.ts
+++ b/packages/core/src/utils/disable-medusa-middlewares.ts
@@ -35,6 +35,7 @@ const OVERRIDES: string[] = [
"dist/api/admin/shipping-options/middlewares.js",
"dist/api/admin/shipping-profiles/middlewares.js",
"dist/api/admin/stock-locations/middlewares.js",
+ "dist/api/admin/inventory-items/middlewares.js",
"dist/api/store/products/middlewares.js",
"dist/api/store/product-categories/middlewares.js",
"dist/api/store/product-variants/middlewares.js",