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: update vendor project configuration and structure
Jakub Sieradzkicd09b2c90b92
diff --git a/packages/vendor/src/components/layout/user-menu/user-menu.tsx b/packages/vendor/src/components/layout/user-menu/user-menu.tsxindex 0ed2c68f0..17f1384ee 100644--- a/packages/vendor/src/components/layout/user-menu/user-menu.tsx+++ b/packages/vendor/src/components/layout/user-menu/user-menu.tsx@@ -59,7 +59,7 @@ export const UserMenu = () => {</DropdownMenu.Item><DropdownMenu.Separator /><DropdownMenu.Item asChild>- <Link to="https://docs.medusajs.com" target="_blank">+ <Link to="https://docs.mercurjs.com/introduction" target="_blank"><BookOpen className="text-ui-fg-subtle me-2" />{t("app.menus.user.documentation")}</Link>diff --git a/packages/vendor/src/pages/products/[id]/_components/product-variant-section/product-variant-section.tsx b/packages/vendor/src/pages/products/[id]/_components/product-variant-section/product-variant-section.tsxindex 93ffd3571..1fcff3a5b 100644--- a/packages/vendor/src/pages/products/[id]/_components/product-variant-section/product-variant-section.tsx+++ b/packages/vendor/src/pages/products/[id]/_components/product-variant-section/product-variant-section.tsx@@ -209,21 +209,22 @@ const useColumns = (product: HttpTypes.AdminProduct) => {{icon: <PencilSquare />,label: t("actions.edit"),- onClick: (row) => {- navigate(- `edit-variant?variant_id=${- row.row.original.id- }&${tableSearchParams.toString()}`,- {- state: {- restore_params: tableSearchParams.toString(),- },- },- );+ onClick: () => {+ navigate(`variants/${variant.id}/edit`);},},];+ if (variant.manage_inventory && variant.inventory_items?.length) {+ mainActions.push({+ label: t("products.variant.inventory.actions.inventoryItems"),+ onClick: () => {+ navigate(`variants/${variant.id}`);+ },+ icon: <Buildings />,+ });+ }+const secondaryActions: DataTableAction<HttpTypes.AdminProductVariant>[] =[{@@ -233,46 +234,6 @@ const useColumns = (product: HttpTypes.AdminProduct) => {},];- const inventoryItemsCount = variant.inventory_items?.length || 0;-- switch (inventoryItemsCount) {- case 0:- break;- case 1: {- const inventoryItemLink = `/inventory/${- variant.inventory_items![0].inventory.id- }`;-- mainActions.push({- label: t("products.variant.inventory.actions.inventoryItems"),- onClick: () => {- navigate(inventoryItemLink);- },- icon: <Buildings />,- });- break;- }- default: {- const ids = variant.inventory_items?.map((i) => i.inventory?.id);-- if (!ids || ids.length === 0) {- break;- }-- const inventoryKitLink = `/inventory?${new URLSearchParams({- id: ids.join(","),- }).toString()}`;-- mainActions.push({- label: t("products.variant.inventory.actions.inventoryKit"),- onClick: () => {- navigate(inventoryKitLink);- },- icon: <Component />,- });- }- }-return [mainActions, secondaryActions];},[handleDelete, navigate, t, tableSearchParams],diff --git a/packages/vendor/src/pages/products/[id]/shipping-profile/product-organization-form/product-shipping-profile-form.tsx b/packages/vendor/src/pages/products/[id]/shipping-profile/product-organization-form/product-shipping-profile-form.tsxindex 90cf7629c..c593d1593 100644--- a/packages/vendor/src/pages/products/[id]/shipping-profile/product-organization-form/product-shipping-profile-form.tsx+++ b/packages/vendor/src/pages/products/[id]/shipping-profile/product-organization-form/product-shipping-profile-form.tsx@@ -40,8 +40,8 @@ export const ProductShippingProfileForm = ({}),getOptions: (data: any) =>(data.shipping_profiles || []).map((sp: any) => ({- label: sp.shipping_profile?.name || sp.name,- value: sp.shipping_profile?.id || sp.id,+ label: sp.name ?? "",+ value: sp.id,})),})diff --git a/packages/vendor/src/pages/products/create/constants.ts b/packages/vendor/src/pages/products/create/constants.tsindex b1bc321ef..e1fc08b9b 100644--- a/packages/vendor/src/pages/products/create/constants.ts+++ b/packages/vendor/src/pages/products/create/constants.ts@@ -55,39 +55,40 @@ export type ProductCreateOptionSchema = z.infer<typeof ProductCreateOptionSchema>-export const ProductCreateSchema = z- .object({- title: z.string().min(1),- subtitle: z.string().optional(),- handle: z.string().optional(),- description: z.string().optional(),- discountable: z.boolean(),- type_id: z.string().optional(),- collection_id: z.string().optional(),- shipping_profile_id: z.string().optional(),- categories: z.array(z.string()),- tags: z.array(z.string()).optional(),- sales_channels: z- .array(- z.object({- id: z.string(),- name: z.string(),- })- )- .optional(),- origin_country: z.string().optional(),- material: z.string().optional(),- width: z.string().optional(),- length: z.string().optional(),- height: z.string().optional(),- weight: z.string().optional(),- mid_code: z.string().optional(),- hs_code: z.string().optional(),- options: z.array(ProductCreateOptionSchema).min(1),- enable_variants: z.boolean(),- variants: z.array(ProductCreateVariantSchema).min(1),- media: z.array(MediaSchema).optional(),- })+export const ProductCreateBaseSchema = z.object({+ title: z.string().min(1),+ subtitle: z.string().optional(),+ handle: z.string().optional(),+ description: z.string().optional(),+ discountable: z.boolean(),+ type_id: z.string().optional(),+ collection_id: z.string().optional(),+ shipping_profile_id: z.string().optional(),+ categories: z.array(z.string()),+ tags: z.array(z.string()).optional(),+ sales_channels: z+ .array(+ z.object({+ id: z.string(),+ name: z.string(),+ })+ )+ .optional(),+ origin_country: z.string().optional(),+ material: z.string().optional(),+ width: z.string().optional(),+ length: z.string().optional(),+ height: z.string().optional(),+ weight: z.string().optional(),+ mid_code: z.string().optional(),+ hs_code: z.string().optional(),+ options: z.array(ProductCreateOptionSchema).min(1),+ enable_variants: z.boolean(),+ variants: z.array(ProductCreateVariantSchema).min(1),+ media: z.array(MediaSchema).optional(),+})++export const ProductCreateSchema = ProductCreateBaseSchema.superRefine((data, ctx) => {if (data.variants.every((v) => !v.should_create)) {return ctx.addIssue({diff --git a/packages/vendor/src/pages/products/create/context.tsx b/packages/vendor/src/pages/products/create/context.tsxdeleted file mode 100644index 5be1572b4..000000000--- a/packages/vendor/src/pages/products/create/context.tsx+++ /dev/null@@ -1,52 +0,0 @@-import { createContext, useContext } from "react"-import { UseFormReturn } from "react-hook-form"-import { HttpTypes } from "@medusajs/types"--export interface ProductCreateFormValues {- title: string- subtitle?: string- handle?: string- description?: string- discountable?: boolean- type_id?: string- collection_id?: string- categories: string[]- tags?: string[]- sales_channels?: { id: string; name: string }[]- options: { title: string; values: string[] }[]- variants: Record<string, any>[]- media?: any[]- enable_variants?: boolean- width?: string- length?: string- height?: string- weight?: string- mid_code?: string- hs_code?: string- origin_country?: string- [key: string]: any-}--export interface ProductCreateContextValue {- form: UseFormReturn<ProductCreateFormValues>- store?: HttpTypes.AdminStore- defaultChannel?: HttpTypes.AdminSalesChannel- regions?: HttpTypes.AdminRegion[]- pricePreferences?: HttpTypes.AdminPricePreference[]-}--const ProductCreateContext = createContext<ProductCreateContextValue | null>(- null-)--export const useProductCreateContext = () => {- const context = useContext(ProductCreateContext)- if (!context) {- throw new Error(- "useProductCreateContext must be used within a ProductCreatePage"- )- }- return context-}--export const ProductCreateProvider = ProductCreateContext.Providerdiff --git a/packages/vendor/src/pages/products/create/index.ts b/packages/vendor/src/pages/products/create/index.tsindex 86a2be1b2..3aba86f1b 100644--- a/packages/vendor/src/pages/products/create/index.ts+++ b/packages/vendor/src/pages/products/create/index.ts@@ -1 +1,2 @@-export * from "./product-create-page";\ No newline at end of file+export * from "./product-create-page";+export * from "./constants";\ No newline at end of filediff --git a/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsx b/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsxindex 84826993a..c02764e27 100644--- a/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsx+++ b/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-general-section/product-create-general-section.tsx@@ -1,19 +1,14 @@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 { ProductCreateSchemaType } from "../../../../types"+import { useTabbedForm } from "@components/tabbed-form"+import { ProductCreateSchemaType } from "../../../types"-type ProductCreateGeneralSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateGeneralSection = ({- form,-}: ProductCreateGeneralSectionProps) => {+export const ProductCreateGeneralSection = () => {const { t } = useTranslation()+ const form = useTabbedForm<ProductCreateSchemaType>()return (<div id="general" className="flex flex-col gap-y-6">diff --git a/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsx b/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsxindex 7ce64ecf0..8e7201731 100644--- a/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsx+++ b/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-media-section/product-create-details-media-section.tsx@@ -27,15 +27,12 @@ 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 { UploadMediaFormItem } from "@pages/products/common/components/upload-media-form-item"-import { ProductCreateSchemaType } from "../../../../types"--type ProductCreateMediaSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}+import { useTabbedForm } from "@components/tabbed-form"+import { ProductCreateSchemaType } from "../../../types"const dropAnimationConfig: DropAnimation = {sideEffects: defaultDropAnimationSideEffects({@@ -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/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx b/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsxindex 110e9c3d9..bc4c129ad 100644--- a/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx+++ b/packages/vendor/src/pages/products/create/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx@@ -15,7 +15,6 @@ import {import {Controller,FieldArrayWithId,- UseFormReturn,useFieldArray,useWatch,} from "react-hook-form"@@ -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 { ProductCreateSchemaType } from "../../../../types"+import { useTabbedForm } from "@components/tabbed-form"+import { ProductCreateSchemaType } from "../../../types"import { decorateVariantsWithDefaultValues } from "@pages/products/create/utils"-type ProductCreateVariantsSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}-const getPermutations = (data: { title: string; values: string[] }[]): { [key: string]: string }[] => {@@ -60,10 +56,9 @@ const getVariantName = (options: Record<string, string>) => {return Object.values(options).join(" / ")}-export const ProductCreateVariantsSection = ({- form,-}: ProductCreateVariantsSectionProps) => {+export const ProductCreateVariantsSection = () => {const { t } = useTranslation()+ const form = useTabbedForm<ProductCreateSchemaType>()const options = useFieldArray({control: form.control,@@ -143,7 +138,6 @@ export const ProductCreateVariantsSection = ({options: permutation,should_create: hasUserSelectedVariants ? false : true,variant_rank: newVariants.length,- // NOTE - prepare inventory array here for now so we prevent rendering issue if we append the items laterinventory: [{ inventory_item_id: "", required_quantity: "" }],})})@@ -209,8 +203,6 @@ export const ProductCreateVariantsSection = ({const handleRankChange = (items: FieldArrayWithId<ProductCreateSchemaType, "variants">[]) => {- // Items in the SortableList are memorised, so we need to find the current- // value to preserve any changes that have been made to `should_create`.const update = items.map((item, index) => {const variant = watchedVariants.find((v) => v.title === item.title)diff --git a/packages/vendor/src/pages/products/create/product-create-details-form/product-create-details-form.tsx b/packages/vendor/src/pages/products/create/product-create-details-form/product-create-details-form.tsxindex 7113f32f7..7f5b08f46 100644--- a/packages/vendor/src/pages/products/create/product-create-details-form/product-create-details-form.tsx+++ b/packages/vendor/src/pages/products/create/product-create-details-form/product-create-details-form.tsx@@ -1,32 +1,45 @@import { Divider, Heading } from "@medusajs/ui";-import { UseFormReturn } from "react-hook-form";+import { Children, ReactNode } from "react";import { useTranslation } from "react-i18next";-import { ProductCreateSchemaType } from "../../types";+import { TabDefinition } 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>;-};+const Root = ({ children }: { children?: ReactNode }) => {+ if (Children.count(children) > 0) {+ return (+ <div className="flex flex-col items-center p-16">+ <div className="flex w-full max-w-[720px] flex-col gap-y-8">+ <Header />+ {children}+ </div>+ </div>+ );+ }-export const ProductCreateDetailsForm = ({ form }: ProductAttributesProps) => {return (<div className="flex flex-col items-center p-16"><div className="flex w-full max-w-[720px] flex-col gap-y-8"><Header /><div className="flex flex-col gap-y-6">- <ProductCreateGeneralSection form={form} />- <ProductCreateMediaSection form={form} />+ <ProductCreateGeneralSection />+ <ProductCreateMediaSection /></div><Divider />- <ProductCreateVariantsSection form={form} />+ <ProductCreateVariantsSection /></div></div>);};+Root._tabMeta = {+ id: "details",+ labelKey: "products.create.tabs.details",+ validationFields: ["title", "media", "options", "variants", "enable_variants"],+} satisfies TabDefinition;+const Header = () => {const { t } = useTranslation();@@ -36,3 +49,10 @@ const Header = () => {</div>);};++export const ProductCreateDetailsForm = Object.assign(Root, {+ _tabMeta: Root._tabMeta,+ GeneralSection: ProductCreateGeneralSection,+ MediaSection: ProductCreateMediaSection,+ VariantsSection: ProductCreateVariantsSection,+});diff --git a/packages/vendor/src/pages/products/create/product-create-form/product-create-form.tsx b/packages/vendor/src/pages/products/create/product-create-form/product-create-form.tsxindex 81009b675..7a1aa502d 100644--- a/packages/vendor/src/pages/products/create/product-create-form/product-create-form.tsx+++ b/packages/vendor/src/pages/products/create/product-create-form/product-create-form.tsx@@ -1,64 +1,47 @@-import { Button, ProgressStatus, ProgressTabs, toast } from "@medusajs/ui";-import { HttpTypes } from "@medusajs/types";-import { useEffect, useMemo, useState } 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 { useCreateProduct } from "@hooks/api/products";-import { uploadFilesQuery } from "@lib/client";+import { Button, toast } from "@medusajs/ui"+import { HttpTypes } from "@medusajs/types"+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 { TabbedForm, TabDefinition } from "@components/tabbed-form"+import { useCreateProduct } from "@hooks/api/products"+import { uploadFilesQuery } from "@lib/client"import {PRODUCT_CREATE_FORM_DEFAULTS,ProductCreateSchema,-} from "@pages/products/create/constants";-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 { usePricePreferences } from "@hooks/api/price-preferences";-import { useRegions } from "@hooks/api";-import { zodResolver } from "@hookform/resolvers/zod";+} from "@pages/products/create/constants"+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 { zodResolver } from "@hookform/resolvers/zod"+import { ProductCreateSchemaType } from "../types"+import { z } from "zod"-enum Tab {- DETAILS = "details",- ORGANIZE = "organize",- VARIANTS = "variants",- INVENTORY = "inventory",-}--type TabState = Record<Tab, ProgressStatus>;--const SAVE_DRAFT_BUTTON = "save-draft-button";+const SAVE_DRAFT_BUTTON = "save-draft-button"type ProductCreateFormProps = {- defaultChannel?: HttpTypes.AdminSalesChannel;- store?: HttpTypes.AdminStore;- pricePreferences?: HttpTypes.AdminPricePreference[];-};+ defaultChannel?: HttpTypes.AdminSalesChannel+ children?: ReactNode+ schema?: z.ZodType<any>+ defaultValues?: Record<string, any>+}export const ProductCreateForm = ({- defaultChannel,- store,+ defaultChannel: defaultChannelProp,+ children,+ schema,+ defaultValues: extraDefaults,}: 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 defaultChannel = defaultChannelProp- const { t } = useTranslation();- const { handleSuccess } = useRouteModal();-- const { regions } = useRegions({ limit: 9999 });- const { price_preferences: pricePreferences } = usePricePreferences({- limit: 9999,- });-- const form = useForm({+ const form = useForm<ProductCreateSchemaType>({defaultValues: {...PRODUCT_CREATE_FORM_DEFAULTS,+ ...extraDefaults,sales_channels: defaultChannel? [{@@ -68,55 +51,78 @@ export const ProductCreateForm = ({]: [],},- resolver: zodResolver(ProductCreateSchema),- });+ resolver: zodResolver(schema ?? ProductCreateSchema),+ })++ const { mutateAsync, isPending } = useCreateProduct()- const { mutateAsync, isPending } = useCreateProduct();+ const defaultTabs = useMemo(+ () => [+ <ProductCreateDetailsForm key="details" />,+ <ProductCreateOrganizeForm key="organize" />,+ <ProductCreateVariantsForm key="variants" />,+ <ProductCreateInventoryKitForm key="inventory" />,+ ],+ []+ )++ const hasCustomChildren = Children.count(children) > 0/*** TODO: Important to revisit this - use variants watch so high in the tree can cause needless rerenders of the entire page* which is suboptimal when rerenders are caused by bulk editor changes*/-const watchedVariants = useWatch({control: form.control,name: "variants",- });-- const showInventoryTab = useMemo(- () => watchedVariants.some((v) => v.manage_inventory && v.inventory_kit),- [watchedVariants],- );+ })++ const transformTabs = useCallback(+ (tabs: TabDefinition<ProductCreateSchemaType>[]) =>+ tabs.map((tab) => {+ if (tab.id === "inventory" && tab.isVisible) {+ return {+ ...tab,+ isVisible: () =>+ watchedVariants.some(+ (v) => v.manage_inventory && v.inventory_kit+ ),+ }+ }+ return tab+ }),+ [watchedVariants]+ )const handleSubmit = form.handleSubmit(async (values, e) => {- let isDraftSubmission = false;+ let isDraftSubmission = falseif (e?.nativeEvent instanceof SubmitEvent) {- const submitter = e?.nativeEvent?.submitter as HTMLButtonElement;- isDraftSubmission = submitter.dataset.name === SAVE_DRAFT_BUTTON;+ const submitter = e?.nativeEvent?.submitter as HTMLButtonElement+ isDraftSubmission = submitter.dataset.name === SAVE_DRAFT_BUTTON}- const media = values.media || [];- const payload = { ...values, media: undefined };+ const media = values.media || []+ const payload = { ...values, media: undefined }let uploadedMedia: (HttpTypes.AdminFile & {- isThumbnail: boolean;- })[] = [];+ isThumbnail: boolean+ })[] = []try {if (media.length) {- const thumbnailReq = media.filter((m) => m.isThumbnail);- const otherMediaReq = media.filter((m) => !m.isThumbnail);+ const thumbnailReq = media.filter((m) => m.isThumbnail)+ const otherMediaReq = media.filter((m) => !m.isThumbnail)- const fileReqs = [];+ const fileReqs = []if (thumbnailReq?.length) {fileReqs.push(uploadFilesQuery(thumbnailReq).then((r: any) =>r.files.map((f: any) => ({...f,isThumbnail: true,- })),- ),- );+ }))+ )+ )}if (otherMediaReq?.length) {fileReqs.push(@@ -124,16 +130,16 @@ export const ProductCreateForm = ({r.files.map((f: any) => ({...f,isThumbnail: false,- })),- ),- );+ }))+ )+ )}- uploadedMedia = (await Promise.all(fileReqs)).flat();+ uploadedMedia = (await Promise.all(fileReqs)).flat()}} catch (error) {if (error instanceof Error) {- toast.error(error.message);+ toast.error(error.message)}}@@ -178,248 +184,66 @@ export const ProductCreateForm = ({toast.success(t("products.create.successToast", {title: data.product.title,- }),- );+ })+ )- handleSuccess(`../${data.product.id}`);+ handleSuccess(`../${data.product.id}`)},onError: (error) => {- toast.error(error.message);+ toast.error(error.message)},- },- );- });-- 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";- }-- setTabState({ ...currentState });- // eslint-disable-next-line react-hooks/exhaustive-deps -- we only want this effect to run when the tab changes- }, [tab]);+ }+ )+ })return (- <RouteFocusModal.Form form={form}>- <KeyboundForm- 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- 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"- >- <RouteFocusModal.Header>- <div className="-my-2 w-full border-l">- <ProgressTabs.List className="justify-start-start flex w-full items-center">- <ProgressTabs.Trigger- status={tabState[Tab.DETAILS]}- value={Tab.DETAILS}- className="max-w-[200px] truncate"- >- {t("products.create.tabs.details")}- </ProgressTabs.Trigger>- <ProgressTabs.Trigger- status={tabState[Tab.ORGANIZE]}- value={Tab.ORGANIZE}- className="max-w-[200px] truncate"- >- {t("products.create.tabs.organize")}- </ProgressTabs.Trigger>- <ProgressTabs.Trigger- status={tabState[Tab.VARIANTS]}- value={Tab.VARIANTS}- className="max-w-[200px] truncate"- >- {t("products.create.tabs.variants")}- </ProgressTabs.Trigger>- {showInventoryTab && (- <ProgressTabs.Trigger- status={tabState[Tab.INVENTORY]}- value={Tab.INVENTORY}- className="max-w-[200px] truncate"- >- {t("products.create.tabs.inventory")}- </ProgressTabs.Trigger>- )}- </ProgressTabs.List>- </div>- </RouteFocusModal.Header>- <RouteFocusModal.Body className="size-full overflow-hidden">- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.DETAILS}- >- <ProductCreateDetailsForm form={form} />- </ProgressTabs.Content>- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.ORGANIZE}- >- <ProductCreateOrganizeForm form={form} />- </ProgressTabs.Content>- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.VARIANTS}+ <TabbedForm+ form={form}+ onSubmit={handleSubmit}+ isLoading={isPending}+ transformTabs={transformTabs}+ footer={({ isLastTab, onNext, isLoading }) => (+ <div className="flex items-center justify-end gap-x-2">+ <RouteFocusModal.Close asChild>+ <Button variant="secondary" size="small">+ {t("actions.cancel")}+ </Button>+ </RouteFocusModal.Close>+ <Button+ data-name={SAVE_DRAFT_BUTTON}+ size="small"+ type="submit"+ isLoading={isLoading}+ className="whitespace-nowrap"+ >+ Draft+ </Button>+ {isLastTab ? (+ <Button+ data-name="publish-button"+ key="submit-button"+ type="submit"+ variant="primary"+ size="small"+ isLoading={isLoading}>- <ProductCreateVariantsForm- form={form}- store={store}- regions={regions}- pricePreferences={pricePreferences}- />- </ProgressTabs.Content>- {showInventoryTab && (- <ProgressTabs.Content- className="size-full overflow-y-auto"- value={Tab.INVENTORY}- >- <ProductCreateInventoryKitForm form={form} />- </ProgressTabs.Content>- )}- </RouteFocusModal.Body>- </ProgressTabs>- <RouteFocusModal.Footer>- <div className="flex items-center justify-end gap-x-2">- <RouteFocusModal.Close asChild>- <Button variant="secondary" size="small">- {t("actions.cancel")}- </Button>- </RouteFocusModal.Close>+ Create Product+ </Button>+ ) : (<Button- data-name={SAVE_DRAFT_BUTTON}+ key="next-button"+ type="button"+ variant="primary"size="small"- type="submit"- isLoading={isPending}- className="whitespace-nowrap"+ onClick={() => onNext()}>- Draft+ {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}- >- Create Product- </Button>- );- }-- return (- <Button- key="next-button"- type="button"- variant="primary"- size="small"- onClick={() => next(tab)}+ )}+ </div>+ )}>- {t("actions.continue")}- </Button>- );-};+ {hasCustomChildren ? children : defaultTabs}+ </TabbedForm>+ )+}diff --git a/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsx b/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsxindex 33125b7af..e85eed904 100644--- a/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsx+++ b/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/components/product-create-inventory-kit-section/product-create-inventory-kit-section.tsx@@ -1,22 +1,23 @@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 { ProductCreateSchemaType } from "../../../types"import { Form } from "@components/common/form"import { Combobox } from "@components/inputs/combobox"import { useComboboxData } from "@hooks/use-combobox-data"import { fetchQuery } from "@lib/client"+import { useTabbedForm } from "@components/tabbed-form"type VariantSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>variant: ProductCreateSchemaType["variants"][0]index: number}-function VariantSection({ form, variant, index }: VariantSectionProps) {+function VariantSection({ variant, index }: VariantSectionProps) {const { t } = useTranslation()+ const form = useTabbedForm<ProductCreateSchemaType>()const inventory = useFieldArray({control: form.control,@@ -42,11 +43,6 @@ function VariantSection({ form, variant, index }: VariantSectionProps) {})),})- /**- * Will mark an option as disabled if another input already selected that option- * @param option- * @param inventoryIndex- */const isItemOptionDisabled = (option: (typeof items.options)[0],inventoryIndex: number@@ -180,14 +176,9 @@ function VariantSection({ form, variant, index }: VariantSectionProps) {)}-type ProductCreateInventoryKitSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateInventoryKitSection = ({- form,-}: ProductCreateInventoryKitSectionProps) => {+export const ProductCreateInventoryKitSection = () => {const { t } = useTranslation()+ const form = useTabbedForm<ProductCreateSchemaType>()const variants = useFieldArray({control: form.control,@@ -203,7 +194,6 @@ export const ProductCreateInventoryKitSection = ({.map((variant, variantIndex) => (<VariantSectionkey={variant.id}- form={form}variant={variant}index={variantIndex}/>diff --git a/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/product-create-inventory-kit-form.tsx b/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/product-create-inventory-kit-form.tsxindex a89918370..ba3f5d4a7 100644--- a/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/product-create-inventory-kit-form.tsx+++ b/packages/vendor/src/pages/products/create/product-create-inventory-kit-form/product-create-inventory-kit-form.tsx@@ -1,20 +1,37 @@+import { Children, ReactNode } from "react"import { UseFormReturn } from "react-hook-form"-import { ProductCreateSchemaType } from "../../types"+import { ProductCreateSchemaType, TabDefinition } from "../types"import { ProductCreateInventoryKitSection } from "./components/product-create-inventory-kit-section/product-create-inventory-kit-section"-type ProductAttributesProps = {- form: UseFormReturn<ProductCreateSchemaType>-}+const Root = ({ children }: { children?: ReactNode }) => {+ if (Children.count(children) > 0) {+ return (+ <div className="flex flex-col items-center p-16">+ <div className="flex w-full max-w-[720px] flex-col gap-y-8">+ {children}+ </div>+ </div>+ )+ }-export const ProductCreateInventoryKitForm = ({- form,-}: ProductAttributesProps) => {return (<div className="flex flex-col items-center p-16"><div className="flex w-full max-w-[720px] flex-col gap-y-8">- <ProductCreateInventoryKitSection form={form} />+ <ProductCreateInventoryKitSection /></div></div>)}++Root._tabMeta = {+ id: "inventory",+ labelKey: "products.create.tabs.inventory",+ isVisible: (form: UseFormReturn<ProductCreateSchemaType>) =>+ form.getValues("variants").some((v) => v.manage_inventory && v.inventory_kit),+} satisfies TabDefinition++export const ProductCreateInventoryKitForm = Object.assign(Root, {+ _tabMeta: Root._tabMeta,+ InventoryKitSection: ProductCreateInventoryKitSection,+})diff --git a/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsx b/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsxindex c3e6345f5..586fc804d 100644--- a/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsx+++ b/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-attribute-section/product-create-details-attribute-section.tsx@@ -1,19 +1,14 @@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 { ProductCreateSchemaType } from "../../../../types"+import { useTabbedForm } from "@components/tabbed-form"+import { ProductCreateSchemaType } from "../../../types"-type ProductCreateAttributeSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>-}--export const ProductCreateAttributeSection = ({- form,-}: ProductCreateAttributeSectionProps) => {+export const ProductCreateAttributeSection = () => {const { t } = useTranslation()+ const form = useTabbedForm<ProductCreateSchemaType>()return (<div id="attributes" className="flex flex-col gap-y-8">diff --git a/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsx b/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsxindex b34a8ea33..50ce5cee7 100644--- a/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsx+++ b/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-organize-section/product-create-details-organize-section.tsx@@ -1,5 +1,4 @@import { Heading } from "@medusajs/ui";-import { UseFormReturn } from "react-hook-form";import { useTranslation } from "react-i18next";import { Form } from "@components/common/form";@@ -7,17 +6,13 @@ import { SwitchBox } from "@components/common/switch-box";import { Combobox } from "@components/inputs/combobox";import { useComboboxData } from "@hooks/use-combobox-data";import { sdk, fetchQuery } from "@lib/client";-import { ProductCreateSchemaType } from "../../../../types";+import { useTabbedForm } from "@components/tabbed-form";+import { ProductCreateSchemaType } from "../../../types";import { CategoryCombobox } from "@pages/products/common/components/category-combobox";-type ProductCreateOrganizationSectionProps = {- form: UseFormReturn<ProductCreateSchemaType>;-};--export const ProductCreateOrganizationSection = ({- form,-}: ProductCreateOrganizationSectionProps) => {+export const ProductCreateOrganizationSection = () => {const { t } = useTranslation();+ const form = useTabbedForm<ProductCreateSchemaType>();const collections = useComboboxData({queryKey: ["product_collections"],@@ -130,7 +125,6 @@ export const ProductCreateOrganizationSection = ({</Form.Label><Form.Control><CategoryCombobox {...field} />- {/* <CategorySelect /> */}</Form.Control><Form.ErrorMessage /></Form.Item>diff --git a/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsx b/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsxindex 034e96a20..f93882593 100644--- a/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsx+++ b/packages/vendor/src/pages/products/create/product-create-organize-form/components/product-create-sales-channel-stacked-modal/product-create-sales-channel-drawer.tsx@@ -5,7 +5,6 @@ import {} from "@medusajs/ui"import { HttpTypes } from "@medusajs/types"import { useEffect, useMemo, useState } from "react"-import { UseFormReturn } from "react-hook-form"import { useTranslation } from "react-i18next"import { keepPreviousData } from "@tanstack/react-query"@@ -16,19 +15,15 @@ import {useStackedModal,} from "@components/modals"import { useSalesChannels } from "@hooks/api/sales-channels"-import { ProductCreateSchemaType } from "../../../../types"+import { useTabbedForm } from "@components/tabbed-form"+import { ProductCreateSchemaType } from "../../../types"import { SC_STACKED_MODAL_ID } from "../../constants"-type ProductCreateSalesChannelStackedModalProps = {- form: UseFormReturn<ProductCreateSchemaType>-}-const PAGE_SIZE = 50-export const ProductCreateSalesChannelStackedModal = ({- form,-}: ProductCreateSalesChannelStackedModalProps) => {+export const ProductCreateSalesChannelStackedModal = () => {const { t } = useTranslation()+ const form = useTabbedForm<ProductCreateSchemaType>()const { getValues, setValue } = formconst { setIsOpen, getIsOpen } = useStackedModal()diff --git a/packages/vendor/src/pages/products/create/product-create-organize-form/product-create-organize-form.tsx b/packages/vendor/src/pages/products/create/product-create-organize-form/product-create-organize-form.tsxindex 62a427c26..7684e7439 100644--- a/packages/vendor/src/pages/products/create/product-create-organize-form/product-create-organize-form.tsx+++ b/packages/vendor/src/pages/products/create/product-create-organize-form/product-create-organize-form.tsx@@ -1,24 +1,47 @@-import { UseFormReturn } from "react-hook-form";+import { Children, ReactNode } from "react";import { StackedFocusModal } from "@components/modals";-import { ProductCreateSchemaType } from "../../types";+import { TabDefinition } from "../types";import { ProductCreateOrganizationSection } from "./components/product-create-organize-section";+import { ProductCreateAttributeSection } from "./components/product-create-organize-attribute-section";import { ProductCreateSalesChannelStackedModal } from "./components/product-create-sales-channel-stacked-modal";import { SC_STACKED_MODAL_ID } from "./constants";-type ProductAttributesProps = {- form: UseFormReturn<ProductCreateSchemaType>;-};+const Root = ({ children }: { children?: ReactNode }) => {+ if (Children.count(children) > 0) {+ return (+ <StackedFocusModal id={SC_STACKED_MODAL_ID}>+ <div className="flex flex-col items-center p-16">+ <div className="flex w-full max-w-[720px] flex-col gap-y-8">+ {children}+ </div>+ </div>+ <ProductCreateSalesChannelStackedModal />+ </StackedFocusModal>+ );+ }-export const ProductCreateOrganizeForm = ({ form }: ProductAttributesProps) => {return (<StackedFocusModal id={SC_STACKED_MODAL_ID}><div className="flex flex-col items-center p-16"><div className="flex w-full max-w-[720px] flex-col gap-y-8">- <ProductCreateOrganizationSection form={form} />+ <ProductCreateOrganizationSection /></div></div>- <ProductCreateSalesChannelStackedModal form={form} />+ <ProductCreateSalesChannelStackedModal /></StackedFocusModal>);};++Root._tabMeta = {+ id: "organize",+ labelKey: "products.create.tabs.organize",+ validationFields: ["discountable", "categories", "tags", "sales_channels"],+} satisfies TabDefinition;++export const ProductCreateOrganizeForm = Object.assign(Root, {+ _tabMeta: Root._tabMeta,+ OrganizationSection: ProductCreateOrganizationSection,+ AttributeSection: ProductCreateAttributeSection,+ SalesChannelModal: ProductCreateSalesChannelStackedModal,+});diff --git a/packages/vendor/src/pages/products/create/product-create-page.tsx b/packages/vendor/src/pages/products/create/product-create-page.tsxindex fbff03661..735bfc857 100644--- a/packages/vendor/src/pages/products/create/product-create-page.tsx+++ b/packages/vendor/src/pages/products/create/product-create-page.tsx@@ -1,71 +1,31 @@-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 "./product-create-form";+import { Children, ReactNode } from "react"+import { useTranslation } from "react-i18next"-export const ProductCreate = () => {- const { t } = useTranslation();+import { RouteFocusModal } from "@components/modals"+import { useSalesChannels } from "@hooks/api"+import { useStore } from "@hooks/api/store"- const {- store,- isPending: isStorePending,- isError: isStoreError,- error: storeError,- } = useStore({- fields: "+default_sales_channel",- });+import { ProductCreateForm } from "./product-create-form/product-create-form"+import { ProductCreateDetailsForm } from "./product-create-details-form"+import { ProductCreateOrganizeForm } from "./product-create-organize-form"+import { ProductCreateVariantsForm } from "./product-create-variants-form"+import { ProductCreateInventoryKitForm } from "./product-create-inventory-kit-form"+import { TabbedForm } from "@components/tabbed-form"+import { HttpTypes } from "@mercurjs/types"- const {- sales_channel,- isPending: isSalesChannelPending,- isError: isSalesChannelError,- error: salesChannelError,- } = useSalesChannel(store?.default_sales_channel_id!);+const Root = ({ children }: { children?: ReactNode }) => {+ const { t } = useTranslation()- const {- regions,- isPending: isRegionsPending,- isError: isRegionsError,- error: regionsError,- } = useRegions({ limit: 9999 });-- const {- price_preferences,- isPending: isPricePreferencesPending,- isError: isPricePreferencesError,- error: pricePreferencesError,- } = usePricePreferences({- limit: 9999,- });+ const { store, isPending: isStorePending } = useStore()+ const { sales_channels, isPending: isSalesChannelPending } =+ useSalesChannels()const ready =- !!store &&- !isStorePending &&- !!regions &&- !isRegionsPending &&- !!sales_channel &&- !isSalesChannelPending &&- !!price_preferences &&- !isPricePreferencesPending;-- if (isStoreError) {- throw storeError;- }-- if (isRegionsError) {- throw regionsError;- }-- if (isSalesChannelError) {- throw salesChannelError;- }+ !!store && !isStorePending && !!sales_channels && !isSalesChannelPending- if (isPricePreferencesError) {- throw pricePreferencesError;- }+ const defaultChannel = sales_channels?.[0] as+ | HttpTypes.AdminSalesChannel+ | undefinedreturn (<RouteFocusModal>@@ -76,13 +36,21 @@ export const ProductCreate = () => {<span className="sr-only">{t("products.create.description")}</span></RouteFocusModal.Description>{ready && (- <ProductCreateForm- defaultChannel={sales_channel}- store={store}- pricePreferences={price_preferences}- regions={regions}- />+ Children.count(children) > 0 ? (+ children+ ) : (+ <ProductCreateForm defaultChannel={defaultChannel} />+ ))}</RouteFocusModal>- );-};+ )+}++export const ProductCreatePage = Object.assign(Root, {+ DetailsForm: ProductCreateDetailsForm,+ OrganizeForm: ProductCreateOrganizeForm,+ VariantsForm: ProductCreateVariantsForm,+ InventoryKitForm: ProductCreateInventoryKitForm,+ Form: ProductCreateForm,+ Tab: TabbedForm.Tab,+})diff --git a/packages/vendor/src/pages/products/create/product-create-variants-form/product-create-variants-form.tsx b/packages/vendor/src/pages/products/create/product-create-variants-form/product-create-variants-form.tsxindex 47e98f0bb..ef33592f8 100644--- a/packages/vendor/src/pages/products/create/product-create-variants-form/product-create-variants-form.tsx+++ b/packages/vendor/src/pages/products/create/product-create-variants-form/product-create-variants-form.tsx@@ -1,7 +1,6 @@-import { useMemo } from "react"-import { UseFormReturn, useWatch } from "react-hook-form"+import { Children, ReactNode, useMemo } from "react"+import { useWatch } from "react-hook-form"import { useTranslation } from "react-i18next"-import { HttpTypes } from "@medusajs/types"import {createDataGridHelper,@@ -9,29 +8,25 @@ import {DataGrid,} from "@components/data-grid"import { useRouteModal } from "@components/modals"+import { useTabbedForm } from "@components/tabbed-form"+import { useStore } from "@hooks/api/store"+import { useRegions } from "@hooks/api"+import { usePricePreferences } from "@hooks/api/price-preferences"import {ProductCreateOptionSchema,ProductCreateVariantSchema,-} from "../../constants"-import { ProductCreateSchemaType } from "../../types"--type ProductCreateVariantsFormProps = {- form: UseFormReturn<ProductCreateSchemaType>- regions?: HttpTypes.AdminRegion[]- store?: HttpTypes.AdminStore- pricePreferences?: HttpTypes.AdminPricePreference[]-}+} from "../constants"+import { ProductCreateSchemaType, TabDefinition } from "../types"type VariantWithIndex = ProductCreateVariantSchema & {originalIndex: number}-export const ProductCreateVariantsForm = ({- form,- regions,- store,- pricePreferences,-}: ProductCreateVariantsFormProps) => {+const Root = ({ children }: { children?: ReactNode }) => {+ const form = useTabbedForm<ProductCreateSchemaType>()+ const { store } = useStore()+ const { regions } = useRegions({ limit: 9999 })+ const { price_preferences: pricePreferences } = usePricePreferences({ limit: 9999 })const { setCloseOnEscape } = useRouteModal()const currencyCodes = useMemo(@@ -51,9 +46,6 @@ export const ProductCreateVariantsForm = ({defaultValue: [],})- /**- * NOTE: anything that goes to the datagrid component needs to be memoised otherwise DataGrid will rerender and inputs will loose focus- */const columns = useColumns({options,currencies: currencyCodes,@@ -73,6 +65,10 @@ export const ProductCreateVariantsForm = ({return ret}, [variants])+ if (Children.count(children) > 0) {+ return <>{children}</>+ }+return (<div className="flex size-full flex-col divide-y overflow-hidden"><DataGrid@@ -85,6 +81,15 @@ export const ProductCreateVariantsForm = ({)}+Root._tabMeta = {+ id: "variants",+ labelKey: "products.create.tabs.variants",+} satisfies TabDefinition++export const ProductCreateVariantsForm = Object.assign(Root, {+ _tabMeta: Root._tabMeta,+})+const columnHelper = createDataGridHelper<VariantWithIndex,ProductCreateSchemaType@@ -98,8 +103,8 @@ const useColumns = ({}: {options: ProductCreateOptionSchema[]currencies?: string[]- regions?: HttpTypes.AdminRegion[]- pricePreferences?: HttpTypes.AdminPricePreference[]+ regions?: import("@medusajs/types").HttpTypes.AdminRegion[]+ pricePreferences?: import("@medusajs/types").HttpTypes.AdminPricePreference[]}) => {const { t } = useTranslation()@@ -150,11 +155,9 @@ const useColumns = ({...createDataGridPriceColumns<VariantWithIndex, ProductCreateSchemaType>({currencies,+ regions,pricePreferences,getFieldName: (context, value) => {- if (context.column.id?.startsWith("currency_prices")) {- return `variants.${context.row.original.originalIndex}.prices.${value}`- }return `variants.${context.row.original.originalIndex}.prices.${value}`},t,diff --git a/packages/vendor/src/pages/products/create/types.ts b/packages/vendor/src/pages/products/create/types.tsnew file mode 100644index 000000000..42d631810--- /dev/null+++ b/packages/vendor/src/pages/products/create/types.ts@@ -0,0 +1,14 @@+import { ReactNode } from "react"+import { z } from "zod"++import { TabDefinition as GenericTabDefinition } from "@components/tabbed-form"++import { ProductCreateSchema } from "./constants"++export type ProductCreateSchemaType = z.infer<typeof ProductCreateSchema>++export type TabDefinition = GenericTabDefinition<ProductCreateSchemaType>++export interface TabProps extends Partial<TabDefinition> {+ children?: ReactNode+}diff --git a/packages/vendor/src/pages/products/index.ts b/packages/vendor/src/pages/products/index.tsindex 10c395a82..ffd783ae6 100644--- a/packages/vendor/src/pages/products/index.ts+++ b/packages/vendor/src/pages/products/index.ts@@ -1 +1,2 @@-export * from './product-list-page'\ No newline at end of file+export * from './product-list-page'+export * from './create'\ No newline at end of file