The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
Feat/products compound components (#752)
Jakub Sieradzkicfaa71178f27
diff --git a/apps/docs/docs/product/subscribers/core.mdx b/apps/docs/docs/product/subscribers/core.mdxindex 37e0ca192..af260513e 100644--- a/apps/docs/docs/product/subscribers/core.mdx+++ b/apps/docs/docs/product/subscribers/core.mdx@@ -286,7 +286,7 @@ These subscribers maintain search index synchronization by listening to intermedUpdates product indexes when fulfillment set configurations change.-**Event**: `algolia.intermediate.fulfillment_set.changed` (IntermediateEvents.FULFULLMENT_SET_CHANGED)\+**Event**: `algolia.intermediate.fulfillment_set.changed` (IntermediateEvents.FULFILLMENT_SET_CHANGED)\**Source**: `packages/modules/b2c-core/src/subscribers/algolia-fulfillment-set-changed.ts`#### Functionalitydiff --git a/packages/admin/src/components/tabbed-form/index.ts b/packages/admin/src/components/tabbed-form/index.tsindex 6e9ac79c3..89914d67a 100644--- a/packages/admin/src/components/tabbed-form/index.ts+++ b/packages/admin/src/components/tabbed-form/index.ts@@ -1,3 +1,4 @@export { TabbedForm, useTabbedForm } from "./tabbed-form"+export { defineTabMeta } from "./types"export type { TabDefinition } from "./types"export { useTabManagement } from "./use-tab-management"diff --git a/packages/admin/src/components/tabbed-form/tabbed-form.tsx b/packages/admin/src/components/tabbed-form/tabbed-form.tsxindex 59be84589..4b080283f 100644--- a/packages/admin/src/components/tabbed-form/tabbed-form.tsx+++ b/packages/admin/src/components/tabbed-form/tabbed-form.tsx@@ -36,10 +36,28 @@ function resolveTabMeta<T extends FieldValues>(return null}+ const id = child.props?.id ?? meta?.id ?? ""+ const labelKey = meta?.labelKey ?? ""+ const label = child.props?.label++ if (process.env.NODE_ENV !== "production") {+ if (!id) {+ console.warn(+ "[TabbedForm] A child component is missing a tab id. " ++ "Either set _tabMeta.id or pass an id prop."+ )+ }+ if (!labelKey && !label) {+ console.warn(+ `[TabbedForm] Tab "${id}" has no label or labelKey — header will be empty.`+ )+ }+ }+return {- id: child.props?.id ?? meta?.id ?? "",- labelKey: meta?.labelKey ?? "",- label: child.props?.label,+ id,+ labelKey,+ label,validationFields: child.props?.validationFields ?? meta?.validationFields,isVisible: child.props?.isVisible ?? meta?.isVisible,}@@ -135,6 +153,10 @@ function Root<T extends FieldValues>({e.preventDefault()if (e.metaKey || e.ctrlKey) {+ if (isLoading) {+ return+ }+if (!isLastTab) {e.preventDefault()e.stopPropagation()diff --git a/packages/admin/src/components/tabbed-form/types.ts b/packages/admin/src/components/tabbed-form/types.tsindex c65cbaf08..9f5c44b87 100644--- a/packages/admin/src/components/tabbed-form/types.ts+++ b/packages/admin/src/components/tabbed-form/types.ts@@ -1,9 +1,43 @@import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"export interface TabDefinition<T extends FieldValues = FieldValues> {+ /** Unique tab identifier, used as ProgressTabs value */id: string+ /** i18n key for the tab label (used when `label` is not provided) */labelKey: string+ /** Raw label string (overrides `labelKey`) */label?: string+ /** Fields validated when navigating forward from this tab. If omitted, full form validation is used. */validationFields?: FieldPath<T>[]+ /** Predicate to conditionally show/hide this tab at runtime */isVisible?: (form: UseFormReturn<T>) => boolean}++/**+ * Helper to declare tab metadata on a component with type safety.+ *+ * Usage:+ * ```ts+ * const MyTab = () => { ... }+ * MyTab._tabMeta = defineTabMeta<MyFormSchema>({+ * id: "details",+ * labelKey: "products.create.tabs.details",+ * validationFields: ["title", "handle"],+ * })+ * ```+ */+export const defineTabMeta = <T extends FieldValues = FieldValues>(+ meta: TabDefinition<T>+): TabDefinition<T> => {+ if (process.env.NODE_ENV !== "production") {+ if (!meta.id) {+ console.warn("[TabbedForm] Tab meta is missing required 'id' field")+ }+ if (!meta.labelKey && !meta.label) {+ console.warn(+ `[TabbedForm] Tab "${meta.id}" has neither 'labelKey' nor 'label' — the tab header will be empty`+ )+ }+ }+ return meta+}diff --git a/packages/admin/src/components/tabbed-form/use-tab-management.ts b/packages/admin/src/components/tabbed-form/use-tab-management.tsindex fe5a8ac1b..64974f487 100644--- a/packages/admin/src/components/tabbed-form/use-tab-management.ts+++ b/packages/admin/src/components/tabbed-form/use-tab-management.ts@@ -1,11 +1,44 @@import { ProgressStatus } from "@medusajs/ui"import { useCallback, useEffect, useMemo, useState } from "react"-import { FieldValues, UseFormReturn } from "react-hook-form"+import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"import { TabDefinition } from "./types"type TabState = Record<string, ProgressStatus>+/**+ * Validates fields for a specific tab. If the tab declares `validationFields`,+ * only those fields are validated. Otherwise falls back to full form validation.+ */+const validateTab = async <T extends FieldValues>(+ form: UseFormReturn<T>,+ tab: TabDefinition<T>+): Promise<boolean> => {+ if (tab.validationFields?.length) {+ return form.trigger(tab.validationFields as FieldPath<T>[])+ }+ return form.trigger()+}++/**+ * Validates all tabs from `fromIndex` to `toIndex` (inclusive) sequentially.+ * Returns false on the first tab that fails validation.+ */+const validateTabRange = async <T extends FieldValues>(+ form: UseFormReturn<T>,+ tabs: TabDefinition<T>[],+ fromIndex: number,+ toIndex: number+): Promise<boolean> => {++ for (let i = fromIndex; i <= toIndex; i++) {+ if (!(await validateTab(form, tabs[i]))) {+ return false+ }+ }+ return true+}+export const useTabManagement = <T extends FieldValues>({tabs,form,@@ -31,13 +64,23 @@ export const useTabManagement = <T extends FieldValues>({})useEffect(() => {+ let resolvedActiveId = activeTabId+ const activeExists = visibleTabs.some((t) => t.id === activeTabId)++ if (!activeExists && visibleTabs.length > 0) {+ resolvedActiveId = visibleTabs[0].id+ setActiveTabId(resolvedActiveId)+ }+const newState: TabState = {}- const activeIndex = visibleTabs.findIndex((t) => t.id === activeTabId)+ const resolvedIndex = visibleTabs.findIndex(+ (t) => t.id === resolvedActiveId+ )visibleTabs.forEach((t, i) => {- if (i < activeIndex) {+ if (i < resolvedIndex) {newState[t.id] = "completed"- } else if (i === activeIndex) {+ } else if (i === resolvedIndex) {newState[t.id] = "in-progress"} else {newState[t.id] = tabState[t.id] ?? "not-started"@@ -52,11 +95,11 @@ export const useTabManagement = <T extends FieldValues>({const isLastTab = activeIndex === visibleTabs.length - 1const onNext = useCallback(async () => {- const valid = await form.trigger()+ const currentTab = visibleTabs[activeIndex]+ if (!currentTab) return- if (!valid) {- return- }+ const valid = await validateTab(form, currentTab)+ if (!valid) returnif (activeIndex < visibleTabs.length - 1) {setActiveTabId(visibleTabs[activeIndex + 1].id)@@ -65,15 +108,34 @@ export const useTabManagement = <T extends FieldValues>({const onTabChange = useCallback(async (tabId: string) => {- const valid = await form.trigger()+ const targetIndex = visibleTabs.findIndex((t) => t.id === tabId)+ if (targetIndex === -1) return++ const currentIndex = visibleTabs.findIndex(+ (t) => t.id === activeTabId+ )- if (!valid) {+ if (currentIndex === -1) {+ setActiveTabId(tabId)return}+ if (targetIndex <= currentIndex) {+ setActiveTabId(tabId)+ return+ }++ const valid = await validateTabRange(+ form,+ visibleTabs,+ currentIndex,+ targetIndex - 1+ )+ if (!valid) return+setActiveTabId(tabId)},- [form]+ [form, visibleTabs, activeTabId])return {diff --git a/packages/admin/src/pages/index.ts b/packages/admin/src/pages/index.tsnew file mode 100644index 000000000..8fd1f0779--- /dev/null+++ b/packages/admin/src/pages/index.ts@@ -0,0 +1,5 @@+export { ProductDetailPage } from "./products/product-detail/product-detail"+export { ProductListPage } from "./products/product-list/product-list"+export { ProductVariantDetailPage } from "./product-variants/product-variant-detail/product-variant-detail"+export { OrderDetail } from "./orders/order-detail/order-detail"+export { OrderList } from "./orders/order-list/order-list"diff --git a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-general-section/variant-general-section.tsx b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-general-section/variant-general-section.tsxindex b2000ddce..bafaea4b2 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-general-section/variant-general-section.tsx+++ b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-general-section/variant-general-section.tsx@@ -1,23 +1,23 @@import { Component, PencilSquare, Trash } from "@medusajs/icons"-import { HttpTypes } from "@medusajs/types"import { Badge, Container, Heading, usePrompt } from "@medusajs/ui"import { useTranslation } from "react-i18next"import { useNavigate } from "react-router-dom"+import { HttpTypes } from "@medusajs/types"import { ActionMenu } from "../../../../../components/common/action-menu"import { SectionRow } from "../../../../../components/common/section"import { useDeleteVariant } from "../../../../../hooks/api/products"-type VariantGeneralSectionProps = {- variant: HttpTypes.AdminProductVariant-}--export function VariantGeneralSection({ variant }: VariantGeneralSectionProps) {+export function VariantGeneralSection({+ variant,+}: {+ variant: HttpTypes.AdminProductVariant;+}) {const { t } = useTranslation()const prompt = usePrompt()const navigate = useNavigate()- const hasInventoryKit = variant.inventory?.length > 1+ const hasInventoryKit = (variant.inventory_items?.length ?? 0) > 1const { mutateAsync } = useDeleteVariant(variant.product_id!, variant.id)diff --git a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/inventory-actions.tsx b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/inventory-actions.tsxindex f3caba5c0..19e282222 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/inventory-actions.tsx+++ b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/inventory-actions.tsx@@ -1,11 +1,11 @@import { useTranslation } from "react-i18next"import { Buildings } from "@medusajs/icons"-import { InventoryItemDTO } from "@medusajs/types"+import { HttpTypes } from "@medusajs/types"import { ActionMenu } from "../../../../../components/common/action-menu"-export const InventoryActions = ({ item }: { item: InventoryItemDTO }) => {+export const InventoryActions = ({ item }: { item: HttpTypes.AdminInventoryItem }) => {const { t } = useTranslation()return (diff --git a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/use-inventory-table-columns.tsx b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/use-inventory-table-columns.tsxindex 0767b09dd..5fb89921c 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/use-inventory-table-columns.tsx+++ b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/use-inventory-table-columns.tsx@@ -1,4 +1,4 @@-import { InventoryNext, ProductVariantDTO } from "@medusajs/types"+import { HttpTypes } from "@medusajs/types"import { InventoryActions } from "./inventory-actions"import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"@@ -6,8 +6,8 @@ import { createColumnHelper } from "@tanstack/react-table"import { useMemo } from "react"import { useTranslation } from "react-i18next"-interface ExtendedInventoryItem extends InventoryNext.InventoryItemDTO {- variants: ProductVariantDTO[]+interface ExtendedInventoryItem extends HttpTypes.AdminInventoryItem {+ required_quantity?: number}const columnHelper = createColumnHelper<ExtendedInventoryItem>()diff --git a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/variant-inventory-section.tsx b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/variant-inventory-section.tsxindex 249242678..5e654a788 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/variant-inventory-section.tsx+++ b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-inventory-section/variant-inventory-section.tsx@@ -17,6 +17,29 @@ type VariantInventorySectionProps = {inventoryItems: HttpTypes.AdminInventoryItem[]}+/**+ * Wrapper that handles manage_inventory gating and inventory_items mapping.+ */+export function VariantInventorySectionConnected({+ variant,+}: {+ variant: HttpTypes.AdminProductVariant;+}) {++ if (!variant.manage_inventory) {+ return <InventorySectionPlaceholder />+ }++ const inventoryItems =+ variant.inventory_items?.map((i) => ({+ ...i.inventory,+ required_quantity: i.required_quantity,+ variant,+ })) ?? []++ return <VariantInventorySection inventoryItems={inventoryItems as HttpTypes.AdminInventoryItem[]} />+}+export function VariantInventorySection({inventoryItems,}: VariantInventorySectionProps) {diff --git a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-prices-section/variant-prices-section.tsx b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-prices-section/variant-prices-section.tsxindex 1c2c85af1..8fef074d9 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-prices-section/variant-prices-section.tsx+++ b/packages/admin/src/pages/product-variants/product-variant-detail/components/variant-prices-section/variant-prices-section.tsx@@ -2,21 +2,21 @@ import { useState } from "react"import { useTranslation } from "react-i18next"import { CurrencyDollar } from "@medusajs/icons"-import { HttpTypes } from "@medusajs/types"import { Button, Container, Heading } from "@medusajs/ui"+import { HttpTypes } from "@medusajs/types"import { ActionMenu } from "../../../../../components/common/action-menu"import { NoRecords } from "../../../../../components/common/empty-table-content"import { getLocaleAmount } from "../../../../../lib/money-amount-helpers"-type VariantPricesSectionProps = {- variant: HttpTypes.AdminProductVariant-}--export function VariantPricesSection({ variant }: VariantPricesSectionProps) {+export function VariantPricesSection({+ variant,+}: {+ variant: HttpTypes.AdminProductVariant;+}) {const { t } = useTranslation()const prices = variant.prices- ?.filter((p) => !Object.keys(p.rules || {}).length)+ ?.filter((p) => !Object.keys(((p as unknown) as { rules?: Record<string, unknown> }).rules || {}).length).sort((p1, p2) => p1.currency_code?.localeCompare(p2.currency_code))const hasPrices = !!prices?.lengthdiff --git a/packages/admin/src/pages/product-variants/product-variant-detail/index.ts b/packages/admin/src/pages/product-variants/product-variant-detail/index.tsindex 73598d513..0c61f1856 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/index.ts+++ b/packages/admin/src/pages/product-variants/product-variant-detail/index.ts@@ -1,3 +1,3 @@export { ProductVariantDetailBreadcrumb as Breadcrumb } from "./breadcrumb"export { variantLoader as loader } from "./loader"-export { ProductVariantDetail as Component } from "./product-variant-detail"+export { ProductVariantDetailPage as Component } from "./product-variant-detail"diff --git a/packages/admin/src/pages/product-variants/product-variant-detail/product-variant-detail.tsx b/packages/admin/src/pages/product-variants/product-variant-detail/product-variant-detail.tsxindex 91fbacaa3..0c493e2e8 100644--- a/packages/admin/src/pages/product-variants/product-variant-detail/product-variant-detail.tsx+++ b/packages/admin/src/pages/product-variants/product-variant-detail/product-variant-detail.tsx@@ -1,3 +1,4 @@+import { Children, ReactNode } from "react"import { useLoaderData, useParams } from "react-router-dom"import { useProduct, useProductVariant } from "../../../hooks/api/products"@@ -6,16 +7,13 @@ import { TwoColumnPageSkeleton } from "../../../components/common/skeleton"import { TwoColumnPage } from "../../../components/layout/pages"import { VariantGeneralSection } from "./components/variant-general-section"-import {- InventorySectionPlaceholder,- VariantInventorySection,-} from "./components/variant-inventory-section"+import { VariantInventorySectionConnected } from "./components/variant-inventory-section"import { VariantPricesSection } from "./components/variant-prices-section"import { ProductSellerSection } from "../../products/product-detail/components/product-seller-section/product-seller-section"import { VARIANT_DETAIL_FIELDS } from "./constants"import { variantLoader } from "./loader"-export const ProductVariantDetail = () => {+const Root = ({ children }: { children?: ReactNode }) => {const initialData = useLoaderData() as Awaited<ReturnType<typeof variantLoader>>@@ -48,28 +46,15 @@ export const ProductVariantDetail = () => {throw error}- return (- <TwoColumnPage- data={variant}- hasOutlet- showJSON- showMetadata- >+ return Children.count(children) > 0 ? (+ <TwoColumnPage>+ {children}+ </TwoColumnPage>+ ) : (+ <TwoColumnPage data={variant} showJSON showMetadata hasOutlet><TwoColumnPage.Main><VariantGeneralSection variant={variant} />- {!variant.manage_inventory ? (- <InventorySectionPlaceholder />- ) : (- <VariantInventorySection- inventoryItems={variant.inventory_items?.map((i) => {- return {- ...i.inventory,- required_quantity: i.required_quantity,- variant,- }- }) ?? []}- />- )}+ <VariantInventorySectionConnected variant={variant} /></TwoColumnPage.Main><TwoColumnPage.Sidebar><ProductSellerSection seller={(product as any)?.seller} />@@ -78,3 +63,12 @@ export const ProductVariantDetail = () => {</TwoColumnPage>)}++export const ProductVariantDetailPage = Object.assign(Root, {+ Main: TwoColumnPage.Main,+ Sidebar: TwoColumnPage.Sidebar,+ MainGeneralSection: VariantGeneralSection,+ MainInventorySection: VariantInventorySectionConnected,+ SidebarSellerSection: ProductSellerSection,+ SidebarPricesSection: VariantPricesSection,+})diff --git a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/create-product-variant-form.tsx b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/create-product-variant-form.tsxindex f43f90131..6e167c593 100644--- a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/create-product-variant-form.tsx+++ b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/create-product-variant-form.tsx@@ -1,46 +1,20 @@import { zodResolver } from "@hookform/resolvers/zod"-import { Button, ProgressStatus, ProgressTabs, toast } from "@medusajs/ui"-import { useEffect, useMemo, useState } from "react"+import { toast } from "@medusajs/ui"+import { useCallback, useEffect, useMemo } from "react"import { useFieldArray, useForm, useWatch } from "react-hook-form"-import { useTranslation } from "react-i18next"import { z } from "zod"import { AdminCreateProductVariantPrice, HttpTypes } from "@medusajs/types"-import {- RouteDrawer,- RouteFocusModal,- useRouteModal,-} from "../../../../../components/modals"-import { KeyboundForm } from "../../../../../components/utilities/keybound-form"+import { useRouteModal } from "../../../../../components/modals"+import { TabbedForm } from "../../../../../components/tabbed-form/tabbed-form"+import { TabDefinition } from "../../../../../components/tabbed-form/types"import { useRegions } from "../../../../../hooks/api"import { useCreateProductVariant } from "../../../../../hooks/api/products"import { castNumber } from "../../../../../lib/cast-number"-import { partialFormValidation } from "../../../../../lib/validation"-import {- CreateProductVariantSchema,- CreateVariantDetailsFields,- CreateVariantDetailsSchema,- CreateVariantPriceFields,- CreateVariantPriceSchema,-} from "./constants"+import { CreateProductVariantSchema } from "./constants"import DetailsTab from "./details-tab"import InventoryKitTab from "./inventory-kit-tab"import PricingTab from "./pricing-tab"-import { useDocumentDirection } from "../../../../../hooks/use-document-direction"--enum Tab {- DETAIL = "detail",- PRICE = "price",- INVENTORY = "inventory",-}--type TabState = Record<Tab, ProgressStatus>--const initialTabState: TabState = {- [Tab.DETAIL]: "in-progress",- [Tab.PRICE]: "not-started",- [Tab.INVENTORY]: "not-started",-}type CreateProductVariantFormProps = {product: HttpTypes.AdminProduct@@ -49,11 +23,7 @@ type CreateProductVariantFormProps = {export const CreateProductVariantForm = ({product,}: CreateProductVariantFormProps) => {- const { t } = useTranslation()const { handleSuccess } = useRouteModal()- const direction = useDocumentDirection()- const [tab, setTab] = useState<Tab>(Tab.DETAIL)- const [tabState, setTabState] = useState<TabState>(initialTabState)const form = useForm<z.infer<typeof CreateProductVariantSchema>>({defaultValues: {@@ -100,16 +70,6 @@ export const CreateProductVariantForm = ({name: `inventory`,})- const inventoryTabEnabled = isManageInventoryEnabled && isInventoryKitEnabled-- const tabOrder = useMemo(() => {- if (inventoryTabEnabled) {- return [Tab.DETAIL, Tab.PRICE, Tab.INVENTORY] as const- }-- return [Tab.DETAIL, Tab.PRICE] as const- }, [inventoryTabEnabled])-useEffect(() => {if (isInventoryKitEnabled && inventoryField.fields.length === 0) {inventoryField.append({@@ -119,89 +79,19 @@ export const CreateProductVariantForm = ({}}, [isInventoryKitEnabled])- const handleChangeTab = (update: Tab) => {- if (tab === update) {- return- }-- if (tabOrder.indexOf(update) < tabOrder.indexOf(tab)) {- const isCurrentTabDirty = false // isTabDirty(tab) TODO-- setTabState((prev) => ({- ...prev,- [tab]: isCurrentTabDirty ? prev[tab] : "not-started",- [update]: "in-progress",- }))-- setTab(update)- return- }-- // get the tabs from the current tab to the update tab including the current tab- const tabs = tabOrder.slice(0, tabOrder.indexOf(update))-- // validate all the tabs from the current tab to the update tab if it fails on any of tabs then set that tab as current tab- for (const tab of tabs) {- if (tab === Tab.DETAIL) {- if (- !partialFormValidation<z.infer<typeof CreateProductVariantSchema>>(- form,- CreateVariantDetailsFields,- CreateVariantDetailsSchema- )- ) {- setTabState((prev) => ({- ...prev,- [tab]: "in-progress",- }))- setTab(tab)- return- }-- setTabState((prev) => ({- ...prev,- [tab]: "completed",- }))- } else if (tab === Tab.PRICE) {- if (- !partialFormValidation<z.infer<typeof CreateProductVariantSchema>>(- form,- CreateVariantPriceFields,- CreateVariantPriceSchema- )- ) {- setTabState((prev) => ({- ...prev,- [tab]: "in-progress",- }))- setTab(tab)+ const inventoryTabEnabled = isManageInventoryEnabled && isInventoryKitEnabled- return+ const transformTabs = useCallback(+ (tabs: TabDefinition<z.infer<typeof CreateProductVariantSchema>>[]) => {+ return tabs.map((tab) => {+ if (tab.id === "inventory") {+ return { ...tab, isVisible: () => !!inventoryTabEnabled }}-- setTabState((prev) => ({- ...prev,- [tab]: "completed",- }))- }- }-- setTabState((prev) => ({- ...prev,- [tab]: "completed",- [update]: "in-progress",- }))- setTab(update)- }-- const handleNextTab = (tab: Tab) => {- if (tabOrder.indexOf(tab) + 1 >= tabOrder.length) {- return- }-- const nextTab = tabOrder[tabOrder.indexOf(tab) + 1]- handleChangeTab(nextTab)- }+ return tab+ })+ },+ [inventoryTabEnabled]+ )const handleSubmit = form.handleSubmit(async (data) => {const { allow_backorder, manage_inventory, sku, title } = data@@ -219,7 +109,7 @@ export const CreateProductVariantForm = ({return undefined}- const ret: AdminCreateProductVariantPrice = {}+ const ret = {} as AdminCreateProductVariantPriceconst amount = castNumber(value)if (currencyOrRegion.startsWith("reg_")) {@@ -259,137 +149,15 @@ export const CreateProductVariantForm = ({})return (- <RouteFocusModal.Form form={form} data-testid="product-variant-create-form">- <ProgressTabs- dir={direction}- value={tab}- onValueChange={(tab) => handleChangeTab(tab as Tab)}- className="flex h-full flex-col overflow-hidden"- >- <KeyboundForm- onSubmit={handleSubmit}- className="flex h-full flex-col overflow-hidden"- >- <RouteFocusModal.Header data-testid="product-variant-create-form-header">- <div className="flex w-full items-center justify-between gap-x-4">- <div className="-my-2 w-full max-w-[600px] border-l">- <ProgressTabs.List className="grid w-full grid-cols-3" data-testid="product-variant-create-form-tabs-list">- <ProgressTabs.Trigger- status={tabState.detail}- value={Tab.DETAIL}- data-testid="product-variant-create-form-tab-details"- >- {t("priceLists.create.tabs.details")}- </ProgressTabs.Trigger>- <ProgressTabs.Trigger- status={tabState.price}- value={Tab.PRICE}- data-testid="product-variant-create-form-tab-pricing"- >- {t("priceLists.create.tabs.prices")}- </ProgressTabs.Trigger>- {!!inventoryTabEnabled && (- <ProgressTabs.Trigger- status={tabState.inventory}- value={Tab.INVENTORY}- data-testid="product-variant-create-form-tab-inventory"- >- {t("products.create.tabs.inventory")}- </ProgressTabs.Trigger>- )}- </ProgressTabs.List>- </div>- </div>- </RouteFocusModal.Header>- <RouteFocusModal.Body className="size-full overflow-hidden" data-testid="product-variant-create-form-body">- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.DETAIL}- data-testid="product-variant-create-form-tab-details-content"- >- <DetailsTab form={form} product={product} />- </ProgressTabs.Content>- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.PRICE}- data-testid="product-variant-create-form-tab-pricing-content"- >- <PricingTab form={form} />- </ProgressTabs.Content>- {!!inventoryTabEnabled && (- <ProgressTabs.Content- className="size-full overflow-hidden"- value={Tab.INVENTORY}- data-testid="product-variant-create-form-tab-inventory-content"- >- <InventoryKitTab form={form} />- </ProgressTabs.Content>- )}- </RouteFocusModal.Body>- <RouteFocusModal.Footer data-testid="product-variant-create-form-footer">- <div className="flex items-center justify-end gap-x-2">- <RouteDrawer.Close asChild>- <Button variant="secondary" size="small" data-testid="product-variant-create-form-cancel-button">- {t("actions.cancel")}- </Button>- </RouteDrawer.Close>- <PrimaryButton- tab={tab}- next={handleNextTab}- isLoading={isPending}- inventoryTabEnabled={!!inventoryTabEnabled}- />- </div>- </RouteFocusModal.Footer>- </KeyboundForm>- </ProgressTabs>- </RouteFocusModal.Form>- )-}--type PrimaryButtonProps = {- tab: Tab- next: (tab: Tab) => void- isLoading?: boolean- inventoryTabEnabled: boolean-}--const PrimaryButton = ({- tab,- next,- isLoading,- inventoryTabEnabled,-}: PrimaryButtonProps) => {- const { t } = useTranslation()-- if (- (inventoryTabEnabled && tab === Tab.INVENTORY) ||- (!inventoryTabEnabled && tab === Tab.PRICE)- ) {- return (- <Button- key="submit-button"- type="submit"- variant="primary"- size="small"- isLoading={isLoading}- data-testid="product-variant-create-form-save-button"- >- {t("actions.save")}- </Button>- )- }-- return (- <Button- key="next-button"- type="button"- variant="primary"- size="small"- onClick={() => next(tab)}- data-testid="product-variant-create-form-continue-button"+ <TabbedForm+ form={form}+ onSubmit={handleSubmit}+ isLoading={isPending}+ transformTabs={transformTabs}>- {t("actions.continue")}- </Button>+ <DetailsTab product={product} />+ <PricingTab />+ <InventoryKitTab />+ </TabbedForm>)}diff --git a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/details-tab.tsx b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/details-tab.tsxindex 5fda73244..dd9a91d09 100644--- a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/details-tab.tsx+++ b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/details-tab.tsx@@ -1,5 +1,5 @@import { Heading, Input, Switch } from "@medusajs/ui"-import { UseFormReturn, useWatch } from "react-hook-form"+import { useWatch } from "react-hook-form"import { useTranslation } from "react-i18next"import { z } from "zod"@@ -7,15 +7,17 @@ import { HttpTypes } from "@medusajs/types"import { Form } from "../../../../../components/common/form"import { Combobox } from "../../../../../components/inputs/combobox"+import { useTabbedForm } from "../../../../../components/tabbed-form/tabbed-form"+import { defineTabMeta } from "../../../../../components/tabbed-form/types"import { CreateProductVariantSchema } from "./constants"type DetailsTabProps = {product: HttpTypes.AdminProduct- form: UseFormReturn<z.infer<typeof CreateProductVariantSchema>>}-function DetailsTab({ form, product }: DetailsTabProps) {+function DetailsTab({ product }: DetailsTabProps) {const { t } = useTranslation()+ const form = useTabbedForm<z.infer<typeof CreateProductVariantSchema>>()const manageInventoryEnabled = useWatch({control: form.control,@@ -194,4 +196,10 @@ function DetailsTab({ form, product }: DetailsTabProps) {)}+DetailsTab._tabMeta = defineTabMeta<z.infer<typeof CreateProductVariantSchema>>({+ id: "detail",+ labelKey: "priceLists.create.tabs.details",+ validationFields: ["title", "sku", "manage_inventory", "allow_backorder", "inventory_kit", "options"],+})+export default DetailsTabdiff --git a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/inventory-kit-tab.tsx b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/inventory-kit-tab.tsxindex 56090f864..f6cebf585 100644--- a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/inventory-kit-tab.tsx+++ b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/inventory-kit-tab.tsx@@ -1,5 +1,5 @@import { z } from "zod"-import { useFieldArray, UseFormReturn } from "react-hook-form"+import { useFieldArray } from "react-hook-form"import { Button, Heading, IconButton, Input, Label } from "@medusajs/ui"import { CreateProductVariantSchema } from "./constants"@@ -10,12 +10,11 @@ import { useComboboxData } from "../../../../../hooks/use-combobox-data"import { sdk } from "../../../../../lib/client"import { Form } from "../../../../../components/common/form"import { Combobox } from "../../../../../components/inputs/combobox"+import { useTabbedForm } from "../../../../../components/tabbed-form/tabbed-form"+import { defineTabMeta } from "../../../../../components/tabbed-form/types"-type InventoryKitTabProps = {- form: UseFormReturn<z.infer<typeof CreateProductVariantSchema>>-}--function InventoryKitTab({ form }: InventoryKitTabProps) {+function InventoryKitTab() {+ const form = useTabbedForm<z.infer<typeof CreateProductVariantSchema>>()const { t } = useTranslation()const inventory = useFieldArray({@@ -192,4 +191,10 @@ function InventoryKitTab({ form }: InventoryKitTabProps) {)}+InventoryKitTab._tabMeta = defineTabMeta<z.infer<typeof CreateProductVariantSchema>>({+ id: "inventory",+ labelKey: "products.create.tabs.inventory",+ validationFields: ["inventory"],+})+export default InventoryKitTabdiff --git a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/pricing-tab.tsx b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/pricing-tab.tsxindex 43899fd79..b0c67664c 100644--- a/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/pricing-tab.tsx+++ b/packages/admin/src/pages/products/product-create-variant/components/create-product-variant-form/pricing-tab.tsx@@ -1,5 +1,5 @@import { useMemo } from "react"-import { UseFormReturn, useWatch } from "react-hook-form"+import { useWatch } from "react-hook-form"import { HttpTypes } from "@medusajs/types"import { useTranslation } from "react-i18next"import { z } from "zod"@@ -13,12 +13,11 @@ import {createDataGridPriceColumns,DataGrid,} from "../../../../../components/data-grid"+import { useTabbedForm } from "../../../../../components/tabbed-form/tabbed-form"+import { defineTabMeta } from "../../../../../components/tabbed-form/types"-type PricingTabProps = {- form: UseFormReturn<z.infer<typeof CreateProductVariantSchema>>-}--function PricingTab({ form }: PricingTabProps) {+function PricingTab() {+ const form = useTabbedForm<z.infer<typeof CreateProductVariantSchema>>()const { store } = useStore()const { regions } = useRegions({ limit: 9999 })const { price_preferences: pricePreferences } = usePricePreferences({})@@ -99,4 +98,10 @@ const useVariantPriceGridColumns = ({}, [t, currencies, regions, pricePreferences])}+PricingTab._tabMeta = defineTabMeta<z.infer<typeof CreateProductVariantSchema>>({+ id: "price",+ labelKey: "priceLists.create.tabs.prices",+ validationFields: ["prices"],+})+export default PricingTabdiff --git a/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsx b/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsxindex 79614654a..73f611244 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsx@@ -1,18 +1,13 @@import { Input, Textarea } from "@medusajs/ui"-import { UseFormReturn } from "react-hook-form"import { useTranslation } from "react-i18next"import { Form } from "../../../../../../../components/common/form"import { HandleInput } from "../../../../../../../components/inputs/handle-input"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { ProductCreateSchemaType } from "../../../../types"-type ProductCreateGeneralSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateGeneralSection = ({- form,-}: ProductCreateGeneralSectionProps) => {+export const ProductCreateGeneralSection = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()return (diff --git a/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsx b/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsxindex 7a42465e8..bdca71d8d 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsx@@ -27,16 +27,13 @@ import {} from "@medusajs/icons"import { IconButton, Text } from "@medusajs/ui"import { useState } from "react"-import { useFieldArray, UseFormReturn } from "react-hook-form"+import { useFieldArray } from "react-hook-form"import { useTranslation } from "react-i18next"import { ActionMenu } from "../../../../../../../components/common/action-menu"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { UploadMediaFormItem } from "../../../../../common/components/upload-media-form-item"import { ProductCreateSchemaType } from "../../../../types"-type ProductCreateMediaSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}-const dropAnimationConfig: DropAnimation = {sideEffects: defaultDropAnimationSideEffects({styles: {@@ -47,9 +44,9 @@ const dropAnimationConfig: DropAnimation = {}),}-export const ProductCreateMediaSection = ({- form,-}: ProductCreateMediaSectionProps) => {+export const ProductCreateMediaSection = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()+const { fields, append, remove } = useFieldArray({name: "media",control: form.control,diff --git a/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx b/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsxindex 04f826001..5ea5c9772 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx@@ -16,7 +16,6 @@ import {Controller,FieldArrayWithId,useFieldArray,- UseFormReturn,useWatch,} from "react-hook-form"import { useTranslation } from "react-i18next"@@ -25,13 +24,10 @@ import { Form } from "../../../../../../../components/common/form"import { SortableList } from "../../../../../../../components/common/sortable-list"import { SwitchBox } from "../../../../../../../components/common/switch-box"import { ChipInput } from "../../../../../../../components/inputs/chip-input"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { ProductCreateSchemaType } from "../../../../types"import { decorateVariantsWithDefaultValues } from "../../../../utils"-type ProductCreateVariantsSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}-const getPermutations = (data: { title: string; values: string[] }[]): { [key: string]: string }[] => {@@ -60,9 +56,8 @@ const getVariantName = (options: Record<string, string>) => {return Object.values(options).join(" / ")}-export const ProductCreateVariantsSection = ({- form,-}: ProductCreateVariantsSectionProps) => {+export const ProductCreateVariantsSection = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()const options = useFieldArray({diff --git a/packages/admin/src/pages/products/product-create/components/product-create-details-form/product-create-details-form.tsx b/packages/admin/src/pages/products/product-create/components/product-create-details-form/product-create-details-form.tsxindex 6074275b3..cc3cec106 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-details-form/product-create-details-form.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-details-form/product-create-details-form.tsx@@ -1,17 +1,13 @@import { Divider, Heading } from "@medusajs/ui";-import { UseFormReturn } from "react-hook-form";import { useTranslation } from "react-i18next";+import { defineTabMeta } from "../../../../../components/tabbed-form/types";import { ProductCreateSchemaType } from "../../types";import { ProductCreateGeneralSection } from "./components/product-create-details-general-section";import { ProductCreateMediaSection } from "./components/product-create-details-media-section";import { ProductCreateVariantsSection } from "./components/product-create-details-variant-section";-type ProductAttributesProps = {- form: UseFormReturn<ProductCreateSchemaType>;-};--export const ProductCreateDetailsForm = ({ form }: ProductAttributesProps) => {+const Root = () => {return (<divclassName="flex flex-col items-center p-16"@@ -26,16 +22,24 @@ export const ProductCreateDetailsForm = ({ form }: ProductAttributesProps) => {className="flex flex-col gap-y-6"data-testid="product-create-details-form-sections">- <ProductCreateGeneralSection form={form} />- <ProductCreateMediaSection form={form} />+ <ProductCreateGeneralSection />+ <ProductCreateMediaSection /></div><Divider data-testid="product-create-details-form-divider" />- <ProductCreateVariantsSection form={form} />+ <ProductCreateVariantsSection /></div></div>);};+Root._tabMeta = defineTabMeta<ProductCreateSchemaType>({+ id: "details",+ labelKey: "products.create.tabs.details",+ validationFields: ["title", "handle", "description", "media", "options", "variants"],+});++export const ProductCreateDetailsForm = Root;+const Header = () => {const { t } = useTranslation();diff --git a/packages/admin/src/pages/products/product-create/components/product-create-form/product-create-form.tsx b/packages/admin/src/pages/products/product-create/components/product-create-form/product-create-form.tsxindex 398e9a331..beebe35fd 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-form/product-create-form.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-form/product-create-form.tsx@@ -1,73 +1,65 @@import { HttpTypes } from "@medusajs/types";-import { Button, ProgressStatus, ProgressTabs, toast } from "@medusajs/ui";-import { useEffect, useMemo, useState } from "react";+import { Button, toast } from "@medusajs/ui";+import { Children, ReactNode, useCallback, useMemo } from "react";import { useForm, useWatch } from "react-hook-form";import { useTranslation } from "react-i18next";import {RouteFocusModal,useRouteModal,} from "../../../../../components/modals";-import { KeyboundForm } from "../../../../../components/utilities/keybound-form";+import { TabbedForm } from "../../../../../components/tabbed-form/tabbed-form";+import { TabDefinition } from "../../../../../components/tabbed-form/types";import { useCreateProduct } from "../../../../../hooks/api/products";+import { useRegions } from "../../../../../hooks/api";import { sdk } from "../../../../../lib/client";import {PRODUCT_CREATE_FORM_DEFAULTS,ProductCreateSchema,} from "../../constants";+import { ProductCreateSchemaType } from "../../types";import { normalizeProductFormValues } from "../../utils";import { ProductCreateDetailsForm } from "../product-create-details-form";import { ProductCreateInventoryKitForm } from "../product-create-inventory-kit-form";import { ProductCreateOrganizeForm } from "../product-create-organize-form";import { ProductCreateVariantsForm } from "../product-create-variants-form";-import { useDocumentDirection } from "../../../../../hooks/use-document-direction";import { zodResolver } from "@hookform/resolvers/zod";-enum Tab {- DETAILS = "details",- ORGANIZE = "organize",- VARIANTS = "variants",- INVENTORY = "inventory",-}--type TabState = Record<Tab, ProgressStatus>;const SAVE_DRAFT_BUTTON = "save-draft-button";type ProductCreateFormProps = {defaultChannel?: HttpTypes.AdminSalesChannel;- regions: HttpTypes.AdminRegion[];- store: HttpTypes.AdminStore;- pricePreferences: HttpTypes.AdminPricePreference[];+ children?: ReactNode;};export const ProductCreateForm = ({defaultChannel,- regions,- store,- pricePreferences,+ children,}: ProductCreateFormProps) => {- const [tab, setTab] = useState<Tab>(Tab.DETAILS);- const [tabState, setTabState] = useState<TabState>({- [Tab.DETAILS]: "in-progress",- [Tab.ORGANIZE]: "not-started",- [Tab.VARIANTS]: "not-started",- [Tab.INVENTORY]: "not-started",- });-const { t } = useTranslation();const { handleSuccess } = useRouteModal();- const direction = useDocumentDirection();- const form = useForm({+ const form = useForm<ProductCreateSchemaType>({defaultValues: {...PRODUCT_CREATE_FORM_DEFAULTS,sales_channels: defaultChannel? [{ id: defaultChannel.id, name: defaultChannel.name }]: [],- },+ } as ProductCreateSchemaType,resolver: zodResolver(ProductCreateSchema),});const { mutateAsync, isPending } = useCreateProduct();+ const {+ regions,+ isPending: isRegionsPending,+ isError: isRegionsError,+ error: regionsError,+ } = useRegions({ limit: 9999 });++ if (isRegionsError) {+ throw regionsError;+ }+const regionsCurrencyMap = useMemo(() => {if (!regions?.length) {return {};@@ -92,12 +84,11 @@ export const ProductCreateForm = ({name: "variants",});- const showInventoryTab = useMemo(- () => watchedVariants.some((v) => v.manage_inventory && v.inventory_kit),- [watchedVariants],- );-const handleSubmit = form.handleSubmit(async (values, e) => {+ if (isRegionsPending) {+ return;+ }+let isDraftSubmission = false;if (e?.nativeEvent instanceof SubmitEvent) {const submitter = e?.nativeEvent?.submitter as HTMLButtonElement;@@ -163,266 +154,92 @@ export const ProductCreateForm = ({);});- const onNext = async (currentTab: Tab) => {- const valid = await form.trigger();-- if (!valid) {- return;- }-- if (currentTab === Tab.DETAILS) {- setTab(Tab.ORGANIZE);- }-- if (currentTab === Tab.ORGANIZE) {- setTab(Tab.VARIANTS);- }-- if (currentTab === Tab.VARIANTS) {- setTab(Tab.INVENTORY);- }- };-- useEffect(() => {- const currentState = { ...tabState };- if (tab === Tab.DETAILS) {- currentState[Tab.DETAILS] = "in-progress";- }- if (tab === Tab.ORGANIZE) {- currentState[Tab.DETAILS] = "completed";- currentState[Tab.ORGANIZE] = "in-progress";- }- if (tab === Tab.VARIANTS) {- currentState[Tab.DETAILS] = "completed";- currentState[Tab.ORGANIZE] = "completed";- currentState[Tab.VARIANTS] = "in-progress";- }- if (tab === Tab.INVENTORY) {- currentState[Tab.DETAILS] = "completed";- currentState[Tab.ORGANIZE] = "completed";- currentState[Tab.VARIANTS] = "completed";- currentState[Tab.INVENTORY] = "in-progress";- }+ const transformTabs = useCallback(+ (tabs: TabDefinition<ProductCreateSchemaType>[]) => {+ const showInventoryTab = watchedVariants?.some(+ (v) => v.manage_inventory && v.inventory_kit+ ) ?? false;++ return tabs.map((tab) => {+ if (tab.id === "inventory") {+ return {+ ...tab,+ isVisible: () => showInventoryTab,+ };+ }+ return tab;+ });+ },+ [watchedVariants],+ );- setTabState({ ...currentState });- // eslint-disable-next-line react-hooks/exhaustive-deps -- we only want this effect to run when the tab changes- }, [tab]);+ const defaultTabs = (+ <>+ <ProductCreateDetailsForm key="details" />+ <ProductCreateOrganizeForm key="organize" />+ <ProductCreateVariantsForm key="variants" />+ <ProductCreateInventoryKitForm key="inventory" />+ </>+ );return (- <RouteFocusModal.Form form={form}>- <KeyboundForm- data-testid="product-create-form"- onKeyDown={(e) => {- // We want to continue to the next tab on enter instead of saving as draft immediately- if (e.key === "Enter") {- if (- e.target instanceof HTMLTextAreaElement &&- !(e.metaKey || e.ctrlKey)- ) {- return;- }-- e.preventDefault();-- if (e.metaKey || e.ctrlKey) {- if (tab !== Tab.VARIANTS) {- e.preventDefault();- e.stopPropagation();- onNext(tab);-- return;- }-- handleSubmit();- }- }- }}- onSubmit={handleSubmit}- className="flex h-full flex-col"- >- <ProgressTabs- dir={direction}- value={tab}- onValueChange={async (tab) => {- const valid = await form.trigger();-- if (!valid) {- return;- }-- setTab(tab as Tab);- }}- className="flex h-full flex-col overflow-hidden"- data-testid="product-create-form-tabs"+ <TabbedForm+ form={form}+ onSubmit={handleSubmit}+ isLoading={isPending || isRegionsPending}+ transformTabs={transformTabs}+ footer={({ isLastTab, onNext, isLoading }) => (+ <div+ className="flex items-center justify-end gap-x-2"+ data-testid="product-create-form-footer-actions">- <RouteFocusModal.Header>- <div- className="-my-2 w-full border-l"- data-testid="product-create-form-tabs-header"+ <RouteFocusModal.Close asChild>+ <Button+ variant="secondary"+ size="small"+ data-testid="product-create-form-cancel-button">- <ProgressTabs.List- className="justify-start-start flex w-full items-center"- data-testid="product-create-form-tabs-list"- >- <ProgressTabs.Trigger- status={tabState[Tab.DETAILS]}- value={Tab.DETAILS}- className="max-w-[200px] truncate"- data-testid="product-create-form-tab-details"- >- {t("products.create.tabs.details")}- </ProgressTabs.Trigger>- <ProgressTabs.Trigger- status={tabState[Tab.ORGANIZE]}- value={Tab.ORGANIZE}- className="max-w-[200px] truncate"- data-testid="product-create-form-tab-organize"- >- {t("products.create.tabs.organize")}- </ProgressTabs.Trigger>- <ProgressTabs.Trigger- status={tabState[Tab.VARIANTS]}- value={Tab.VARIANTS}- className="max-w-[200px] truncate"- data-testid="product-create-form-tab-variants"- >- {t("products.create.tabs.variants")}- </ProgressTabs.Trigger>- {showInventoryTab && (- <ProgressTabs.Trigger- status={tabState[Tab.INVENTORY]}- value={Tab.INVENTORY}- className="max-w-[200px] truncate"- data-testid="product-create-form-tab-inventory"- >- {t("products.create.tabs.inventory")}- </ProgressTabs.Trigger>- )}- </ProgressTabs.List>- </div>- </RouteFocusModal.Header>- <RouteFocusModal.Body- className="size-full overflow-hidden"- data-testid="product-create-form-body"+ {t("actions.cancel")}+ </Button>+ </RouteFocusModal.Close>+ <Button+ data-name={SAVE_DRAFT_BUTTON}+ size="small"+ type="submit"+ isLoading={isLoading}+ className="whitespace-nowrap"+ data-testid="product-create-form-save-draft-button">- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.DETAILS}- data-testid="product-create-form-tab-content-details"- >- <ProductCreateDetailsForm form={form} />- </ProgressTabs.Content>- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.ORGANIZE}- data-testid="product-create-form-tab-content-organize"- >- <ProductCreateOrganizeForm form={form} />- </ProgressTabs.Content>- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.VARIANTS}- data-testid="product-create-form-tab-content-variants"+ {t("actions.saveAsDraft")}+ </Button>+ {isLastTab ? (+ <Button+ data-name="publish-button"+ key="submit-button"+ type="submit"+ variant="primary"+ size="small"+ isLoading={isLoading}+ data-testid="product-create-form-publish-button">- <ProductCreateVariantsForm- form={form}- store={store}- regions={regions}- pricePreferences={pricePreferences}- />- </ProgressTabs.Content>- {showInventoryTab && (- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.INVENTORY}- data-testid="product-create-form-tab-content-inventory"- >- <ProductCreateInventoryKitForm form={form} />- </ProgressTabs.Content>- )}- </RouteFocusModal.Body>- </ProgressTabs>- <RouteFocusModal.Footer data-testid="product-create-form-footer">- <div- className="flex items-center justify-end gap-x-2"- data-testid="product-create-form-footer-actions"- >- <RouteFocusModal.Close asChild>- <Button- variant="secondary"- size="small"- data-testid="product-create-form-cancel-button"- >- {t("actions.cancel")}- </Button>- </RouteFocusModal.Close>+ {t("actions.publish")}+ </Button>+ ) : (<Button- data-name={SAVE_DRAFT_BUTTON}+ key="next-button"+ type="button"+ variant="primary"size="small"- type="submit"- isLoading={isPending}- className="whitespace-nowrap"- data-testid="product-create-form-save-draft-button"+ onClick={() => onNext()}+ data-testid="product-create-form-continue-button">- {t("actions.saveAsDraft")}+ {t("actions.continue")}</Button>- <PrimaryButton- tab={tab}- next={onNext}- isLoading={isPending}- showInventoryTab={showInventoryTab}- />- </div>- </RouteFocusModal.Footer>- </KeyboundForm>- </RouteFocusModal.Form>- );-};--type PrimaryButtonProps = {- tab: Tab;- next: (tab: Tab) => void;- isLoading?: boolean;- showInventoryTab: boolean;-};--const PrimaryButton = ({- tab,- next,- isLoading,- showInventoryTab,-}: PrimaryButtonProps) => {- const { t } = useTranslation();-- if (- (tab === Tab.VARIANTS && !showInventoryTab) ||- (tab === Tab.INVENTORY && showInventoryTab)- ) {- return (- <Button- data-name="publish-button"- key="submit-button"- type="submit"- variant="primary"- size="small"- isLoading={isLoading}- data-testid="product-create-form-publish-button"- >- {t("actions.publish")}- </Button>- );- }-- return (- <Button- key="next-button"- type="button"- variant="primary"- size="small"- onClick={() => next(tab)}- data-testid="product-create-form-continue-button"+ )}+ </div>+ )}>- {t("actions.continue")}- </Button>+ {Children.count(children) > 0 ? children : defaultTabs}+ </TabbedForm>);};diff --git a/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsx b/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsxindex 5d12d3199..b485f7dd8 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsx@@ -1,16 +1,16 @@import { Button, Heading, IconButton, Input, Label } from "@medusajs/ui"-import { useFieldArray, UseFormReturn, useWatch } from "react-hook-form"+import { useFieldArray, useWatch } from "react-hook-form"import { XMarkMini } from "@medusajs/icons"import { useTranslation } from "react-i18next"import { ProductCreateSchemaType } from "../../../../types"import { Form } from "../../../../../../../components/common/form"import { Combobox } from "../../../../../../../components/inputs/combobox"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { useComboboxData } from "../../../../../../../hooks/use-combobox-data"import { sdk } from "../../../../../../../lib/client"type InventoryItemRowProps = {- form: UseFormReturn<ProductCreateSchemaType>variantIndex: numberinventoryIndex: numberinventoryItem: any@@ -22,13 +22,13 @@ type InventoryItemRowProps = {}function InventoryItemRow({- form,variantIndex,inventoryIndex,inventoryItem,isItemOptionDisabled,onRemove,}: InventoryItemRowProps) {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()const selectedInventoryItemId = useWatch({@@ -148,12 +148,12 @@ function InventoryItemRow({}type VariantSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>variant: ProductCreateSchemaType["variants"][0]index: number}-function VariantSection({ form, variant, index }: VariantSectionProps) {+function VariantSection({ variant, index }: VariantSectionProps) {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()const inventory = useFieldArray({@@ -203,7 +203,6 @@ function VariantSection({ form, variant, index }: VariantSectionProps) {{inventory.fields.map((inventoryItem, inventoryIndex) => (<InventoryItemRowkey={inventoryItem.id}- form={form}variantIndex={index}inventoryIndex={inventoryIndex}inventoryItem={inventoryItem}@@ -215,13 +214,8 @@ function VariantSection({ form, variant, index }: VariantSectionProps) {)}-type ProductCreateInventoryKitSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateInventoryKitSection = ({- form,-}: ProductCreateInventoryKitSectionProps) => {+export const ProductCreateInventoryKitSection = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()const variants = useFieldArray({@@ -238,7 +232,6 @@ export const ProductCreateInventoryKitSection = ({.map((variant, variantIndex) => (<VariantSectionkey={variant.id}- form={form}variant={variant}index={variantIndex}/>diff --git a/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/product-create-inventory-kit-form.tsx b/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/product-create-inventory-kit-form.tsxindex 12f6d0439..74427de50 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/product-create-inventory-kit-form.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-inventory-kit-form/product-create-inventory-kit-form.tsx@@ -1,20 +1,21 @@-import { UseFormReturn } from "react-hook-form"-+import { defineTabMeta } from "../../../../../components/tabbed-form/types"import { ProductCreateSchemaType } from "../../types"import { ProductCreateInventoryKitSection } from "./components/product-create-inventory-kit-section/product-create-inventory-kit-section"-type ProductAttributesProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateInventoryKitForm = ({- form,-}: ProductAttributesProps) => {+const Root = () => {return (<div className="flex flex-col items-center p-16" data-testid="product-create-inventory-kit-form"><div className="flex w-full max-w-[720px] flex-col gap-y-8" data-testid="product-create-inventory-kit-form-content">- <ProductCreateInventoryKitSection form={form} />+ <ProductCreateInventoryKitSection /></div></div>)}++Root._tabMeta = defineTabMeta<ProductCreateSchemaType>({+ id: "inventory",+ labelKey: "products.create.tabs.inventory",+ validationFields: ["variants"],+})++export const ProductCreateInventoryKitForm = Rootdiff --git a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsx b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsxindex 93c67b527..5c2d0f94b 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsx@@ -1,18 +1,13 @@import { Heading, Input } from "@medusajs/ui"-import { UseFormReturn } from "react-hook-form"import { useTranslation } from "react-i18next"import { Form } from "../../../../../../../components/common/form"import { CountrySelect } from "../../../../../../../components/inputs/country-select"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { ProductCreateSchemaType } from "../../../../types"-type ProductCreateAttributeSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateAttributeSection = ({- form,-}: ProductCreateAttributeSectionProps) => {+export const ProductCreateAttributeSection = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()return (diff --git a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsx b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsxindex b832f07f4..5a0f2f229 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsx@@ -1,5 +1,5 @@import { Button, Heading } from "@medusajs/ui"-import { UseFormReturn, useFieldArray } from "react-hook-form"+import { useFieldArray } from "react-hook-form"import { Trans, useTranslation } from "react-i18next"import { ChipGroup } from "../../../../../../../components/common/chip-group"@@ -7,18 +7,14 @@ import { Form } from "../../../../../../../components/common/form"import { SwitchBox } from "../../../../../../../components/common/switch-box"import { Combobox } from "../../../../../../../components/inputs/combobox"import { StackedFocusModal } from "../../../../../../../components/modals"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { useComboboxData } from "../../../../../../../hooks/use-combobox-data"import { sdk } from "../../../../../../../lib/client"import { CategoryCombobox } from "../../../../../common/components/category-combobox"import { ProductCreateSchemaType } from "../../../../types"-type ProductCreateOrganizationSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateOrganizationSection = ({- form,-}: ProductCreateOrganizationSectionProps) => {+export const ProductCreateOrganizationSection = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()const sellers = useComboboxData({diff --git a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsx b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsxindex c8090aa8e..10f6eedd8 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsx@@ -5,7 +5,6 @@ import {DataTableRowSelectionState,} from "@medusajs/ui"import { useEffect, useMemo, useState } from "react"-import { UseFormReturn } from "react-hook-form"import { useTranslation } from "react-i18next"import { keepPreviousData } from "@tanstack/react-query"@@ -15,19 +14,15 @@ import {StackedFocusModal,useStackedModal,} from "../../../../../../../components/modals"+import { useTabbedForm } from "../../../../../../../components/tabbed-form/tabbed-form"import { useSalesChannels } from "../../../../../../../hooks/api/sales-channels"import { ProductCreateSchemaType } from "../../../../types"import { SC_STACKED_MODAL_ID } from "../../constants"-type ProductCreateSalesChannelStackedModalProps = {- form: UseFormReturn<ProductCreateSchemaType>-}-const PAGE_SIZE = 20-export const ProductCreateSalesChannelStackedModal = ({- form,-}: ProductCreateSalesChannelStackedModalProps) => {+export const ProductCreateSalesChannelStackedModal = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { t } = useTranslation()const { getValues, setValue } = formconst { setIsOpen, getIsOpen } = useStackedModal()diff --git a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/product-create-organize-form.tsx b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/product-create-organize-form.tsxindex 3dfa1beee..1269d5073 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-organize-form/product-create-organize-form.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-organize-form/product-create-organize-form.tsx@@ -1,16 +1,11 @@-import { UseFormReturn } from "react-hook-form";-import { StackedFocusModal } from "../../../../../components/modals";+import { defineTabMeta } from "../../../../../components/tabbed-form/types";import { ProductCreateSchemaType } from "../../types";import { ProductCreateOrganizationSection } from "./components/product-create-organize-section";import { ProductCreateSalesChannelStackedModal } from "./components/product-create-sales-channel-stacked-modal";import { SC_STACKED_MODAL_ID } from "./constants";-type ProductAttributesProps = {- form: UseFormReturn<ProductCreateSchemaType>;-};--export const ProductCreateOrganizeForm = ({ form }: ProductAttributesProps) => {+const Root = () => {return (<StackedFocusModal id={SC_STACKED_MODAL_ID}><div@@ -21,10 +16,22 @@ export const ProductCreateOrganizeForm = ({ form }: ProductAttributesProps) => {className="flex w-full max-w-[720px] flex-col gap-y-8"data-testid="product-create-organize-form-content">- <ProductCreateOrganizationSection form={form} />+ <ProductCreateOrganizationSection /></div></div>- <ProductCreateSalesChannelStackedModal form={form} />+ <ProductCreateSalesChannelStackedModal /></StackedFocusModal>);};++Root._tabMeta = defineTabMeta<ProductCreateSchemaType>({+ id: "organize",+ labelKey: "products.create.tabs.organize",+ validationFields: [+ "type_id", "collection_id", "categories", "tags", "sales_channels",+ "shipping_profile_id", "origin_country", "material",+ "width", "length", "height", "weight", "mid_code", "hs_code",+ ],+});++export const ProductCreateOrganizeForm = Root;diff --git a/packages/admin/src/pages/products/product-create/components/product-create-variants-form/product-create-variants-form.tsx b/packages/admin/src/pages/products/product-create/components/product-create-variants-form/product-create-variants-form.tsxindex b695c7ee0..fd5d6a3bd 100644--- a/packages/admin/src/pages/products/product-create/components/product-create-variants-form/product-create-variants-form.tsx+++ b/packages/admin/src/pages/products/product-create/components/product-create-variants-form/product-create-variants-form.tsx@@ -1,6 +1,6 @@import { HttpTypes } from "@medusajs/types"import { useMemo } from "react"-import { UseFormReturn, useWatch } from "react-hook-form"+import { useWatch } from "react-hook-form"import { useTranslation } from "react-i18next"import {@@ -9,27 +9,31 @@ import {DataGrid,} 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 { useRegions } from "../../../../../hooks/api"+import { usePricePreferences } from "../../../../../hooks/api/price-preferences"+import { useStore } from "../../../../../hooks/api/store"import {ProductCreateOptionSchema,ProductCreateVariantSchema,} from "../../constants"import { ProductCreateSchemaType } from "../../types"-type ProductCreateVariantsFormProps = {- form: UseFormReturn<ProductCreateSchemaType>- regions: HttpTypes.AdminRegion[]- store: HttpTypes.AdminStore- pricePreferences: HttpTypes.AdminPricePreference[]-}--export const ProductCreateVariantsForm = ({- form,- regions,- store,- pricePreferences,-}: ProductCreateVariantsFormProps) => {+const Root = () => {+ const form = useTabbedForm<ProductCreateSchemaType>()const { setCloseOnEscape } = useRouteModal()+ const { store } = useStore({+ fields: "+default_sales_channel",+ })++ const { regions } = useRegions({ limit: 9999 })++ const { price_preferences: pricePreferences } = usePricePreferences({+ limit: 9999,+ })+const currencyCodes = useMemo(() => store?.supported_currencies?.map((c) => c.currency_code) || [],[store]@@ -53,12 +57,12 @@ export const ProductCreateVariantsForm = ({const columns = useColumns({options,currencies: currencyCodes,- regions,- pricePreferences,+ regions: regions ?? [],+ pricePreferences: pricePreferences ?? [],})const variantData = useMemo(() => {- const ret = []+ const ret: (ProductCreateVariantSchema & { originalIndex: number })[] = []variants.forEach((v, i) => {if (v.should_create) {@@ -83,8 +87,18 @@ export const ProductCreateVariantsForm = ({)}+Root._tabMeta = defineTabMeta<ProductCreateSchemaType>({+ id: "variants",+ labelKey: "products.create.tabs.variants",+ validationFields: ["variants"],+})++export const ProductCreateVariantsForm = Root++type VariantRow = ProductCreateVariantSchema & { originalIndex: number }+const columnHelper = createDataGridHelper<- ProductCreateVariantSchema,+ VariantRow,ProductCreateSchemaType>()@@ -186,7 +200,7 @@ const useColumns = ({}),...createDataGridPriceColumns<- ProductCreateVariantSchema,+ VariantRow,ProductCreateSchemaType>({currencies,diff --git a/packages/admin/src/pages/products/product-create/product-create.tsx b/packages/admin/src/pages/products/product-create/product-create.tsxindex fd65e86e1..b6b150328 100644--- a/packages/admin/src/pages/products/product-create/product-create.tsx+++ b/packages/admin/src/pages/products/product-create/product-create.tsx@@ -1,7 +1,5 @@import { useTranslation } from "react-i18next"import { RouteFocusModal } from "../../../components/modals"-import { useRegions } from "../../../hooks/api"-import { usePricePreferences } from "../../../hooks/api/price-preferences"import { useSalesChannel } from "../../../hooks/api/sales-channels"import { useStore } from "../../../hooks/api/store"import { ProductCreateForm } from "./components/product-create-form/product-create-form"@@ -27,48 +25,20 @@ export const ProductCreate = () => {enabled: !!store?.default_sales_channel_id,})- const {- regions,- isPending: isRegionsPending,- isError: isRegionsError,- error: regionsError,- } = useRegions({ limit: 9999 })-- const {- price_preferences,- isPending: isPricePreferencesPending,- isError: isPricePreferencesError,- error: pricePreferencesError,- } = usePricePreferences({- limit: 9999,- })-const ready =!!store &&!isStorePending &&- !!regions &&- !isRegionsPending &&!!sales_channel &&- !isSalesChannelPending &&- !!price_preferences &&- !isPricePreferencesPending+ !isSalesChannelPendingif (isStoreError) {throw storeError}- if (isRegionsError) {- throw regionsError- }-if (isSalesChannelError) {throw salesChannelError}- if (isPricePreferencesError) {- throw pricePreferencesError- }-return (<RouteFocusModal><RouteFocusModal.Title asChild>@@ -80,9 +50,6 @@ export const ProductCreate = () => {{ready && (<ProductCreateFormdefaultChannel={sales_channel}- store={store}- pricePreferences={price_preferences}- regions={regions}/>)}</RouteFocusModal>diff --git a/packages/admin/src/pages/products/product-detail/components/product-attribute-section/product-attribute-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-attribute-section/product-attribute-section.tsxindex 3b9203dfb..d9938c2df 100644--- a/packages/admin/src/pages/products/product-detail/components/product-attribute-section/product-attribute-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-attribute-section/product-attribute-section.tsx@@ -1,18 +1,16 @@import { PencilSquare } from "@medusajs/icons";-import { HttpTypes } from "@medusajs/types";import { Container, Heading } from "@medusajs/ui";import { useTranslation } from "react-i18next";+import { HttpTypes } from "@medusajs/types";import { ActionMenu } from "../../../../../components/common/action-menu";import { SectionRow } from "../../../../../components/common/section";import { getFormattedCountry } from "../../../../../lib/addresses";-type ProductAttributeSectionProps = {- product: HttpTypes.AdminProduct;-};-export const ProductAttributeSection = ({product,-}: ProductAttributeSectionProps) => {+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation();return (diff --git a/packages/admin/src/pages/products/product-detail/components/product-general-section/product-general-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-general-section/product-general-section.tsxindex cc4fd233d..6297fa2c7 100644--- a/packages/admin/src/pages/products/product-detail/components/product-general-section/product-general-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-general-section/product-general-section.tsx@@ -1,10 +1,10 @@import { PencilSquare, Trash } from "@medusajs/icons";-import { HttpTypes } from "@medusajs/types";import { Container, Heading, StatusBadge, usePrompt } from "@medusajs/ui";import { useTranslation } from "react-i18next";import { useNavigate } from "react-router-dom";+import { HttpTypes } from "@medusajs/types";import { ActionMenu } from "../../../../../components/common/action-menu";import { SectionRow } from "../../../../../components/common/section";import { useDeleteProduct } from "../../../../../hooks/api/products";@@ -24,13 +24,11 @@ const productStatusColor = (status: string) => {}};-type ProductGeneralSectionProps = {- product: HttpTypes.AdminProduct;-};-export const ProductGeneralSection = ({product,-}: ProductGeneralSectionProps) => {+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation();const prompt = usePrompt();const navigate = useNavigate();diff --git a/packages/admin/src/pages/products/product-detail/components/product-media-section/product-media-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-media-section/product-media-section.tsxindex ce3b2591c..e6b15e950 100644--- a/packages/admin/src/pages/products/product-detail/components/product-media-section/product-media-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-media-section/product-media-section.tsx@@ -13,15 +13,15 @@ import {import { useState } from "react"import { useTranslation } from "react-i18next"import { Link } from "react-router-dom"+import { HttpTypes } from "@medusajs/types"import { ActionMenu } from "../../../../../components/common/action-menu"import { useUpdateProduct } from "../../../../../hooks/api/products"-import { HttpTypes } from "@medusajs/types"--type ProductMedisaSectionProps = {- product: HttpTypes.AdminProduct-}-export const ProductMediaSection = ({ product }: ProductMedisaSectionProps) => {+export const ProductMediaSection = ({+ product,+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation()const prompt = usePrompt()const [selection, setSelection] = useState<Record<string, boolean>>({})diff --git a/packages/admin/src/pages/products/product-detail/components/product-option-section/product-option-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-option-section/product-option-section.tsxindex a8ce121f7..cce03edd5 100644--- a/packages/admin/src/pages/products/product-detail/components/product-option-section/product-option-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-option-section/product-option-section.tsx@@ -7,14 +7,14 @@ import { useDeleteProductOption } from "../../../../../hooks/api/products"import { HttpTypes } from "@medusajs/types"const OptionActions = ({- product,+ productId,option,}: {- product: HttpTypes.AdminProduct+ productId: stringoption: HttpTypes.AdminProductOption}) => {const { t } = useTranslation()- const { mutateAsync } = useDeleteProductOption(product.id, option.id)+ const { mutateAsync } = useDeleteProductOption(productId, option.id)const prompt = usePrompt()const handleDelete = async () => {@@ -61,13 +61,11 @@ const OptionActions = ({)}-type ProductOptionSectionProps = {- product: HttpTypes.AdminProduct-}-export const ProductOptionSection = ({product,-}: ProductOptionSectionProps) => {+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation()return (@@ -107,7 +105,7 @@ export const ProductOptionSection = ({</Badge>)})}- actions={<OptionActions product={product} option={option} />}+ actions={<OptionActions productId={product.id} option={option} />}data-testid={`product-option-row-${option.id}`}/>)diff --git a/packages/admin/src/pages/products/product-detail/components/product-organization-section/product-organization-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-organization-section/product-organization-section.tsxindex b2233ed05..f5aaef0b4 100644--- a/packages/admin/src/pages/products/product-detail/components/product-organization-section/product-organization-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-organization-section/product-organization-section.tsx@@ -1,18 +1,16 @@import { PencilSquare } from "@medusajs/icons";-import { HttpTypes } from "@medusajs/types";import { Badge, Container, Heading, Tooltip } from "@medusajs/ui";import { useTranslation } from "react-i18next";import { Link } from "react-router-dom";+import { HttpTypes } from "@medusajs/types";import { ActionMenu } from "../../../../../components/common/action-menu";import { SectionRow } from "../../../../../components/common/section";-type ProductOrganizationSectionProps = {- product: HttpTypes.AdminProduct;-};-export const ProductOrganizationSection = ({product,-}: ProductOrganizationSectionProps) => {+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation();return (diff --git a/packages/admin/src/pages/products/product-detail/components/product-sales-channel-section/product-sales-channel-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-sales-channel-section/product-sales-channel-section.tsxindex ef046d0f1..947dd7744 100644--- a/packages/admin/src/pages/products/product-detail/components/product-sales-channel-section/product-sales-channel-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-sales-channel-section/product-sales-channel-section.tsx@@ -1,18 +1,16 @@import { Channels, PencilSquare } from "@medusajs/icons"import { Container, Heading, Text, Tooltip } from "@medusajs/ui"import { Trans, useTranslation } from "react-i18next"+import { HttpTypes } from "@medusajs/types"import { ActionMenu } from "../../../../../components/common/action-menu"import { useSalesChannels } from "../../../../../hooks/api/sales-channels"-import { HttpTypes } from "@medusajs/types"--type ProductSalesChannelSectionProps = {- product: HttpTypes.AdminProduct-}// TODO: The fetched sales channel doesn't contain all necessary infoexport const ProductSalesChannelSection = ({product,-}: ProductSalesChannelSectionProps) => {+}: {+ product: HttpTypes.AdminProduct;+}) => {const { count } = useSalesChannels()const { t } = useTranslation()diff --git a/packages/admin/src/pages/products/product-detail/components/product-shipping-profile-section/product-shipping-profile-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-shipping-profile-section/product-shipping-profile-section.tsxindex 1cfab5435..736113eb9 100644--- a/packages/admin/src/pages/products/product-detail/components/product-shipping-profile-section/product-shipping-profile-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-shipping-profile-section/product-shipping-profile-section.tsx@@ -1,20 +1,16 @@import { PencilSquare, ShoppingBag } from "@medusajs/icons"-import { HttpTypes } from "@medusajs/types"import { Container, Heading } from "@medusajs/ui"import { useTranslation } from "react-i18next"+import { HttpTypes } from "@medusajs/types"import { SidebarLink } from "../../../../../components/common/sidebar-link/sidebar-link"import { ActionMenu } from "../../../../../components/common/action-menu"-type ProductShippingProfileSectionProps = {- product: HttpTypes.AdminProduct & {- shipping_profile: HttpTypes.AdminShippingProfile- }-}-export const ProductShippingProfileSection = ({product,-}: ProductShippingProfileSectionProps) => {+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation()const shippingProfile = product.shipping_profilediff --git a/packages/admin/src/pages/products/product-detail/components/product-variant-section/product-variant-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-variant-section/product-variant-section.tsxindex edd7b9a3d..620fde6a2 100644--- a/packages/admin/src/pages/products/product-detail/components/product-variant-section/product-variant-section.tsx+++ b/packages/admin/src/pages/products/product-detail/components/product-variant-section/product-variant-section.tsx@@ -24,15 +24,14 @@ import { useDataTableDateFilters } from '../../../../../components/data-table/heimport { useDeleteVariantLazy, useProductVariants } from '../../../../../hooks/api/products';import { useQueryParams } from '../../../../../hooks/use-query-params';import { PRODUCT_VARIANT_IDS_KEY } from '../../../common/constants';--type ProductVariantSectionProps = {- product: HttpTypes.AdminProduct;-};-const PAGE_SIZE = 10;const PREFIX = 'pv';-export const ProductVariantSection = ({ product }: ProductVariantSectionProps) => {+export const ProductVariantSection = ({+ product,+}: {+ product: HttpTypes.AdminProduct;+}) => {const { t } = useTranslation();const { q, order, offset, allow_backorder, manage_inventory, created_at, updated_at } =diff --git a/packages/admin/src/pages/products/product-detail/index.ts b/packages/admin/src/pages/products/product-detail/index.tsindex eeb6d5461..508e5be05 100644--- a/packages/admin/src/pages/products/product-detail/index.ts+++ b/packages/admin/src/pages/products/product-detail/index.ts@@ -1,3 +1,3 @@export { ProductDetailBreadcrumb as Breadcrumb } from "./breadcrumb"export { productLoader as loader } from "./loader"-export { ProductDetail as Component } from "./product-detail"+export { ProductDetailPage as Component } from "./product-detail"diff --git a/packages/admin/src/pages/products/product-detail/product-detail.tsx b/packages/admin/src/pages/products/product-detail/product-detail.tsxindex 7cf07da5e..f813395cd 100644--- a/packages/admin/src/pages/products/product-detail/product-detail.tsx+++ b/packages/admin/src/pages/products/product-detail/product-detail.tsx@@ -1,3 +1,4 @@+import { Children, ReactNode } from "react";import { useLoaderData, useParams } from "react-router-dom";import { TwoColumnPageSkeleton } from "../../../components/common/skeleton";@@ -15,7 +16,7 @@ import { ProductShippingProfileSection } from "./components/product-shipping-proimport { ProductVariantSection } from "./components/product-variant-section";import { productLoader } from "./loader";-export const ProductDetail = () => {+const Root = ({ children }: { children?: ReactNode }) => {const initialData = useLoaderData() as Awaited<ReturnType<typeof productLoader>>;@@ -44,23 +45,44 @@ export const ProductDetail = () => {throw error;}- return (- <div data-testid="product-detail-page">- <TwoColumnPage showJSON showMetadata data={product}>- <TwoColumnPage.Main data-testid="product-detail-main">- <ProductGeneralSection product={product} />- <ProductMediaSection product={product} />- <ProductOptionSection product={product} />- <ProductVariantSection product={product} />- </TwoColumnPage.Main>- <TwoColumnPage.Sidebar data-testid="product-detail-sidebar">- <ProductSellerSection seller={(product as any).seller} />- <ProductSalesChannelSection product={product} />- <ProductShippingProfileSection product={product} />- <ProductOrganizationSection product={product} />- <ProductAttributeSection product={product} />- </TwoColumnPage.Sidebar>- </TwoColumnPage>- </div>+ return Children.count(children) > 0 ? (+ <TwoColumnPage data-testid="product-detail-page">+ {children}+ </TwoColumnPage>+ ) : (+ <TwoColumnPage+ data={product}+ showJSON+ showMetadata+ data-testid="product-detail-page"+ >+ <TwoColumnPage.Main data-testid="product-detail-main">+ <ProductGeneralSection product={product} />+ <ProductMediaSection product={product} />+ <ProductOptionSection product={product} />+ <ProductVariantSection product={product} />+ </TwoColumnPage.Main>+ <TwoColumnPage.Sidebar data-testid="product-detail-sidebar">+ <ProductSellerSection seller={(product as any).seller} />+ <ProductSalesChannelSection product={product} />+ <ProductShippingProfileSection product={product} />+ <ProductOrganizationSection product={product} />+ <ProductAttributeSection product={product} />+ </TwoColumnPage.Sidebar>+ </TwoColumnPage>);};++export const ProductDetailPage = Object.assign(Root, {+ Main: TwoColumnPage.Main,+ Sidebar: TwoColumnPage.Sidebar,+ MainGeneralSection: ProductGeneralSection,+ MainMediaSection: ProductMediaSection,+ MainOptionSection: ProductOptionSection,+ MainVariantSection: ProductVariantSection,+ SidebarSellerSection: ProductSellerSection,+ SidebarSalesChannelSection: ProductSalesChannelSection,+ SidebarShippingProfileSection: ProductShippingProfileSection,+ SidebarOrganizationSection: ProductOrganizationSection,+ SidebarAttributeSection: ProductAttributeSection,+});diff --git a/packages/admin/src/pages/products/product-list/components/product-list-table/index.ts b/packages/admin/src/pages/products/product-list/components/product-list-table/index.tsindex ee665245d..85968c0ed 100644--- a/packages/admin/src/pages/products/product-list/components/product-list-table/index.ts+++ b/packages/admin/src/pages/products/product-list/components/product-list-table/index.ts@@ -1 +1,10 @@-export * from "./product-list-table"+export {+ ProductListTable,+ ProductListHeader,+ ProductListTitle,+ ProductListActions,+ ProductListCreateButton,+ ProductListExportButton,+ ProductListImportButton,+ ProductListDataTable,+} from "./product-list-table"diff --git a/packages/admin/src/pages/products/product-list/components/product-list-table/product-list-table.tsx b/packages/admin/src/pages/products/product-list/components/product-list-table/product-list-table.tsxindex 0b12697bf..986f52072 100644--- a/packages/admin/src/pages/products/product-list/components/product-list-table/product-list-table.tsx+++ b/packages/admin/src/pages/products/product-list/components/product-list-table/product-list-table.tsx@@ -2,7 +2,7 @@ import { PencilSquare, Trash } from "@medusajs/icons";import { Button, Container, Heading, toast, usePrompt } from "@medusajs/ui";import { keepPreviousData } from "@tanstack/react-query";import { createColumnHelper } from "@tanstack/react-table";-import { useMemo } from "react";+import { Children, ReactNode, useMemo } from "react";import { useTranslation } from "react-i18next";import { Link, Outlet, useLoaderData, useLocation } from "react-router-dom";@@ -21,10 +21,115 @@ import { productsLoader } from "../../loader";const PAGE_SIZE = 20;-export const ProductListTable = () => {+export const ProductListTitle = () => {+ const { t } = useTranslation();++ return (+ <Heading level="h2" data-testid="products-list-title">+ {t("products.domain")}+ </Heading>+ );+};++export const ProductListCreateButton = () => {+ const { t } = useTranslation();++ return (+ <Button+ size="small"+ variant="secondary"+ asChild+ data-testid="products-create-button"+ >+ <Link to="create" data-testid="products-create-link">+ {t("actions.create")}+ </Link>+ </Button>+ );+};++export const ProductListExportButton = () => {const { t } = useTranslation();const location = useLocation();+ return (+ <Button+ size="small"+ variant="secondary"+ asChild+ data-testid="products-export-button"+ >+ <Link+ to={`export${location.search}`}+ data-testid="products-export-link"+ >+ {t("actions.export")}+ </Link>+ </Button>+ );+};++export const ProductListImportButton = () => {+ const { t } = useTranslation();+ const location = useLocation();++ return (+ <Button+ size="small"+ variant="secondary"+ asChild+ data-testid="products-import-button"+ >+ <Link+ to={`import${location.search}`}+ data-testid="products-import-link"+ >+ {t("actions.import")}+ </Link>+ </Button>+ );+};++export const ProductListActions = ({ children }: { children?: ReactNode }) => {+ return (+ <div+ className="flex items-center justify-center gap-x-2"+ data-testid="products-list-actions"+ >+ {Children.count(children) > 0 ? (+ children+ ) : (+ <>+ <ProductListExportButton />+ <ProductListImportButton />+ <ProductListCreateButton />+ </>+ )}+ </div>+ );+};++export const ProductListHeader = ({ children }: { children?: ReactNode }) => {+ return (+ <div+ className="flex items-center justify-between px-6 py-4"+ data-testid="products-list-header"+ >+ {Children.count(children) > 0 ? (+ children+ ) : (+ <>+ <ProductListTitle />+ <ProductListActions />+ </>+ )}+ </div>+ );+};++export const ProductListDataTable = () => {+ const { t } = useTranslation();+const initialData = useLoaderData() as Awaited<ReturnType<ReturnType<typeof productsLoader>>>;@@ -57,79 +162,43 @@ export const ProductListTable = () => {throw error;}+ return (+ <div data-testid="products-data-table">+ <_DataTable+ table={table}+ columns={columns}+ count={count}+ pageSize={PAGE_SIZE}+ filters={filters}+ search+ pagination+ isLoading={isLoading}+ queryObject={raw}+ navigateTo={(row) => `${row.original.id}`}+ orderBy={[+ { key: "title", label: t("fields.title") },+ { key: "created_at", label: t("fields.createdAt") },+ { key: "updated_at", label: t("fields.updatedAt") },+ ]}+ noRecords={{+ message: t("products.list.noRecordsMessage"),+ }}+ />+ </div>+ );+};++export const ProductListTable = ({ children }: { children?: ReactNode }) => {return (<Container className="divide-y p-0" data-testid="products-list-table">- <div- className="flex items-center justify-between px-6 py-4"- data-testid="products-list-header"- >- <Heading level="h2" data-testid="products-list-title">- {t("products.domain")}- </Heading>- <div- className="flex items-center justify-center gap-x-2"- data-testid="products-list-actions"- >- <Button- size="small"- variant="secondary"- asChild- data-testid="products-export-button"- >- <Link- to={`export${location.search}`}- data-testid="products-export-link"- >- {t("actions.export")}- </Link>- </Button>- <Button- size="small"- variant="secondary"- asChild- data-testid="products-import-button"- >- <Link- to={`import${location.search}`}- data-testid="products-import-link"- >- {t("actions.import")}- </Link>- </Button>- <Button- size="small"- variant="secondary"- asChild- data-testid="products-create-button"- >- <Link to="create" data-testid="products-create-link">- {t("actions.create")}- </Link>- </Button>- </div>- </div>- <div data-testid="products-data-table">- <_DataTable- table={table}- columns={columns}- count={count}- pageSize={PAGE_SIZE}- filters={filters}- search- pagination- isLoading={isLoading}- queryObject={raw}- navigateTo={(row) => `${row.original.id}`}- orderBy={[- { key: "title", label: t("fields.title") },- { key: "created_at", label: t("fields.createdAt") },- { key: "updated_at", label: t("fields.updatedAt") },- ]}- noRecords={{- message: t("products.list.noRecordsMessage"),- }}- />- </div>+ {Children.count(children) > 0 ? (+ children+ ) : (+ <>+ <ProductListHeader />+ <ProductListDataTable />+ </>+ )}<Outlet /></Container>);diff --git a/packages/admin/src/pages/products/product-list/index.ts b/packages/admin/src/pages/products/product-list/index.tsindex 085cd656a..72b1e88fd 100644--- a/packages/admin/src/pages/products/product-list/index.ts+++ b/packages/admin/src/pages/products/product-list/index.ts@@ -1,2 +1,2 @@export { productsLoader as productLoader } from "./loader"-export { ProductList as Component } from "./product-list"+export { ProductListPage as Component } from "./product-list"diff --git a/packages/admin/src/pages/products/product-list/product-list.tsx b/packages/admin/src/pages/products/product-list/product-list.tsxindex 7b8a5ab0f..dbd811c3f 100644--- a/packages/admin/src/pages/products/product-list/product-list.tsx+++ b/packages/admin/src/pages/products/product-list/product-list.tsx@@ -1,12 +1,33 @@+import { Children, ReactNode } from "react"import { SingleColumnPage } from "../../../components/layout/pages"-import { ProductListTable } from "./components/product-list-table"+import {+ ProductListTable,+ ProductListHeader,+ ProductListTitle,+ ProductListActions,+ ProductListCreateButton,+ ProductListExportButton,+ ProductListImportButton,+ ProductListDataTable,+} from "./components/product-list-table"-export const ProductList = () => {+const Root = ({ children }: { children?: ReactNode }) => {return (<div data-testid="products-page"><SingleColumnPage>- <ProductListTable />+ {Children.count(children) > 0 ? children : <ProductListTable />}</SingleColumnPage></div>)}++export const ProductListPage = Object.assign(Root, {+ Table: ProductListTable,+ Header: ProductListHeader,+ HeaderTitle: ProductListTitle,+ HeaderActions: ProductListActions,+ HeaderCreateButton: ProductListCreateButton,+ HeaderExportButton: ProductListExportButton,+ HeaderImportButton: ProductListImportButton,+ DataTable: ProductListDataTable,+})