Skip to content

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

feat(admin, core-plugin): redesign seller details page and add admin seller update endpoint

vholikef8659510e18
diff --git a/packages/admin/src/get-route-map.tsx b/packages/admin/src/get-route-map.tsx
index 740b93d03..10d3eb0b9 100644
--- a/packages/admin/src/get-route-map.tsx
+++ b/packages/admin/src/get-route-map.tsx
@@ -751,10 +751,12 @@ export function getRouteMap({
{
path: ":id",
lazy: () => import("./pages/sellers/seller-details"),
- },
- {
- path: ":id/edit",
- lazy: () => import("./pages/sellers/seller-edit"),
+ children: [
+ {
+ path: "edit",
+ lazy: () => import("./pages/sellers/seller-edit"),
+ },
+ ],
},
],
},
diff --git a/packages/admin/src/hooks/table/columns/use-seller-table-columns.tsx b/packages/admin/src/hooks/table/columns/use-seller-table-columns.tsx
index f60a13f14..d4101e422 100644
--- a/packages/admin/src/hooks/table/columns/use-seller-table-columns.tsx
+++ b/packages/admin/src/hooks/table/columns/use-seller-table-columns.tsx
@@ -23,13 +23,15 @@ export const useSellersTableColumns = () => {
columnHelper.display({
id: "status",
header: "Status",
- cell: ({ row }) => <SellerStatusCell status={row.original.status} />,
+ cell: ({ row }) => {
+ return <SellerStatusCell status={row.original.status} />;
+ },
}),
columnHelper.display({
id: "created_at",
header: "Created",
- cell: ({ getValue }) => {
- return <DateCell date={getValue()} />;
+ cell: ({ row }) => {
+ return <DateCell date={row.original.created_at} />;
},
}),
],
diff --git a/packages/admin/src/i18n/translations/$schema.json b/packages/admin/src/i18n/translations/$schema.json
index ff0510e35..7af05a643 100644
--- a/packages/admin/src/i18n/translations/$schema.json
+++ b/packages/admin/src/i18n/translations/$schema.json
@@ -12055,6 +12055,22 @@
],
"additionalProperties": false
},
+ "status": {
+ "type": "object",
+ "properties": {
+ "pending": {
+ "type": "string"
+ },
+ "active": {
+ "type": "string"
+ },
+ "suspended": {
+ "type": "string"
+ }
+ },
+ "required": ["pending", "active", "suspended"],
+ "additionalProperties": false
+ },
"edit": {
"type": "object",
"properties": {
@@ -12069,7 +12085,7 @@
"additionalProperties": false
}
},
- "required": ["domain", "fields", "edit"],
+ "required": ["domain", "fields", "status", "edit"],
"additionalProperties": false
},
"messages": {
diff --git a/packages/admin/src/i18n/translations/en.json b/packages/admin/src/i18n/translations/en.json
index e9cdbb10e..0d6c71e02 100644
--- a/packages/admin/src/i18n/translations/en.json
+++ b/packages/admin/src/i18n/translations/en.json
@@ -3239,6 +3239,11 @@
"country_code": "Country Code",
"tax_id": "Tax ID"
},
+ "status": {
+ "pending": "Pending",
+ "active": "Active",
+ "suspended": "Suspended"
+ },
"edit": {
"header": "Edit Seller",
"successToast": "Seller {{name}} was successfully updated."
diff --git a/packages/admin/src/pages/sellers/common/components/seller-general-section.tsx b/packages/admin/src/pages/sellers/common/components/seller-general-section.tsx
deleted file mode 100644
index 2c69de076..000000000
--- a/packages/admin/src/pages/sellers/common/components/seller-general-section.tsx
+++ /dev/null
@@ -1,316 +0,0 @@
-import { PencilSquare, User } from "@medusajs/icons";
-import { Badge, Container, Heading, Text, usePrompt } from "@medusajs/ui";
-
-import type { VendorSeller } from "@custom-types/seller";
-
-import { ActionMenu } from "../../../../components/common/action-menu";
-
-import { SellerStatus } from "@mercurjs/types";
-import { useUpdateSeller } from "@/hooks/api";
-
-const getStatusBadgeColor = (status: string) => {
- const colors: Record<string, "orange" | "green" | "red"> = {
- [SellerStatus.PENDING]: "orange",
- [SellerStatus.ACTIVE]: "green",
- [SellerStatus.SUSPENDED]: "red",
- };
- return colors[status] || "orange";
-};
-
-const getStatusLabel = (status: string) => {
- const labels: Record<string, string> = {
- [SellerStatus.PENDING]: "Pending",
- [SellerStatus.ACTIVE]: "Active",
- [SellerStatus.SUSPENDED]: "Suspended",
- };
- return labels[status] || "Pending";
-};
-
-export const SellerGeneralSection = ({ seller }: { seller: VendorSeller }) => {
- const { mutateAsync: suspendSeller } = useUpdateSeller(seller.id);
-
- const dialog = usePrompt();
-
- const handleSuspend = async () => {
- const res = await dialog({
- title:
- seller.store_status === "SUSPENDED"
- ? "Activate account"
- : "Suspend account",
- description:
- seller.store_status === "SUSPENDED"
- ? "Are you sure you want to activate this account?"
- : "Are you sure you want to suspend this account?",
- verificationText: seller.email || seller.name || "",
- });
-
- if (!res) {
- return;
- }
-
- if (seller.store_status === "SUSPENDED") {
- await suspendSeller({ id: seller.id, data: { store_status: "ACTIVE" } });
- } else {
- await suspendSeller({
- id: seller.id,
- data: { store_status: "SUSPENDED" },
- });
- }
- };
-
- return (
- <>
- <Container
- className="mb-2 divide-y p-0"
- data-testid="seller-general-section-header"
- >
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading data-testid="seller-general-section-name">
- {seller.email || seller.name}
- </Heading>
- <div className="flex items-center gap-x-2 mt-1">
- <Badge
- size="2xsmall"
- color={getStatusBadgeColor(seller.store_status || "pending")}
- data-testid="seller-general-section-status-badge"
- >
- {getStatusLabel(seller.store_status || "pending")}
- </Badge>
- </div>
- </div>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- label: "Edit",
- to: `/sellers/${seller.id}/edit`,
- icon: <PencilSquare />,
- },
- {
- label:
- seller.store_status === "SUSPENDED"
- ? "Activate account"
- : "Suspend account",
- onClick: () => handleSuspend(),
- icon: <User />,
- },
- ],
- },
- ]}
- data-testid="seller-general-section-action-menu"
- />
- </div>
- </Container>
- <div className="flex gap-4">
- <Container
- className="divide-y p-0"
- data-testid="seller-general-section-store"
- >
- <div className="flex items-center justify-between px-6 py-4">
- <Heading
- level="h2"
- data-testid="seller-general-section-store-heading"
- >
- Store
- </Heading>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-store-name-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-store-name-label"
- >
- Name
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-store-name-value"
- >
- {seller.name}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-store-email-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-store-email-label"
- >
- Email
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-store-email-value"
- >
- {seller.email}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-store-phone-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-store-phone-label"
- >
- Phone
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-store-phone-value"
- >
- {seller.phone || "-"}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-store-description-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-store-description-label"
- >
- Description
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-store-description-value"
- >
- {seller.description || "-"}
- </Text>
- </div>
- </Container>
- <Container
- className="divide-y p-0"
- data-testid="seller-general-section-address"
- >
- <div className="flex items-center justify-between px-6 py-4">
- <Heading
- level="h2"
- data-testid="seller-general-section-address-heading"
- >
- Address
- </Heading>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-address-line-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-address-line-label"
- >
- Address
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-address-line-value"
- >
- {seller.address_line || "-"}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-postal-code-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-postal-code-label"
- >
- Postal Code
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-postal-code-value"
- >
- {seller.postal_code || "-"}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-city-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-city-label"
- >
- City
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-city-value"
- >
- {seller.city || "-"}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-country-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-country-label"
- >
- Country
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-country-value"
- >
- {seller.country_code || "-"}
- </Text>
- </div>
- <div
- className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4"
- data-testid="seller-general-section-tax-id-row"
- >
- <Text
- size="small"
- leading="compact"
- weight="plus"
- data-testid="seller-general-section-tax-id-label"
- >
- TaxID
- </Text>
- <Text
- size="small"
- leading="compact"
- data-testid="seller-general-section-tax-id-value"
- >
- {seller.tax_id || "-"}
- </Text>
- </div>
- </Container>
- </div>
- </>
- );
-};
diff --git a/packages/admin/src/pages/sellers/seller-details/components/seller-details.tsx b/packages/admin/src/pages/sellers/seller-details/components/seller-details.tsx
index f58ce0ab7..355b579da 100644
--- a/packages/admin/src/pages/sellers/seller-details/components/seller-details.tsx
+++ b/packages/admin/src/pages/sellers/seller-details/components/seller-details.tsx
@@ -1,59 +1,35 @@
-import type { AdminProductListResponse } from "@medusajs/types";
+import { useParams } from "react-router-dom"
-import type { AdminOrderListResponse } from "@custom-types/order";
-import type { VendorSeller } from "@custom-types/seller";
-
-import { useSellerOrdersTableQuery } from "@hooks/table/query";
-import { SellerGeneralSection } from "../../common/components/seller-general-section";
-import { SellerOrdersSection } from "../../common/components/seller-orders-section";
-import { SellerProductsSection } from "../../common/components/seller-products-section";
-import { useOrders, useProducts } from "@/hooks/api";
-
-const PAGE_SIZE = 10;
-const ORDER_PREFIX = "so";
-const PRODUCT_PREFIX = "sp";
+import { SingleColumnPageSkeleton } from "../../../../components/common/skeleton"
+import { SingleColumnPage } from "../../../../components/layout/pages"
+import { useSeller } from "@/hooks/api"
+import { SellerGeneralSection } from "./seller-general-section"
+import { SellerOrderSection } from "./seller-order-section"
+import { SellerProductSection } from "./seller-product-section"
export const SellerDetails = () => {
- const { searchParams: orderSearchParams } = useSellerOrdersTableQuery({
- pageSize: PAGE_SIZE,
- offset: 0,
- prefix: ORDER_PREFIX,
- });
+ const { id } = useParams()
- const { searchParams: productSearchParams } = useSellerOrdersTableQuery({
- pageSize: PAGE_SIZE,
- offset: 0,
- prefix: PRODUCT_PREFIX,
- });
+ const { seller, isLoading, isError, error } = useSeller(id!)
- const { orders, isLoading: ordersLoading } = useOrders({
- fields:
- "id,display_id,created_at,updated_at,*customer,currency_code,total,fulfillment_status,payment_status,status,region_id,sales_channel_id",
- ...orderSearchParams,
- });
-
- const {
- products,
- isLoading: productsLoading,
- refetch: productsRefetch,
- } = useProducts({
- fields:
- "*collection,+type_id,+tag_id,+sales_channel_id,+status,+created_at,+updated_at",
- ...productSearchParams,
- });
+ if (isLoading || !seller) {
+ return <SingleColumnPageSkeleton sections={2} showJSON showMetadata />
+ }
- if (ordersLoading || productsLoading) {
- return <div>Loading...</div>;
+ if (isError) {
+ throw error
}
return (
- <>
- <SellerGeneralSection seller={data?.seller as VendorSeller} />
- <SellerOrdersSection seller_orders={orders as AdminOrderListResponse} />
- <SellerProductsSection
- seller_products={products as AdminProductListResponse}
- refetch={productsRefetch}
- />
- </>
- );
-};
+ <SingleColumnPage
+ data={seller}
+ hasOutlet
+ showJSON
+ showMetadata
+ >
+ <SellerGeneralSection seller={seller} />
+ <SellerOrderSection />
+ <SellerProductSection />
+ </SingleColumnPage>
+ )
+}
diff --git a/packages/admin/src/pages/sellers/seller-details/components/seller-general-section.tsx b/packages/admin/src/pages/sellers/seller-details/components/seller-general-section.tsx
new file mode 100644
index 000000000..e90106de0
--- /dev/null
+++ b/packages/admin/src/pages/sellers/seller-details/components/seller-general-section.tsx
@@ -0,0 +1,177 @@
+import { PencilSquare, User } from "@medusajs/icons"
+import {
+ Container,
+ Heading,
+ StatusBadge,
+ Text,
+ toast,
+ usePrompt,
+} from "@medusajs/ui"
+import { useTranslation } from "react-i18next"
+
+import { InferClientOutput } from "@mercurjs/client"
+import { sdk } from "@lib/client"
+
+import { ActionMenu } from "../../../../components/common/action-menu"
+import { useUpdateSeller } from "@/hooks/api"
+import { SellerStatus } from "@mercurjs/types"
+
+type Seller = InferClientOutput<typeof sdk.admin.sellers.$id.query>["seller"]
+
+type SellerGeneralSectionProps = {
+ seller: Seller
+}
+
+const statusColorMap: Record<string, "orange" | "green" | "red"> = {
+ [SellerStatus.PENDING]: "orange",
+ [SellerStatus.ACTIVE]: "green",
+ [SellerStatus.SUSPENDED]: "red",
+}
+
+export const SellerGeneralSection = ({
+ seller,
+}: SellerGeneralSectionProps) => {
+ const { t } = useTranslation()
+ const prompt = usePrompt()
+
+ const { mutateAsync: updateSeller } = useUpdateSeller(seller.id)
+
+ const statusColor = statusColorMap[seller.status] ?? "orange"
+
+ const statusTextMap: Record<string, string> = {
+ [SellerStatus.PENDING]: t("sellers.status.pending"),
+ [SellerStatus.ACTIVE]: t("sellers.status.active"),
+ [SellerStatus.SUSPENDED]: t("sellers.status.suspended"),
+ }
+ const statusText = statusTextMap[seller.status] ?? t("sellers.status.pending")
+
+ const handleSuspend = async () => {
+ const isSuspended = seller.status === SellerStatus.SUSPENDED
+
+ const res = await prompt({
+ title: isSuspended
+ ? t("sellers.status.active")
+ : t("sellers.status.suspended"),
+ description: isSuspended
+ ? "Are you sure you want to activate this account?"
+ : "Are you sure you want to suspend this account?",
+ verificationText: seller.email || seller.name || "",
+ confirmText: t("actions.confirm"),
+ cancelText: t("actions.cancel"),
+ })
+
+ if (!res) {
+ return
+ }
+
+ await updateSeller(
+ {
+ status: isSuspended ? SellerStatus.ACTIVE : SellerStatus.SUSPENDED,
+ },
+ {
+ onSuccess: () => {
+ toast.success(
+ isSuspended
+ ? "Seller account activated"
+ : "Seller account suspended"
+ )
+ },
+ onError: (error) => {
+ toast.error(error.message)
+ },
+ }
+ )
+ }
+
+ return (
+ <Container className="divide-y p-0">
+ <div className="flex items-center justify-between px-6 py-4">
+ <Heading>{seller.name || seller.email}</Heading>
+ <div className="flex items-center gap-x-2">
+ <StatusBadge color={statusColor}>{statusText}</StatusBadge>
+ <ActionMenu
+ groups={[
+ {
+ actions: [
+ {
+ label: t("actions.edit"),
+ to: `/sellers/${seller.id}/edit`,
+ icon: <PencilSquare />,
+ },
+ ],
+ },
+ {
+ actions: [
+ {
+ label:
+ seller.status === SellerStatus.SUSPENDED
+ ? "Activate account"
+ : "Suspend account",
+ onClick: handleSuspend,
+ icon: <User />,
+ },
+ ],
+ },
+ ]}
+ />
+ </div>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.name")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.name || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.email")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.email || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.phone")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.phone || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.address_line")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.address_1 || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.city")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.city || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.postal_code")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.postal_code || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("sellers.fields.country_code")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.country_code || "-"}
+ </Text>
+ </div>
+ </Container>
+ )
+}
diff --git a/packages/admin/src/pages/sellers/common/components/seller-orders-section.tsx b/packages/admin/src/pages/sellers/seller-details/components/seller-order-section.tsx
similarity index 63%
rename from packages/admin/src/pages/sellers/common/components/seller-orders-section.tsx
rename to packages/admin/src/pages/sellers/seller-details/components/seller-order-section.tsx
index 1f7ce28d7..0c3c09fc8 100644
--- a/packages/admin/src/pages/sellers/common/components/seller-orders-section.tsx
+++ b/packages/admin/src/pages/sellers/seller-details/components/seller-order-section.tsx
@@ -1,22 +1,24 @@
-import { useMemo } from "react";
+import { useMemo } from "react"
-import type { AdminOrder } from "@medusajs/types";
-import { Badge, Container, Heading } from "@medusajs/ui";
+import type { AdminOrder } from "@medusajs/types"
+import { Badge, Container, Heading } from "@medusajs/ui"
+import { keepPreviousData } from "@tanstack/react-query"
+import { createColumnHelper } from "@tanstack/react-table"
+import { useTranslation } from "react-i18next"
-import { getStylizedAmount } from "@lib/money-amount-helpers";
-import { createColumnHelper } from "@tanstack/react-table";
+import { DateCell } from "@components/table/table-cells/common/date-cell"
+import { _DataTable } from "@components/table/data-table"
-import type { AdminOrderListResponse } from "@custom-types/order";
+import { useOrders } from "../../../../hooks/api/orders"
+import { useOrderTableFilters } from "@hooks/table/filters"
+import { useOrderTableQuery } from "@hooks/table/query"
+import { useDataTable } from "@hooks/use-data-table"
+import { getStylizedAmount } from "@lib/money-amount-helpers"
-import { DateCell } from "@components/table/table-cells/common/date-cell";
-import { _DataTable } from "@components/table/data-table";
-
-import { useOrderTableFilters } from "@hooks/table/filters";
-import { useSellerOrdersTableQuery } from "@hooks/table/query";
-import { useDataTable } from "@hooks/use-data-table";
-
-const PAGE_SIZE = 10;
-const PREFIX = "so";
+const PAGE_SIZE = 10
+const PREFIX = "selord"
+const DEFAULT_FIELDS =
+ "id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code,*customer"
const getOrderStatusBadgeColor = (status: string) => {
const colors: Record<string, "orange" | "green" | "red" | "grey"> = {
@@ -26,9 +28,9 @@ const getOrderStatusBadgeColor = (status: string) => {
archived: "grey",
requires_action: "orange",
draft: "grey",
- };
- return colors[status] || "grey";
-};
+ }
+ return colors[status] || "grey"
+}
const getPaymentStatusBadgeColor = (status: string) => {
const colors: Record<string, "orange" | "green" | "red" | "blue" | "grey"> =
@@ -45,9 +47,9 @@ const getPaymentStatusBadgeColor = (status: string) => {
canceled: "red",
not_paid: "grey",
requires_action: "orange",
- };
- return colors[status] || "grey";
-};
+ }
+ return colors[status] || "grey"
+}
const getFulfillmentStatusBadgeColor = (status: string) => {
const colors: Record<string, "orange" | "green" | "red" | "grey"> = {
@@ -62,75 +64,80 @@ const getFulfillmentStatusBadgeColor = (status: string) => {
returned: "red",
partially_returned: "orange",
requires_action: "orange",
- };
- return colors[status] || "grey";
-};
+ }
+ return colors[status] || "grey"
+}
const formatStatus = (status: string) =>
status
.replace(/_/g, " ")
- .replace(/\b\w/g, (c) => c.toUpperCase());
+ .replace(/\b\w/g, (c) => c.toUpperCase())
-export const SellerOrdersSection = ({
- seller_orders,
-}: {
- seller_orders: AdminOrderListResponse;
-}) => {
- const { orders, count } = seller_orders;
+export const SellerOrderSection = () => {
+ const { t } = useTranslation()
- const { raw } = useSellerOrdersTableQuery({
+ const { searchParams, raw } = useOrderTableQuery({
pageSize: PAGE_SIZE,
prefix: PREFIX,
- offset: 0,
- });
+ })
+
+ const { orders, count, isLoading, isError, error } = useOrders(
+ {
+ fields: DEFAULT_FIELDS,
+ ...searchParams,
+ },
+ {
+ placeholderData: keepPreviousData,
+ }
+ )
- const columns = useColumns();
- const filters = useOrderTableFilters();
+ const columns = useColumns()
+ const filters = useOrderTableFilters()
const { table } = useDataTable({
- data: orders,
+ data: orders ?? [],
columns,
- count,
enablePagination: true,
+ count,
pageSize: PAGE_SIZE,
- getRowId: (row) => row?.id || "",
prefix: PREFIX,
- });
+ })
+
+ if (isError) {
+ throw error
+ }
return (
- <Container className="divide-y p-0" data-testid="seller-orders-section">
- <div
- className="flex items-center justify-between px-6 py-4"
- data-testid="seller-orders-section-header"
- >
- <Heading data-testid="seller-orders-section-heading">Orders</Heading>
+ <Container className="divide-y p-0">
+ <div className="flex items-center justify-between px-6 py-4">
+ <Heading level="h2">{t("orders.domain")}</Heading>
</div>
<_DataTable
- table={table}
columns={columns}
- count={count}
+ table={table}
+ pagination
+ navigateTo={(row) => `/orders/${row.original.id}`}
filters={filters}
+ count={count}
+ isLoading={isLoading}
pageSize={PAGE_SIZE}
- isLoading={false}
- queryObject={raw}
- search
- pagination
- navigateTo={(row) => `/orders/${row.id}`}
orderBy={[
- { key: "display_id", label: "Order" },
- { key: "created_at", label: "Created" },
- { key: "updated_at", label: "Updated" },
+ { key: "display_id", label: t("orders.fields.displayId") },
+ { key: "created_at", label: t("fields.createdAt") },
+ { key: "updated_at", label: t("fields.updatedAt") },
]}
+ search
+ queryObject={raw}
prefix={PREFIX}
/>
</Container>
- );
-};
+ )
+}
-const columnHelper = createColumnHelper<AdminOrder>();
+const columnHelper = createColumnHelper<AdminOrder>()
const useColumns = () => {
- const columns = useMemo(
+ return useMemo(
() => [
columnHelper.display({
id: "display_id",
@@ -149,7 +156,7 @@ const useColumns = () => {
return row.original.customer?.first_name &&
row.original.customer?.last_name
? `${row.original.customer?.first_name} ${row.original.customer?.last_name}`
- : row.original.customer?.email;
+ : row.original.customer?.email
},
}),
columnHelper.display({
@@ -168,8 +175,8 @@ const useColumns = () => {
id: "payment_status",
header: "Payment Status",
cell: ({ row }) => {
- const status = row.original?.payment_status;
- if (!status) return "-";
+ const status = row.original?.payment_status
+ if (!status) return "-"
return (
<Badge
size="2xsmall"
@@ -177,15 +184,15 @@ const useColumns = () => {
>
{formatStatus(status)}
</Badge>
- );
+ )
},
}),
columnHelper.display({
id: "fulfillment_status",
header: "Fulfillment Status",
cell: ({ row }) => {
- const status = row.original.fulfillment_status;
- if (!status) return "-";
+ const status = row.original.fulfillment_status
+ if (!status) return "-"
return (
<Badge
size="2xsmall"
@@ -193,7 +200,7 @@ const useColumns = () => {
>
{formatStatus(status)}
</Badge>
- );
+ )
},
}),
columnHelper.display({
@@ -204,24 +211,22 @@ const useColumns = () => {
typeof row.original.total === "undefined" ||
row.original.total === null
) {
- return "-";
+ return "-"
}
const formatted = getStylizedAmount(
row.original.total,
- row.original.currency_code,
- );
+ row.original.currency_code
+ )
return (
<div className="flex h-full w-full items-center justify-start overflow-hidden text-left">
<span className="truncate">{formatted}</span>
</div>
- );
+ )
},
}),
],
- [],
- );
-
- return columns;
-};
+ []
+ )
+}
diff --git a/packages/admin/src/pages/sellers/common/components/seller-products-section.tsx b/packages/admin/src/pages/sellers/seller-details/components/seller-product-section.tsx
similarity index 52%
rename from packages/admin/src/pages/sellers/common/components/seller-products-section.tsx
rename to packages/admin/src/pages/sellers/seller-details/components/seller-product-section.tsx
index c08896072..9c5697214 100644
--- a/packages/admin/src/pages/sellers/common/components/seller-products-section.tsx
+++ b/packages/admin/src/pages/sellers/seller-details/components/seller-product-section.tsx
@@ -1,90 +1,95 @@
-import { useMemo } from "react";
-
-import { PencilSquare, Trash } from "@medusajs/icons";
-import { Container, Divider, Heading, toast, usePrompt } from "@medusajs/ui";
-
-import { sdk } from "@lib/client";
-import { createColumnHelper } from "@tanstack/react-table";
-import { useTranslation } from "react-i18next";
-
-import type { AdminProductListResponse } from "@custom-types/product";
-import type { AdminProduct } from "@custom-types/product/common";
-
-import { ActionMenu } from "../../../../components/common/action-menu";
-import { Thumbnail } from "@components/common/thumbnail";
-import { ProductStatusCell } from "@components/table/table-cells/product/product-status-cell";
-import { _DataTable } from "@components/table/data-table";
-
-import { useProductTableFilters } from "@hooks/table/filters";
-import { useSellerOrdersTableQuery } from "@hooks/table/query";
-import { useDataTable } from "@hooks/use-data-table";
-
-const PAGE_SIZE = 10;
-const PREFIX = "sp";
-
-export const SellerProductsSection = ({
- seller_products,
- refetch,
-}: {
- seller_products: AdminProductListResponse;
- refetch: () => void;
-}) => {
- const { products, count } = seller_products;
-
- const { raw } = useSellerOrdersTableQuery({
+import { useMemo } from "react"
+
+import { PencilSquare, Trash } from "@medusajs/icons"
+import { HttpTypes } from "@medusajs/types"
+import { Container, Heading, toast, usePrompt } from "@medusajs/ui"
+import { keepPreviousData } from "@tanstack/react-query"
+import { createColumnHelper } from "@tanstack/react-table"
+import { useTranslation } from "react-i18next"
+
+import { ActionMenu } from "../../../../components/common/action-menu"
+import { Thumbnail } from "@components/common/thumbnail"
+import { ProductStatusCell } from "@components/table/table-cells/product/product-status-cell"
+import { _DataTable } from "@components/table/data-table"
+
+import { useProducts } from "../../../../hooks/api/products"
+import { useProductTableFilters } from "@hooks/table/filters"
+import { useProductTableQuery } from "@hooks/table/query"
+import { useDataTable } from "@hooks/use-data-table"
+
+const PAGE_SIZE = 10
+const PREFIX = "selprod"
+const DEFAULT_FIELDS =
+ "*collection,+type_id,+tag_id,+sales_channel_id,+status,+created_at,+updated_at"
+
+export const SellerProductSection = () => {
+ const { t } = useTranslation()
+
+ const { searchParams, raw } = useProductTableQuery({
pageSize: PAGE_SIZE,
- offset: 0,
prefix: PREFIX,
- });
+ })
+
+ const { products, count, isLoading, isError, error } = useProducts(
+ {
+ fields: DEFAULT_FIELDS,
+ ...searchParams,
+ },
+ {
+ placeholderData: keepPreviousData,
+ }
+ )
- const columns = useColumns(refetch);
- const filters = useProductTableFilters();
+ const columns = useColumns()
+ const filters = useProductTableFilters()
const { table } = useDataTable({
- data: products,
+ data: products ?? [],
columns,
- count,
enablePagination: true,
+ count,
pageSize: PAGE_SIZE,
- getRowId: (row) => row?.id || "",
prefix: PREFIX,
- });
+ })
+
+ if (isError) {
+ throw error
+ }
return (
- <Container className="mt-2 px-0" data-testid="seller-products-section">
- <div className="px-8 pb-4" data-testid="seller-products-section-header">
- <Heading data-testid="seller-products-section-heading">Products</Heading>
+ <Container className="divide-y p-0">
+ <div className="flex items-center justify-between px-6 py-4">
+ <Heading level="h2">{t("products.domain")}</Heading>
</div>
- <Divider />
<_DataTable
- filters={filters}
- table={table}
columns={columns}
- count={count}
- pageSize={PAGE_SIZE}
- isLoading={false}
- queryObject={raw}
- search
+ table={table}
pagination
navigateTo={(row) => `/products/${row.id}`}
+ filters={filters}
+ count={count}
+ isLoading={isLoading}
+ pageSize={PAGE_SIZE}
orderBy={[
- { key: "title", label: "Title" },
- { key: "created_at", label: "Created" },
- { key: "updated_at", label: "Updated" },
+ { key: "title", label: t("fields.title") },
+ { key: "created_at", label: t("fields.createdAt") },
+ { key: "updated_at", label: t("fields.updatedAt") },
]}
+ search
+ queryObject={raw}
prefix={PREFIX}
/>
</Container>
- );
-};
+ )
+}
-const columnHelper = createColumnHelper<AdminProduct>();
+const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
-const useColumns = (refetch: () => void) => {
- const { t } = useTranslation();
- const prompt = usePrompt();
+const useColumns = () => {
+ const { t } = useTranslation()
+ const prompt = usePrompt()
- const handleDelete = async (product: AdminProduct) => {
+ const handleDelete = async (product: HttpTypes.AdminProduct) => {
const res = await prompt({
title: t("general.areYouSure"),
description: t("products.deleteWarning", {
@@ -92,30 +97,33 @@ const useColumns = (refetch: () => void) => {
}),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
- });
+ })
if (!res) {
- return;
+ return
}
try {
- await sdk.client.fetch(`/admin/products/${product.id}`, {
+ // TODO: use useDeleteProduct hook when refactoring to per-row component
+ const response = await fetch(`/admin/products/${product.id}`, {
method: "DELETE",
- });
+ })
+ if (!response.ok) {
+ throw new Error("Failed to delete product")
+ }
toast.success(t("products.toasts.delete.success.header"), {
description: t("products.toasts.delete.success.description", {
title: product.title,
}),
- });
- await refetch();
+ })
} catch (e: unknown) {
toast.error(t("products.toasts.delete.error.header"), {
description: (e as Error)?.message,
- });
+ })
}
- };
+ }
- const columns = useMemo(
+ return useMemo(
() => [
columnHelper.display({
id: "product",
@@ -130,24 +138,23 @@ const useColumns = (refetch: () => void) => {
{row.original.title}
</span>
</div>
- );
+ )
},
}),
columnHelper.display({
id: "collection",
header: "Collection",
cell: ({ row }) => {
- return row.original.collection?.title;
+ return row.original.collection?.title
},
}),
columnHelper.display({
id: "variants",
header: "Variants",
cell: ({ row }) => {
- const variants = row.original.variants?.length || 0;
- const suffix = variants > 1 ? "variants" : "variant";
-
- return `${variants} ${suffix}`;
+ const variants = row.original.variants?.length || 0
+ const suffix = variants > 1 ? "variants" : "variant"
+ return `${variants} ${suffix}`
},
}),
columnHelper.display({
@@ -160,12 +167,11 @@ const useColumns = (refetch: () => void) => {
header: "",
cell: ({ row }) => (
<ActionMenu
- data-testid={`seller-products-section-row-actions-${row.original.id}`}
groups={[
{
actions: [
{
- label: "Edit",
+ label: t("actions.edit"),
to: `/products/${row.original.id}/edit`,
icon: <PencilSquare />,
},
@@ -174,7 +180,7 @@ const useColumns = (refetch: () => void) => {
{
actions: [
{
- label: "Delete",
+ label: t("actions.delete"),
onClick: () => handleDelete(row.original),
icon: <Trash />,
},
@@ -185,8 +191,6 @@ const useColumns = (refetch: () => void) => {
),
}),
],
- [],
- );
-
- return columns;
-};
+ []
+ )
+}
diff --git a/packages/admin/src/pages/sellers/seller-edit/seller-edit.tsx b/packages/admin/src/pages/sellers/seller-edit/seller-edit.tsx
index 13c46b03d..849a9455f 100644
--- a/packages/admin/src/pages/sellers/seller-edit/seller-edit.tsx
+++ b/packages/admin/src/pages/sellers/seller-edit/seller-edit.tsx
@@ -1,32 +1,29 @@
-import { useParams } from "react-router-dom";
+import { Heading } from "@medusajs/ui"
+import { useTranslation } from "react-i18next"
+import { useParams } from "react-router-dom"
-import { RouteDrawer } from "@components/modals";
-
-import { useSeller } from "@hooks/api/sellers";
-
-import { useTranslation } from "react-i18next";
-import { SellerEditForm } from "./components/seller-edit-form";
-import { SellerDetails } from "../seller-details/components/seller-details";
+import { RouteDrawer } from "../../../components/modals"
+import { useSeller } from "../../../hooks/api/sellers"
+import { SellerEditForm } from "./components/seller-edit-form"
export const SellerEdit = () => {
- const { t } = useTranslation();
- const params = useParams();
+ const { id } = useParams()
+ const { t } = useTranslation()
- const { seller, isLoading } = useSeller(params.id!);
+ const { seller, isLoading, isError, error } = useSeller(id!)
- if (isLoading) {
- return <div>Loading...</div>;
+ if (isError) {
+ throw error
}
return (
- <>
- <SellerDetails />
- <RouteDrawer>
- <RouteDrawer.Header>
- <RouteDrawer.Title>{t("sellers.edit.header")}</RouteDrawer.Title>
- </RouteDrawer.Header>
- {seller && <SellerEditForm seller={seller} />}
- </RouteDrawer>
- </>
- );
-};
+ <RouteDrawer>
+ <RouteDrawer.Header>
+ <RouteDrawer.Title asChild>
+ <Heading>{t("sellers.edit.header")}</Heading>
+ </RouteDrawer.Title>
+ </RouteDrawer.Header>
+ {!isLoading && seller && <SellerEditForm seller={seller} />}
+ </RouteDrawer>
+ )
+}
diff --git a/packages/core-plugin/src/api/admin/sellers/[id]/route.ts b/packages/core-plugin/src/api/admin/sellers/[id]/route.ts
index 38ff8f119..077131726 100644
--- a/packages/core-plugin/src/api/admin/sellers/[id]/route.ts
+++ b/packages/core-plugin/src/api/admin/sellers/[id]/route.ts
@@ -8,6 +8,9 @@ import {
} from "@medusajs/framework/utils"
import { HttpTypes } from "@mercurjs/types"
+import { AdminUpdateSellerType } from "../validators"
+import { updateSellerWorkflow } from "../../../../workflows/seller"
+
export const GET = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse<HttpTypes.AdminSellerResponse>
@@ -31,3 +34,34 @@ export const GET = async (
res.json({ seller })
}
+
+export const POST = async (
+ req: AuthenticatedMedusaRequest<AdminUpdateSellerType>,
+ res: MedusaResponse<HttpTypes.AdminSellerResponse>
+) => {
+ const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
+
+ await updateSellerWorkflow(req.scope).run({
+ input: {
+ id: req.params.id,
+ ...req.validatedBody,
+ },
+ })
+
+ const {
+ data: [seller],
+ } = await query.graph({
+ entity: "seller",
+ fields: req.queryConfig.fields,
+ filters: { id: req.params.id },
+ })
+
+ if (!seller) {
+ throw new MedusaError(
+ MedusaError.Types.NOT_FOUND,
+ `Seller with id ${req.params.id} was not found`
+ )
+ }
+
+ res.json({ seller })
+}
diff --git a/packages/core-plugin/src/api/admin/sellers/middlewares.ts b/packages/core-plugin/src/api/admin/sellers/middlewares.ts
index dbce52746..a55565886 100644
--- a/packages/core-plugin/src/api/admin/sellers/middlewares.ts
+++ b/packages/core-plugin/src/api/admin/sellers/middlewares.ts
@@ -1,8 +1,15 @@
import { MiddlewareRoute } from "@medusajs/framework/http"
-import { validateAndTransformQuery } from "@medusajs/framework"
+import {
+ validateAndTransformBody,
+ validateAndTransformQuery,
+} from "@medusajs/framework"
import { adminSellerQueryConfig } from "./query-config"
-import { AdminGetSellerParams, AdminGetSellersParams } from "./validators"
+import {
+ AdminGetSellerParams,
+ AdminGetSellersParams,
+ AdminUpdateSeller,
+} from "./validators"
export const adminSellersMiddlewares: MiddlewareRoute[] = [
{
@@ -25,4 +32,15 @@ export const adminSellersMiddlewares: MiddlewareRoute[] = [
),
],
},
+ {
+ method: ["POST"],
+ matcher: "/admin/sellers/:id",
+ middlewares: [
+ validateAndTransformBody(AdminUpdateSeller),
+ validateAndTransformQuery(
+ AdminGetSellerParams,
+ adminSellerQueryConfig.retrieve
+ ),
+ ],
+ },
]
diff --git a/packages/core-plugin/src/api/admin/sellers/validators.ts b/packages/core-plugin/src/api/admin/sellers/validators.ts
index 5cea39b11..8bc0c218e 100644
--- a/packages/core-plugin/src/api/admin/sellers/validators.ts
+++ b/packages/core-plugin/src/api/admin/sellers/validators.ts
@@ -4,10 +4,28 @@ import {
createOperatorMap,
createSelectParams,
} from "@medusajs/medusa/api/utils/validators"
+import { SellerStatus } from "@mercurjs/types"
export type AdminGetSellerParamsType = z.infer<typeof AdminGetSellerParams>
export const AdminGetSellerParams = createSelectParams()
+export const AdminUpdateSeller = z.object({
+ name: z.preprocess((val: string) => val?.trim(), z.string().min(1)).optional(),
+ handle: z.preprocess((val: string) => val?.trim(), z.string().min(1)).optional(),
+ email: z.string().email().optional(),
+ phone: z.string().nullish(),
+ logo: z.string().nullish(),
+ cover_image: z.string().nullish(),
+ address_1: z.string().nullish(),
+ address_2: z.string().nullish(),
+ city: z.string().nullish(),
+ country_code: z.string().nullish(),
+ province: z.string().nullish(),
+ postal_code: z.string().nullish(),
+ status: z.nativeEnum(SellerStatus).optional(),
+}).strict()
+export type AdminUpdateSellerType = z.infer<typeof AdminUpdateSeller>
+
export type AdminGetSellersParamsType = z.infer<typeof AdminGetSellersParams>
export const AdminGetSellersParams = createFindParams({
offset: 0,