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(admin): add seller field to product create and seller section to detail pages
vholikce94670fa928
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 ea2bc0a15..91fbacaa3 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,6 +1,6 @@import { useLoaderData, useParams } from "react-router-dom"-import { useProductVariant } from "../../../hooks/api/products"+import { useProduct, useProductVariant } from "../../../hooks/api/products"import { TwoColumnPageSkeleton } from "../../../components/common/skeleton"import { TwoColumnPage } from "../../../components/layout/pages"@@ -11,6 +11,7 @@ import {VariantInventorySection,} 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"@@ -20,6 +21,9 @@ export const ProductVariantDetail = () => {>const { id, variant_id } = useParams()+ const { product } = useProduct(id!, {+ fields: "*seller",+ })const { variant, isLoading, isError, error } = useProductVariant(id!,variant_id!,@@ -68,6 +72,7 @@ export const ProductVariantDetail = () => {)}</TwoColumnPage.Main><TwoColumnPage.Sidebar>+ <ProductSellerSection seller={(product as any)?.seller} /><VariantPricesSection variant={variant} /></TwoColumnPage.Sidebar></TwoColumnPage>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 711f4437d..b832f07f4 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@@ -21,6 +21,16 @@ export const ProductCreateOrganizationSection = ({}: ProductCreateOrganizationSectionProps) => {const { t } = useTranslation()+ const sellers = useComboboxData({+ queryKey: ["sellers"],+ queryFn: (params) => sdk.admin.sellers.query(params),+ getOptions: (data) =>+ data.sellers.map((seller) => ({+ label: seller.name,+ value: seller.id,+ })),+ })+const collections = useComboboxData({queryKey: ["product_collections"],queryFn: (params) => sdk.admin.productCollection.list(params),@@ -82,6 +92,29 @@ export const ProductCreateOrganizationSection = ({optionaldata-testid="product-create-organize-section-discountable-switch"/>+ <div className="grid grid-cols-1 gap-4 md:grid-cols-2">+ <Form.Field+ control={form.control}+ name="seller_id"+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label optional>Seller</Form.Label>+ <Form.Control>+ <Combobox+ {...field}+ options={sellers.options}+ searchValue={sellers.searchValue}+ onSearchValueChange={sellers.onSearchValueChange}+ fetchNextPage={sellers.fetchNextPage}+ />+ </Form.Control>+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}+ />+ </div><div className="grid grid-cols-1 gap-4 md:grid-cols-2" data-testid="product-create-organize-section-type-collection"><Form.Fieldcontrol={form.control}diff --git a/packages/admin/src/pages/products/product-create/constants.ts b/packages/admin/src/pages/products/product-create/constants.tsindex 0668e3f04..75bb2ff67 100644--- a/packages/admin/src/pages/products/product-create/constants.ts+++ b/packages/admin/src/pages/products/product-create/constants.ts@@ -67,6 +67,7 @@ export const ProductCreateSchema = zshipping_profile_id: z.string().optional(),categories: z.array(z.string()),tags: z.array(z.string()).optional(),+ seller_id: z.string().optional(),sales_channels: z.array(z.object({@@ -145,6 +146,7 @@ export const PRODUCT_CREATE_FORM_DEFAULTS: Partial<enable_variants: false,media: [],categories: [],+ seller_id: "",collection_id: "",shipping_profile_id: "",description: "",diff --git a/packages/admin/src/pages/products/product-create/utils.ts b/packages/admin/src/pages/products/product-create/utils.tsindex 31c74fd95..d12c61da2 100644--- a/packages/admin/src/pages/products/product-create/utils.ts+++ b/packages/admin/src/pages/products/product-create/utils.ts@@ -16,6 +16,9 @@ export const normalizeProductFormValues = (return {status: values.status,is_giftcard: false,+ ...(values.seller_id+ ? { additional_data: { seller_id: values.seller_id } }+ : {}),tags: values?.tags?.length? values.tags?.map((tag) => ({ id: tag })): undefined,diff --git a/packages/admin/src/pages/products/product-detail/components/product-seller-section/product-seller-section.tsx b/packages/admin/src/pages/products/product-detail/components/product-seller-section/product-seller-section.tsxnew file mode 100644index 000000000..b4ff30968--- /dev/null+++ b/packages/admin/src/pages/products/product-detail/components/product-seller-section/product-seller-section.tsx@@ -0,0 +1,45 @@+import { TriangleRightMini } from "@medusajs/icons";+import { Avatar, Container, Heading } from "@medusajs/ui";+import { SellerDTO } from "@mercurjs/types";+import { Link } from "react-router-dom";++type ProductSellerSectionProps = {+ seller?: SellerDTO | null;+};++export const ProductSellerSection = ({ seller }: ProductSellerSectionProps) => {+ if (!seller) {+ return null;+ }++ return (+ <Container className="p-0">+ <div className="flex items-center justify-between px-6 py-4">+ <Heading level="h2">Associated Seller</Heading>+ </div>+ <div className="txt-small flex flex-col gap-2 px-2 pb-2">+ <Link+ to={`/sellers/${seller.id}`}+ className="outline-none focus-within:shadow-borders-interactive-with-focus rounded-md [&:hover>div]:bg-ui-bg-component-hover"+ >+ <div className="shadow-elevation-card-rest bg-ui-bg-component rounded-md px-4 py-2 transition-colors">+ <div className="flex items-center gap-3">+ <Avatar+ src={seller.logo ?? undefined}+ fallback={seller.name.charAt(0).toUpperCase()}+ />+ <div className="flex flex-1 flex-col">+ <span className="text-ui-fg-base font-medium">+ {seller.name}+ </span>+ </div>+ <div className="size-7 flex items-center justify-center">+ <TriangleRightMini className="text-ui-fg-muted rtl:rotate-180" />+ </div>+ </div>+ </div>+ </Link>+ </div>+ </Container>+ );+};diff --git a/packages/admin/src/pages/products/product-detail/loader.ts b/packages/admin/src/pages/products/product-detail/loader.tsindex 2430aebad..e7cf5ff07 100644--- a/packages/admin/src/pages/products/product-detail/loader.ts+++ b/packages/admin/src/pages/products/product-detail/loader.ts@@ -8,7 +8,7 @@ import { AdminProductResponse } from "@mercurjs/types"const productDetailQuery = (id: string) => ({queryKey: productsQueryKeys.detail(id),queryFn: async () =>- sdk.admin.products.$id.query({ $id: id }),+ sdk.admin.products.$id.query({ $id: id, fields: "*seller" }),})export const productLoader = async ({ params }: LoaderFunctionArgs): Promise<AdminProductResponse> => {diff --git a/packages/admin/src/pages/products/product-detail/product-detail.tsx b/packages/admin/src/pages/products/product-detail/product-detail.tsxindex f7f930054..7cf07da5e 100644--- a/packages/admin/src/pages/products/product-detail/product-detail.tsx+++ b/packages/admin/src/pages/products/product-detail/product-detail.tsx@@ -10,6 +10,7 @@ import { ProductMediaSection } from "./components/product-media-section";import { ProductOptionSection } from "./components/product-option-section";import { ProductOrganizationSection } from "./components/product-organization-section";import { ProductSalesChannelSection } from "./components/product-sales-channel-section";+import { ProductSellerSection } from "./components/product-seller-section/product-seller-section";import { ProductShippingProfileSection } from "./components/product-shipping-profile-section";import { ProductVariantSection } from "./components/product-variant-section";import { productLoader } from "./loader";@@ -53,6 +54,7 @@ export const ProductDetail = () => {<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} />