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.

Fix/vendor product routes (#729)

Viktor Holik24715975de9d
diff --git a/apps/vendor-test/src/main.tsx b/apps/vendor-test/src/main.tsx
index 5321a5cbe..ce1b1e708 100644
--- a/apps/vendor-test/src/main.tsx
+++ b/apps/vendor-test/src/main.tsx
@@ -6,5 +6,5 @@ import App from "@mercurjs/vendor";
createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
- </StrictMode>
+ </StrictMode>,
);
diff --git a/apps/vendor-test/src/pages/products/page.tsx b/apps/vendor-test/src/pages/products/page.tsx
new file mode 100644
index 000000000..5eaf795bb
--- /dev/null
+++ b/apps/vendor-test/src/pages/products/page.tsx
@@ -0,0 +1,23 @@
+import { ProductListPage } from "@mercurjs/vendor/pages";
+import { Button } from "@medusajs/ui";
+
+const ProductsOverride = () => {
+ return (
+ <ProductListPage>
+ <ProductListPage.Table>
+ <ProductListPage.Header>
+ <ProductListPage.HeaderTitle />
+ <ProductListPage.HeaderActions>
+ <Button size="small" variant="secondary">
+ Export
+ </Button>
+ <ProductListPage.HeaderCreateButton />
+ </ProductListPage.HeaderActions>
+ </ProductListPage.Header>
+ <ProductListPage.DataTable />
+ </ProductListPage.Table>
+ </ProductListPage>
+ );
+};
+
+export default ProductsOverride;
diff --git a/apps/vendor-test/src/pages/settings/custom-fields/page.tsx b/apps/vendor-test/src/pages/settings/custom-fields/page.tsx
deleted file mode 100644
index ca21ed03c..000000000
--- a/apps/vendor-test/src/pages/settings/custom-fields/page.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import type { RouteConfig } from "@mercurjs/dashboard-sdk";
-import { useTranslation } from "react-i18next";
-
-export const config: RouteConfig = {
- label: "Custom Fields",
-};
-
-export default function CustomFieldsPage() {
- const { t } = useTranslation();
-
- return (
- <div>
- <h1>{t("customFields.title")}</h1>
- <p>{t("customFields.description")}</p>
- <p>{t("customFields.noFields")}</p>
- </div>
- );
-}
diff --git a/packages/dashboard-sdk/src/plugin.ts b/packages/dashboard-sdk/src/plugin.ts
index e9269c982..baa818e6a 100644
--- a/packages/dashboard-sdk/src/plugin.ts
+++ b/packages/dashboard-sdk/src/plugin.ts
@@ -56,6 +56,20 @@ export function dashboardPlugin(): Vite.Plugin {
load(id) {
return loadVirtualModule({ cwd: root, id, mercurConfig: config })
},
+ configureServer(server) {
+ const handlePageChange = (file: string) => {
+ if (!isPageFile(file)) return
+
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ROUTES_MODULE)
+ if (mod) {
+ server.moduleGraph.invalidateModule(mod)
+ server.ws.send({ type: "full-reload" })
+ }
+ }
+
+ server.watcher.on("add", handlePageChange)
+ server.watcher.on("unlink", handlePageChange)
+ },
handleHotUpdate({ file, server }) {
const configPath = path.resolve(root, CONFIG_NAME)
diff --git a/packages/vendor/package.json b/packages/vendor/package.json
index 050d2d192..b60f0737b 100644
--- a/packages/vendor/package.json
+++ b/packages/vendor/package.json
@@ -9,6 +9,10 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
+ "./pages": {
+ "types": "./dist/pages/index.d.ts",
+ "import": "./dist/pages/index.js"
+ },
"./index.css": "./dist/index.css"
},
"files": [
diff --git a/packages/vendor/src/components/layout/main-layout/main-layout.tsx b/packages/vendor/src/components/layout/main-layout/main-layout.tsx
index 9f5647b2e..448482125 100644
--- a/packages/vendor/src/components/layout/main-layout/main-layout.tsx
+++ b/packages/vendor/src/components/layout/main-layout/main-layout.tsx
@@ -140,7 +140,7 @@ const Logout = () => {
);
};
-const Header = () => {
+export const Header = () => {
const { t } = useTranslation();
const { seller, isPending, isError, error } = useMe();
const direction = useDocumentDirection();
diff --git a/packages/vendor/src/components/layout/settings-layout/settings-layout.tsx b/packages/vendor/src/components/layout/settings-layout/settings-layout.tsx
index 01b6de4f7..9f584a67c 100644
--- a/packages/vendor/src/components/layout/settings-layout/settings-layout.tsx
+++ b/packages/vendor/src/components/layout/settings-layout/settings-layout.tsx
@@ -7,7 +7,7 @@ import { Link, useLocation } from "react-router-dom";
import { INavItem, NavItem } from "../nav-item";
import { Shell } from "../shell";
-import { UserMenu } from "../user-menu";
+import { Header as SellerDropdown } from "../main-layout/main-layout";
import components from "virtual:mercur/components";
import menuItemsModule from "virtual:mercur/menu-items";
import { getMenuItemsByType, getNestedMenuItems } from "../../../utils/routes";
@@ -181,7 +181,7 @@ const UserSection = () => {
<div className="px-3">
<Divider variant="dashed" />
</div>
- <UserMenu />
+ <SellerDropdown />
</div>
);
};
diff --git a/packages/vendor/src/get-route-map.tsx b/packages/vendor/src/get-route-map.tsx
index b64db0d32..a3e435371 100644
--- a/packages/vendor/src/get-route-map.tsx
+++ b/packages/vendor/src/get-route-map.tsx
@@ -63,8 +63,6 @@ export function getRouteMap({
errorElement: <ErrorBoundary />,
lazy: () => import("./pages/home"),
},
-
- // PRODUCTS
{
path: "/products",
errorElement: <ErrorBoundary />,
@@ -72,19 +70,32 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/products"),
+ lazy: async () => {
+ const { ProductListPage } =
+ await import("./pages/products");
+ return {
+ Component: ProductListPage,
+ };
+ },
children: [
{
path: "create",
- lazy: () => import("./pages/products/create"),
+ lazy: async () => {
+ const { ProductCreate } =
+ await import("./pages/products/create");
+ return {
+ Component: ProductCreate,
+ };
+ },
},
],
},
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
- await import("./pages/products/[id]");
+ const { loader } = await import("./pages/products/[id]");
+ const { Breadcrumb } =
+ await import("./pages/products/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -98,7 +109,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/products/[id]"),
+ lazy: async () => {
+ const { ProductDetailPage } =
+ await import("./pages/products/[id]");
+ return {
+ Component: ProductDetailPage,
+ };
+ },
children: [
{
path: "edit",
@@ -171,13 +188,17 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/orders"),
+ lazy: async () => {
+ const { OrderListPage } = await import("./pages/orders");
+ return { Component: OrderListPage };
+ },
},
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
- await import("./pages/orders/[id]");
+ const { loader } = await import("./pages/orders/[id]");
+ const { Breadcrumb } =
+ await import("./pages/orders/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -191,7 +212,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/orders/[id]"),
+ lazy: async () => {
+ const { OrderDetailPage } =
+ await import("./pages/orders/[id]");
+ return { Component: OrderDetailPage };
+ },
children: [
{
path: "fulfillment",
@@ -222,13 +247,17 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/payouts"),
+ lazy: async () => {
+ const { PayoutListPage } =
+ await import("./pages/payouts");
+ return { Component: PayoutListPage };
+ },
},
{
path: ":id",
lazy: async () => {
const { Breadcrumb } =
- await import("./pages/payouts/[id]");
+ await import("./pages/payouts/[id]/breadcrumb");
return {
Component: Outlet,
handle: {
@@ -241,7 +270,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/payouts/[id]"),
+ lazy: async () => {
+ const { PayoutDetailPage } =
+ await import("./pages/payouts/[id]");
+ return { Component: PayoutDetailPage };
+ },
},
],
},
@@ -256,7 +289,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/categories"),
+ lazy: async () => {
+ const { CategoryListPage } =
+ await import("./pages/categories");
+ return {
+ Component: CategoryListPage,
+ };
+ },
children: [
{
path: "organize",
@@ -267,8 +306,10 @@ export function getRouteMap({
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
+ const { loader } =
await import("./pages/categories/[id]");
+ const { Breadcrumb } =
+ await import("./pages/categories/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -282,7 +323,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/categories/[id]"),
+ lazy: async () => {
+ const { CategoryDetailPage } =
+ await import("./pages/categories/[id]");
+ return {
+ Component: CategoryDetailPage,
+ };
+ },
children: [
{
path: "products",
@@ -314,19 +361,21 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/collections"),
- children: [
- {
- path: "create",
- lazy: () => import("./pages/collections/create"),
- },
- ],
+ lazy: async () => {
+ const { CollectionListPage } =
+ await import("./pages/collections");
+ return {
+ Component: CollectionListPage,
+ };
+ },
},
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
+ const { loader } =
await import("./pages/collections/[id]");
+ const { Breadcrumb } =
+ await import("./pages/collections/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -340,7 +389,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/collections/[id]"),
+ lazy: async () => {
+ const { CollectionDetailPage } =
+ await import("./pages/collections/[id]");
+ return {
+ Component: CollectionDetailPage,
+ };
+ },
children: [
{
path: "add-products",
@@ -367,19 +422,20 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/customers"),
- children: [
- {
- path: "create",
- lazy: () => import("./pages/customers/create"),
- },
- ],
+ lazy: async () => {
+ const { CustomerListPage } =
+ await import("./pages/customers");
+ return {
+ Component: CustomerListPage,
+ };
+ },
},
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
- await import("./pages/customers/[id]");
+ const { loader } = await import("./pages/customers/[id]");
+ const { Breadcrumb } =
+ await import("./pages/customers/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -393,7 +449,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/customers/[id]"),
+ lazy: async () => {
+ const { CustomerDetailPage } =
+ await import("./pages/customers/[id]");
+ return {
+ Component: CustomerDetailPage,
+ };
+ },
children: [
{
path: "edit",
@@ -430,7 +492,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/inventory"),
+ lazy: async () => {
+ const { InventoryListPage } =
+ await import("./pages/inventory");
+ return {
+ Component: InventoryListPage,
+ };
+ },
children: [
{
path: "create",
@@ -445,8 +513,9 @@ export function getRouteMap({
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
- await import("./pages/inventory/[id]");
+ const { loader } = await import("./pages/inventory/[id]");
+ const { Breadcrumb } =
+ await import("./pages/inventory/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -460,7 +529,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/inventory/[id]"),
+ lazy: async () => {
+ const { InventoryDetailPage } =
+ await import("./pages/inventory/[id]");
+ return {
+ Component: InventoryDetailPage,
+ };
+ },
children: [
{
path: "edit",
@@ -502,7 +577,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/promotions"),
+ lazy: async () => {
+ const { PromotionListPage } =
+ await import("./pages/promotions");
+ return {
+ Component: PromotionListPage,
+ };
+ },
children: [
{
path: "create",
@@ -513,8 +594,10 @@ export function getRouteMap({
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
+ const { loader } =
await import("./pages/promotions/[id]");
+ const { Breadcrumb } =
+ await import("./pages/promotions/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -528,7 +611,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/promotions/[id]"),
+ lazy: async () => {
+ const { PromotionDetailPage } =
+ await import("./pages/promotions/[id]");
+ return {
+ Component: PromotionDetailPage,
+ };
+ },
children: [
{
path: "edit",
@@ -559,7 +648,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/campaigns"),
+ lazy: async () => {
+ const { CampaignListPage } =
+ await import("./pages/campaigns");
+ return {
+ Component: CampaignListPage,
+ };
+ },
children: [
{
path: "create",
@@ -570,8 +665,9 @@ export function getRouteMap({
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
- await import("./pages/campaigns/[id]");
+ const { loader } = await import("./pages/campaigns/[id]");
+ const { Breadcrumb } =
+ await import("./pages/campaigns/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -585,7 +681,13 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/campaigns/[id]"),
+ lazy: async () => {
+ const { CampaignDetailPage } =
+ await import("./pages/campaigns/[id]");
+ return {
+ Component: CampaignDetailPage,
+ };
+ },
children: [
{
path: "edit",
@@ -603,8 +705,13 @@ export function getRouteMap({
},
{
path: "add-promotions",
- lazy: () =>
- import("./pages/campaigns/[id]/add-promotions"),
+ lazy: async () => {
+ const { AddPromotionsPage } =
+ await import("./pages/campaigns/[id]/add-promotions");
+ return {
+ Component: AddPromotionsPage,
+ };
+ },
},
],
},
@@ -621,7 +728,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/price-lists"),
+ lazy: async () => {
+ const { PriceListListPage } =
+ await import("./pages/price-lists");
+ return { Component: PriceListListPage };
+ },
children: [
{
path: "create",
@@ -632,8 +743,10 @@ export function getRouteMap({
{
path: ":id",
lazy: async () => {
- const { Breadcrumb, loader } =
+ const { loader } =
await import("./pages/price-lists/[id]");
+ const { Breadcrumb } =
+ await import("./pages/price-lists/[id]/breadcrumb");
return {
Component: Outlet,
loader,
@@ -647,7 +760,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/price-lists/[id]"),
+ lazy: async () => {
+ const { PriceListDetailPage } =
+ await import("./pages/price-lists/[id]");
+ return { Component: PriceListDetailPage };
+ },
children: [
{
path: "edit",
@@ -753,83 +870,15 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/settings/seller"),
- children: [
- {
- path: "edit",
- lazy: () => import("./pages/settings/seller/edit"),
- },
- ],
- },
- ],
- },
-
- // PROFILE
- {
- path: "profile",
- errorElement: <ErrorBoundary />,
- handle: { breadcrumb: () => t("profile.domain") },
- children: [
- {
- path: "",
- lazy: () => import("./pages/settings/profile"),
- children: [
- {
- path: "edit",
- lazy: () => import("./pages/settings/profile/edit"),
- },
- ],
- },
- ],
- },
-
- // REGIONS
- {
- path: "regions",
- errorElement: <ErrorBoundary />,
- element: <Outlet />,
- handle: { breadcrumb: () => t("regions.domain") },
- children: [
- {
- path: "",
- lazy: () => import("./pages/settings/regions"),
- children: [
- {
- path: "create",
- lazy: () => import("./pages/settings/regions/create"),
- },
- ],
- },
- {
- path: ":id",
lazy: async () => {
- const { Component, Breadcrumb, loader } =
- await import("./pages/settings/regions/[id]");
- return {
- Component,
- loader,
- handle: {
- breadcrumb: (match: UIMatch<any>) => (
- <Breadcrumb {...match} />
- ),
- },
- };
+ const { SellerDetailPage } =
+ await import("./pages/settings/seller");
+ return { Component: SellerDetailPage };
},
children: [
{
path: "edit",
- lazy: () =>
- import("./pages/settings/regions/[id]/edit"),
- },
- {
- path: "countries/add",
- lazy: () =>
- import("./pages/settings/regions/[id]/countries/add"),
- },
- {
- path: "metadata/edit",
- lazy: () =>
- import("./pages/settings/regions/[id]/metadata"),
+ lazy: () => import("./pages/settings/seller/edit"),
},
],
},
@@ -845,7 +894,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/settings/locations"),
+ lazy: async () => {
+ const { LocationListPage } =
+ await import("./pages/settings/locations");
+ return { Component: LocationListPage };
+ },
children: [
{
path: "create",
@@ -862,8 +915,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () =>
- import("./pages/settings/shipping-profiles"),
+ lazy: async () => {
+ const { ShippingProfileListPage } =
+ await import("./pages/settings/shipping-profiles");
+ return { Component: ShippingProfileListPage };
+ },
children: [
{
path: "create",
@@ -875,10 +931,14 @@ export function getRouteMap({
{
path: ":shipping_profile_id",
lazy: async () => {
- const { Component, Breadcrumb, loader } =
+ const { shippingProfileLoader: loader } =
await import("./pages/settings/shipping-profiles/[id]");
+ const {
+ ShippingProfileDetailBreadcrumb: Breadcrumb,
+ } =
+ await import("./pages/settings/shipping-profiles/[id]/breadcrumb");
return {
- Component,
+ Component: Outlet,
loader,
handle: {
breadcrumb: (match: UIMatch<any>) => (
@@ -889,9 +949,21 @@ export function getRouteMap({
},
children: [
{
- path: "metadata/edit",
- lazy: () =>
- import("./pages/settings/shipping-profiles/[id]/metadata"),
+ path: "",
+ lazy: async () => {
+ const { ShippingProfileDetailPage } =
+ await import("./pages/settings/shipping-profiles/[id]");
+ return {
+ Component: ShippingProfileDetailPage,
+ };
+ },
+ children: [
+ {
+ path: "metadata/edit",
+ lazy: () =>
+ import("./pages/settings/shipping-profiles/[id]/metadata"),
+ },
+ ],
},
],
},
@@ -900,10 +972,12 @@ export function getRouteMap({
{
path: ":location_id",
lazy: async () => {
- const { Component, Breadcrumb, loader } =
+ const { loader } =
await import("./pages/settings/locations/[location_id]");
+ const { LocationDetailBreadcrumb: Breadcrumb } =
+ await import("./pages/settings/locations/[location_id]/breadcrumb");
return {
- Component,
+ Component: Outlet,
loader,
handle: {
breadcrumb: (match: UIMatch<any>) => (
@@ -914,49 +988,59 @@ export function getRouteMap({
},
children: [
{
- path: "edit",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/edit"),
- },
- {
- path: "sales-channels",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/sales-channels"),
- },
- {
- path: "fulfillment-providers",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-providers"),
- },
- {
- path: "fulfillment-set/:fset_id/service-zones/create",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zones/create"),
- },
- {
- path: "fulfillment-set/:fset_id/service-zone/:zone_id/edit",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/edit"),
- },
- {
- path: "fulfillment-set/:fset_id/service-zone/:zone_id/areas",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/areas"),
- },
- {
- path: "fulfillment-set/:fset_id/service-zone/:zone_id/shipping-option/create",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/create"),
- },
- {
- path: "fulfillment-set/:fset_id/service-zone/:zone_id/shipping-option/:so_id/edit",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/edit"),
- },
- {
- path: "fulfillment-set/:fset_id/service-zone/:zone_id/shipping-option/:so_id/pricing",
- lazy: () =>
- import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/pricing"),
+ path: "",
+ lazy: async () => {
+ const { LocationDetailPage } =
+ await import("./pages/settings/locations/[location_id]");
+ return { Component: LocationDetailPage };
+ },
+ children: [
+ {
+ path: "edit",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/edit"),
+ },
+ {
+ path: "sales-channels",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/sales-channels"),
+ },
+ {
+ path: "fulfillment-providers",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-providers"),
+ },
+ {
+ path: "fulfillment-set/:fset_id/service-zones/create",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zones/create"),
+ },
+ {
+ path: "fulfillment-set/:fset_id/service-zone/:zone_id/edit",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/edit"),
+ },
+ {
+ path: "fulfillment-set/:fset_id/service-zone/:zone_id/areas",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/areas"),
+ },
+ {
+ path: "fulfillment-set/:fset_id/service-zone/:zone_id/shipping-option/create",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/create"),
+ },
+ {
+ path: "fulfillment-set/:fset_id/service-zone/:zone_id/shipping-option/:so_id/edit",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/edit"),
+ },
+ {
+ path: "fulfillment-set/:fset_id/service-zone/:zone_id/shipping-option/:so_id/pricing",
+ lazy: () =>
+ import("./pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/pricing"),
+ },
+ ],
},
],
},
@@ -1074,15 +1158,21 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/settings/product-tags"),
+ lazy: async () => {
+ const { ProductTagListPage } =
+ await import("./pages/settings/product-tags");
+ return { Component: ProductTagListPage };
+ },
},
{
path: ":id",
lazy: async () => {
- const { Component, Breadcrumb, loader } =
+ const { loader } =
await import("./pages/settings/product-tags/[id]");
+ const { ProductTagDetailBreadcrumb: Breadcrumb } =
+ await import("./pages/settings/product-tags/[id]/breadcrumb");
return {
- Component,
+ Component: Outlet,
loader,
handle: {
breadcrumb: (match: UIMatch<any>) => (
@@ -1093,9 +1183,19 @@ export function getRouteMap({
},
children: [
{
- path: "edit",
- lazy: () =>
- import("./pages/settings/product-tags/[id]/edit"),
+ path: "",
+ lazy: async () => {
+ const { ProductTagDetailPage } =
+ await import("./pages/settings/product-tags/[id]");
+ return { Component: ProductTagDetailPage };
+ },
+ children: [
+ {
+ path: "edit",
+ lazy: () =>
+ import("./pages/settings/product-tags/[id]/edit"),
+ },
+ ],
},
],
},
@@ -1111,7 +1211,11 @@ export function getRouteMap({
children: [
{
path: "",
- lazy: () => import("./pages/settings/product-types"),
+ lazy: async () => {
+ const { ProductTypeListPage } =
+ await import("./pages/settings/product-types");
+ return { Component: ProductTypeListPage };
+ },
children: [
{
path: "create",
@@ -1123,10 +1227,12 @@ export function getRouteMap({
{
path: ":id",
lazy: async () => {
- const { Component, Breadcrumb, loader } =
+ const { productTypeLoader: loader } =
await import("./pages/settings/product-types/[id]");
+ const { ProductTypeDetailBreadcrumb: Breadcrumb } =
+ await import("./pages/settings/product-types/[id]/breadcrumb");
return {
- Component,
+ Component: Outlet,
loader,
handle: {
breadcrumb: (match: UIMatch<any>) => (
@@ -1137,9 +1243,19 @@ export function getRouteMap({
},
children: [
{
- path: "edit",
- lazy: () =>
- import("./pages/settings/product-types/[id]/edit"),
+ path: "",
+ lazy: async () => {
+ const { ProductTypeDetailPage } =
+ await import("./pages/settings/product-types/[id]");
+ return { Component: ProductTypeDetailPage };
+ },
+ children: [
+ {
+ path: "edit",
+ lazy: () =>
+ import("./pages/settings/product-types/[id]/edit"),
+ },
+ ],
},
],
},
@@ -1187,16 +1303,15 @@ export function getRouteMap({
children: [
{
path: "/login",
- lazy: () => import("./pages/login"),
+ lazy: async () => {
+ const { LoginPage } = await import("./pages/login");
+ return { Component: LoginPage };
+ },
},
{
path: "/reset-password",
lazy: () => import("./pages/reset-password"),
},
- {
- path: "/invite",
- lazy: () => import("./pages/invite"),
- },
{
path: "*",
lazy: () => import("./pages/no-match"),
diff --git a/packages/vendor/src/hooks/api/stock-locations.tsx b/packages/vendor/src/hooks/api/stock-locations.tsx
index 2e543038f..05ac47531 100644
--- a/packages/vendor/src/hooks/api/stock-locations.tsx
+++ b/packages/vendor/src/hooks/api/stock-locations.tsx
@@ -14,23 +14,24 @@ import { sdk } from "../../lib/client";
import { queryClient } from "../../lib/query-client";
import { queryKeysFactory } from "../../lib/query-key-factory";
import { fulfillmentProvidersQueryKeys } from "./fulfillment-providers";
+import { HttpTypes } from "@mercurjs/types";
const STOCK_LOCATIONS_QUERY_KEY = "stock_locations" as const;
export const stockLocationsQueryKeys = queryKeysFactory(
- STOCK_LOCATIONS_QUERY_KEY
+ STOCK_LOCATIONS_QUERY_KEY,
);
export const useStockLocation = (
id: string,
query?: Omit<
InferClientInput<typeof sdk.vendor.stockLocations.$id.query>,
- "$id"
+ "$id"
>,
options?: UseQueryOptions<
unknown,
ClientError,
InferClientOutput<typeof sdk.vendor.stockLocations.$id.query>
- >
+ >,
) => {
const { data, ...rest } = useQuery({
queryFn: () => sdk.vendor.stockLocations.$id.query({ $id: id, ...query }),
@@ -46,8 +47,8 @@ export const useStockLocations = (
options?: UseQueryOptions<
unknown,
ClientError,
- InferClientOutput<typeof sdk.vendor.stockLocations.query>
- >
+ HttpTypes.VendorStockLocationListResponse
+ >,
) => {
const { data, ...rest } = useQuery({
queryFn: () => sdk.vendor.stockLocations.query({ ...query }),
@@ -63,7 +64,7 @@ export const useCreateStockLocation = (
InferClientOutput<typeof sdk.vendor.stockLocations.mutate>,
ClientError,
InferClientInput<typeof sdk.vendor.stockLocations.mutate>
- >
+ >,
) => {
return useMutation({
mutationFn: (payload) => sdk.vendor.stockLocations.mutate(payload),
@@ -84,7 +85,7 @@ export const useUpdateStockLocation = (
InferClientOutput<typeof sdk.vendor.stockLocations.$id.mutate>,
ClientError,
Omit<InferClientInput<typeof sdk.vendor.stockLocations.$id.mutate>, "$id">
- >
+ >,
) => {
return useMutation({
mutationFn: (payload) =>
@@ -116,11 +117,14 @@ export const useUpdateStockLocationSalesChannels = (
>,
"$id"
>
- >
+ >,
) => {
return useMutation({
mutationFn: (payload) =>
- sdk.vendor.stockLocations.$id.salesChannels.mutate({ $id: id, ...payload }),
+ sdk.vendor.stockLocations.$id.salesChannels.mutate({
+ $id: id,
+ ...payload,
+ }),
onSuccess: async (data, variables, context) => {
await queryClient.invalidateQueries({
queryKey: stockLocationsQueryKeys.details(),
@@ -141,7 +145,7 @@ export const useDeleteStockLocation = (
InferClientOutput<typeof sdk.vendor.stockLocations.$id.delete>,
ClientError,
void
- >
+ >,
) => {
return useMutation({
mutationFn: () => sdk.vendor.stockLocations.$id.delete({ $id: id }),
@@ -172,7 +176,7 @@ export const useCreateStockLocationFulfillmentSet = (
>,
"$id"
>
- >
+ >,
) => {
return useMutation({
mutationFn: (payload) =>
@@ -204,7 +208,7 @@ export const useUpdateStockLocationFulfillmentProviders = (
>,
"$id"
>
- >
+ >,
) => {
return useMutation({
mutationFn: (payload) =>
diff --git a/packages/vendor/src/index.ts b/packages/vendor/src/index.ts
index c99191663..9b577ed77 100644
--- a/packages/vendor/src/index.ts
+++ b/packages/vendor/src/index.ts
@@ -1,14 +1 @@
-export { default } from './app'
-
-// Compound components for page overrides
-export {
- ProductDetailPage,
- useProductDetailContext,
- ProductListPage,
- ProductCreatePage,
- useProductCreateContext,
-} from './pages/products/exports'
-export type {
- ProductDetailContextValue,
- ProductCreateContextValue,
-} from './pages/products/exports'
+export { default } from './app'
\ No newline at end of file
diff --git a/packages/vendor/src/lib/addresses.ts b/packages/vendor/src/lib/addresses.ts
index 3c4b23399..12fed13b4 100644
--- a/packages/vendor/src/lib/addresses.ts
+++ b/packages/vendor/src/lib/addresses.ts
@@ -25,7 +25,20 @@ export const isSameAddress = (
export const getFormattedAddress = ({
address,
}: {
- address?: HttpTypes.AdminOrderAddress | null
+ address?: {
+ first_name?: string | null
+ last_name?: string | null
+ company?: string | null
+ address_1?: string | null
+ address_2?: string | null
+ city?: string | null
+ postal_code?: string | null
+ province?: string | null
+ country_code?: string | null
+ country?: {
+ display_name?: string | null
+ } | null
+ } | null
}) => {
if (!address) {
return []
diff --git a/packages/vendor/src/lib/promotions.ts b/packages/vendor/src/lib/promotions.ts
index ef6966705..bbf98a80c 100644
--- a/packages/vendor/src/lib/promotions.ts
+++ b/packages/vendor/src/lib/promotions.ts
@@ -17,11 +17,11 @@ export const promotionStatusMap: StatusMap = {
[PromotionStatus.DRAFT]: ["grey", i18n.t("statuses.draft")],
[PromotionStatus.SCHEDULED]: [
"orange",
- `${i18n.t("promotions.fields.campaign")} ${i18n.t("statuses.scheduled").toLowerCase()}`,
+ `${i18n.t("promotions.fields.campaign")} ${i18n.t("statuses.scheduled")?.toLowerCase()}`,
],
[PromotionStatus.EXPIRED]: [
"red",
- `${i18n.t("promotions.fields.campaign")} ${i18n.t("statuses.expired").toLowerCase()}`,
+ `${i18n.t("promotions.fields.campaign")} ${i18n.t("statuses.expired")?.toLowerCase()}`,
],
}
diff --git a/packages/vendor/src/pages/campaigns/[id]/add-promotions/add-promotions-page.tsx b/packages/vendor/src/pages/campaigns/[id]/add-promotions/add-promotions-page.tsx
new file mode 100644
index 000000000..3f01396d5
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/[id]/add-promotions/add-promotions-page.tsx
@@ -0,0 +1,19 @@
+import { useParams } from "react-router-dom";
+import { RouteFocusModal } from "@components/modals";
+import { useCampaign } from "@hooks/api/campaigns";
+import { AddCampaignPromotionsForm } from "./add-campaign-promotions-form";
+
+export const AddPromotionsPage = () => {
+ const { id } = useParams();
+ const { campaign, isError, error } = useCampaign(id!);
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <RouteFocusModal>
+ {campaign && <AddCampaignPromotionsForm campaign={campaign} />}
+ </RouteFocusModal>
+ );
+};
diff --git a/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.ts b/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.ts
index 7e4a29e33..1bd873c09 100644
--- a/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.ts
+++ b/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.ts
@@ -1 +1 @@
-export * from "./add-campaign-promotions-form"
+export * from "./add-promotions-page"
diff --git a/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.tsx b/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.tsx
deleted file mode 100644
index 9157a03e6..000000000
--- a/packages/vendor/src/pages/campaigns/[id]/add-promotions/index.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-// Route: /campaigns/:id/add-promotions
-import { useParams } from "react-router-dom"
-import { RouteFocusModal } from "@components/modals"
-import { useCampaign } from "@hooks/api/campaigns"
-import { AddCampaignPromotionsForm } from "./add-campaign-promotions-form"
-
-export const Component = () => {
- const { id } = useParams()
- const { campaign, isError, error } = useCampaign(id!)
-
- if (isError) {
- throw error
- }
-
- return (
- <RouteFocusModal>
- {campaign && <AddCampaignPromotionsForm campaign={campaign} />}
- </RouteFocusModal>
- )
-}
diff --git a/packages/vendor/src/pages/campaigns/[id]/breadcrumb.tsx b/packages/vendor/src/pages/campaigns/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..4d70157af
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/[id]/breadcrumb.tsx
@@ -0,0 +1,29 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { useCampaign } from "@hooks/api/campaigns";
+
+import { CAMPAIGN_DETAIL_FIELDS } from "./constants";
+
+type CampaignDetailBreadcrumbProps = UIMatch<HttpTypes.AdminCampaignResponse>;
+
+export const Breadcrumb = (props: CampaignDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+
+ const { campaign } = useCampaign(
+ id!,
+ {
+ fields: CAMPAIGN_DETAIL_FIELDS,
+ },
+ {
+ initialData: props.data,
+ enabled: Boolean(id),
+ },
+ );
+
+ if (!campaign) {
+ return null;
+ }
+
+ return <span>{campaign.name}</span>;
+};
diff --git a/packages/vendor/src/pages/campaigns/[id]/campaign-detail-page.tsx b/packages/vendor/src/pages/campaigns/[id]/campaign-detail-page.tsx
new file mode 100644
index 000000000..e8403c362
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/[id]/campaign-detail-page.tsx
@@ -0,0 +1,67 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { TwoColumnPageSkeleton } from "@components/common/skeleton";
+import { TwoColumnPage } from "@components/layout/pages";
+import { useCampaign } from "@hooks/api/campaigns";
+import { usePromotionTableQuery } from "@hooks/table/query/use-promotion-table-query";
+
+import { CampaignBudget } from "./_components/campaign-budget";
+import { CampaignConfigurationSection } from "./_components/campaign-configuration-section";
+import { CampaignGeneralSection } from "./_components/campaign-general-section";
+import { CampaignPromotionSection } from "./_components/campaign-promotion-section";
+import { CampaignSpend } from "./_components/campaign-spend";
+import { CAMPAIGN_DETAIL_FIELDS } from "./constants";
+
+import type { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { id } = useParams();
+ const { searchParams } = usePromotionTableQuery({});
+ const { campaign, isLoading, isError, error } = useCampaign(
+ id!,
+ { ...searchParams, fields: CAMPAIGN_DETAIL_FIELDS },
+ {
+ placeholderData: initialData,
+ },
+ );
+
+ if (isLoading || !campaign) {
+ return <TwoColumnPageSkeleton mainSections={2} sidebarSections={3} />;
+ }
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage hasOutlet data={campaign}>
+ <TwoColumnPage.Main>
+ <CampaignGeneralSection campaign={campaign} />
+ <CampaignPromotionSection campaign={campaign} />
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <CampaignConfigurationSection campaign={campaign} />
+ <CampaignSpend campaign={campaign} />
+ <CampaignBudget campaign={campaign} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
+ );
+};
+
+export const CampaignDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: CampaignGeneralSection,
+ MainPromotionSection: CampaignPromotionSection,
+ SidebarConfigurationSection: CampaignConfigurationSection,
+ SidebarSpend: CampaignSpend,
+ SidebarBudget: CampaignBudget,
+});
diff --git a/packages/vendor/src/pages/campaigns/[id]/index.ts b/packages/vendor/src/pages/campaigns/[id]/index.ts
new file mode 100644
index 000000000..e5f2a6068
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './campaign-detail-page'
diff --git a/packages/vendor/src/pages/campaigns/[id]/index.tsx b/packages/vendor/src/pages/campaigns/[id]/index.tsx
deleted file mode 100644
index 7c8b57d1d..000000000
--- a/packages/vendor/src/pages/campaigns/[id]/index.tsx
+++ /dev/null
@@ -1,93 +0,0 @@
-// Route: /campaigns/:id
-import { useLoaderData, useParams, LoaderFunctionArgs } from "react-router-dom";
-import { HttpTypes } from "@medusajs/types";
-import { UIMatch } from "react-router-dom";
-import { TwoColumnPageSkeleton } from "@components/common/skeleton";
-import { TwoColumnPage } from "@components/layout/pages";
-import { useCampaign, campaignsQueryKeys } from "@hooks/api/campaigns";
-import { usePromotionTableQuery } from "@hooks/table/query/use-promotion-table-query";
-import { fetchQuery } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-import { CampaignBudget } from "./_components/campaign-budget";
-import { CampaignConfigurationSection } from "./_components/campaign-configuration-section";
-import { CampaignGeneralSection } from "./_components/campaign-general-section";
-import { CampaignPromotionSection } from "./_components/campaign-promotion-section";
-import { CampaignSpend } from "./_components/campaign-spend";
-import { CAMPAIGN_DETAIL_FIELDS } from "./constants";
-
-const campaignDetailQuery = (id: string) => ({
- queryKey: campaignsQueryKeys.detail(id, { fields: CAMPAIGN_DETAIL_FIELDS }),
- queryFn: async () =>
- fetchQuery(`/vendor/campaigns/${id}`, {
- method: "GET",
- query: {
- fields: CAMPAIGN_DETAIL_FIELDS,
- },
- }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = campaignDetailQuery(id!);
-
- return queryClient.ensureQueryData(query);
-};
-
-type CampaignDetailBreadcrumbProps = UIMatch<HttpTypes.AdminCampaignResponse>;
-
-export const Breadcrumb = (props: CampaignDetailBreadcrumbProps) => {
- const { id } = props.params || {};
-
- const { campaign } = useCampaign(
- id!,
- {
- fields: CAMPAIGN_DETAIL_FIELDS,
- },
- {
- initialData: props.data,
- enabled: Boolean(id),
- },
- );
-
- if (!campaign) {
- return null;
- }
-
- return <span>{campaign.name}</span>;
-};
-
-export const Component = () => {
- const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
-
- const { id } = useParams();
- const { searchParams } = usePromotionTableQuery({});
- const { campaign, isLoading, isError, error } = useCampaign(
- id!,
- { ...searchParams, fields: CAMPAIGN_DETAIL_FIELDS },
- {
- placeholderData: initialData,
- },
- );
-
- if (isLoading || !campaign) {
- return <TwoColumnPageSkeleton mainSections={2} sidebarSections={3} />;
- }
-
- if (isError) {
- throw error;
- }
-
- return (
- <TwoColumnPage hasOutlet data={campaign}>
- <TwoColumnPage.Main>
- <CampaignGeneralSection campaign={campaign} />
- <CampaignPromotionSection campaign={campaign} />
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <CampaignConfigurationSection campaign={campaign} />
- <CampaignSpend campaign={campaign} />
- <CampaignBudget campaign={campaign} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/campaigns/[id]/loader.tsx b/packages/vendor/src/pages/campaigns/[id]/loader.tsx
new file mode 100644
index 000000000..946c16e16
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/[id]/loader.tsx
@@ -0,0 +1,25 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { campaignsQueryKeys } from "@hooks/api/campaigns";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+import { CAMPAIGN_DETAIL_FIELDS } from "./constants";
+
+const campaignDetailQuery = (id: string) => ({
+ queryKey: campaignsQueryKeys.detail(id, { fields: CAMPAIGN_DETAIL_FIELDS }),
+ queryFn: async () =>
+ fetchQuery(`/vendor/campaigns/${id}`, {
+ method: "GET",
+ query: {
+ fields: CAMPAIGN_DETAIL_FIELDS,
+ },
+ }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = campaignDetailQuery(id!);
+
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/campaigns/_components/campaign-list-table.tsx b/packages/vendor/src/pages/campaigns/_components/campaign-list-table.tsx
deleted file mode 100644
index 2f9325843..000000000
--- a/packages/vendor/src/pages/campaigns/_components/campaign-list-table.tsx
+++ /dev/null
@@ -1,157 +0,0 @@
-import { PencilSquare, Trash } from "@medusajs/icons"
-import { AdminCampaign } from "@medusajs/types"
-import { Button, Container, Heading, toast, usePrompt } from "@medusajs/ui"
-import { keepPreviousData } from "@tanstack/react-query"
-import { createColumnHelper } from "@tanstack/react-table"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-import { Link } from "react-router-dom"
-import { ActionMenu } from "@components/common/action-menu"
-import { _DataTable } from "@components/table/data-table"
-import {
- useCampaigns,
- useDeleteCampaign,
-} from "@hooks/api/campaigns"
-import { useCampaignTableColumns } from "@hooks/table/columns/use-campaign-table-columns"
-import { useCampaignTableQuery } from "@hooks/table/query/use-campaign-table-query"
-import { useDataTable } from "@hooks/use-data-table"
-
-const PAGE_SIZE = 20
-
-export const CampaignListTable = () => {
- const { t } = useTranslation()
- const { raw, searchParams } = useCampaignTableQuery({ pageSize: PAGE_SIZE })
-
- const {
- campaigns,
- count,
- isPending: isLoading,
- isError,
- error,
- } = useCampaigns(searchParams, {
- placeholderData: keepPreviousData,
- })
-
- const columns = useColumns()
-
- const { table } = useDataTable({
- data: campaigns ?? [],
- columns,
- count,
- enablePagination: true,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- })
-
- if (isError) {
- throw error
- }
-
- return (
- <Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading level="h2">{t("campaigns.domain")}</Heading>
- <Link to="/campaigns/create">
- <Button size="small" variant="secondary">
- {t("actions.create")}
- </Button>
- </Link>
- </div>
-
- <_DataTable
- table={table}
- columns={columns}
- count={count}
- pageSize={PAGE_SIZE}
- pagination
- search
- navigateTo={(row) => row.id}
- isLoading={isLoading}
- queryObject={raw}
- orderBy={[
- { key: "name", label: t("fields.name") },
- { key: "created_at", label: t("fields.createdAt") },
- { key: "updated_at", label: t("fields.updatedAt") },
- ]}
- />
- </Container>
- )
-}
-
-const CampaignActions = ({ campaign }: { campaign: AdminCampaign }) => {
- const { t } = useTranslation()
- const prompt = usePrompt()
- const { mutateAsync } = useDeleteCampaign(campaign.id)
-
- const handleDelete = async () => {
- const confirm = await prompt({
- title: t("general.areYouSure"),
- description: t("campaigns.deleteCampaignWarning", {
- name: campaign.name,
- }),
- verificationInstruction: t("general.typeToConfirm"),
- verificationText: campaign.name,
- confirmText: t("actions.delete"),
- cancelText: t("actions.cancel"),
- })
-
- if (!confirm) {
- return
- }
-
- await mutateAsync(undefined, {
- onSuccess: () => {
- toast.success(
- t("campaigns.delete.successToast", { name: campaign.name })
- )
- },
- onError: (e) => {
- toast.error(e.message)
- },
- })
- }
-
- return (
- <ActionMenu
- groups={[
- {
- actions: [
- {
- icon: <PencilSquare />,
- label: t("actions.edit"),
- to: `/campaigns/${campaign.id}/edit`,
- },
- ],
- },
- {
- actions: [
- {
- icon: <Trash />,
- label: t("actions.delete"),
- onClick: handleDelete,
- },
- ],
- },
- ]}
- />
- )
-}
-
-const columnHelper = createColumnHelper<AdminCampaign>()
-
-const useColumns = () => {
- const base = useCampaignTableColumns()
-
- return useMemo(
- () => [
- ...base,
- columnHelper.display({
- id: "actions",
- cell: ({ row }) => {
- return <CampaignActions campaign={row.original} />
- },
- }),
- ],
- [base]
- )
-}
diff --git a/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-data-table.tsx b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-data-table.tsx
new file mode 100644
index 000000000..866e5dcc7
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-data-table.tsx
@@ -0,0 +1,146 @@
+import { PencilSquare, Trash } from "@medusajs/icons";
+import { AdminCampaign } from "@medusajs/types";
+import { toast, usePrompt } from "@medusajs/ui";
+import { keepPreviousData } from "@tanstack/react-query";
+import { createColumnHelper } from "@tanstack/react-table";
+import { useMemo } from "react";
+import { useTranslation } from "react-i18next";
+
+import { ActionMenu } from "@components/common/action-menu";
+import { _DataTable } from "@components/table/data-table";
+import {
+ useCampaigns,
+ useDeleteCampaign,
+} from "@hooks/api/campaigns";
+import { useCampaignTableColumns } from "@hooks/table/columns/use-campaign-table-columns";
+import { useCampaignTableQuery } from "@hooks/table/query/use-campaign-table-query";
+import { useDataTable } from "@hooks/use-data-table";
+
+const PAGE_SIZE = 20;
+
+export const CampaignListDataTable = () => {
+ const { t } = useTranslation();
+ const { raw, searchParams } = useCampaignTableQuery({ pageSize: PAGE_SIZE });
+
+ const {
+ campaigns,
+ count,
+ isPending: isLoading,
+ isError,
+ error,
+ } = useCampaigns(searchParams, {
+ placeholderData: keepPreviousData,
+ });
+
+ const columns = useColumns();
+
+ const { table } = useDataTable({
+ data: campaigns ?? [],
+ columns,
+ count,
+ enablePagination: true,
+ getRowId: (row) => row.id,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ columns={columns}
+ count={count}
+ pageSize={PAGE_SIZE}
+ pagination
+ search
+ navigateTo={(row) => row.id}
+ isLoading={isLoading}
+ queryObject={raw}
+ orderBy={[
+ { key: "name", label: t("fields.name") },
+ { key: "created_at", label: t("fields.createdAt") },
+ { key: "updated_at", label: t("fields.updatedAt") },
+ ]}
+ />
+ );
+};
+
+const CampaignActions = ({ campaign }: { campaign: AdminCampaign }) => {
+ const { t } = useTranslation();
+ const prompt = usePrompt();
+ const { mutateAsync } = useDeleteCampaign(campaign.id);
+
+ const handleDelete = async () => {
+ const confirm = await prompt({
+ title: t("general.areYouSure"),
+ description: t("campaigns.deleteCampaignWarning", {
+ name: campaign.name,
+ }),
+ verificationInstruction: t("general.typeToConfirm"),
+ verificationText: campaign.name,
+ confirmText: t("actions.delete"),
+ cancelText: t("actions.cancel"),
+ });
+
+ if (!confirm) {
+ return;
+ }
+
+ await mutateAsync(undefined, {
+ onSuccess: () => {
+ toast.success(
+ t("campaigns.delete.successToast", { name: campaign.name }),
+ );
+ },
+ onError: (e) => {
+ toast.error(e.message);
+ },
+ });
+ };
+
+ return (
+ <ActionMenu
+ groups={[
+ {
+ actions: [
+ {
+ icon: <PencilSquare />,
+ label: t("actions.edit"),
+ to: `/campaigns/${campaign.id}/edit`,
+ },
+ ],
+ },
+ {
+ actions: [
+ {
+ icon: <Trash />,
+ label: t("actions.delete"),
+ onClick: handleDelete,
+ },
+ ],
+ },
+ ]}
+ />
+ );
+};
+
+const columnHelper = createColumnHelper<AdminCampaign>();
+
+const useColumns = () => {
+ const base = useCampaignTableColumns();
+
+ return useMemo(
+ () => [
+ ...base,
+ columnHelper.display({
+ id: "actions",
+ cell: ({ row }) => {
+ return <CampaignActions campaign={row.original} />;
+ },
+ }),
+ ],
+ [base],
+ );
+};
diff --git a/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-header.tsx b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-header.tsx
new file mode 100644
index 000000000..997b8603e
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-header.tsx
@@ -0,0 +1,55 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Link } from "react-router-dom";
+import { Button, Heading } from "@medusajs/ui";
+
+export const CampaignListTitle = () => {
+ const { t } = useTranslation();
+ return <Heading level="h2">{t("campaigns.domain")}</Heading>;
+};
+
+export const CampaignListCreateButton = () => {
+ const { t } = useTranslation();
+ return (
+ <Link to="/campaigns/create">
+ <Button size="small" variant="secondary">
+ {t("actions.create")}
+ </Button>
+ </Link>
+ );
+};
+
+export const CampaignListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <CampaignListCreateButton />
+ )}
+ </div>
+ );
+};
+
+export const CampaignListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CampaignListTitle />
+ <CampaignListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-table.tsx b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-table.tsx
new file mode 100644
index 000000000..da037444b
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/campaign-list-table.tsx
@@ -0,0 +1,20 @@
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
+
+import { CampaignListHeader } from "./campaign-list-header";
+import { CampaignListDataTable } from "./campaign-list-data-table";
+
+export const CampaignListTable = ({ children }: { children?: ReactNode }) => {
+ return (
+ <Container className="divide-y p-0">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CampaignListHeader />
+ <CampaignListDataTable />
+ </>
+ )}
+ </Container>
+ );
+};
diff --git a/packages/vendor/src/pages/campaigns/_components/campaign-list-table/index.ts b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/index.ts
new file mode 100644
index 000000000..d9aceb0a8
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/_components/campaign-list-table/index.ts
@@ -0,0 +1,3 @@
+export * from "./campaign-list-table"
+export * from "./campaign-list-header"
+export * from "./campaign-list-data-table"
diff --git a/packages/vendor/src/pages/campaigns/campaign-list-page.tsx b/packages/vendor/src/pages/campaigns/campaign-list-page.tsx
new file mode 100644
index 000000000..2e4c4b414
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/campaign-list-page.tsx
@@ -0,0 +1,29 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ CampaignListTable,
+ CampaignListDataTable,
+ CampaignListHeader,
+ CampaignListActions,
+ CampaignListTitle,
+ CampaignListCreateButton,
+} from "./_components/campaign-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage hasOutlet>
+ {Children.count(children) > 0 ? children : <CampaignListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const CampaignListPage = Object.assign(Root, {
+ Table: CampaignListTable,
+ Header: CampaignListHeader,
+ HeaderTitle: CampaignListTitle,
+ HeaderActions: CampaignListActions,
+ HeaderCreateButton: CampaignListCreateButton,
+ DataTable: CampaignListDataTable,
+});
diff --git a/packages/vendor/src/pages/campaigns/index.ts b/packages/vendor/src/pages/campaigns/index.ts
new file mode 100644
index 000000000..a83181181
--- /dev/null
+++ b/packages/vendor/src/pages/campaigns/index.ts
@@ -0,0 +1 @@
+export * from './campaign-list-page'
diff --git a/packages/vendor/src/pages/campaigns/index.tsx b/packages/vendor/src/pages/campaigns/index.tsx
deleted file mode 100644
index c1e7d97d2..000000000
--- a/packages/vendor/src/pages/campaigns/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /campaigns
-import { SingleColumnPage } from "@components/layout/pages";
-import { CampaignListTable } from "./_components/campaign-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage hasOutlet>
- <CampaignListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/categories/[id]/breadcrumb.tsx b/packages/vendor/src/pages/categories/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..c3a4d6bc2
--- /dev/null
+++ b/packages/vendor/src/pages/categories/[id]/breadcrumb.tsx
@@ -0,0 +1,23 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { useProductCategory } from "@hooks/api";
+
+type CategoryDetailBreadcrumbProps =
+ UIMatch<HttpTypes.AdminProductCategoryResponse>;
+
+export const Breadcrumb = (props: CategoryDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+
+ const { product_category } = useProductCategory(
+ id!,
+ { fields: "name" },
+ { initialData: props.data, enabled: Boolean(id) },
+ );
+
+ if (!product_category) {
+ return null;
+ }
+
+ return <span>{product_category.name}</span>;
+};
diff --git a/packages/vendor/src/pages/categories/[id]/category-detail-page.tsx b/packages/vendor/src/pages/categories/[id]/category-detail-page.tsx
new file mode 100644
index 000000000..0dbd826e9
--- /dev/null
+++ b/packages/vendor/src/pages/categories/[id]/category-detail-page.tsx
@@ -0,0 +1,64 @@
+import { Children, ReactNode } from "react";
+import { useParams } from "react-router-dom";
+
+import { TwoColumnPageSkeleton } from "@components/common/skeleton";
+import { TwoColumnPage } from "@components/layout/pages";
+import { useProductCategory } from "@hooks/api";
+
+import { CategoryGeneralSection } from "./_components/category-general-section";
+import { CategoryOrganizeSection } from "./_components/category-organize-section";
+import { CategoryProductSection } from "./_components/category-product-section";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const { id } = useParams();
+
+ const {
+ product_category,
+ isLoading: categoryLoading,
+ isError: categoryError,
+ error,
+ } = useProductCategory(id!, {
+ fields: "+is_active,+is_internal",
+ });
+
+ if (categoryLoading || !product_category) {
+ return (
+ <TwoColumnPageSkeleton
+ mainSections={2}
+ sidebarSections={1}
+ showJSON
+ showMetadata
+ />
+ );
+ }
+
+ if (categoryError) {
+ throw error;
+ }
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage data={product_category}>
+ <TwoColumnPage.Main>
+ <CategoryGeneralSection category={product_category} />
+ <CategoryProductSection category={product_category} />
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <CategoryOrganizeSection category={product_category} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
+ );
+};
+
+export const CategoryDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: CategoryGeneralSection,
+ MainProductSection: CategoryProductSection,
+ SidebarOrganizeSection: CategoryOrganizeSection,
+});
diff --git a/packages/vendor/src/pages/categories/[id]/index.ts b/packages/vendor/src/pages/categories/[id]/index.ts
new file mode 100644
index 000000000..93fa94764
--- /dev/null
+++ b/packages/vendor/src/pages/categories/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './category-detail-page'
diff --git a/packages/vendor/src/pages/categories/[id]/index.tsx b/packages/vendor/src/pages/categories/[id]/index.tsx
deleted file mode 100644
index 7362774a0..000000000
--- a/packages/vendor/src/pages/categories/[id]/index.tsx
+++ /dev/null
@@ -1,91 +0,0 @@
-// Route: /categories/:id
-import { HttpTypes } from "@medusajs/types";
-import { UIMatch, useParams, LoaderFunctionArgs } from "react-router-dom";
-
-import { TwoColumnPageSkeleton } from "@components/common/skeleton";
-import { TwoColumnPage } from "@components/layout/pages";
-import { useProductCategory } from "@hooks/api";
-import { categoriesQueryKeys } from "@hooks/api/categories";
-import { fetchQuery } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-
-import { CategoryGeneralSection } from "./_components/category-general-section";
-import { CategoryOrganizeSection } from "./_components/category-organize-section";
-import { CategoryProductSection } from "./_components/category-product-section";
-
-// Loader
-const categoryDetailQuery = (id: string) => ({
- queryKey: categoriesQueryKeys.detail(id),
- queryFn: async () =>
- fetchQuery(`/vendor/product-categories/${id}`, {
- method: "GET",
- }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = categoryDetailQuery(id!);
-
- return queryClient.ensureQueryData(query);
-};
-
-// Breadcrumb
-type CategoryDetailBreadcrumbProps =
- UIMatch<HttpTypes.AdminProductCategoryResponse>;
-
-export const Breadcrumb = (props: CategoryDetailBreadcrumbProps) => {
- const { id } = props.params || {};
-
- const { product_category } = useProductCategory(
- id!,
- { fields: "name" },
- { initialData: props.data, enabled: Boolean(id) },
- );
-
- if (!product_category) {
- return null;
- }
-
- return <span>{product_category.name}</span>;
-};
-
-// Main component
-export const Component = () => {
- const { id } = useParams();
-
- const {
- product_category,
- isLoading: categoryLoading,
- isError: categoryError,
- error,
- } = useProductCategory(id!, {
- fields: "+is_active,+is_internal",
- });
-
- if (categoryLoading || !product_category) {
- return (
- <TwoColumnPageSkeleton
- mainSections={2}
- sidebarSections={1}
- showJSON
- showMetadata
- />
- );
- }
-
- if (categoryError) {
- throw error;
- }
-
- return (
- <TwoColumnPage data={product_category}>
- <TwoColumnPage.Main>
- <CategoryGeneralSection category={product_category} />
- <CategoryProductSection category={product_category} />
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <CategoryOrganizeSection category={product_category} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/categories/[id]/loader.tsx b/packages/vendor/src/pages/categories/[id]/loader.tsx
new file mode 100644
index 000000000..aa3d17805
--- /dev/null
+++ b/packages/vendor/src/pages/categories/[id]/loader.tsx
@@ -0,0 +1,20 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { categoriesQueryKeys } from "@hooks/api/categories";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+const categoryDetailQuery = (id: string) => ({
+ queryKey: categoriesQueryKeys.detail(id),
+ queryFn: async () =>
+ fetchQuery(`/vendor/product-categories/${id}`, {
+ method: "GET",
+ }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = categoryDetailQuery(id!);
+
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/categories/_components/category-list-table/category-list-data-table.tsx b/packages/vendor/src/pages/categories/_components/category-list-table/category-list-data-table.tsx
new file mode 100644
index 000000000..081df84ba
--- /dev/null
+++ b/packages/vendor/src/pages/categories/_components/category-list-table/category-list-data-table.tsx
@@ -0,0 +1,75 @@
+import { keepPreviousData } from "@tanstack/react-query";
+import { useMemo } from "react";
+
+import { _DataTable } from "@components/table/data-table";
+import { useProductCategories } from "@hooks/api/categories";
+import { useDataTable } from "@hooks/use-data-table";
+import { useCategoryTableColumns } from "./use-category-table-columns";
+import { useCategoryTableQuery } from "./use-category-table-query";
+
+const PAGE_SIZE = 20;
+
+export const CategoryListDataTable = () => {
+ const { raw, searchParams } = useCategoryTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+
+ const query = raw.q
+ ? {
+ include_ancestors_tree: true,
+ fields: "id,name,handle,is_active,is_internal,parent_category",
+ ...searchParams,
+ }
+ : {
+ include_descendants_tree: true,
+ parent_category_id: "null",
+ fields: "id,name,category_children,handle,is_internal,is_active",
+ ...searchParams,
+ };
+
+ const { product_categories, count, isLoading, isError, error } =
+ useProductCategories(
+ {
+ ...query,
+ },
+ {
+ placeholderData: keepPreviousData,
+ },
+ );
+
+ const columns = useColumns();
+
+ const { table } = useDataTable({
+ data: product_categories || [],
+ columns,
+ count,
+ getRowId: (original) => original.id,
+ getSubRows: (original) => original.category_children,
+ enableExpandableRows: true,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ columns={columns}
+ count={count}
+ pageSize={PAGE_SIZE}
+ isLoading={isLoading}
+ navigateTo={(row) => row.id}
+ queryObject={raw}
+ search
+ pagination
+ />
+ );
+};
+
+const useColumns = () => {
+ const base = useCategoryTableColumns();
+
+ return useMemo(() => [...base], [base]);
+};
diff --git a/packages/vendor/src/pages/categories/_components/category-list-table/category-list-header.tsx b/packages/vendor/src/pages/categories/_components/category-list-table/category-list-header.tsx
new file mode 100644
index 000000000..328498c30
--- /dev/null
+++ b/packages/vendor/src/pages/categories/_components/category-list-table/category-list-header.tsx
@@ -0,0 +1,46 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Heading, Text } from "@medusajs/ui";
+
+export const CategoryListTitle = () => {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Heading>{t("categories.domain")}</Heading>
+ <Text className="text-ui-fg-subtle" size="small">
+ Organize products into categories.
+ </Text>
+ </div>
+ );
+};
+
+export const CategoryListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center gap-x-2">
+ {Children.count(children) > 0 ? children : null}
+ </div>
+ );
+};
+
+export const CategoryListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CategoryListTitle />
+ <CategoryListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/categories/_components/category-list-table/category-list-table.tsx b/packages/vendor/src/pages/categories/_components/category-list-table/category-list-table.tsx
index 06d6a4b3d..3c4423ee6 100644
--- a/packages/vendor/src/pages/categories/_components/category-list-table/category-list-table.tsx
+++ b/packages/vendor/src/pages/categories/_components/category-list-table/category-list-table.tsx
@@ -1,91 +1,22 @@
-import { Container, Heading, Text } from "@medusajs/ui"
-import { keepPreviousData } from "@tanstack/react-query"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
+import { Outlet } from "react-router-dom";
-import { _DataTable } from "@components/table/data-table"
-import { useProductCategories } from "@hooks/api/categories"
-import { useDataTable } from "@hooks/use-data-table"
-import { useCategoryTableColumns } from "./use-category-table-columns"
-import { useCategoryTableQuery } from "./use-category-table-query"
-
-const PAGE_SIZE = 20
-
-export const CategoryListTable = () => {
- const { t } = useTranslation()
-
- const { raw, searchParams } = useCategoryTableQuery({
- pageSize: PAGE_SIZE,
- })
-
- const query = raw.q
- ? {
- include_ancestors_tree: true,
- fields: "id,name,handle,is_active,is_internal,parent_category",
- ...searchParams,
- }
- : {
- include_descendants_tree: true,
- parent_category_id: "null",
- fields: "id,name,category_children,handle,is_internal,is_active",
- ...searchParams,
- }
-
- const { product_categories, count, isLoading, isError, error } =
- useProductCategories(
- {
- ...query,
- },
- {
- placeholderData: keepPreviousData,
- }
- )
-
- const columns = useColumns()
-
- const { table } = useDataTable({
- data: product_categories || [],
- columns,
- count,
- getRowId: (original) => original.id,
- getSubRows: (original) => original.category_children,
- enableExpandableRows: true,
- pageSize: PAGE_SIZE,
- })
-
- if (isError) {
- throw error
- }
+import { CategoryListHeader } from "./category-list-header";
+import { CategoryListDataTable } from "./category-list-data-table";
+export const CategoryListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("categories.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- Organize products into categories.
- </Text>
- </div>
- <div className="flex items-center gap-x-2">
- </div>
- </div>
- <_DataTable
- table={table}
- columns={columns}
- count={count}
- pageSize={PAGE_SIZE}
- isLoading={isLoading}
- navigateTo={(row) => row.id}
- queryObject={raw}
- search
- pagination
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CategoryListHeader />
+ <CategoryListDataTable />
+ </>
+ )}
+ <Outlet />
</Container>
- )
-}
-
-const useColumns = () => {
- const base = useCategoryTableColumns()
-
- return useMemo(() => [...base], [base])
-}
+ );
+};
diff --git a/packages/vendor/src/pages/categories/_components/category-list-table/index.ts b/packages/vendor/src/pages/categories/_components/category-list-table/index.ts
index 0422d9cf0..e10cf1bdc 100644
--- a/packages/vendor/src/pages/categories/_components/category-list-table/index.ts
+++ b/packages/vendor/src/pages/categories/_components/category-list-table/index.ts
@@ -1 +1,3 @@
export * from "./category-list-table"
+export * from "./category-list-header"
+export * from "./category-list-data-table"
diff --git a/packages/vendor/src/pages/categories/category-list-page.tsx b/packages/vendor/src/pages/categories/category-list-page.tsx
new file mode 100644
index 000000000..ca2d07507
--- /dev/null
+++ b/packages/vendor/src/pages/categories/category-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ CategoryListTable,
+ CategoryListDataTable,
+ CategoryListHeader,
+ CategoryListActions,
+ CategoryListTitle,
+} from "./_components/category-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage hasOutlet>
+ {Children.count(children) > 0 ? children : <CategoryListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const CategoryListPage = Object.assign(Root, {
+ Table: CategoryListTable,
+ Header: CategoryListHeader,
+ HeaderTitle: CategoryListTitle,
+ HeaderActions: CategoryListActions,
+ DataTable: CategoryListDataTable,
+});
diff --git a/packages/vendor/src/pages/categories/index.ts b/packages/vendor/src/pages/categories/index.ts
new file mode 100644
index 000000000..71e236d68
--- /dev/null
+++ b/packages/vendor/src/pages/categories/index.ts
@@ -0,0 +1 @@
+export * from './category-list-page'
diff --git a/packages/vendor/src/pages/categories/index.tsx b/packages/vendor/src/pages/categories/index.tsx
deleted file mode 100644
index db89ebedb..000000000
--- a/packages/vendor/src/pages/categories/index.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { SingleColumnPage } from "@components/layout/pages";
-import { CategoryListTable } from "./_components/category-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage hasOutlet>
- <CategoryListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/collections/[id]/breadcrumb.tsx b/packages/vendor/src/pages/collections/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..00d404417
--- /dev/null
+++ b/packages/vendor/src/pages/collections/[id]/breadcrumb.tsx
@@ -0,0 +1,17 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { useCollection } from "@hooks/api/collections";
+
+type CollectionDetailBreadcrumbProps =
+ UIMatch<HttpTypes.AdminCollectionResponse>;
+
+export const Breadcrumb = (props: CollectionDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+ const { collection } = useCollection(id!, {
+ initialData: { collection: props.data?.collection },
+ });
+
+ if (!collection) return null;
+ return <span>{collection.title}</span>;
+};
diff --git a/packages/vendor/src/pages/collections/[id]/collection-detail-page.tsx b/packages/vendor/src/pages/collections/[id]/collection-detail-page.tsx
new file mode 100644
index 000000000..efa11081a
--- /dev/null
+++ b/packages/vendor/src/pages/collections/[id]/collection-detail-page.tsx
@@ -0,0 +1,43 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { SingleColumnPageSkeleton } from "@components/common/skeleton";
+import { SingleColumnPage } from "@components/layout/pages";
+import { useCollection } from "@hooks/api/collections";
+
+import { CollectionGeneralSection } from "./_components/collection-general-section";
+import { CollectionProductSection } from "./_components/collection-product-section";
+
+import type { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { id } = useParams();
+ const { collection, isLoading, isError, error } = useCollection(id!, {
+ initialData,
+ });
+
+ if (isLoading || !collection) {
+ return <SingleColumnPageSkeleton sections={2} />;
+ }
+
+ if (isError) throw error;
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <SingleColumnPage data={collection}>
+ <CollectionGeneralSection collection={collection} />
+ <CollectionProductSection collection={collection} />
+ </SingleColumnPage>
+ )}
+ </>
+ );
+};
+
+export const CollectionDetailPage = Object.assign(Root, {
+ GeneralSection: CollectionGeneralSection,
+ ProductSection: CollectionProductSection,
+});
diff --git a/packages/vendor/src/pages/collections/[id]/index.ts b/packages/vendor/src/pages/collections/[id]/index.ts
new file mode 100644
index 000000000..c7c024168
--- /dev/null
+++ b/packages/vendor/src/pages/collections/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './collection-detail-page'
diff --git a/packages/vendor/src/pages/collections/[id]/index.tsx b/packages/vendor/src/pages/collections/[id]/index.tsx
deleted file mode 100644
index 1b8eaa2df..000000000
--- a/packages/vendor/src/pages/collections/[id]/index.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-// Route: /collections/:id
-import { HttpTypes } from "@medusajs/types";
-import {
- UIMatch,
- useLoaderData,
- useParams,
- LoaderFunctionArgs,
-} from "react-router-dom";
-
-import { SingleColumnPageSkeleton } from "@components/common/skeleton";
-import { SingleColumnPage } from "@components/layout/pages";
-import { useDashboardExtension } from "@/extensions";
-import { useCollection } from "@hooks/api/collections";
-import { collectionsQueryKeys } from "@hooks/api/collections";
-import { sdk } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-
-import { CollectionGeneralSection } from "./_components/collection-general-section";
-import { CollectionProductSection } from "./_components/collection-product-section";
-
-// Loader
-const collectionDetailQuery = (id: string) => ({
- queryKey: collectionsQueryKeys.detail(id),
- queryFn: async () => sdk.vendor.collections.$id.query({ $id: id }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = collectionDetailQuery(id!);
- return queryClient.ensureQueryData(query);
-};
-
-// Breadcrumb
-type CollectionDetailBreadcrumbProps =
- UIMatch<HttpTypes.AdminCollectionResponse>;
-
-export const Breadcrumb = (props: CollectionDetailBreadcrumbProps) => {
- const { id } = props.params || {};
- const { collection } = useCollection(id!, {
- initialData: { collection: props.data?.collection },
- });
-
- if (!collection) return null;
- return <span>{collection.title}</span>;
-};
-
-// Main component
-export const Component = () => {
- const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
- const { id } = useParams();
- const { collection, isLoading, isError, error } = useCollection(id!, {
- initialData,
- });
-
- if (isLoading || !collection) {
- return <SingleColumnPageSkeleton sections={2} />;
- }
-
- if (isError) throw error;
-
- return (
- <SingleColumnPage data={collection}>
- <CollectionGeneralSection collection={collection} />
- <CollectionProductSection collection={collection} />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/collections/[id]/loader.tsx b/packages/vendor/src/pages/collections/[id]/loader.tsx
new file mode 100644
index 000000000..a46568a68
--- /dev/null
+++ b/packages/vendor/src/pages/collections/[id]/loader.tsx
@@ -0,0 +1,16 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { collectionsQueryKeys } from "@hooks/api/collections";
+import { sdk } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+const collectionDetailQuery = (id: string) => ({
+ queryKey: collectionsQueryKeys.detail(id),
+ queryFn: async () => sdk.vendor.collections.$id.query({ $id: id }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = collectionDetailQuery(id!);
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-data-table.tsx b/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-data-table.tsx
new file mode 100644
index 000000000..9645c08cc
--- /dev/null
+++ b/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-data-table.tsx
@@ -0,0 +1,76 @@
+import { useTranslation } from "react-i18next";
+import { keepPreviousData } from "@tanstack/react-query";
+import { useMemo } from "react";
+
+import { _DataTable } from "@components/table/data-table";
+import { useCollections } from "@hooks/api/collections";
+import { useCollectionTableColumns } from "@hooks/table/columns/use-collection-table-columns";
+import { useCollectionTableFilters } from "@hooks/table/filters";
+import { useCollectionTableQuery } from "@hooks/table/query";
+import { useDataTable } from "@hooks/use-data-table";
+
+const PAGE_SIZE = 20;
+
+export const CollectionListDataTable = () => {
+ const { t } = useTranslation();
+ const { searchParams, raw } = useCollectionTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+ const { collections, count, isError, error, isLoading } = useCollections(
+ {
+ ...searchParams,
+ fields: "*products",
+ },
+ {
+ placeholderData: keepPreviousData,
+ },
+ );
+
+ const filters = useCollectionTableFilters();
+ const columns = useColumns();
+
+ const { table } = useDataTable({
+ data: collections ?? [],
+ columns,
+ count,
+ enablePagination: true,
+ getRowId: (row, index) => row.id ?? `${index}`,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ columns={columns}
+ pageSize={PAGE_SIZE}
+ count={count}
+ filters={filters}
+ orderBy={[
+ { key: "title", label: t("fields.title") },
+ { key: "handle", label: t("fields.handle") },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ search
+ navigateTo={(row) => `/collections/${row.original.id}`}
+ queryObject={raw}
+ isLoading={isLoading}
+ />
+ );
+};
+
+const useColumns = () => {
+ const base = useCollectionTableColumns();
+
+ return useMemo(() => [...base], [base]);
+};
diff --git a/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-header.tsx b/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-header.tsx
new file mode 100644
index 000000000..979c00109
--- /dev/null
+++ b/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-header.tsx
@@ -0,0 +1,44 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Heading, Text } from "@medusajs/ui";
+
+export const CollectionListTitle = () => {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Heading>{t("collections.domain")}</Heading>
+ <Text className="text-ui-fg-subtle" size="small">
+ {t("collections.subtitle")}
+ </Text>
+ </div>
+ );
+};
+
+export const CollectionListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">{children}</div>
+ );
+};
+
+export const CollectionListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CollectionListTitle />
+ <CollectionListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-table.tsx b/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-table.tsx
index 94465380a..a86cd696b 100644
--- a/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-table.tsx
+++ b/packages/vendor/src/pages/collections/_components/collection-list-table/collection-list-table.tsx
@@ -1,87 +1,22 @@
-import { Container, Heading, Text } from "@medusajs/ui";
-import { useTranslation } from "react-i18next";
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
+import { Outlet } from "react-router-dom";
-import { keepPreviousData } from "@tanstack/react-query";
-import { useMemo } from "react";
-import { _DataTable } from "@components/table/data-table";
-import { useCollections } from "@hooks/api/collections";
-import { useCollectionTableColumns } from "@hooks/table/columns/use-collection-table-columns";
-import { useCollectionTableFilters } from "@hooks/table/filters";
-import { useCollectionTableQuery } from "@hooks/table/query";
-import { useDataTable } from "@hooks/use-data-table";
-
-const PAGE_SIZE = 20;
-
-export const CollectionListTable = () => {
- const { t } = useTranslation();
- const { searchParams, raw } = useCollectionTableQuery({
- pageSize: PAGE_SIZE,
- });
- const { collections, count, isError, error, isLoading } = useCollections(
- {
- ...searchParams,
- fields: "*products",
- },
- {
- placeholderData: keepPreviousData,
- },
- );
-
- const filters = useCollectionTableFilters();
- const columns = useColumns();
-
- const { table } = useDataTable({
- data: collections ?? [],
- columns,
- count,
- enablePagination: true,
- getRowId: (row, index) => row.id ?? `${index}`,
- pageSize: PAGE_SIZE,
- });
-
- if (isError) {
- throw error;
- }
+import { CollectionListHeader } from "./collection-list-header";
+import { CollectionListDataTable } from "./collection-list-data-table";
+export const CollectionListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("collections.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- {t("collections.subtitle")}
- </Text>
- </div>
- </div>
- <_DataTable
- table={table}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- filters={filters}
- orderBy={[
- { key: "title", label: t("fields.title") },
- { key: "handle", label: t("fields.handle") },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- search
- navigateTo={(row) => `/collections/${row.original.id}`}
- queryObject={raw}
- isLoading={isLoading}
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CollectionListHeader />
+ <CollectionListDataTable />
+ </>
+ )}
+ <Outlet />
</Container>
);
};
-
-const useColumns = () => {
- const base = useCollectionTableColumns();
-
- return useMemo(() => [...base], [base]);
-};
diff --git a/packages/vendor/src/pages/collections/_components/collection-list-table/index.ts b/packages/vendor/src/pages/collections/_components/collection-list-table/index.ts
index cd5c7323f..1ca69a8e9 100644
--- a/packages/vendor/src/pages/collections/_components/collection-list-table/index.ts
+++ b/packages/vendor/src/pages/collections/_components/collection-list-table/index.ts
@@ -1 +1,3 @@
export * from "./collection-list-table"
+export * from "./collection-list-header"
+export * from "./collection-list-data-table"
diff --git a/packages/vendor/src/pages/collections/collection-list-page.tsx b/packages/vendor/src/pages/collections/collection-list-page.tsx
new file mode 100644
index 000000000..3c130da9e
--- /dev/null
+++ b/packages/vendor/src/pages/collections/collection-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ CollectionListTable,
+ CollectionListDataTable,
+ CollectionListHeader,
+ CollectionListActions,
+ CollectionListTitle,
+} from "./_components/collection-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage>
+ {Children.count(children) > 0 ? children : <CollectionListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const CollectionListPage = Object.assign(Root, {
+ Table: CollectionListTable,
+ Header: CollectionListHeader,
+ HeaderTitle: CollectionListTitle,
+ HeaderActions: CollectionListActions,
+ DataTable: CollectionListDataTable,
+});
diff --git a/packages/vendor/src/pages/collections/index.ts b/packages/vendor/src/pages/collections/index.ts
new file mode 100644
index 000000000..e76611098
--- /dev/null
+++ b/packages/vendor/src/pages/collections/index.ts
@@ -0,0 +1 @@
+export * from './collection-list-page'
diff --git a/packages/vendor/src/pages/collections/index.tsx b/packages/vendor/src/pages/collections/index.tsx
deleted file mode 100644
index d5cb08504..000000000
--- a/packages/vendor/src/pages/collections/index.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { SingleColumnPage } from "@components/layout/pages";
-import { CollectionListTable } from "./_components/collection-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage>
- <CollectionListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-customer-section/customer-group-customer-section.tsx b/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-customer-section/customer-group-customer-section.tsx
deleted file mode 100644
index 4171ecbc7..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-customer-section/customer-group-customer-section.tsx
+++ /dev/null
@@ -1,241 +0,0 @@
-import { Trash } from "@medusajs/icons"
-import { HttpTypes } from "@medusajs/types"
-import { Button, Checkbox, Container, Heading, usePrompt } from "@medusajs/ui"
-import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
-import { useMemo, useState } from "react"
-import { useTranslation } from "react-i18next"
-import { Link } from "react-router-dom"
-
-import { ActionMenu } from "@components/common/action-menu"
-import { _DataTable } from "@components/table/data-table"
-import { useRemoveCustomersFromGroup } from "@hooks/api/customer-groups"
-import { useCustomerTableColumns } from "@hooks/table/columns/use-customer-table-columns"
-import { useCustomerTableFilters } from "@hooks/table/filters/use-customer-table-filters"
-import { useCustomerTableQuery } from "@hooks/table/query/use-customer-table-query"
-import { useDataTable } from "@hooks/use-data-table"
-
-type CustomerGroupCustomerSectionProps = {
- group: HttpTypes.AdminCustomerGroup
-}
-
-const PAGE_SIZE = 10
-
-export const CustomerGroupCustomerSection = ({
- group,
-}: CustomerGroupCustomerSectionProps) => {
- const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
- const { t } = useTranslation()
- const prompt = usePrompt()
-
- const { raw } = useCustomerTableQuery({
- pageSize: PAGE_SIZE,
- })
-
- const customers = group.customers
- const count = customers.length
-
- const columns = useColumns()
- const filters = useCustomerTableFilters(["groups"])
-
- const { table } = useDataTable({
- data: customers ?? [],
- columns,
- count,
- getRowId: (row) => row.id,
- enablePagination: true,
- enableRowSelection: true,
- pageSize: PAGE_SIZE,
- rowSelection: {
- state: rowSelection,
- updater: setRowSelection,
- },
- meta: {
- customerGroupId: group.id,
- },
- })
-
- const { mutateAsync } = useRemoveCustomersFromGroup(group.id)
-
- const handleRemove = async () => {
- const keys = Object.keys(rowSelection)
-
- const res = await prompt({
- title: t("customerGroups.customers.remove.title", {
- count: keys.length,
- }),
- description: t("customerGroups.customers.remove.description", {
- count: keys.length,
- }),
- confirmText: t("actions.continue"),
- cancelText: t("actions.cancel"),
- })
-
- if (!res) {
- return
- }
-
- await mutateAsync(keys, {
- onSuccess: () => {
- setRowSelection({})
- },
- })
- }
-
- return (
- <Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading level="h2">{t("customers.domain")}</Heading>
- <Link to={`/customer-groups/${group.id}/add-customers`}>
- <Button variant="secondary" size="small">
- {t("general.add")}
- </Button>
- </Link>
- </div>
- <_DataTable
- table={table}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- navigateTo={(row) => `/customers/${row.id}`}
- filters={filters}
- search
- pagination
- orderBy={[
- { key: "email", label: t("fields.email") },
- {
- key: "first_name",
- label: t("fields.firstName"),
- },
- { key: "last_name", label: t("fields.lastName") },
- {
- key: "has_account",
- label: t("customers.hasAccount"),
- },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- queryObject={raw}
- commands={[
- {
- action: handleRemove,
- label: t("actions.remove"),
- shortcut: "r",
- },
- ]}
- noRecords={{
- message: t("customerGroups.customers.list.noRecordsMessage"),
- }}
- />
- </Container>
- )
-}
-
-const CustomerActions = ({
- customer,
- customerGroupId,
-}: {
- customer: HttpTypes.AdminCustomer
- customerGroupId: string
-}) => {
- const { t } = useTranslation()
- const { mutateAsync } = useRemoveCustomersFromGroup(customerGroupId)
-
- const prompt = usePrompt()
-
- const handleRemove = async () => {
- const res = await prompt({
- title: t("customerGroups.customers.remove.title", {
- count: 1,
- }),
- description: t("customerGroups.customers.remove.description", {
- count: 1,
- }),
- confirmText: t("actions.continue"),
- cancelText: t("actions.cancel"),
- })
-
- if (!res) {
- return
- }
-
- await mutateAsync([customer.id])
- }
-
- return (
- <ActionMenu
- groups={[
- {
- actions: [
- {
- icon: <Trash />,
- label: t("actions.remove"),
- onClick: handleRemove,
- },
- ],
- },
- ]}
- />
- )
-}
-
-const columnHelper = createColumnHelper<HttpTypes.AdminCustomer>()
-
-const useColumns = () => {
- const columns = useCustomerTableColumns()
-
- return useMemo(
- () => [
- columnHelper.display({
- id: "select",
- header: ({ table }) => {
- return (
- <Checkbox
- checked={
- table.getIsSomePageRowsSelected()
- ? "indeterminate"
- : table.getIsAllPageRowsSelected()
- }
- onCheckedChange={(value) =>
- table.toggleAllPageRowsSelected(!!value)
- }
- />
- )
- },
- cell: ({ row }) => {
- return (
- <Checkbox
- checked={row.getIsSelected()}
- onCheckedChange={(value) => row.toggleSelected(!!value)}
- onClick={(e) => {
- e.stopPropagation()
- }}
- />
- )
- },
- }),
- ...columns,
- columnHelper.display({
- id: "actions",
- cell: ({ row, table }) => {
- const { customerGroupId } = table.options.meta as {
- customerGroupId: string
- }
-
- return (
- <CustomerActions
- customer={row.original}
- customerGroupId={customerGroupId}
- />
- )
- },
- }),
- ],
- [columns]
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-customer-section/index.ts b/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-customer-section/index.ts
deleted file mode 100644
index 3098ff7ac..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-customer-section/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./customer-group-customer-section"
diff --git a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-general-section/customer-group-general-section.tsx b/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-general-section/customer-group-general-section.tsx
deleted file mode 100644
index de4b901ef..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-general-section/customer-group-general-section.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { PencilSquare, Trash } from "@medusajs/icons"
-import { HttpTypes } from "@medusajs/types"
-import { Container, Heading, Text, toast, usePrompt } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-import { useNavigate } from "react-router-dom"
-
-import { ActionMenu } from "@components/common/action-menu"
-import { useDeleteCustomerGroup } from "@hooks/api/customer-groups"
-
-type CustomerGroupGeneralSectionProps = {
- group: HttpTypes.AdminCustomerGroup
-}
-
-export const CustomerGroupGeneralSection = ({
- group,
-}: CustomerGroupGeneralSectionProps) => {
- const { t } = useTranslation()
- const prompt = usePrompt()
- const navigate = useNavigate()
-
- const { mutateAsync } = useDeleteCustomerGroup(group.id)
-
- const handleDelete = async () => {
- const res = await prompt({
- title: t("customerGroups.delete.title"),
- description: t("customerGroups.delete.description", {
- name: group.name,
- }),
- confirmText: t("actions.delete"),
- cancelText: t("actions.cancel"),
- })
-
- if (!res) {
- return
- }
-
- await mutateAsync(undefined, {
- onSuccess: () => {
- toast.success(
- t("customerGroups.delete.successToast", {
- name: group.name,
- })
- )
-
- navigate("/customer-groups", { replace: true })
- },
- 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>{group.name}</Heading>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- icon: <PencilSquare />,
- label: t("actions.edit"),
- to: `/customer-groups/${group.id}/edit`,
- },
- ],
- },
- {
- actions: [
- {
- icon: <Trash />,
- label: t("actions.delete"),
- onClick: handleDelete,
- },
- ],
- },
- ]}
- />
- </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("customers.domain")}
- </Text>
- <Text size="small" leading="compact">
- {group.customers?.length || "-"}
- </Text>
- </div>
- </Container>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-general-section/index.ts b/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-general-section/index.ts
deleted file mode 100644
index dfe709902..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/_components/customer-group-general-section/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./customer-group-general-section"
diff --git a/packages/vendor/src/pages/customer-groups/[id]/_components/index.ts b/packages/vendor/src/pages/customer-groups/[id]/_components/index.ts
deleted file mode 100644
index 8a4283982..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/_components/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from "./customer-group-customer-section"
-export * from "./customer-group-general-section"
diff --git a/packages/vendor/src/pages/customer-groups/[id]/add-customers/add-customers-form/add-customers-form.tsx b/packages/vendor/src/pages/customer-groups/[id]/add-customers/add-customers-form/add-customers-form.tsx
deleted file mode 100644
index 97d64fdc8..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/add-customers/add-customers-form/add-customers-form.tsx
+++ /dev/null
@@ -1,259 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { Button, Checkbox, Hint, Tooltip, toast } from "@medusajs/ui"
-import {
- OnChangeFn,
- RowSelectionState,
- createColumnHelper,
-} from "@tanstack/react-table"
-import { useEffect, useMemo, useState } from "react"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import * as zod from "zod"
-
-import { HttpTypes } from "@medusajs/types"
-import {
- RouteFocusModal,
- useRouteModal,
-} from "@components/modals"
-import { _DataTable } from "@components/table/data-table"
-import { KeyboundForm } from "@components/utilities/keybound-form"
-import { useAddCustomersToGroup } from "@hooks/api/customer-groups"
-import { useCustomers } from "@hooks/api/customers"
-import { useCustomerTableColumns } from "@hooks/table/columns/use-customer-table-columns"
-import { useCustomerTableFilters } from "@hooks/table/filters/use-customer-table-filters"
-import { useCustomerTableQuery } from "@hooks/table/query/use-customer-table-query"
-import { useDataTable } from "@hooks/use-data-table"
-
-type AddCustomersFormProps = {
- customerGroupId: string
-}
-
-export const AddCustomersSchema = zod.object({
- customer_ids: zod.array(zod.string()).min(1),
-})
-
-const PAGE_SIZE = 10
-
-export const AddCustomersForm = ({
- customerGroupId,
-}: AddCustomersFormProps) => {
- const { t } = useTranslation()
- const { handleSuccess } = useRouteModal()
-
- const form = useForm<zod.infer<typeof AddCustomersSchema>>({
- defaultValues: {
- customer_ids: [],
- },
- resolver: zodResolver(AddCustomersSchema),
- })
-
- const { setValue } = form
-
- const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
-
- useEffect(() => {
- setValue(
- "customer_ids",
- Object.keys(rowSelection).filter((k) => rowSelection[k]),
- {
- shouldDirty: true,
- shouldTouch: true,
- }
- )
- }, [rowSelection, setValue])
-
- const { searchParams, raw } = useCustomerTableQuery({
- pageSize: PAGE_SIZE,
- })
- const filters = useCustomerTableFilters()
-
- const { customers, count, isLoading, isError, error } = useCustomers({
- ...searchParams,
- })
-
- const updater: OnChangeFn<RowSelectionState> = (fn) => {
- const state = typeof fn === "function" ? fn(rowSelection) : fn
-
- const ids = Object.keys(state)
-
- setValue("customer_ids", ids, {
- shouldDirty: true,
- shouldTouch: true,
- })
-
- setRowSelection(state)
- }
-
- const columns = useColumns()
-
- const { table } = useDataTable({
- data: customers ?? [],
- columns,
- count,
- enablePagination: true,
- enableRowSelection: (row) => {
- return !row.original.groups?.map((gc) => gc.id).includes(customerGroupId)
- },
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- rowSelection: {
- state: rowSelection,
- updater,
- },
- })
-
- const { mutateAsync, isPending } = useAddCustomersToGroup(customerGroupId)
-
- const handleSubmit = form.handleSubmit(async (data) => {
- await mutateAsync(data.customer_ids, {
- onSuccess: () => {
- toast.success(
- t("customerGroups.customers.add.successToast", {
- count: data.customer_ids.length,
- })
- )
-
- handleSuccess(`/customer-groups/${customerGroupId}`)
- },
- onError: (error) => {
- toast.error(error.message)
- },
- })
- })
-
- if (isError) {
- throw error
- }
-
- return (
- <RouteFocusModal.Form form={form}>
- <KeyboundForm
- className="flex h-full flex-col overflow-hidden"
- onSubmit={handleSubmit}
- >
- <RouteFocusModal.Header>
- <div className="flex items-center justify-end gap-x-2">
- {form.formState.errors.customer_ids && (
- <Hint variant="error">
- {form.formState.errors.customer_ids.message}
- </Hint>
- )}
- <RouteFocusModal.Close asChild>
- <Button variant="secondary" size="small">
- {t("actions.cancel")}
- </Button>
- </RouteFocusModal.Close>
- <Button
- type="submit"
- variant="primary"
- size="small"
- isLoading={isPending}
- >
- {t("actions.save")}
- </Button>
- </div>
- </RouteFocusModal.Header>
- <RouteFocusModal.Body className="size-full overflow-hidden">
- <_DataTable
- table={table}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- filters={filters}
- orderBy={[
- { key: "email", label: t("fields.email") },
- {
- key: "first_name",
- label: t("fields.firstName"),
- },
- {
- key: "last_name",
- label: t("fields.lastName"),
- },
- {
- key: "has_account",
- label: t("customers.hasAccount"),
- },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- isLoading={isLoading}
- layout="fill"
- search="autofocus"
- queryObject={raw}
- noRecords={{
- message: t("customerGroups.customers.add.list.noRecordsMessage"),
- }}
- />
- </RouteFocusModal.Body>
- </KeyboundForm>
- </RouteFocusModal.Form>
- )
-}
-
-const columnHelper = createColumnHelper<HttpTypes.AdminCustomer>()
-
-const useColumns = () => {
- const { t } = useTranslation()
- const base = useCustomerTableColumns()
-
- const columns = useMemo(
- () => [
- columnHelper.display({
- id: "select",
- header: ({ table }) => {
- return (
- <Checkbox
- checked={
- table.getIsSomePageRowsSelected()
- ? "indeterminate"
- : table.getIsAllPageRowsSelected()
- }
- onCheckedChange={(value) =>
- table.toggleAllPageRowsSelected(!!value)
- }
- />
- )
- },
- cell: ({ row }) => {
- const isPreSelected = !row.getCanSelect()
- const isSelected = row.getIsSelected() || isPreSelected
-
- const Component = (
- <Checkbox
- checked={isSelected}
- disabled={isPreSelected}
- onCheckedChange={(value) => row.toggleSelected(!!value)}
- onClick={(e) => {
- e.stopPropagation()
- }}
- />
- )
-
- if (isPreSelected) {
- return (
- <Tooltip
- content={t("customerGroups.customers.alreadyAddedTooltip")}
- side="right"
- >
- {Component}
- </Tooltip>
- )
- }
-
- return Component
- },
- }),
- ...base,
- ],
- [t, base]
- )
-
- return columns
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/add-customers/add-customers-form/index.ts b/packages/vendor/src/pages/customer-groups/[id]/add-customers/add-customers-form/index.ts
deleted file mode 100644
index 512d1edf6..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/add-customers/add-customers-form/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./add-customers-form"
diff --git a/packages/vendor/src/pages/customer-groups/[id]/add-customers/index.tsx b/packages/vendor/src/pages/customer-groups/[id]/add-customers/index.tsx
deleted file mode 100644
index c4f4e1f70..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/add-customers/index.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-// Route: /customer-groups/:id/add-customers
-import { useParams } from "react-router-dom"
-import { RouteFocusModal } from "@components/modals"
-import { AddCustomersForm } from "./add-customers-form"
-
-export const Component = () => {
- const { id } = useParams()
- return (
- <RouteFocusModal>
- <AddCustomersForm customerGroupId={id!} />
- </RouteFocusModal>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/constants.ts b/packages/vendor/src/pages/customer-groups/[id]/constants.ts
deleted file mode 100644
index c87c7a184..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/constants.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const CUSTOMER_GROUP_DETAIL_FIELDS = "*customers"
diff --git a/packages/vendor/src/pages/customer-groups/[id]/edit/edit-customer-group-form/edit-customer-group-form.tsx b/packages/vendor/src/pages/customer-groups/[id]/edit/edit-customer-group-form/edit-customer-group-form.tsx
deleted file mode 100644
index 91b3f197d..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/edit/edit-customer-group-form/edit-customer-group-form.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { HttpTypes } from "@medusajs/types"
-import { Button, Input, toast } from "@medusajs/ui"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import * as z from "zod"
-import { Form } from "@components/common/form"
-import { RouteDrawer, useRouteModal } from "@components/modals"
-import { KeyboundForm } from "@components/utilities/keybound-form"
-import { useUpdateCustomerGroup } from "@hooks/api/customer-groups"
-
-type EditCustomerGroupFormProps = {
- group: HttpTypes.AdminCustomerGroup
-}
-
-export const EditCustomerGroupSchema = z.object({
- name: z.string().min(1),
-})
-
-export const EditCustomerGroupForm = ({
- group,
-}: EditCustomerGroupFormProps) => {
- const { t } = useTranslation()
- const { handleSuccess } = useRouteModal()
-
- const form = useForm<z.infer<typeof EditCustomerGroupSchema>>({
- defaultValues: {
- name: group.name || "",
- },
- resolver: zodResolver(EditCustomerGroupSchema),
- })
-
- const { mutateAsync, isPending } = useUpdateCustomerGroup(group.id)
-
- const handleSubmit = form.handleSubmit(async (data) => {
- await mutateAsync(data, {
- onSuccess: ({ customer_group }) => {
- toast.success(
- t("customerGroups.edit.successToast", {
- name: customer_group.name,
- })
- )
-
- handleSuccess()
- },
- onError: (error) => {
- toast.error(error.message)
- },
- })
- })
-
- return (
- <RouteDrawer.Form form={form}>
- <KeyboundForm
- onSubmit={handleSubmit}
- className="flex flex-1 flex-col overflow-hidden"
- >
- <RouteDrawer.Body className="flex max-w-full flex-1 flex-col gap-y-8 overflow-y-auto">
- <Form.Field
- control={form.control}
- name="name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label>{t("fields.name")}</Form.Label>
- <Form.Control>
- <Input {...field} size="small" />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- </RouteDrawer.Body>
- <RouteDrawer.Footer>
- <div className="flex items-center justify-end gap-x-2">
- <RouteDrawer.Close asChild>
- <Button size="small" variant="secondary">
- {t("actions.cancel")}
- </Button>
- </RouteDrawer.Close>
- <Button size="small" type="submit" isLoading={isPending}>
- {t("actions.save")}
- </Button>
- </div>
- </RouteDrawer.Footer>
- </KeyboundForm>
- </RouteDrawer.Form>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/edit/edit-customer-group-form/index.ts b/packages/vendor/src/pages/customer-groups/[id]/edit/edit-customer-group-form/index.ts
deleted file mode 100644
index 3062389f7..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/edit/edit-customer-group-form/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./edit-customer-group-form"
diff --git a/packages/vendor/src/pages/customer-groups/[id]/edit/index.tsx b/packages/vendor/src/pages/customer-groups/[id]/edit/index.tsx
deleted file mode 100644
index 725d2cd91..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/edit/index.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-// Route: /customer-groups/:id/edit
-import { Heading } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-import { useParams } from "react-router-dom"
-import { RouteDrawer } from "@components/modals"
-import { useCustomerGroup } from "@hooks/api/customer-groups"
-import { EditCustomerGroupForm } from "./edit-customer-group-form"
-
-export const Component = () => {
- const { id } = useParams()
- const { customer_group, isLoading, isError, error } = useCustomerGroup(id!)
- const { t } = useTranslation()
-
- if (isError) throw error
-
- return (
- <RouteDrawer>
- <RouteDrawer.Header>
- <Heading>{t("customerGroups.edit.header")}</Heading>
- </RouteDrawer.Header>
- {!isLoading && customer_group && <EditCustomerGroupForm group={customer_group} />}
- </RouteDrawer>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/index.tsx b/packages/vendor/src/pages/customer-groups/[id]/index.tsx
deleted file mode 100644
index ed29218d6..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/index.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-// Route: /customer-groups/:id
-import { HttpTypes } from "@medusajs/types"
-import { UIMatch, useParams } from "react-router-dom"
-
-import { SingleColumnPageSkeleton } from "@components/common/skeleton"
-import { SingleColumnPage } from "@components/layout/pages"
-import { useDashboardExtension } from "@/extensions"
-import { useCustomerGroup } from "@hooks/api/customer-groups"
-
-import { CustomerGroupCustomerSection } from "./_components/customer-group-customer-section"
-import { CustomerGroupGeneralSection } from "./_components/customer-group-general-section"
-import { CUSTOMER_GROUP_DETAIL_FIELDS } from "./constants"
-
-// Breadcrumb
-type CustomerGroupDetailBreadcrumbProps = UIMatch<HttpTypes.AdminCustomerGroupResponse>
-
-export const Breadcrumb = (props: CustomerGroupDetailBreadcrumbProps) => {
- const { id } = props.params || {}
- const { customer_group } = useCustomerGroup(id!, { fields: CUSTOMER_GROUP_DETAIL_FIELDS }, { enabled: Boolean(id) })
-
- if (!customer_group) return null
- return <span>{customer_group.name}</span>
-}
-
-// Main component
-export const Component = () => {
- const { id } = useParams()
- const { customer_group, isLoading } = useCustomerGroup(id!, { fields: CUSTOMER_GROUP_DETAIL_FIELDS })
- const { getWidgets } = useDashboardExtension()
-
- if (isLoading || !customer_group) return <SingleColumnPageSkeleton sections={2} />
-
- return (
- <SingleColumnPage
- widgets={{
- before: getWidgets("customer_group.details.before"),
- after: getWidgets("customer_group.details.after"),
- }}
- data={customer_group}
- >
- <CustomerGroupGeneralSection group={customer_group} />
- <CustomerGroupCustomerSection group={customer_group} />
- </SingleColumnPage>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/[id]/metadata/index.tsx b/packages/vendor/src/pages/customer-groups/[id]/metadata/index.tsx
deleted file mode 100644
index 5d6a6c4b9..000000000
--- a/packages/vendor/src/pages/customer-groups/[id]/metadata/index.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-// Route: /customer-groups/:id/metadata
-import { useParams } from "react-router-dom"
-import { MetadataForm } from "@components/forms/metadata-form"
-import { useCustomerGroup, useUpdateCustomerGroup } from "@hooks/api/customer-groups"
-
-export const Component = () => {
- const { id } = useParams()
- const { customer_group, isPending, isError, error } = useCustomerGroup(id!)
- const { mutateAsync, isPending: isMutating } = useUpdateCustomerGroup(id!)
-
- if (isError) throw error
-
- return (
- <MetadataForm
- metadata={customer_group?.metadata}
- hook={mutateAsync}
- isPending={isPending}
- isMutating={isMutating}
- />
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/_components/customer-group-list-table/customer-group-list-table.tsx b/packages/vendor/src/pages/customer-groups/_components/customer-group-list-table/customer-group-list-table.tsx
deleted file mode 100644
index 6d4963eb7..000000000
--- a/packages/vendor/src/pages/customer-groups/_components/customer-group-list-table/customer-group-list-table.tsx
+++ /dev/null
@@ -1,217 +0,0 @@
-import { useCallback, useMemo } from 'react';
-
-import { PencilSquare, Trash } from '@medusajs/icons';
-import {
- Button,
- Container,
- createDataTableColumnHelper,
- DataTableRow,
- Heading,
- Text,
- toast,
- usePrompt
-} from '@medusajs/ui';
-import { useTranslation } from 'react-i18next';
-import { Link, useNavigate } from 'react-router-dom';
-
-import { ActionMenu } from "@components/common/action-menu"
-import { SingleColumnPage } from "@components/layout/pages"
-import { _DataTable } from "@components/table/data-table"
-import { DataTableQuery } from "@components/table/data-table/data-table-query"
-import { TextCell } from "@components/table/table-cells/common/text-cell"
-import { useDashboardExtension } from "@/extensions"
-import { useCustomerGroups, useDeleteCustomerGroupLazy } from "@hooks/api"
-import { useDataTable } from "@hooks/use-data-table"
-import { useDate } from "@hooks/use-date"
-import { CustomerGroupData } from '@pages/orders/common/customerGroupFiltering';
-import { customerGroupFilter } from '../../common/customer-group-filter';
-import { useCustomerGroupsTableQuery } from '../../common/use-customer-groups-table-query';
-
-const PAGE_SIZE = 10;
-
-export const CustomerGroupListTable = () => {
- const { t } = useTranslation();
- const { getWidgets } = useDashboardExtension();
-
- const columns = useColumns();
-
- const { searchParams } = useCustomerGroupsTableQuery({
- pageSize: PAGE_SIZE
- });
-
- const { customer_groups, isPending } = useCustomerGroups();
-
- const filteredList = customerGroupFilter(
- customer_groups ?? [],
- searchParams.order,
- searchParams.q ?? ''
- );
-
- const count = filteredList?.length || 0;
-
- const { table } = useDataTable({
- data: filteredList ?? [],
- columns,
- count: count,
- enablePagination: true,
- getRowId: row => row.customer_group_id,
- pageSize: PAGE_SIZE
- });
-
- return (
- <SingleColumnPage
- widgets={{
- before: getWidgets('customer_group.list.before'),
- after: getWidgets('customer_group.list.after')
- }}
- >
- <Container className="overflow-hidden p-0">
- <div className="flex flex-col items-start justify-between gap-2 p-6 md:flex-row md:items-center">
- <div className="items-center justify-between gap-2">
- <Heading>{t('customerGroups.domain')}</Heading>
- <Text
- size="small"
- className="text-ui-fg-subtle"
- >
- Organize customers into groups. Groups can have different promotions and prices.
- </Text>
- </div>
- <div className="flex items-center">
- <div className="-mx-4">
- <DataTableQuery
- search
- orderBy={[
- { key: 'name', label: t('fields.name') },
- {
- key: 'customers',
- label: t('customers.domain')
- }
- ]}
- />
- </div>
-
- <Link to="/customer-groups/create">
- <Button
- size="small"
- variant="secondary"
- >
- {t('actions.create')}
- </Button>
- </Link>
- </div>
- </div>
-
- <div className="border-t">
- <_DataTable
- table={table}
- columns={columns}
- count={count}
- navigateTo={(row: DataTableRow<CustomerGroupData>) =>
- `/customer-groups/${row.original.customer_group_id}`
- }
- noRecords={{
- title: t('customerGroups.list.empty.heading'),
- message: t('customerGroups.list.empty.description')
- }}
- pageSize={PAGE_SIZE}
- isLoading={isPending}
- />
- </div>
- </Container>
- </SingleColumnPage>
- );
-};
-
-const columnHelper = createDataTableColumnHelper<CustomerGroupData>();
-
-const useColumns = () => {
- const { t } = useTranslation();
- const { getFullDate } = useDate();
- const navigate = useNavigate();
- const prompt = usePrompt();
-
- const { mutateAsync: deleteCustomerGroup } = useDeleteCustomerGroupLazy();
-
- const handleDeleteCustomerGroup = useCallback(
- async ({ id, name }: { id: string; name: string }) => {
- const res = await prompt({
- title: t('customerGroups.delete.title'),
- description: t('customerGroups.delete.description', {
- name
- }),
- verificationText: name,
- verificationInstruction: t('general.typeToConfirm'),
- confirmText: t('actions.delete'),
- cancelText: t('actions.cancel')
- });
-
- if (!res) {
- return;
- }
-
- await deleteCustomerGroup(
- { id },
- {
- onSuccess: () => {
- toast.success(
- t('customerGroups.delete.successToast', {
- name
- })
- );
- },
- onError: e => {
- toast.error(e.message);
- }
- }
- );
- },
- [t, prompt, deleteCustomerGroup]
- );
-
- return useMemo(() => {
- return [
- columnHelper.accessor('customer_group.name', {
- header: t('fields.name'),
- cell: ({ row }) => {
- return <TextCell text={row?.original?.customer_group?.name || '-'} />;
- }
- }),
- columnHelper.accessor('customer_group.customers', {
- header: t('customers.domain'),
- cell: ({ row }) => {
- return <span>{row?.original?.customer_group?.customers?.length ?? 0}</span>;
- }
- }),
- columnHelper.display({
- id: 'actions',
- cell: ({ row }) => {
- return (
- <ActionMenu
- groups={[
- {
- actions: [
- {
- icon: <PencilSquare />,
- label: t('actions.edit'),
- to: `/customer-groups/${row.original.customer_group_id}/edit`
- },
- {
- icon: <Trash />,
- label: t('actions.delete'),
- onClick: () => {
- handleDeleteCustomerGroup({
- id: row.original.customer_group_id,
- name: row.original.customer_group.name ?? ''
- });
- }
- }
- ]
- }
- ]}
- />
- );
- }
- })
- ];
- }, [t, navigate, getFullDate, handleDeleteCustomerGroup]);
-};
diff --git a/packages/vendor/src/pages/customer-groups/_components/customer-group-list-table/index.ts b/packages/vendor/src/pages/customer-groups/_components/customer-group-list-table/index.ts
deleted file mode 100644
index ead4d7474..000000000
--- a/packages/vendor/src/pages/customer-groups/_components/customer-group-list-table/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./customer-group-list-table"
diff --git a/packages/vendor/src/pages/customer-groups/_components/index.ts b/packages/vendor/src/pages/customer-groups/_components/index.ts
deleted file mode 100644
index ead4d7474..000000000
--- a/packages/vendor/src/pages/customer-groups/_components/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./customer-group-list-table"
diff --git a/packages/vendor/src/pages/customer-groups/common/customer-group-filter.ts b/packages/vendor/src/pages/customer-groups/common/customer-group-filter.ts
deleted file mode 100644
index 46f612564..000000000
--- a/packages/vendor/src/pages/customer-groups/common/customer-group-filter.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { CustomerGroupData } from "@pages/orders/common/customerGroupFiltering"
-
-export const customerGroupFilter = (
- groups: CustomerGroupData[],
- sortOrder?: string,
- searchQuery?: string
-): CustomerGroupData[] => {
- let filtered = groups
-
- // Filter by search query
- if (searchQuery) {
- filtered = filtered.filter((group) => {
- const name = group.customer_group?.name?.toLowerCase() || ""
- return name.includes(searchQuery.toLowerCase())
- })
- }
-
- // Sort by order
- if (sortOrder) {
- const isDescending = sortOrder.startsWith("-")
- const field = isDescending ? sortOrder.slice(1) : sortOrder
- const direction = isDescending ? -1 : 1
-
- filtered = [...filtered].sort((a, b) => {
- const aValue = a.customer_group?.[field as keyof typeof a.customer_group]
- const bValue = b.customer_group?.[field as keyof typeof b.customer_group]
-
- if (typeof aValue === "string" && typeof bValue === "string") {
- return direction * aValue.localeCompare(bValue)
- }
-
- return 0
- })
- }
-
- return filtered
-}
diff --git a/packages/vendor/src/pages/customer-groups/common/use-customer-groups-table-query.ts b/packages/vendor/src/pages/customer-groups/common/use-customer-groups-table-query.ts
deleted file mode 100644
index 50d1940f7..000000000
--- a/packages/vendor/src/pages/customer-groups/common/use-customer-groups-table-query.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { useQueryParams } from "@hooks/use-query-params"
-
-export const useCustomerGroupsTableQuery = ({
- pageSize = 10,
-}: {
- pageSize?: number
-}) => {
- const queryParams = useQueryParams(["q", "order", "offset"])
-
- const searchParams = {
- q: queryParams.q,
- order: queryParams.order,
- offset: queryParams.offset ? Number(queryParams.offset) : 0,
- limit: pageSize,
- }
-
- return {
- searchParams,
- raw: queryParams,
- }
-}
diff --git a/packages/vendor/src/pages/customer-groups/create/create-customer-group-form/create-customer-group-form.tsx b/packages/vendor/src/pages/customer-groups/create/create-customer-group-form/create-customer-group-form.tsx
deleted file mode 100644
index 49f734073..000000000
--- a/packages/vendor/src/pages/customer-groups/create/create-customer-group-form/create-customer-group-form.tsx
+++ /dev/null
@@ -1,110 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { Button, Heading, Input, Text, toast } from "@medusajs/ui"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import * as zod from "zod"
-
-import { Form } from "@components/common/form"
-import {
- RouteFocusModal,
- useRouteModal,
-} from "@components/modals"
-import { KeyboundForm } from "@components/utilities/keybound-form"
-import { useCreateCustomerGroup } from "@hooks/api/customer-groups"
-
-export const CreateCustomerGroupSchema = zod.object({
- name: zod.string().min(1),
-})
-
-export const CreateCustomerGroupForm = () => {
- const { t } = useTranslation()
- const { handleSuccess } = useRouteModal()
-
- const form = useForm<zod.infer<typeof CreateCustomerGroupSchema>>({
- defaultValues: {
- name: "",
- },
- resolver: zodResolver(CreateCustomerGroupSchema),
- })
-
- const { mutateAsync, isPending } = useCreateCustomerGroup()
-
- const handleSubmit = form.handleSubmit(async (data) => {
- await mutateAsync(
- {
- name: data.name,
- },
- {
- onSuccess: ({ customer_group }) => {
- toast.success(
- t("customerGroups.create.successToast", {
- name: customer_group.name,
- })
- )
-
- handleSuccess(`/customer-groups/${customer_group.id}`)
- },
- onError: (error) => {
- toast.error(error.message)
- },
- }
- )
- })
-
- return (
- <RouteFocusModal.Form form={form}>
- <KeyboundForm
- className="flex h-full flex-col overflow-hidden"
- onSubmit={handleSubmit}
- >
- <RouteFocusModal.Header />
- <RouteFocusModal.Body className="flex flex-col items-center pt-[72px]">
- <div className="flex size-full max-w-[720px] flex-col gap-y-8">
- <div>
- <RouteFocusModal.Title asChild>
- <Heading>{t("customerGroups.create.header")}</Heading>
- </RouteFocusModal.Title>
- <RouteFocusModal.Description asChild>
- <Text size="small" className="text-ui-fg-subtle">
- {t("customerGroups.create.hint")}
- </Text>
- </RouteFocusModal.Description>
- </div>
- <div className="grid grid-cols-2 gap-4">
- <Form.Field
- control={form.control}
- name="name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label>{t("fields.name")}</Form.Label>
- <Form.Control>
- <Input {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- </div>
- </div>
- </RouteFocusModal.Body>
- <RouteFocusModal.Footer>
- <RouteFocusModal.Close asChild>
- <Button variant="secondary" size="small">
- {t("actions.cancel")}
- </Button>
- </RouteFocusModal.Close>
- <Button
- type="submit"
- variant="primary"
- size="small"
- isLoading={isPending}
- >
- {t("actions.create")}
- </Button>
- </RouteFocusModal.Footer>
- </KeyboundForm>
- </RouteFocusModal.Form>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/create/create-customer-group-form/index.ts b/packages/vendor/src/pages/customer-groups/create/create-customer-group-form/index.ts
deleted file mode 100644
index 960232c9c..000000000
--- a/packages/vendor/src/pages/customer-groups/create/create-customer-group-form/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./create-customer-group-form"
diff --git a/packages/vendor/src/pages/customer-groups/create/index.tsx b/packages/vendor/src/pages/customer-groups/create/index.tsx
deleted file mode 100644
index 1c3776138..000000000
--- a/packages/vendor/src/pages/customer-groups/create/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /customer-groups/create
-import { RouteFocusModal } from "@components/modals"
-import { CreateCustomerGroupForm } from "./create-customer-group-form"
-
-export const Component = () => {
- return (
- <RouteFocusModal>
- <CreateCustomerGroupForm />
- </RouteFocusModal>
- )
-}
diff --git a/packages/vendor/src/pages/customer-groups/index.tsx b/packages/vendor/src/pages/customer-groups/index.tsx
deleted file mode 100644
index 6c1acca95..000000000
--- a/packages/vendor/src/pages/customer-groups/index.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-// Route: /customer-groups
-import { SingleColumnPage } from "@components/layout/pages"
-import { useDashboardExtension } from "@/extensions"
-import { CustomerGroupListTable } from "./_components/customer-group-list-table"
-
-export const Component = () => {
- const { getWidgets } = useDashboardExtension()
-
- return (
- <SingleColumnPage
- widgets={{
- after: getWidgets("customer_group.list.after"),
- before: getWidgets("customer_group.list.before"),
- }}
- >
- <CustomerGroupListTable />
- </SingleColumnPage>
- )
-}
diff --git a/packages/vendor/src/pages/customers/[id]/breadcrumb.tsx b/packages/vendor/src/pages/customers/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..ad6eea9d4
--- /dev/null
+++ b/packages/vendor/src/pages/customers/[id]/breadcrumb.tsx
@@ -0,0 +1,21 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { useCustomer } from "@hooks/api/customers";
+
+type CustomerDetailBreadcrumbProps = UIMatch<HttpTypes.AdminCustomerResponse>;
+
+export const Breadcrumb = (props: CustomerDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+ const { customer } = useCustomer(id!, undefined, {
+ initialData: props.data,
+ enabled: Boolean(id),
+ });
+
+ if (!customer) return null;
+
+ const name = [customer.first_name, customer.last_name]
+ .filter(Boolean)
+ .join(" ");
+ return <span>{name || customer.email}</span>;
+};
diff --git a/packages/vendor/src/pages/customers/[id]/customer-detail-page.tsx b/packages/vendor/src/pages/customers/[id]/customer-detail-page.tsx
new file mode 100644
index 000000000..de9b83765
--- /dev/null
+++ b/packages/vendor/src/pages/customers/[id]/customer-detail-page.tsx
@@ -0,0 +1,44 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { SingleColumnPageSkeleton } from "@components/common/skeleton";
+import { SingleColumnPage } from "@components/layout/pages";
+import { useCustomer } from "@hooks/api/customers";
+
+import { CustomerGeneralSection } from "./_components/customer-general-section";
+import { CustomerGroupSection } from "./_components/customer-group-section";
+import { CustomerOrderSection } from "./_components/customer-order-section";
+
+import type { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const { id } = useParams();
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { customer, isLoading, isError, error } = useCustomer(
+ id!,
+ {},
+ { initialData },
+ );
+
+ if (isLoading || !customer) return <SingleColumnPageSkeleton sections={2} />;
+ if (isError) throw error;
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <SingleColumnPage data={customer} hasOutlet>
+ <CustomerGeneralSection customer={customer} />
+ <CustomerOrderSection customer={customer} />
+ </SingleColumnPage>
+ )}
+ </>
+ );
+};
+
+export const CustomerDetailPage = Object.assign(Root, {
+ GeneralSection: CustomerGeneralSection,
+ OrderSection: CustomerOrderSection,
+ GroupSection: CustomerGroupSection,
+});
diff --git a/packages/vendor/src/pages/customers/[id]/index.ts b/packages/vendor/src/pages/customers/[id]/index.ts
new file mode 100644
index 000000000..6143ac25a
--- /dev/null
+++ b/packages/vendor/src/pages/customers/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './customer-detail-page'
diff --git a/packages/vendor/src/pages/customers/[id]/index.tsx b/packages/vendor/src/pages/customers/[id]/index.tsx
deleted file mode 100644
index 3057f6cf7..000000000
--- a/packages/vendor/src/pages/customers/[id]/index.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-// Route: /customers/:id
-import { HttpTypes } from "@medusajs/types";
-import {
- UIMatch,
- useLoaderData,
- useParams,
- LoaderFunctionArgs,
-} from "react-router-dom";
-
-import { SingleColumnPageSkeleton } from "@components/common/skeleton";
-import { SingleColumnPage } from "@components/layout/pages";
-import { useCustomer } from "@hooks/api/customers";
-import { productsQueryKeys } from "@hooks/api/products";
-import { fetchQuery } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-
-import { CustomerGeneralSection } from "./_components/customer-general-section";
-import { CustomerOrderSection } from "./_components/customer-order-section";
-
-// Loader
-const customerDetailQuery = (id: string) => ({
- queryKey: productsQueryKeys.detail(id),
- queryFn: async () =>
- fetchQuery(`/vendor/customers/${id}`, {
- method: "GET",
- query: { fields: "*groups, *groups.customers" },
- }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = customerDetailQuery(id!);
- return queryClient.ensureQueryData(query);
-};
-
-// Breadcrumb
-type CustomerDetailBreadcrumbProps = UIMatch<HttpTypes.AdminCustomerResponse>;
-
-export const Breadcrumb = (props: CustomerDetailBreadcrumbProps) => {
- const { id } = props.params || {};
- const { customer } = useCustomer(id!, undefined, {
- initialData: props.data,
- enabled: Boolean(id),
- });
-
- if (!customer) return null;
-
- const name = [customer.first_name, customer.last_name]
- .filter(Boolean)
- .join(" ");
- return <span>{name || customer.email}</span>;
-};
-
-// Main component
-export const Component = () => {
- const { id } = useParams();
- const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
- const { customer, isLoading, isError, error } = useCustomer(
- id!,
- {},
- { initialData },
- );
-
- if (isLoading || !customer) return <SingleColumnPageSkeleton sections={2} />;
- if (isError) throw error;
-
- return (
- <SingleColumnPage data={customer} hasOutlet>
- <CustomerGeneralSection customer={customer} />
- <CustomerOrderSection customer={customer} />
- {/* TODO: Customer groups - vendor API does not support customer groups yet
- <CustomerGroupSection customer={customer} />
- */}
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/customers/[id]/loader.tsx b/packages/vendor/src/pages/customers/[id]/loader.tsx
new file mode 100644
index 000000000..5afd9b650
--- /dev/null
+++ b/packages/vendor/src/pages/customers/[id]/loader.tsx
@@ -0,0 +1,20 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { productsQueryKeys } from "@hooks/api/products";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+const customerDetailQuery = (id: string) => ({
+ queryKey: productsQueryKeys.detail(id),
+ queryFn: async () =>
+ fetchQuery(`/vendor/customers/${id}`, {
+ method: "GET",
+ query: { fields: "*groups, *groups.customers" },
+ }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = customerDetailQuery(id!);
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-data-table.tsx b/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-data-table.tsx
new file mode 100644
index 000000000..6da1f0d78
--- /dev/null
+++ b/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-data-table.tsx
@@ -0,0 +1,94 @@
+import { keepPreviousData } from "@tanstack/react-query";
+import { useMemo } from "react";
+import { useTranslation } from "react-i18next";
+
+import { _DataTable } from "@components/table/data-table";
+import { useCustomers } from "@hooks/api/customers";
+import { useCustomerTableColumns } from "@hooks/table/columns/use-customer-table-columns";
+import { useCustomerTableFilters } from "@hooks/table/filters/use-customer-table-filters";
+import { useCustomerTableQuery } from "@hooks/table/query/use-customer-table-query";
+import { useDataTable } from "@hooks/use-data-table";
+
+const PAGE_SIZE = 20;
+
+export const CustomerListDataTable = () => {
+ const { t } = useTranslation();
+
+ const { searchParams, raw } = useCustomerTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+
+ const { customers, count, isLoading, isError, error } = useCustomers(
+ {
+ offset: searchParams.offset,
+ limit: searchParams.limit,
+ },
+ {
+ placeholderData: keepPreviousData,
+ },
+ {
+ has_account: searchParams.has_account,
+ order: searchParams.order,
+ q: searchParams.q,
+ },
+ );
+
+ const filters = useCustomerTableFilters();
+ const columns = useColumns();
+
+ const { table } = useDataTable({
+ data: customers ?? [],
+ columns,
+ count,
+ enablePagination: true,
+ getRowId: (row) => row.id,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ columns={columns}
+ pageSize={PAGE_SIZE}
+ count={count}
+ filters={filters}
+ orderBy={[
+ { key: "email", label: t("fields.email") },
+ {
+ key: "first_name",
+ label: t("fields.firstName"),
+ },
+ { key: "last_name", label: t("fields.lastName") },
+ {
+ key: "has_account",
+ label: t("customers.hasAccount"),
+ },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ isLoading={isLoading}
+ navigateTo={(row) => row.original.id}
+ queryObject={raw}
+ search
+ noRecords={{
+ message: t("customers.list.noRecordsMessage"),
+ }}
+ />
+ );
+};
+
+const useColumns = () => {
+ const columns = useCustomerTableColumns();
+
+ return useMemo(() => [...columns], [columns]);
+};
diff --git a/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-header.tsx b/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-header.tsx
new file mode 100644
index 000000000..fe926a293
--- /dev/null
+++ b/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-header.tsx
@@ -0,0 +1,39 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Heading } from "@medusajs/ui";
+
+export const CustomerListTitle = () => {
+ const { t } = useTranslation();
+ return <Heading>{t("customers.domain")}</Heading>;
+};
+
+export const CustomerListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? children : null}
+ </div>
+ );
+};
+
+export const CustomerListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CustomerListTitle />
+ <CustomerListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-table.tsx b/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-table.tsx
index c3562a6a0..3e11cf40b 100644
--- a/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-table.tsx
+++ b/packages/vendor/src/pages/customers/_components/customer-list-table/customer-list-table.tsx
@@ -1,101 +1,22 @@
-import { Container, Heading } from "@medusajs/ui";
-import { keepPreviousData } from "@tanstack/react-query";
-import { useMemo } from "react";
-import { useTranslation } from "react-i18next";
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
+import { Outlet } from "react-router-dom";
-import { _DataTable } from "@components/table/data-table";
-import { useCustomers } from "@hooks/api/customers";
-import { useCustomerTableColumns } from "@hooks/table/columns/use-customer-table-columns";
-import { useCustomerTableFilters } from "@hooks/table/filters/use-customer-table-filters";
-import { useCustomerTableQuery } from "@hooks/table/query/use-customer-table-query";
-import { useDataTable } from "@hooks/use-data-table";
-
-const PAGE_SIZE = 20;
-
-export const CustomerListTable = () => {
- const { t } = useTranslation();
-
- const { searchParams, raw } = useCustomerTableQuery({
- pageSize: PAGE_SIZE,
- });
-
- const { customers, count, isLoading, isError, error } = useCustomers(
- {
- offset: searchParams.offset,
- limit: searchParams.limit,
- },
- {
- placeholderData: keepPreviousData,
- },
- {
- // groups: searchParams.groups,
- has_account: searchParams.has_account,
- order: searchParams.order,
- q: searchParams.q,
- },
- );
-
- const filters = useCustomerTableFilters();
- const columns = useColumns();
-
- const { table } = useDataTable({
- data: customers ?? [],
- columns,
- count,
- enablePagination: true,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- });
-
- if (isError) {
- throw error;
- }
+import { CustomerListHeader } from "./customer-list-header";
+import { CustomerListDataTable } from "./customer-list-data-table";
+export const CustomerListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading>{t("customers.domain")}</Heading>
- </div>
- <_DataTable
- table={table}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- filters={filters}
- orderBy={[
- { key: "email", label: t("fields.email") },
- {
- key: "first_name",
- label: t("fields.firstName"),
- },
- { key: "last_name", label: t("fields.lastName") },
- {
- key: "has_account",
- label: t("customers.hasAccount"),
- },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- isLoading={isLoading}
- navigateTo={(row) => row.original.id}
- queryObject={raw}
- search
- noRecords={{
- message: t("customers.list.noRecordsMessage"),
- }}
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <CustomerListHeader />
+ <CustomerListDataTable />
+ </>
+ )}
+ <Outlet />
</Container>
);
};
-
-const useColumns = () => {
- const columns = useCustomerTableColumns();
-
- return useMemo(() => [...columns], [columns]);
-};
diff --git a/packages/vendor/src/pages/customers/_components/customer-list-table/index.ts b/packages/vendor/src/pages/customers/_components/customer-list-table/index.ts
index c2e0ca7b0..edb7a649e 100644
--- a/packages/vendor/src/pages/customers/_components/customer-list-table/index.ts
+++ b/packages/vendor/src/pages/customers/_components/customer-list-table/index.ts
@@ -1 +1,3 @@
export * from "./customer-list-table"
+export * from "./customer-list-header"
+export * from "./customer-list-data-table"
diff --git a/packages/vendor/src/pages/customers/create/create-customer-form/create-customer-form.tsx b/packages/vendor/src/pages/customers/create/create-customer-form/create-customer-form.tsx
deleted file mode 100644
index 60bc304bd..000000000
--- a/packages/vendor/src/pages/customers/create/create-customer-form/create-customer-form.tsx
+++ /dev/null
@@ -1,179 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { Button, Heading, Input, Text, toast } from "@medusajs/ui"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import * as zod from "zod"
-
-import { Form } from "@components/common/form"
-import {
- RouteFocusModal,
- useRouteModal,
-} from "@components/modals"
-import { KeyboundForm } from "@components/utilities/keybound-form"
-import { useCreateCustomer } from "@hooks/api/customers"
-
-const CreateCustomerSchema = zod.object({
- email: zod.string().email(),
- first_name: zod.string().optional(),
- last_name: zod.string().optional(),
- company_name: zod.string().optional(),
- phone: zod.string().optional(),
-})
-
-export const CreateCustomerForm = () => {
- const { t } = useTranslation()
- const { handleSuccess } = useRouteModal()
-
- const { mutateAsync, isPending } = useCreateCustomer()
-
- const form = useForm<zod.infer<typeof CreateCustomerSchema>>({
- defaultValues: {
- email: "",
- first_name: "",
- last_name: "",
- phone: "",
- company_name: "",
- },
- resolver: zodResolver(CreateCustomerSchema),
- })
-
- const handleSubmit = form.handleSubmit(async (data) => {
- await mutateAsync(
- {
- email: data.email,
- first_name: data.first_name || undefined,
- last_name: data.last_name || undefined,
- company_name: data.company_name || undefined,
- phone: data.phone || undefined,
- },
- {
- onSuccess: ({ customer }) => {
- toast.success(
- t("customers.create.successToast", {
- email: customer.email,
- })
- )
- handleSuccess(`/customers/${customer.id}`)
- },
- onError: (error) => {
- toast.error(error.message)
- },
- }
- )
- })
-
- return (
- <RouteFocusModal.Form form={form}>
- <KeyboundForm
- onSubmit={handleSubmit}
- className="flex flex-1 flex-col overflow-hidden"
- >
- <RouteFocusModal.Header />
- <RouteFocusModal.Body className="flex flex-1 flex-col items-center overflow-y-auto py-16">
- <div className="flex w-full max-w-[720px] flex-col gap-y-8">
- <div>
- <Heading>{t("customers.create.header")}</Heading>
- <Text size="small" className="text-ui-fg-subtle">
- {t("customers.create.hint")}
- </Text>
- </div>
- <div className="grid grid-cols-1 gap-4 md:grid-cols-2">
- <Form.Field
- control={form.control}
- name="first_name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label optional>{t("fields.firstName")}</Form.Label>
- <Form.Control>
- <Input autoComplete="off" {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="last_name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label optional>{t("fields.lastName")}</Form.Label>
- <Form.Control>
- <Input autoComplete="off" {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="email"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label>{t("fields.email")}</Form.Label>
- <Form.Control>
- <Input autoComplete="off" {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="company_name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label optional>{t("fields.company")}</Form.Label>
- <Form.Control>
- <Input autoComplete="off" {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="phone"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label optional>{t("fields.phone")}</Form.Label>
- <Form.Control>
- <Input autoComplete="off" {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- </div>
- </div>
- </RouteFocusModal.Body>
- <RouteFocusModal.Footer>
- <div className="flex items-center justify-end gap-x-2">
- <RouteFocusModal.Close asChild>
- <Button size="small" variant="secondary">
- {t("actions.cancel")}
- </Button>
- </RouteFocusModal.Close>
- <Button
- size="small"
- variant="primary"
- type="submit"
- isLoading={isPending}
- >
- {t("actions.create")}
- </Button>
- </div>
- </RouteFocusModal.Footer>
- </KeyboundForm>
- </RouteFocusModal.Form>
- )
-}
diff --git a/packages/vendor/src/pages/customers/create/create-customer-form/index.ts b/packages/vendor/src/pages/customers/create/create-customer-form/index.ts
deleted file mode 100644
index e3a418be9..000000000
--- a/packages/vendor/src/pages/customers/create/create-customer-form/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./create-customer-form"
diff --git a/packages/vendor/src/pages/customers/create/index.tsx b/packages/vendor/src/pages/customers/create/index.tsx
deleted file mode 100644
index 3d5d9af1f..000000000
--- a/packages/vendor/src/pages/customers/create/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /customers/create
-import { RouteFocusModal } from "@components/modals"
-import { CreateCustomerForm } from "./create-customer-form"
-
-export const Component = () => {
- return (
- <RouteFocusModal>
- <CreateCustomerForm />
- </RouteFocusModal>
- )
-}
diff --git a/packages/vendor/src/pages/customers/customer-list-page.tsx b/packages/vendor/src/pages/customers/customer-list-page.tsx
new file mode 100644
index 000000000..214e3e2f7
--- /dev/null
+++ b/packages/vendor/src/pages/customers/customer-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ CustomerListTable,
+ CustomerListDataTable,
+ CustomerListHeader,
+ CustomerListActions,
+ CustomerListTitle,
+} from "./_components/customer-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage>
+ {Children.count(children) > 0 ? children : <CustomerListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const CustomerListPage = Object.assign(Root, {
+ Table: CustomerListTable,
+ Header: CustomerListHeader,
+ HeaderTitle: CustomerListTitle,
+ HeaderActions: CustomerListActions,
+ DataTable: CustomerListDataTable,
+});
diff --git a/packages/vendor/src/pages/customers/index.ts b/packages/vendor/src/pages/customers/index.ts
new file mode 100644
index 000000000..a101e63f3
--- /dev/null
+++ b/packages/vendor/src/pages/customers/index.ts
@@ -0,0 +1 @@
+export * from './customer-list-page'
diff --git a/packages/vendor/src/pages/customers/index.tsx b/packages/vendor/src/pages/customers/index.tsx
deleted file mode 100644
index c80a784e0..000000000
--- a/packages/vendor/src/pages/customers/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /customers
-import { SingleColumnPage } from "@components/layout/pages";
-import { CustomerListTable } from "./_components/customer-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage>
- <CustomerListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/index.ts b/packages/vendor/src/pages/index.ts
new file mode 100644
index 000000000..843222dbb
--- /dev/null
+++ b/packages/vendor/src/pages/index.ts
@@ -0,0 +1,12 @@
+export * from "./campaigns"
+export * from "./categories"
+export * from "./collections"
+export * from "./customers"
+export * from "./inventory"
+export * from "./login"
+export * from "./orders"
+export * from "./payouts"
+export * from "./price-lists"
+export * from "./products"
+export * from "./promotions"
+export * from "./settings"
diff --git a/packages/vendor/src/pages/inventory/[id]/breadcrumb.tsx b/packages/vendor/src/pages/inventory/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..d1c787518
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/[id]/breadcrumb.tsx
@@ -0,0 +1,21 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { useInventoryItem } from "@hooks/api/inventory";
+
+import { INVENTORY_DETAIL_FIELDS } from "./constants";
+
+type InventoryDetailBreadcrumbProps =
+ UIMatch<HttpTypes.AdminInventoryItemResponse>;
+
+export const Breadcrumb = (props: InventoryDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+ const { inventory_item } = useInventoryItem(
+ id!,
+ { fields: INVENTORY_DETAIL_FIELDS },
+ { initialData: props.data, enabled: Boolean(id) },
+ );
+
+ if (!inventory_item) return null;
+ return <span>{inventory_item.title ?? inventory_item.sku ?? id}</span>;
+};
diff --git a/packages/vendor/src/pages/inventory/[id]/index.ts b/packages/vendor/src/pages/inventory/[id]/index.ts
new file mode 100644
index 000000000..ac55e98bb
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './inventory-detail-page'
diff --git a/packages/vendor/src/pages/inventory/[id]/index.tsx b/packages/vendor/src/pages/inventory/[id]/index.tsx
deleted file mode 100644
index 6d443ad72..000000000
--- a/packages/vendor/src/pages/inventory/[id]/index.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-// Route: /inventory/:id
-import { HttpTypes } from "@medusajs/types";
-import {
- UIMatch,
- useLoaderData,
- useParams,
- LoaderFunctionArgs,
-} from "react-router-dom";
-
-import { TwoColumnPageSkeleton } from "@components/common/skeleton";
-import { TwoColumnPage } from "@components/layout/pages";
-import { useDashboardExtension } from "@/extensions";
-import { useInventoryItem } from "@hooks/api/inventory";
-import { inventoryItemsQueryKeys } from "@hooks/api/inventory";
-import { fetchQuery } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-
-import { InventoryItemAttributeSection } from "./_components/inventory-item-attributes/attributes-section";
-import { InventoryItemGeneralSection } from "./_components/inventory-item-general-section";
-import { InventoryItemLocationLevelsSection } from "./_components/inventory-item-location-levels";
-import { InventoryItemVariantsSection } from "./_components/inventory-item-variants/variants-section";
-import { INVENTORY_DETAIL_FIELDS } from "./constants";
-
-// Loader
-const inventoryDetailQuery = (id: string) => ({
- queryKey: inventoryItemsQueryKeys.detail(id),
- queryFn: async () =>
- fetchQuery(
- `/vendor/inventory-items/${id}?fields=${INVENTORY_DETAIL_FIELDS}`,
- { method: "GET" },
- ),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = inventoryDetailQuery(id!);
- return queryClient.ensureQueryData(query);
-};
-
-// Breadcrumb
-type InventoryDetailBreadcrumbProps =
- UIMatch<HttpTypes.AdminInventoryItemResponse>;
-
-export const Breadcrumb = (props: InventoryDetailBreadcrumbProps) => {
- const { id } = props.params || {};
- const { inventory_item } = useInventoryItem(
- id!,
- { fields: INVENTORY_DETAIL_FIELDS },
- { initialData: props.data, enabled: Boolean(id) },
- );
-
- if (!inventory_item) return null;
- return <span>{inventory_item.title ?? inventory_item.sku ?? id}</span>;
-};
-
-// Main component
-export const Component = () => {
- const { id } = useParams();
- const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
- const { inventory_item, isPending: isLoading } = useInventoryItem(
- id!,
- { fields: INVENTORY_DETAIL_FIELDS },
- { initialData },
- );
-
- if (isLoading || !inventory_item) {
- return (
- <TwoColumnPageSkeleton
- showJSON
- mainSections={3}
- sidebarSections={2}
- showMetadata
- />
- );
- }
-
- return (
- <TwoColumnPage data={inventory_item}>
- <TwoColumnPage.Main>
- <InventoryItemGeneralSection inventoryItem={inventory_item} />
- <InventoryItemLocationLevelsSection inventoryItem={inventory_item} />
- {/* <InventoryItemReservationsSection inventoryItem={inventory_item} /> */}
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <InventoryItemVariantsSection
- variants={(inventory_item as any).variants}
- />
- <InventoryItemAttributeSection inventoryItem={inventory_item as any} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/inventory/[id]/inventory-detail-page.tsx b/packages/vendor/src/pages/inventory/[id]/inventory-detail-page.tsx
new file mode 100644
index 000000000..c32b1bb54
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/[id]/inventory-detail-page.tsx
@@ -0,0 +1,65 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { TwoColumnPageSkeleton } from "@components/common/skeleton";
+import { TwoColumnPage } from "@components/layout/pages";
+import { useInventoryItem } from "@hooks/api/inventory";
+
+import { InventoryItemAttributeSection } from "./_components/inventory-item-attributes/attributes-section";
+import { InventoryItemGeneralSection } from "./_components/inventory-item-general-section";
+import { InventoryItemLocationLevelsSection } from "./_components/inventory-item-location-levels";
+import { InventoryItemVariantsSection } from "./_components/inventory-item-variants/variants-section";
+import { INVENTORY_DETAIL_FIELDS } from "./constants";
+
+import { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const { id } = useParams();
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { inventory_item, isPending: isLoading } = useInventoryItem(
+ id!,
+ { fields: INVENTORY_DETAIL_FIELDS },
+ { initialData },
+ );
+
+ if (isLoading || !inventory_item) {
+ return (
+ <TwoColumnPageSkeleton
+ showJSON
+ mainSections={3}
+ sidebarSections={2}
+ showMetadata
+ />
+ );
+ }
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage data={inventory_item}>
+ <TwoColumnPage.Main>
+ <InventoryItemGeneralSection inventoryItem={inventory_item} />
+ <InventoryItemLocationLevelsSection inventoryItem={inventory_item} />
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <InventoryItemVariantsSection
+ variants={(inventory_item as any).variants}
+ />
+ <InventoryItemAttributeSection inventoryItem={inventory_item as any} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
+ );
+};
+
+export const InventoryDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: InventoryItemGeneralSection,
+ MainLocationLevelsSection: InventoryItemLocationLevelsSection,
+ SidebarVariantsSection: InventoryItemVariantsSection,
+ SidebarAttributeSection: InventoryItemAttributeSection,
+});
diff --git a/packages/vendor/src/pages/inventory/[id]/loader.tsx b/packages/vendor/src/pages/inventory/[id]/loader.tsx
new file mode 100644
index 000000000..90961a3b6
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/[id]/loader.tsx
@@ -0,0 +1,22 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { inventoryItemsQueryKeys } from "@hooks/api/inventory";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+import { INVENTORY_DETAIL_FIELDS } from "./constants";
+
+const inventoryDetailQuery = (id: string) => ({
+ queryKey: inventoryItemsQueryKeys.detail(id),
+ queryFn: async () =>
+ fetchQuery(
+ `/vendor/inventory-items/${id}?fields=${INVENTORY_DETAIL_FIELDS}`,
+ { method: "GET" },
+ ),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = inventoryDetailQuery(id!);
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/inventory/_components/index.ts b/packages/vendor/src/pages/inventory/_components/index.ts
index a7535bdcb..3a1f2f85d 100644
--- a/packages/vendor/src/pages/inventory/_components/index.ts
+++ b/packages/vendor/src/pages/inventory/_components/index.ts
@@ -1,4 +1,6 @@
export * from "./inventory-list-table"
+export * from "./inventory-list-header"
+export * from "./inventory-list-data-table"
export * from "./use-inventory-table-columns"
export * from "./use-inventory-table-filters"
export * from "./use-inventory-table-query"
diff --git a/packages/vendor/src/pages/inventory/_components/inventory-list-data-table.tsx b/packages/vendor/src/pages/inventory/_components/inventory-list-data-table.tsx
new file mode 100644
index 000000000..c51254192
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/_components/inventory-list-data-table.tsx
@@ -0,0 +1,97 @@
+import { InventoryTypes } from "@medusajs/types";
+
+import { RowSelectionState } from "@tanstack/react-table";
+import { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { useNavigate } from "react-router-dom";
+import { _DataTable } from "@components/table/data-table";
+import { useInventoryItems } from "@hooks/api/inventory";
+import { useDataTable } from "@hooks/use-data-table";
+import { INVENTORY_ITEM_IDS_KEY } from "../common/constants";
+import { useInventoryTableColumns } from "./use-inventory-table-columns";
+import { useInventoryTableFilters } from "./use-inventory-table-filters";
+import { useInventoryTableQuery } from "./use-inventory-table-query";
+import { keepPreviousData } from "@tanstack/react-query";
+
+const PAGE_SIZE = 20;
+
+export const InventoryListDataTable = () => {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+
+ const [selection, setSelection] = useState<RowSelectionState>({});
+
+ const { raw, searchParams } = useInventoryTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+
+ const {
+ inventory_items,
+ count,
+ isPending: isLoading,
+ isError,
+ error,
+ } = useInventoryItems(
+ {
+ ...searchParams,
+ },
+ {
+ placeholderData: keepPreviousData,
+ },
+ );
+
+ const filters = useInventoryTableFilters();
+ const columns = useInventoryTableColumns();
+
+ const { table } = useDataTable({
+ data: (inventory_items ?? []) as InventoryTypes.InventoryItemDTO[],
+ columns,
+ count,
+ enablePagination: true,
+ getRowId: (row) => row.id,
+ pageSize: PAGE_SIZE,
+ enableRowSelection: true,
+ rowSelection: {
+ state: selection,
+ updater: setSelection,
+ },
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ columns={columns}
+ pageSize={PAGE_SIZE}
+ count={count}
+ isLoading={isLoading}
+ pagination
+ search
+ filters={filters}
+ queryObject={raw}
+ orderBy={[
+ { key: "title", label: t("fields.title") },
+ { key: "sku", label: t("fields.sku") },
+ { key: "stocked_quantity", label: t("fields.inStock") },
+ { key: "reserved_quantity", label: t("inventory.reserved") },
+ ]}
+ navigateTo={(row) => `${row.id}`}
+ commands={[
+ {
+ action: async (selection) => {
+ navigate(
+ `stock?${INVENTORY_ITEM_IDS_KEY}=${Object.keys(selection).join(
+ ",",
+ )}`,
+ );
+ },
+ label: t("inventory.stock.action"),
+ shortcut: "i",
+ },
+ ]}
+ />
+ );
+};
diff --git a/packages/vendor/src/pages/inventory/_components/inventory-list-header.tsx b/packages/vendor/src/pages/inventory/_components/inventory-list-header.tsx
new file mode 100644
index 000000000..0adaeef65
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/_components/inventory-list-header.tsx
@@ -0,0 +1,29 @@
+import { Button, Heading, Text } from "@medusajs/ui";
+import { useTranslation } from "react-i18next";
+import { Link } from "react-router-dom";
+
+export const InventoryListHeader = () => {
+ const { t } = useTranslation();
+
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ <div>
+ <Heading>{t("inventory.domain")}</Heading>
+ <Text className="text-ui-fg-subtle" size="small">
+ {t("inventory.subtitle")}
+ </Text>
+ </div>
+ <InventoryListCreateButton />
+ </div>
+ );
+};
+
+export const InventoryListCreateButton = () => {
+ const { t } = useTranslation();
+
+ return (
+ <Button size="small" variant="secondary" asChild>
+ <Link to="create">{t("actions.create")}</Link>
+ </Button>
+ );
+};
diff --git a/packages/vendor/src/pages/inventory/_components/inventory-list-table.tsx b/packages/vendor/src/pages/inventory/_components/inventory-list-table.tsx
index f738f1580..faa2988a8 100644
--- a/packages/vendor/src/pages/inventory/_components/inventory-list-table.tsx
+++ b/packages/vendor/src/pages/inventory/_components/inventory-list-table.tsx
@@ -1,111 +1,22 @@
-import { InventoryTypes } from "@medusajs/types";
-import { Button, Container, Heading, Text } from "@medusajs/ui";
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
+import { Outlet } from "react-router-dom";
-import { RowSelectionState } from "@tanstack/react-table";
-import { useState } from "react";
-import { useTranslation } from "react-i18next";
-import { Link, useNavigate } from "react-router-dom";
-import { _DataTable } from "@components/table/data-table";
-import { useInventoryItems } from "@hooks/api/inventory";
-import { useDataTable } from "@hooks/use-data-table";
-import { INVENTORY_ITEM_IDS_KEY } from "../common/constants";
-import { useInventoryTableColumns } from "./use-inventory-table-columns";
-import { useInventoryTableFilters } from "./use-inventory-table-filters";
-import { useInventoryTableQuery } from "./use-inventory-table-query";
-import { keepPreviousData } from "@tanstack/react-query";
-
-const PAGE_SIZE = 20;
-
-export const InventoryListTable = () => {
- const { t } = useTranslation();
- const navigate = useNavigate();
-
- const [selection, setSelection] = useState<RowSelectionState>({});
-
- const { raw, searchParams } = useInventoryTableQuery({
- pageSize: PAGE_SIZE,
- });
-
- const {
- inventory_items,
- count,
- isPending: isLoading,
- isError,
- error,
- } = useInventoryItems(
- {
- ...searchParams,
- },
- {
- placeholderData: keepPreviousData,
- },
- );
-
- const filters = useInventoryTableFilters();
- const columns = useInventoryTableColumns();
-
- const { table } = useDataTable({
- data: (inventory_items ?? []) as InventoryTypes.InventoryItemDTO[],
- columns,
- count,
- enablePagination: true,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- enableRowSelection: true,
- rowSelection: {
- state: selection,
- updater: setSelection,
- },
- });
-
- if (isError) {
- throw error;
- }
+import { InventoryListHeader } from "./inventory-list-header";
+import { InventoryListDataTable } from "./inventory-list-data-table";
+export const InventoryListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("inventory.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- {t("inventory.subtitle")}
- </Text>
- </div>
- <Button size="small" variant="secondary" asChild>
- <Link to="create">{t("actions.create")}</Link>
- </Button>
- </div>
- <_DataTable
- table={table}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- isLoading={isLoading}
- pagination
- search
- filters={filters}
- queryObject={raw}
- orderBy={[
- { key: "title", label: t("fields.title") },
- { key: "sku", label: t("fields.sku") },
- { key: "stocked_quantity", label: t("fields.inStock") },
- { key: "reserved_quantity", label: t("inventory.reserved") },
- ]}
- navigateTo={(row) => `${row.id}`}
- commands={[
- {
- action: async (selection) => {
- navigate(
- `stock?${INVENTORY_ITEM_IDS_KEY}=${Object.keys(selection).join(
- ",",
- )}`,
- );
- },
- label: t("inventory.stock.action"),
- shortcut: "i",
- },
- ]}
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <InventoryListHeader />
+ <InventoryListDataTable />
+ </>
+ )}
+ <Outlet />
</Container>
);
};
diff --git a/packages/vendor/src/pages/inventory/index.ts b/packages/vendor/src/pages/inventory/index.ts
new file mode 100644
index 000000000..73726131d
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/index.ts
@@ -0,0 +1 @@
+export * from './inventory-list-page'
diff --git a/packages/vendor/src/pages/inventory/index.tsx b/packages/vendor/src/pages/inventory/index.tsx
deleted file mode 100644
index 73c04a4ac..000000000
--- a/packages/vendor/src/pages/inventory/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /inventory
-import { SingleColumnPage } from "@components/layout/pages";
-import { InventoryListTable } from "./_components/inventory-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage>
- <InventoryListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/inventory/inventory-list-page.tsx b/packages/vendor/src/pages/inventory/inventory-list-page.tsx
new file mode 100644
index 000000000..5e38cd289
--- /dev/null
+++ b/packages/vendor/src/pages/inventory/inventory-list-page.tsx
@@ -0,0 +1,25 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ InventoryListTable,
+ InventoryListDataTable,
+ InventoryListHeader,
+ InventoryListCreateButton,
+} from "./_components";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage>
+ {Children.count(children) > 0 ? children : <InventoryListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const InventoryListPage = Object.assign(Root, {
+ Table: InventoryListTable,
+ Header: InventoryListHeader,
+ HeaderCreateButton: InventoryListCreateButton,
+ DataTable: InventoryListDataTable,
+});
diff --git a/packages/vendor/src/pages/invite/index.ts b/packages/vendor/src/pages/invite/index.ts
deleted file mode 100644
index b49eed973..000000000
--- a/packages/vendor/src/pages/invite/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { Invite as Component } from "./invite"
diff --git a/packages/vendor/src/pages/invite/invite.tsx b/packages/vendor/src/pages/invite/invite.tsx
deleted file mode 100644
index 062c97914..000000000
--- a/packages/vendor/src/pages/invite/invite.tsx
+++ /dev/null
@@ -1,410 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { Alert, Button, Heading, Hint, Input, Text, toast } from "@medusajs/ui"
-import i18n from "i18next"
-import { AnimatePresence, motion } from "motion/react"
-import { useState } from "react"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import { decodeToken } from "react-jwt"
-import { Link, useSearchParams } from "react-router-dom"
-import * as z from "zod"
-import { Form } from "@components/common/form"
-import AvatarBox from "@components/common/logo-box/avatar-box"
-import { useSignUpForInvite } from "@hooks/api/auth"
-import { useAcceptInvite } from "@hooks/api/invites"
-import { isFetchError } from "@lib/is-fetch-error"
-
-const CreateAccountSchema = z
- .object({
- email: z.string().email(),
- first_name: z.string().min(1),
- last_name: z.string().min(1),
- password: z.string().min(1),
- repeat_password: z.string().min(1),
- })
- .superRefine(({ password, repeat_password }, ctx) => {
- if (password !== repeat_password) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: i18n.t("invite.passwordMismatch"),
- path: ["repeat_password"],
- })
- }
- })
-
-// TODO: Update to V2 format
-type DecodedInvite = {
- id: string
- jti: any
- exp: string
- iat: number
- email: string
-}
-
-export const Invite = () => {
- const [searchParams] = useSearchParams()
- const [success, setSuccess] = useState(false)
-
- const token = searchParams.get("token") || null
- const invite: DecodedInvite | null = token ? decodeToken(token) : null
- const isValidInvite = invite && validateDecodedInvite(invite)
-
- return (
- <div className="bg-ui-bg-subtle relative flex min-h-dvh w-dvw items-center justify-center p-4">
- <div className="flex w-full max-w-[360px] flex-col items-center">
- <AvatarBox checked={success} />
- <div className="max-h-[557px] w-full will-change-contents">
- {isValidInvite ? (
- <AnimatePresence>
- {!success ? (
- <motion.div
- key="create-account"
- initial={false}
- animate={{
- height: "557px",
- y: 0,
- }}
- exit={{
- height: 0,
- y: 40,
- }}
- transition={{
- duration: 0.8,
- delay: 0.6,
- ease: [0, 0.71, 0.2, 1.01],
- }}
- className="w-full will-change-transform"
- >
- <motion.div
- initial={false}
- animate={{
- opacity: 1,
- scale: 1,
- }}
- exit={{
- opacity: 0,
- scale: 0.7,
- }}
- transition={{
- duration: 0.6,
- delay: 0,
- ease: [0, 0.71, 0.2, 1.01],
- }}
- key="inner-create-account"
- >
- <CreateView
- onSuccess={() => setSuccess(true)}
- token={token!}
- invite={invite}
- />
- </motion.div>
- </motion.div>
- ) : (
- <motion.div
- key="success-view"
- initial={{
- opacity: 0,
- scale: 0.4,
- }}
- animate={{
- opacity: 1,
- scale: 1,
- }}
- transition={{
- duration: 1,
- delay: 0.6,
- ease: [0, 0.71, 0.2, 1.01],
- }}
- className="w-full"
- >
- <SuccessView />
- </motion.div>
- )}
- </AnimatePresence>
- ) : (
- <InvalidView />
- )}
- </div>
- </div>
- </div>
- )
-}
-
-const LoginLink = () => {
- const { t } = useTranslation()
-
- return (
- <div className="flex w-full flex-col items-center">
- <div className="my-6 h-px w-full border-b border-dotted" />
- <Link
- key="login-link"
- to="/login"
- className="txt-small text-ui-fg-base transition-fg hover:text-ui-fg-base-hover focus-visible:text-ui-fg-base-hover font-medium outline-none"
- >
- {t("invite.backToLogin")}
- </Link>
- </div>
- )
-}
-
-const InvalidView = () => {
- const { t } = useTranslation()
-
- return (
- <div className="flex flex-col items-center">
- <div className="flex flex-col items-center gap-y-1">
- <Heading>{t("invite.invalidTokenTitle")}</Heading>
- <Text size="small" className="text-ui-fg-subtle text-center">
- {t("invite.invalidTokenHint")}
- </Text>
- </div>
- <LoginLink />
- </div>
- )
-}
-
-const CreateView = ({
- onSuccess,
- token,
- invite,
-}: {
- onSuccess: () => void
- token: string
- invite: DecodedInvite
-}) => {
- const { t } = useTranslation()
- const [invalid, setInvalid] = useState(false)
-
- const [params] = useSearchParams()
- const isFirstRun = params.get("first_run") === "true" // true when the invite page is open during a "create medusa app" run
-
- const form = useForm<z.infer<typeof CreateAccountSchema>>({
- resolver: zodResolver(CreateAccountSchema),
- defaultValues: {
- email: isFirstRun ? "" : invite.email || "",
- first_name: "",
- last_name: "",
- password: "",
- repeat_password: "",
- },
- })
-
- const { mutateAsync: signUpEmailPass, isPending: isCreatingAuthUser } =
- useSignUpForInvite()
-
- const { mutateAsync: acceptInvite, isPending: isAcceptingInvite } =
- useAcceptInvite(token)
-
- const handleSubmit = form.handleSubmit(async (data) => {
- try {
- const authToken = await signUpEmailPass({
- email: data.email,
- password: data.password,
- })
-
- const invitePayload = {
- name: `${data.first_name} ${data.last_name}`,
- }
-
- await acceptInvite({
- ...invitePayload,
- auth_token: authToken,
- })
-
- toast.success(t("invite.toast.accepted"))
-
- onSuccess()
- } catch (error: any) {
- toast.error(error.message)
- if (isFetchError(error) && error.status === 400) {
- form.setError("root", {
- type: "manual",
- message: t("invite.invalidInvite"),
- })
- setInvalid(true)
- return
- }
- }
- })
-
- const serverError = form.formState.errors.root?.message
- const validationError =
- form.formState.errors.email?.message ||
- form.formState.errors.password?.message ||
- form.formState.errors.repeat_password?.message ||
- form.formState.errors.first_name?.message ||
- form.formState.errors.last_name?.message
-
- return (
- <div className="flex w-full flex-col items-center">
- <div className="mb-4 flex flex-col items-center">
- <Heading>{t("invite.title")}</Heading>
- <Text size="small" className="text-ui-fg-subtle text-center">
- {t("invite.hint")}
- </Text>
- </div>
- <Form {...form}>
- <form onSubmit={handleSubmit} className="flex w-full flex-col gap-y-6">
- <div className="flex flex-col gap-y-2">
- <Form.Field
- control={form.control}
- name="email"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Control>
- <Input
- autoComplete="off"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.email")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="first_name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Control>
- <Input
- autoComplete="given-name"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.firstName")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="last_name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Control>
- <Input
- autoComplete="family-name"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.lastName")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="password"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Control>
- <Input
- autoComplete="new-password"
- type="password"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.password")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="repeat_password"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Control>
- <Input
- autoComplete="off"
- type="password"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.repeatPassword")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- {validationError && (
- <div className="mt-6 text-center">
- <Hint className="inline-flex" variant={"error"}>
- {validationError}
- </Hint>
- </div>
- )}
- {serverError && (
- <Alert
- className="bg-ui-bg-base items-center p-2"
- dismissible
- variant="error"
- >
- {serverError}
- </Alert>
- )}
- </div>
- <Button
- className="w-full"
- type="submit"
- isLoading={isCreatingAuthUser || isAcceptingInvite}
- disabled={invalid}
- >
- {t("invite.createAccount")}
- </Button>
- </form>
- </Form>
- <LoginLink />
- </div>
- )
-}
-
-const SuccessView = () => {
- const { t } = useTranslation()
-
- return (
- <div className="flex w-full flex-col items-center gap-y-6">
- <div className="flex flex-col items-center gap-y-1">
- <Heading className="text-center">{t("invite.successTitle")}</Heading>
- <Text size="small" className="text-ui-fg-subtle text-center">
- {t("invite.successHint")}
- </Text>
- </div>
- <Button variant="secondary" asChild className="w-full">
- <Link to="/login" replace>
- {t("invite.successAction")}
- </Link>
- </Button>
-
- <Link
- key="login-link"
- to="/login"
- className="txt-small text-ui-fg-base transition-fg hover:text-ui-fg-base-hover focus-visible:text-ui-fg-base-hover font-medium outline-none"
- >
- {t("invite.backToLogin")}
- </Link>
- </div>
- )
-}
-
-const InviteSchema = z.object({
- id: z.string(),
- // jti: z.string(),
- exp: z.number(),
- iat: z.number(),
-})
-
-const validateDecodedInvite = (decoded: any): decoded is DecodedInvite => {
- return InviteSchema.safeParse(decoded).success
-}
diff --git a/packages/vendor/src/pages/login/index.ts b/packages/vendor/src/pages/login/index.ts
index f1fc40c3a..1e5b56ede 100644
--- a/packages/vendor/src/pages/login/index.ts
+++ b/packages/vendor/src/pages/login/index.ts
@@ -1 +1 @@
-export { Login as Component } from "./login"
+export * from "./login"
diff --git a/packages/vendor/src/pages/login/login.tsx b/packages/vendor/src/pages/login/login.tsx
index c44da849c..13f3c4b80 100644
--- a/packages/vendor/src/pages/login/login.tsx
+++ b/packages/vendor/src/pages/login/login.tsx
@@ -1,3 +1,4 @@
+import { Children, ReactNode } from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Alert, Button, Heading, Hint, Input, Text } from "@medusajs/ui"
import { useForm } from "react-hook-form"
@@ -16,7 +17,24 @@ const LoginSchema = z.object({
password: z.string(),
})
-export const Login = () => {
+const LoginLogo = () => {
+ return <AvatarBox />
+}
+
+const LoginHeader = () => {
+ const { t } = useTranslation()
+
+ return (
+ <div className="mb-4 flex flex-col items-center">
+ <Heading>{t("login.title", { name: config.name ?? "Mercur" })}</Heading>
+ <Text size="small" className="text-ui-fg-subtle text-center">
+ {t("login.hint")}
+ </Text>
+ </div>
+ )
+}
+
+const LoginForm = () => {
const { t } = useTranslation()
const navigate = useNavigate()
const [searchParams] = useSearchParams()
@@ -75,98 +93,118 @@ export const Login = () => {
form.formState.errors.email?.message ||
form.formState.errors.password?.message
+ return (
+ <div className="flex w-full flex-col gap-y-3">
+ <Form {...form}>
+ <form
+ onSubmit={handleSubmit}
+ className="flex w-full flex-col gap-y-6"
+ >
+ <div className="flex flex-col gap-y-1">
+ <Form.Field
+ control={form.control}
+ name="email"
+ render={({ field }) => {
+ return (
+ <Form.Item>
+ <Form.Control>
+ <Input
+ autoComplete="email"
+ {...field}
+ className="bg-ui-bg-field-component"
+ placeholder={t("fields.email")}
+ />
+ </Form.Control>
+ </Form.Item>
+ )
+ }}
+ />
+ <Form.Field
+ control={form.control}
+ name="password"
+ render={({ field }) => {
+ return (
+ <Form.Item>
+ <Form.Label>{}</Form.Label>
+ <Form.Control>
+ <Input
+ type="password"
+ autoComplete="current-password"
+ {...field}
+ className="bg-ui-bg-field-component"
+ placeholder={t("fields.password")}
+ />
+ </Form.Control>
+ </Form.Item>
+ )
+ }}
+ />
+ </div>
+ {validationError && (
+ <div className="text-center">
+ <Hint className="inline-flex" variant={"error"}>
+ {validationError}
+ </Hint>
+ </div>
+ )}
+
+ {serverError && (
+ <Alert
+ className="bg-ui-bg-base items-center p-2"
+ dismissible
+ variant="error"
+ >
+ {serverError}
+ </Alert>
+ )}
+ <Button className="w-full" type="submit" isLoading={isPending}>
+ Sign In
+ </Button>
+ </form>
+ </Form>
+ </div>
+ )
+}
+
+const LoginFooter = () => {
+ return (
+ <span className="text-ui-fg-muted txt-small my-6">
+ <Trans
+ i18nKey="login.forgotPassword"
+ components={[
+ <Link
+ key="reset-password-link"
+ to="/reset-password"
+ className="text-ui-fg-interactive transition-fg hover:text-ui-fg-interactive-hover focus-visible:text-ui-fg-interactive-hover font-medium outline-none"
+ />,
+ ]}
+ />
+ </span>
+ )
+}
+
+const Root = ({ children }: { children?: ReactNode }) => {
return (
<div className="bg-ui-bg-subtle flex min-h-dvh w-dvw items-center justify-center">
<div className="m-4 flex w-full max-w-[280px] flex-col items-center">
- <AvatarBox />
- <div className="mb-4 flex flex-col items-center">
- <Heading>{t("login.title", { name: config.name ?? "Mercur" })}</Heading>
- <Text size="small" className="text-ui-fg-subtle text-center">
- {t("login.hint")}
- </Text>
- </div>
- <div className="flex w-full flex-col gap-y-3">
- <Form {...form}>
- <form
- onSubmit={handleSubmit}
- className="flex w-full flex-col gap-y-6"
- >
- <div className="flex flex-col gap-y-1">
- <Form.Field
- control={form.control}
- name="email"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Control>
- <Input
- autoComplete="email"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.email")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- <Form.Field
- control={form.control}
- name="password"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label>{}</Form.Label>
- <Form.Control>
- <Input
- type="password"
- autoComplete="current-password"
- {...field}
- className="bg-ui-bg-field-component"
- placeholder={t("fields.password")}
- />
- </Form.Control>
- </Form.Item>
- )
- }}
- />
- </div>
- {validationError && (
- <div className="text-center">
- <Hint className="inline-flex" variant={"error"}>
- {validationError}
- </Hint>
- </div>
- )}
-
- {serverError && (
- <Alert
- className="bg-ui-bg-base items-center p-2"
- dismissible
- variant="error"
- >
- {serverError}
- </Alert>
- )}
- <Button className="w-full" type="submit" isLoading={isPending}>
- Sign In
- </Button>
- </form>
- </Form>
- </div>
- <span className="text-ui-fg-muted txt-small my-6">
- <Trans
- i18nKey="login.forgotPassword"
- components={[
- <Link
- key="reset-password-link"
- to="/reset-password"
- className="text-ui-fg-interactive transition-fg hover:text-ui-fg-interactive-hover focus-visible:text-ui-fg-interactive-hover font-medium outline-none"
- />,
- ]}
- />
- </span>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <LoginLogo />
+ <LoginHeader />
+ <LoginForm />
+ <LoginFooter />
+ </>
+ )}
</div>
</div>
)
}
+
+export const LoginPage = Object.assign(Root, {
+ Logo: LoginLogo,
+ Header: LoginHeader,
+ Form: LoginForm,
+ Footer: LoginFooter,
+})
diff --git a/packages/vendor/src/pages/orders/[id]/breadcrumb.tsx b/packages/vendor/src/pages/orders/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..0f01d4a7e
--- /dev/null
+++ b/packages/vendor/src/pages/orders/[id]/breadcrumb.tsx
@@ -0,0 +1,29 @@
+import { HttpTypes } from "@mercurjs/types";
+import { UIMatch } from "react-router-dom";
+
+import { useOrder } from "@hooks/api/orders";
+
+import { DEFAULT_FIELDS } from "./constants";
+
+type OrderDetailBreadcrumbProps = UIMatch<HttpTypes.VendorOrderResponse>;
+
+export const Breadcrumb = (props: OrderDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+
+ const { order } = useOrder(
+ id!,
+ {
+ fields: DEFAULT_FIELDS,
+ },
+ {
+ initialData: props.data,
+ enabled: Boolean(id),
+ },
+ );
+
+ if (!order) {
+ return null;
+ }
+
+ return <span>#{order.display_id}</span>;
+};
diff --git a/packages/vendor/src/pages/orders/[id]/index.ts b/packages/vendor/src/pages/orders/[id]/index.ts
new file mode 100644
index 000000000..04f375039
--- /dev/null
+++ b/packages/vendor/src/pages/orders/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './order-detail-page'
diff --git a/packages/vendor/src/pages/orders/[id]/index.tsx b/packages/vendor/src/pages/orders/[id]/index.tsx
deleted file mode 100644
index 576d4d683..000000000
--- a/packages/vendor/src/pages/orders/[id]/index.tsx
+++ /dev/null
@@ -1,118 +0,0 @@
-// Route: /orders/:id
-import {
- UIMatch,
- useLoaderData,
- useParams,
- LoaderFunctionArgs,
-} from "react-router-dom";
-
-import { TwoColumnPageSkeleton } from "@components/common/skeleton";
-import { TwoColumnPage } from "@components/layout/pages";
-import { useOrder } from "@hooks/api/orders";
-import { ordersQueryKeys } from "@hooks/api/orders";
-import { fetchQuery } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-
-import { OrderCustomerSection } from "./_components/order-customer-section";
-import { OrderFulfillmentSection } from "./_components/order-fulfillment-section";
-import { OrderGeneralSection } from "./_components/order-general-section";
-import { OrderPaymentSection } from "./_components/order-payment-section";
-import { OrderSummarySection } from "./_components/order-summary-section";
-import { DEFAULT_FIELDS } from "./constants";
-import { HttpTypes } from "@mercurjs/types";
-
-// Loader
-const orderDetailQuery = (id: string) => ({
- queryKey: ordersQueryKeys.detail(id),
- queryFn: async () =>
- fetchQuery(`/vendor/orders/${id}`, {
- method: "GET",
- query: { fields: DEFAULT_FIELDS },
- }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = orderDetailQuery(id!);
-
- return queryClient.ensureQueryData(query);
-};
-
-// Breadcrumb
-type OrderDetailBreadcrumbProps = UIMatch<HttpTypes.VendorOrderResponse>;
-
-export const Breadcrumb = (props: OrderDetailBreadcrumbProps) => {
- const { id } = props.params || {};
-
- const { order } = useOrder(
- id!,
- {
- fields: DEFAULT_FIELDS,
- },
- {
- initialData: props.data,
- enabled: Boolean(id),
- },
- );
-
- if (!order) {
- return null;
- }
-
- return <span>#{order.display_id}</span>;
-};
-
-// Main component
-export const Component = () => {
- const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
-
- const { id } = useParams();
-
- const { order, isLoading, isError, error } = useOrder(
- id!,
- {
- fields: DEFAULT_FIELDS,
- },
- {
- initialData,
- },
- );
-
- if (order) {
- order.items = order.items.sort((itemA: any, itemB: any) => {
- if (itemA.created_at > itemB.created_at) {
- return 1;
- }
-
- if (itemA.created_at < itemB.created_at) {
- return -1;
- }
-
- return 0;
- });
- }
-
- if (isLoading || !order) {
- return (
- <TwoColumnPageSkeleton mainSections={4} sidebarSections={2} showJSON />
- );
- }
-
- if (isError) {
- throw error;
- }
-
- return (
- <TwoColumnPage data={order} hasOutlet>
- <TwoColumnPage.Main>
- <OrderGeneralSection order={order} />
- <OrderSummarySection order={order} />
- <OrderPaymentSection order={order} />
- <OrderFulfillmentSection order={order} />
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <OrderCustomerSection order={order} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/orders/[id]/loader.tsx b/packages/vendor/src/pages/orders/[id]/loader.tsx
new file mode 100644
index 000000000..812a25d81
--- /dev/null
+++ b/packages/vendor/src/pages/orders/[id]/loader.tsx
@@ -0,0 +1,23 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { ordersQueryKeys } from "@hooks/api/orders";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+import { DEFAULT_FIELDS } from "./constants";
+
+const orderDetailQuery = (id: string) => ({
+ queryKey: ordersQueryKeys.detail(id),
+ queryFn: async () =>
+ fetchQuery(`/vendor/orders/${id}`, {
+ method: "GET",
+ query: { fields: DEFAULT_FIELDS },
+ }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = orderDetailQuery(id!);
+
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx b/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx
new file mode 100644
index 000000000..9f573adbe
--- /dev/null
+++ b/packages/vendor/src/pages/orders/[id]/order-detail-page.tsx
@@ -0,0 +1,84 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { TwoColumnPageSkeleton } from "@components/common/skeleton";
+import { TwoColumnPage } from "@components/layout/pages";
+import { useOrder } from "@hooks/api/orders";
+
+import { OrderCustomerSection } from "./_components/order-customer-section";
+import { OrderFulfillmentSection } from "./_components/order-fulfillment-section";
+import { OrderGeneralSection } from "./_components/order-general-section";
+import { OrderPaymentSection } from "./_components/order-payment-section";
+import { OrderSummarySection } from "./_components/order-summary-section";
+import { DEFAULT_FIELDS } from "./constants";
+
+import type { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { id } = useParams();
+
+ const { order, isLoading, isError, error } = useOrder(
+ id!,
+ {
+ fields: DEFAULT_FIELDS,
+ },
+ {
+ initialData,
+ },
+ );
+
+ if (order) {
+ order.items = order.items.sort((itemA: any, itemB: any) => {
+ if (itemA.created_at > itemB.created_at) {
+ return 1;
+ }
+
+ if (itemA.created_at < itemB.created_at) {
+ return -1;
+ }
+
+ return 0;
+ });
+ }
+
+ if (isLoading || !order) {
+ return (
+ <TwoColumnPageSkeleton mainSections={4} sidebarSections={2} showJSON />
+ );
+ }
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage data={order} hasOutlet>
+ <TwoColumnPage.Main>
+ <OrderGeneralSection order={order} />
+ <OrderSummarySection order={order} />
+ <OrderPaymentSection order={order} />
+ <OrderFulfillmentSection order={order} />
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <OrderCustomerSection order={order} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
+ );
+};
+
+export const OrderDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: OrderGeneralSection,
+ MainSummarySection: OrderSummarySection,
+ MainPaymentSection: OrderPaymentSection,
+ MainFulfillmentSection: OrderFulfillmentSection,
+ SidebarCustomerSection: OrderCustomerSection,
+});
diff --git a/packages/vendor/src/pages/orders/_components/order-list-table/index.ts b/packages/vendor/src/pages/orders/_components/order-list-table/index.ts
index f65207073..aeb75fb76 100644
--- a/packages/vendor/src/pages/orders/_components/order-list-table/index.ts
+++ b/packages/vendor/src/pages/orders/_components/order-list-table/index.ts
@@ -1 +1,3 @@
export * from "./order-list-table"
+export * from "./order-list-header"
+export * from "./order-list-data-table"
diff --git a/packages/vendor/src/pages/orders/_components/order-list-table/order-list-data-table.tsx b/packages/vendor/src/pages/orders/_components/order-list-table/order-list-data-table.tsx
new file mode 100644
index 000000000..b40418b5d
--- /dev/null
+++ b/packages/vendor/src/pages/orders/_components/order-list-table/order-list-data-table.tsx
@@ -0,0 +1,82 @@
+import { useTranslation } from "react-i18next";
+
+import { _DataTable } from "@components/table/data-table/data-table";
+import { useOrders } from "@hooks/api/orders";
+import { useOrderTableColumns } from "@hooks/table/columns/use-order-table-columns";
+import { useOrderTableQuery } from "@hooks/table/query/use-order-table-query";
+import { useDataTable } from "@hooks/use-data-table";
+import { useOrderTableFilters } from "@hooks/table/filters";
+
+const PAGE_SIZE = 10;
+
+export const OrderListDataTable = () => {
+ const { t } = useTranslation();
+ const { raw, searchParams } = useOrderTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+
+ const { orders, count, isError, error, isLoading } = useOrders({
+ fields: [
+ "id",
+ "status",
+ "created_at",
+ "email",
+ "display_id",
+ "custom_display_id",
+ "payment_status",
+ "fulfillment_status",
+ "total",
+ "currency_code",
+ "*customer",
+ "*sales_channel",
+ "*payment_collections",
+ ].join(","),
+ ...searchParams,
+ });
+
+ const columns = useOrderTableColumns({});
+ const filters = useOrderTableFilters();
+
+ const { table } = useDataTable({
+ data: orders ?? [],
+ columns,
+ enablePagination: true,
+ count: count,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ columns={columns}
+ table={table}
+ pagination
+ filters={filters}
+ navigateTo={(row) => `/orders/${row.original.id}`}
+ count={count}
+ isLoading={isLoading}
+ pageSize={PAGE_SIZE}
+ orderBy={[
+ {
+ key: "display_id",
+ label: t("orders.fields.displayId"),
+ },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ queryObject={raw}
+ noRecords={{
+ message: t("orders.list.noRecordsMessage"),
+ }}
+ />
+ );
+};
diff --git a/packages/vendor/src/pages/orders/_components/order-list-table/order-list-header.tsx b/packages/vendor/src/pages/orders/_components/order-list-table/order-list-header.tsx
new file mode 100644
index 000000000..de8b4c8cc
--- /dev/null
+++ b/packages/vendor/src/pages/orders/_components/order-list-table/order-list-header.tsx
@@ -0,0 +1,36 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Heading } from "@medusajs/ui";
+
+export const OrderListTitle = () => {
+ const { t } = useTranslation();
+ return <Heading>{t("orders.domain")}</Heading>;
+};
+
+export const OrderListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? children : null}
+ </div>
+ );
+};
+
+export const OrderListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <OrderListTitle />
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/orders/_components/order-list-table/order-list-table.tsx b/packages/vendor/src/pages/orders/_components/order-list-table/order-list-table.tsx
index 1262bc89c..ed88cd77b 100644
--- a/packages/vendor/src/pages/orders/_components/order-list-table/order-list-table.tsx
+++ b/packages/vendor/src/pages/orders/_components/order-list-table/order-list-table.tsx
@@ -1,88 +1,20 @@
-import { Container, Heading } from "@medusajs/ui";
-import { useTranslation } from "react-i18next";
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-import { _DataTable } from "@components/table/data-table/data-table";
-import { useOrders } from "@hooks/api/orders";
-import { useOrderTableColumns } from "@hooks/table/columns/use-order-table-columns";
-import { useOrderTableQuery } from "@hooks/table/query/use-order-table-query";
-import { useDataTable } from "@hooks/use-data-table";
-import { useOrderTableFilters } from "@hooks/table/filters";
-
-const PAGE_SIZE = 10;
-
-export const OrderListTable = () => {
- const { t } = useTranslation();
- const { raw, searchParams } = useOrderTableQuery({
- pageSize: PAGE_SIZE,
- });
-
- const { orders, count, isError, error, isLoading } = useOrders({
- fields: [
- "id",
- "status",
- "created_at",
- "email",
- "display_id",
- "custom_display_id",
- "payment_status",
- "fulfillment_status",
- "total",
- "currency_code",
- "*customer",
- "*sales_channel",
- "*payment_collections",
- ].join(","),
- ...searchParams,
- });
-
- const columns = useOrderTableColumns({});
- const filters = useOrderTableFilters();
-
- const { table } = useDataTable({
- data: orders ?? [],
- columns,
- enablePagination: true,
- count: count,
- pageSize: PAGE_SIZE,
- });
-
- if (isError) {
- throw error;
- }
+import { OrderListHeader } from "./order-list-header";
+import { OrderListDataTable } from "./order-list-data-table";
+export const OrderListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading>{t("orders.domain")}</Heading>
- </div>
- <_DataTable
- columns={columns}
- table={table}
- pagination
- filters={filters}
- navigateTo={(row) => `/orders/${row.original.id}`}
- count={count}
- isLoading={isLoading}
- pageSize={PAGE_SIZE}
- orderBy={[
- {
- key: "display_id",
- label: t("orders.fields.displayId"),
- },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- queryObject={raw}
- noRecords={{
- message: t("orders.list.noRecordsMessage"),
- }}
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <OrderListHeader />
+ <OrderListDataTable />
+ </>
+ )}
</Container>
);
};
diff --git a/packages/vendor/src/pages/orders/index.ts b/packages/vendor/src/pages/orders/index.ts
new file mode 100644
index 000000000..d525bcdff
--- /dev/null
+++ b/packages/vendor/src/pages/orders/index.ts
@@ -0,0 +1 @@
+export * from './order-list-page'
diff --git a/packages/vendor/src/pages/orders/index.tsx b/packages/vendor/src/pages/orders/index.tsx
deleted file mode 100644
index 123190a3d..000000000
--- a/packages/vendor/src/pages/orders/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /orders
-import { SingleColumnPage } from "@components/layout/pages";
-import { OrderListTable } from "./_components/order-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage hasOutlet={false}>
- <OrderListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/orders/order-list-page.tsx b/packages/vendor/src/pages/orders/order-list-page.tsx
new file mode 100644
index 000000000..00642a936
--- /dev/null
+++ b/packages/vendor/src/pages/orders/order-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ OrderListTable,
+ OrderListDataTable,
+ OrderListHeader,
+ OrderListActions,
+ OrderListTitle,
+} from "./_components/order-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage>
+ {Children.count(children) > 0 ? children : <OrderListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const OrderListPage = Object.assign(Root, {
+ Table: OrderListTable,
+ Header: OrderListHeader,
+ HeaderTitle: OrderListTitle,
+ HeaderActions: OrderListActions,
+ DataTable: OrderListDataTable,
+});
diff --git a/packages/vendor/src/pages/payouts/[id]/breadcrumb.tsx b/packages/vendor/src/pages/payouts/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..3d4dfc498
--- /dev/null
+++ b/packages/vendor/src/pages/payouts/[id]/breadcrumb.tsx
@@ -0,0 +1,17 @@
+import { UIMatch } from "react-router-dom";
+
+import { usePayout } from "@hooks/api/payouts";
+
+export const Breadcrumb = (props: UIMatch) => {
+ const { id } = props.params || {};
+
+ const { payout } = usePayout(id!, undefined, {
+ enabled: Boolean(id),
+ });
+
+ if (!payout) {
+ return null;
+ }
+
+ return <span>#{payout.display_id}</span>;
+};
diff --git a/packages/vendor/src/pages/payouts/[id]/index.ts b/packages/vendor/src/pages/payouts/[id]/index.ts
new file mode 100644
index 000000000..a860ebf5f
--- /dev/null
+++ b/packages/vendor/src/pages/payouts/[id]/index.ts
@@ -0,0 +1 @@
+export * from './payout-detail-page'
diff --git a/packages/vendor/src/pages/payouts/[id]/index.tsx b/packages/vendor/src/pages/payouts/[id]/payout-detail-page.tsx
similarity index 59%
rename from packages/vendor/src/pages/payouts/[id]/index.tsx
rename to packages/vendor/src/pages/payouts/[id]/payout-detail-page.tsx
index e88dbb698..2957eebb8 100644
--- a/packages/vendor/src/pages/payouts/[id]/index.tsx
+++ b/packages/vendor/src/pages/payouts/[id]/payout-detail-page.tsx
@@ -1,4 +1,5 @@
-import { UIMatch, useParams } from "react-router-dom";
+import { Children, ReactNode } from "react";
+import { useParams } from "react-router-dom";
import { SingleColumnPageSkeleton } from "@components/common/skeleton";
import { SingleColumnPage } from "@components/layout/pages";
@@ -6,21 +7,7 @@ import { usePayout } from "@hooks/api/payouts";
import { PayoutGeneralSection } from "./_components/payout-general-section";
-export const Breadcrumb = (props: UIMatch) => {
- const { id } = props.params || {};
-
- const { payout } = usePayout(id!, undefined, {
- enabled: Boolean(id),
- });
-
- if (!payout) {
- return null;
- }
-
- return <span>#{payout.display_id}</span>;
-};
-
-export const Component = () => {
+const Root = ({ children }: { children?: ReactNode }) => {
const { id } = useParams();
const { payout, isLoading, isError, error } = usePayout(id!);
@@ -35,7 +22,15 @@ export const Component = () => {
return (
<SingleColumnPage showMetadata>
- <PayoutGeneralSection payout={payout} />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <PayoutGeneralSection payout={payout} />
+ )}
</SingleColumnPage>
);
};
+
+export const PayoutDetailPage = Object.assign(Root, {
+ GeneralSection: PayoutGeneralSection,
+});
diff --git a/packages/vendor/src/pages/payouts/_components/payout-list-table/index.ts b/packages/vendor/src/pages/payouts/_components/payout-list-table/index.ts
index acbca8a1b..97c86353c 100644
--- a/packages/vendor/src/pages/payouts/_components/payout-list-table/index.ts
+++ b/packages/vendor/src/pages/payouts/_components/payout-list-table/index.ts
@@ -1 +1,3 @@
export * from "./payout-list-table"
+export * from "./payout-list-header"
+export * from "./payout-list-data-table"
diff --git a/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-data-table.tsx b/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-data-table.tsx
new file mode 100644
index 000000000..1fd676aa2
--- /dev/null
+++ b/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-data-table.tsx
@@ -0,0 +1,67 @@
+import { useTranslation } from "react-i18next";
+import { keepPreviousData } from "@tanstack/react-query";
+
+import { _DataTable } from "@components/table/data-table/data-table";
+import { usePayouts } from "@hooks/api/payouts";
+import { usePayoutTableColumns } from "@hooks/table/columns/use-payout-table-columns";
+import { usePayoutTableQuery } from "@hooks/table/query/use-payout-table-query";
+import { useDataTable } from "@hooks/use-data-table";
+import { usePayoutTableFilters } from "@hooks/table/filters/use-payout-table-filters";
+
+const PAGE_SIZE = 10;
+
+export const PayoutListDataTable = () => {
+ const { t } = useTranslation();
+ const { raw, searchParams } = usePayoutTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+
+ const { payouts, count, isError, error, isLoading } = usePayouts(
+ searchParams,
+ {
+ initialData: keepPreviousData,
+ },
+ );
+
+ const columns = usePayoutTableColumns();
+ const filters = usePayoutTableFilters();
+
+ const { table } = useDataTable({
+ data: payouts ?? [],
+ columns,
+ enablePagination: true,
+ count: count,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ columns={columns}
+ table={table}
+ pagination
+ filters={filters}
+ navigateTo={(row) => `/payouts/${row.original.id}`}
+ count={count}
+ isLoading={isLoading}
+ pageSize={PAGE_SIZE}
+ orderBy={[
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ queryObject={raw}
+ noRecords={{
+ message: "No payouts found",
+ }}
+ />
+ );
+};
diff --git a/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-header.tsx b/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-header.tsx
new file mode 100644
index 000000000..58beec62e
--- /dev/null
+++ b/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-header.tsx
@@ -0,0 +1,34 @@
+import { Children, ReactNode } from "react";
+import { Heading } from "@medusajs/ui";
+
+export const PayoutListTitle = () => {
+ return <Heading>Payouts</Heading>;
+};
+
+export const PayoutListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? children : null}
+ </div>
+ );
+};
+
+export const PayoutListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <PayoutListTitle />
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-table.tsx b/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-table.tsx
index 8cf7868a9..300d9f15d 100644
--- a/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-table.tsx
+++ b/packages/vendor/src/pages/payouts/_components/payout-list-table/payout-list-table.tsx
@@ -1,73 +1,20 @@
-import { Container, Heading } from "@medusajs/ui";
-import { useTranslation } from "react-i18next";
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-import { _DataTable } from "@components/table/data-table/data-table";
-import { usePayouts } from "@hooks/api/payouts";
-import { usePayoutTableColumns } from "@hooks/table/columns/use-payout-table-columns";
-import { usePayoutTableQuery } from "@hooks/table/query/use-payout-table-query";
-import { useDataTable } from "@hooks/use-data-table";
-import { usePayoutTableFilters } from "@hooks/table/filters/use-payout-table-filters";
-import { keepPreviousData } from "@tanstack/react-query";
-
-const PAGE_SIZE = 10;
-
-export const PayoutListTable = () => {
- const { t } = useTranslation();
- const { raw, searchParams } = usePayoutTableQuery({
- pageSize: PAGE_SIZE,
- });
-
- const { payouts, count, isError, error, isLoading } = usePayouts(
- searchParams,
- {
- initialData: keepPreviousData,
- },
- );
-
- const columns = usePayoutTableColumns();
- const filters = usePayoutTableFilters();
-
- const { table } = useDataTable({
- data: payouts ?? [],
- columns,
- enablePagination: true,
- count: count,
- pageSize: PAGE_SIZE,
- });
-
- if (isError) {
- throw error;
- }
+import { PayoutListHeader } from "./payout-list-header";
+import { PayoutListDataTable } from "./payout-list-data-table";
+export const PayoutListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading>Payouts</Heading>
- </div>
- <_DataTable
- columns={columns}
- table={table}
- pagination
- filters={filters}
- navigateTo={(row) => `/payouts/${row.original.id}`}
- count={count}
- isLoading={isLoading}
- pageSize={PAGE_SIZE}
- orderBy={[
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- queryObject={raw}
- noRecords={{
- message: "No payouts found",
- }}
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <PayoutListHeader />
+ <PayoutListDataTable />
+ </>
+ )}
</Container>
);
};
diff --git a/packages/vendor/src/pages/payouts/index.ts b/packages/vendor/src/pages/payouts/index.ts
new file mode 100644
index 000000000..40c6476a0
--- /dev/null
+++ b/packages/vendor/src/pages/payouts/index.ts
@@ -0,0 +1 @@
+export * from './payout-list-page'
diff --git a/packages/vendor/src/pages/payouts/index.tsx b/packages/vendor/src/pages/payouts/index.tsx
deleted file mode 100644
index 116922e39..000000000
--- a/packages/vendor/src/pages/payouts/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /payouts
-import { SingleColumnPage } from "@components/layout/pages"
-import { PayoutListTable } from "./_components/payout-list-table"
-
-export const Component = () => {
- return (
- <SingleColumnPage hasOutlet={false}>
- <PayoutListTable />
- </SingleColumnPage>
- )
-}
diff --git a/packages/vendor/src/pages/payouts/payout-list-page.tsx b/packages/vendor/src/pages/payouts/payout-list-page.tsx
new file mode 100644
index 000000000..b42232c83
--- /dev/null
+++ b/packages/vendor/src/pages/payouts/payout-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ PayoutListTable,
+ PayoutListDataTable,
+ PayoutListHeader,
+ PayoutListActions,
+ PayoutListTitle,
+} from "./_components/payout-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage>
+ {Children.count(children) > 0 ? children : <PayoutListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const PayoutListPage = Object.assign(Root, {
+ Table: PayoutListTable,
+ Header: PayoutListHeader,
+ HeaderTitle: PayoutListTitle,
+ HeaderActions: PayoutListActions,
+ DataTable: PayoutListDataTable,
+});
diff --git a/packages/vendor/src/pages/price-lists/[id]/breadcrumb.tsx b/packages/vendor/src/pages/price-lists/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..935af0415
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/[id]/breadcrumb.tsx
@@ -0,0 +1,21 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { usePriceList } from "@hooks/api/price-lists";
+
+type PriceListDetailBreadcrumbProps = UIMatch<HttpTypes.AdminPriceListResponse>;
+
+export const Breadcrumb = (props: PriceListDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+
+ const { price_list } = usePriceList(id!, undefined, {
+ initialData: props.data,
+ enabled: Boolean(id),
+ });
+
+ if (!price_list) {
+ return null;
+ }
+
+ return <span>{price_list.title}</span>;
+};
diff --git a/packages/vendor/src/pages/price-lists/[id]/index.ts b/packages/vendor/src/pages/price-lists/[id]/index.ts
new file mode 100644
index 000000000..640b3640b
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './price-list-detail-page'
diff --git a/packages/vendor/src/pages/price-lists/[id]/index.tsx b/packages/vendor/src/pages/price-lists/[id]/index.tsx
deleted file mode 100644
index 8b044b095..000000000
--- a/packages/vendor/src/pages/price-lists/[id]/index.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-// Route: /price-lists/:id
-import { useParams, LoaderFunctionArgs } from "react-router-dom"
-import { HttpTypes } from "@medusajs/types"
-import { UIMatch } from "react-router-dom"
-import { TwoColumnPageSkeleton } from "@components/common/skeleton"
-import { TwoColumnPage } from "@components/layout/pages"
-import { useDashboardExtension } from "@/extensions"
-import { usePriceList, priceListsQueryKeys } from "@hooks/api/price-lists"
-import { fetchQuery } from "@lib/client"
-import { queryClient } from "@lib/query-client"
-import { PriceListConfigurationSection } from "./_components/price-list-configuration-section"
-import { PriceListGeneralSection } from "./_components/price-list-general-section"
-import { PriceListProductSection } from "./_components/price-list-product-section"
-
-const pricingDetailQuery = (id: string) => ({
- queryKey: priceListsQueryKeys.detail(id),
- queryFn: async () =>
- await fetchQuery(`/vendor/price-lists/${id}`, {
- method: "GET",
- }),
-})
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id
- const query = pricingDetailQuery(id!)
-
- return queryClient.ensureQueryData(query)
-}
-
-type PriceListDetailBreadcrumbProps = UIMatch<HttpTypes.AdminPriceListResponse>
-
-export const Breadcrumb = (props: PriceListDetailBreadcrumbProps) => {
- const { id } = props.params || {}
-
- const { price_list } = usePriceList(id!, undefined, {
- initialData: props.data,
- enabled: Boolean(id),
- })
-
- if (!price_list) {
- return null
- }
-
- return <span>{price_list.title}</span>
-}
-
-export const Component = () => {
- const { id } = useParams()
-
- const { price_list, isLoading, isError, error } = usePriceList(id!)
-
- if (isLoading || !price_list) {
- return (
- <TwoColumnPageSkeleton mainSections={2} sidebarSections={1} showJSON />
- )
- }
-
- if (isError) {
- throw error
- }
-
- return (
- <TwoColumnPage
- data={price_list}
- >
- <TwoColumnPage.Main>
- <PriceListGeneralSection priceList={price_list} />
- <PriceListProductSection priceList={price_list} />
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <PriceListConfigurationSection priceList={price_list} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- )
-}
diff --git a/packages/vendor/src/pages/price-lists/[id]/loader.tsx b/packages/vendor/src/pages/price-lists/[id]/loader.tsx
new file mode 100644
index 000000000..02b59dd31
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/[id]/loader.tsx
@@ -0,0 +1,20 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { priceListsQueryKeys } from "@hooks/api/price-lists";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+const pricingDetailQuery = (id: string) => ({
+ queryKey: priceListsQueryKeys.detail(id),
+ queryFn: async () =>
+ await fetchQuery(`/vendor/price-lists/${id}`, {
+ method: "GET",
+ }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = pricingDetailQuery(id!);
+
+ return queryClient.ensureQueryData(query);
+};
diff --git a/packages/vendor/src/pages/price-lists/[id]/price-list-detail-page.tsx b/packages/vendor/src/pages/price-lists/[id]/price-list-detail-page.tsx
new file mode 100644
index 000000000..c8efd379e
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/[id]/price-list-detail-page.tsx
@@ -0,0 +1,57 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { TwoColumnPageSkeleton } from "@components/common/skeleton";
+import { TwoColumnPage } from "@components/layout/pages";
+import { usePriceList } from "@hooks/api/price-lists";
+
+import { PriceListConfigurationSection } from "./_components/price-list-configuration-section";
+import { PriceListGeneralSection } from "./_components/price-list-general-section";
+import { PriceListProductSection } from "./_components/price-list-product-section";
+
+import type { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { id } = useParams();
+
+ const { price_list, isLoading, isError, error } = usePriceList(id!, undefined, {
+ placeholderData: initialData,
+ });
+
+ if (isLoading || !price_list) {
+ return (
+ <TwoColumnPageSkeleton mainSections={2} sidebarSections={1} showJSON />
+ );
+ }
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage hasOutlet data={price_list}>
+ <TwoColumnPage.Main>
+ <PriceListGeneralSection priceList={price_list} />
+ <PriceListProductSection priceList={price_list} />
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <PriceListConfigurationSection priceList={price_list} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
+ );
+};
+
+export const PriceListDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: PriceListGeneralSection,
+ MainProductSection: PriceListProductSection,
+ SidebarConfigurationSection: PriceListConfigurationSection,
+});
diff --git a/packages/vendor/src/pages/price-lists/_components/price-list-list-table/index.ts b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/index.ts
index 1ca9698bc..6b205cbce 100644
--- a/packages/vendor/src/pages/price-lists/_components/price-list-list-table/index.ts
+++ b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/index.ts
@@ -1 +1,3 @@
export * from "./price-list-list-table"
+export * from "./price-list-list-header"
+export * from "./price-list-list-data-table"
diff --git a/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-data-table.tsx b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-data-table.tsx
new file mode 100644
index 000000000..d6419f1a3
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-data-table.tsx
@@ -0,0 +1,67 @@
+import { keepPreviousData } from "@tanstack/react-query";
+import { useTranslation } from "react-i18next";
+import { _DataTable } from "@components/table/data-table";
+import { usePriceLists } from "@hooks/api/price-lists";
+import { useDataTable } from "@hooks/use-data-table";
+import { usePricingTableColumns } from "./use-pricing-table-columns";
+import { usePricingTableFilters } from "./use-pricing-table-filters";
+import { usePricingTableQuery } from "./use-pricing-table-query";
+
+const PAGE_SIZE = 20;
+
+export const PriceListListDataTable = () => {
+ const { t } = useTranslation();
+
+ const { searchParams, raw } = usePricingTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+ const { price_lists, count, isLoading, isError, error } = usePriceLists(
+ searchParams,
+ {
+ placeholderData: keepPreviousData,
+ },
+ );
+
+ const filters = usePricingTableFilters();
+ const columns = usePricingTableColumns();
+
+ const { table } = useDataTable({
+ data: price_lists || [],
+ columns,
+ count,
+ enablePagination: true,
+ getRowId: (row) => row.id,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ columns={columns}
+ count={count}
+ filters={filters}
+ orderBy={[
+ { key: "title", label: t("fields.title") },
+ { key: "status", label: t("fields.status") },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ queryObject={raw}
+ pageSize={PAGE_SIZE}
+ navigateTo={(row) => row.original.id}
+ isLoading={isLoading}
+ pagination
+ search
+ />
+ );
+};
diff --git a/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-header.tsx b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-header.tsx
new file mode 100644
index 000000000..226570464
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-header.tsx
@@ -0,0 +1,60 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Link } from "react-router-dom";
+import { Button, Heading, Text } from "@medusajs/ui";
+
+export const PriceListListTitle = () => {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Heading>{t("priceLists.domain")}</Heading>
+ <Text className="text-ui-fg-subtle" size="small">
+ {t("priceLists.subtitle")}
+ </Text>
+ </div>
+ );
+};
+
+export const PriceListListCreateButton = () => {
+ const { t } = useTranslation();
+ return (
+ <Button size="small" variant="secondary" asChild>
+ <Link to="create">{t("actions.create")}</Link>
+ </Button>
+ );
+};
+
+export const PriceListListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <PriceListListCreateButton />
+ )}
+ </div>
+ );
+};
+
+export const PriceListListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <PriceListListTitle />
+ <PriceListListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-table.tsx b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-table.tsx
index ace59eaf7..3c0707c0f 100644
--- a/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-table.tsx
+++ b/packages/vendor/src/pages/price-lists/_components/price-list-list-table/price-list-list-table.tsx
@@ -1,82 +1,20 @@
-import { Button, Container, Heading, Text } from "@medusajs/ui";
-import { keepPreviousData } from "@tanstack/react-query";
-import { useTranslation } from "react-i18next";
-import { Link } from "react-router-dom";
-import { _DataTable } from "@components/table/data-table";
-import { usePriceLists } from "@hooks/api/price-lists";
-import { useDataTable } from "@hooks/use-data-table";
-import { usePricingTableColumns } from "./use-pricing-table-columns";
-import { usePricingTableFilters } from "./use-pricing-table-filters";
-import { usePricingTableQuery } from "./use-pricing-table-query";
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-const PAGE_SIZE = 20;
-
-export const PriceListListTable = () => {
- const { t } = useTranslation();
-
- const { searchParams, raw } = usePricingTableQuery({
- pageSize: PAGE_SIZE,
- });
- const { price_lists, count, isLoading, isError, error } = usePriceLists(
- searchParams,
- {
- placeholderData: keepPreviousData,
- },
- );
-
- const filters = usePricingTableFilters();
- const columns = usePricingTableColumns();
-
- const { table } = useDataTable({
- data: price_lists || [],
- columns,
- count,
- enablePagination: true,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- });
-
- if (isError) {
- throw error;
- }
+import { PriceListListHeader } from "./price-list-list-header";
+import { PriceListListDataTable } from "./price-list-list-data-table";
+export const PriceListListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("priceLists.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- {t("priceLists.subtitle")}
- </Text>
- </div>
- <Button size="small" variant="secondary" asChild>
- <Link to="create">{t("actions.create")}</Link>
- </Button>
- </div>
- <_DataTable
- table={table}
- columns={columns}
- count={count}
- filters={filters}
- orderBy={[
- { key: "title", label: t("fields.title") },
- { key: "status", label: t("fields.status") },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- queryObject={raw}
- pageSize={PAGE_SIZE}
- navigateTo={(row) => row.original.id}
- isLoading={isLoading}
- pagination
- search
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <PriceListListHeader />
+ <PriceListListDataTable />
+ </>
+ )}
</Container>
);
};
diff --git a/packages/vendor/src/pages/price-lists/index.ts b/packages/vendor/src/pages/price-lists/index.ts
new file mode 100644
index 000000000..3c8b0bd32
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/index.ts
@@ -0,0 +1 @@
+export * from './price-list-list-page'
diff --git a/packages/vendor/src/pages/price-lists/index.tsx b/packages/vendor/src/pages/price-lists/index.tsx
deleted file mode 100644
index 90a05d323..000000000
--- a/packages/vendor/src/pages/price-lists/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /price-lists
-import { SingleColumnPage } from "@components/layout/pages";
-import { PriceListListTable } from "./_components/price-list-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage>
- <PriceListListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/price-lists/price-list-list-page.tsx b/packages/vendor/src/pages/price-lists/price-list-list-page.tsx
new file mode 100644
index 000000000..9e38f2b20
--- /dev/null
+++ b/packages/vendor/src/pages/price-lists/price-list-list-page.tsx
@@ -0,0 +1,29 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ PriceListListTable,
+ PriceListListDataTable,
+ PriceListListHeader,
+ PriceListListActions,
+ PriceListListTitle,
+ PriceListListCreateButton,
+} from "./_components/price-list-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage hasOutlet>
+ {Children.count(children) > 0 ? children : <PriceListListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const PriceListListPage = Object.assign(Root, {
+ Table: PriceListListTable,
+ Header: PriceListListHeader,
+ HeaderTitle: PriceListListTitle,
+ HeaderActions: PriceListListActions,
+ HeaderCreateButton: PriceListListCreateButton,
+ DataTable: PriceListListDataTable,
+});
diff --git a/packages/vendor/src/pages/products/[id]/breadcrumb.tsx b/packages/vendor/src/pages/products/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..88003fc60
--- /dev/null
+++ b/packages/vendor/src/pages/products/[id]/breadcrumb.tsx
@@ -0,0 +1,16 @@
+import { useProduct } from "@/hooks/api/products";
+import { UIMatch } from "react-router-dom";
+
+type ProductDetailBreadcrumbProps = UIMatch<ExtendedAdminProductResponse>;
+
+export const Breadcrumb = (props: ProductDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+
+ const { product } = useProduct(id!);
+
+ if (!product) {
+ return null;
+ }
+
+ return <span>{product?.title}</span>;
+};
diff --git a/packages/vendor/src/pages/products/[id]/index.ts b/packages/vendor/src/pages/products/[id]/index.ts
new file mode 100644
index 000000000..045d40546
--- /dev/null
+++ b/packages/vendor/src/pages/products/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './product-detail-page'
\ No newline at end of file
diff --git a/packages/vendor/src/pages/products/[id]/index.tsx b/packages/vendor/src/pages/products/[id]/index.tsx
deleted file mode 100644
index 3e01160f9..000000000
--- a/packages/vendor/src/pages/products/[id]/index.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-// Route: /products/:id
-import { UIMatch } from "react-router-dom";
-import { LoaderFunctionArgs } from "react-router-dom";
-
-import { useProduct } from "@hooks/api";
-import { productsQueryKeys } from "@hooks/api/products";
-import { sdk } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-import { ExtendedAdminProductResponse } from "@custom-types/products";
-
-import { ProductDetailPage } from "./product-detail-page";
-
-// Loader
-const productDetailQuery = (id: string) => ({
- queryKey: productsQueryKeys.detail(id),
- queryFn: async () => sdk.vendor.products.$id.query({ $id: id }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- const query = productDetailQuery(id!);
-
- const response = await queryClient.ensureQueryData({
- ...query,
- staleTime: 90000,
- });
-
- return response;
-};
-
-// Breadcrumb
-type ProductDetailBreadcrumbProps = UIMatch<ExtendedAdminProductResponse>;
-
-export const Breadcrumb = (props: ProductDetailBreadcrumbProps) => {
- const { id } = props.params || {};
-
- const { product } = useProduct(id!);
-
- if (!product) {
- return null;
- }
-
- return <span>{product?.title}</span>;
-};
-
-// Main component
-export const Component = () => {
- return <ProductDetailPage />;
-};
diff --git a/packages/vendor/src/pages/products/[id]/loader.tsx b/packages/vendor/src/pages/products/[id]/loader.tsx
new file mode 100644
index 000000000..6310da1a0
--- /dev/null
+++ b/packages/vendor/src/pages/products/[id]/loader.tsx
@@ -0,0 +1,22 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { productsQueryKeys } from "@hooks/api/products";
+import { sdk } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+const productDetailQuery = (id: string) => ({
+ queryKey: productsQueryKeys.detail(id),
+ queryFn: async () => sdk.vendor.products.$id.query({ $id: id }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ const query = productDetailQuery(id!);
+
+ const response = await queryClient.ensureQueryData({
+ ...query,
+ staleTime: 90000,
+ });
+
+ return response;
+};
diff --git a/packages/vendor/src/pages/products/[id]/product-detail-page.tsx b/packages/vendor/src/pages/products/[id]/product-detail-page.tsx
index 0687f538d..ce09ca052 100644
--- a/packages/vendor/src/pages/products/[id]/product-detail-page.tsx
+++ b/packages/vendor/src/pages/products/[id]/product-detail-page.tsx
@@ -52,14 +52,16 @@ const Root = ({ children }: { children?: ReactNode }) => {
};
export const ProductDetailPage = Object.assign(Root, {
- GeneralSection: ProductGeneralSection,
- MediaSection: ProductMediaSection,
- OptionSection: ProductOptionSection,
- VariantSection: ProductVariantSection,
- OrganizationSection: ProductOrganizationSection,
- AttributeSection: ProductAttributeSection,
- AdditionalAttributeSection: ProductAdditionalAttributesSection,
- ShippingProfileSection: ProductShippingProfileSection,
- SalesChannelSection: ProductSalesChannelSection,
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: ProductGeneralSection,
+ MainMediaSection: ProductMediaSection,
+ MainOptionSection: ProductOptionSection,
+ MainVariantSection: ProductVariantSection,
+ MainAttributeSection: ProductAttributeSection,
+ MainAdditionalAttributeSection: ProductAdditionalAttributesSection,
+ SidebarShippingProfileSection: ProductShippingProfileSection,
+ SidebarOrganizationSection: ProductOrganizationSection,
+ SidebarSalesChannelSection: ProductSalesChannelSection,
useContext: useProductDetailContext,
});
diff --git a/packages/vendor/src/pages/products/_components/product-list-table/product-list-data-table.tsx b/packages/vendor/src/pages/products/_components/product-list-table/product-list-data-table.tsx
index b8867e2a5..a4d47ccf9 100644
--- a/packages/vendor/src/pages/products/_components/product-list-table/product-list-data-table.tsx
+++ b/packages/vendor/src/pages/products/_components/product-list-table/product-list-data-table.tsx
@@ -1,57 +1,55 @@
-import { Checkbox, toast, usePrompt } from "@medusajs/ui"
-import { keepPreviousData } from "@tanstack/react-query"
+import { Checkbox, toast, usePrompt } from "@medusajs/ui";
+import { keepPreviousData } from "@tanstack/react-query";
import {
createColumnHelper,
OnChangeFn,
RowSelectionState,
-} from "@tanstack/react-table"
-import { useMemo, useState } from "react"
-import { useTranslation } from "react-i18next"
-import { Trash } from "@medusajs/icons"
-
-import { ExtendedAdminProduct } from "@custom-types/products"
-import { ActionMenu } from "@components/common/action-menu"
-import { _DataTable } from "@components/table/data-table"
+} from "@tanstack/react-table";
+import { useMemo, useState } from "react";
+import { useTranslation } from "react-i18next";
+import { Trash } from "@medusajs/icons";
+
+import { ExtendedAdminProduct } from "@custom-types/products";
+import { ActionMenu } from "@components/common/action-menu";
+import { _DataTable } from "@components/table/data-table";
import {
useDeleteProduct,
useBulkDeleteProducts,
useProducts,
-} from "@hooks/api/products"
-import { useProductTableColumns } from "@hooks/table/columns/use-product-table-columns"
-import { useProductTableFilters } from "@hooks/table/filters/use-product-table-filters"
-import { useProductTableQuery } from "@hooks/table/query/use-product-table-query"
-import { useDataTable } from "@hooks/use-data-table"
+} from "@hooks/api/products";
+import { useProductTableColumns } from "@hooks/table/columns/use-product-table-columns";
+import { useProductTableFilters } from "@hooks/table/filters/use-product-table-filters";
+import { useProductTableQuery } from "@hooks/table/query/use-product-table-query";
+import { useDataTable } from "@hooks/use-data-table";
-export const PAGE_SIZE = 10
+export const PAGE_SIZE = 10;
export const ProductListDataTable = () => {
- const { t } = useTranslation()
+ const { t } = useTranslation();
- const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
+ const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
const updater: OnChangeFn<RowSelectionState> = (newSelection) => {
const update =
typeof newSelection === "function"
? newSelection(rowSelection)
- : newSelection
- setRowSelection(update)
- }
+ : newSelection;
+ setRowSelection(update);
+ };
const { searchParams, raw } = useProductTableQuery({
pageSize: PAGE_SIZE,
- })
-
- const options = {
- placeholderData: keepPreviousData,
- }
+ });
const { products, count, isLoading, isError, error } = useProducts(
searchParams,
- options
- )
+ {
+ placeholderData: keepPreviousData,
+ },
+ );
- const filters = useProductTableFilters()
- const columns = useColumns()
+ const filters = useProductTableFilters();
+ const columns = useColumns();
const { table } = useDataTable({
data: products,
@@ -65,16 +63,16 @@ export const ProductListDataTable = () => {
state: rowSelection,
updater,
},
- })
+ });
- const { mutateAsync } = useBulkDeleteProducts()
- const prompt = usePrompt()
+ const { mutateAsync } = useBulkDeleteProducts();
+ const prompt = usePrompt();
const handleDelete = async () => {
- const keys = Object.keys(rowSelection)
+ const keys = Object.keys(rowSelection);
if (keys.length === 0) {
- return
+ return;
}
const res = await prompt({
@@ -84,31 +82,31 @@ export const ProductListDataTable = () => {
}),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
- })
+ });
if (!res) {
- return
+ return;
}
await mutateAsync(keys, {
onSuccess: () => {
- setRowSelection({})
+ setRowSelection({});
toast.success(
t("products.bulkDelete.success", {
count: keys.length,
- })
- )
+ }),
+ );
},
onError: (error) => {
toast.error(t("products.bulkDelete.error"), {
description: error.message,
- })
+ });
},
- })
- }
+ });
+ };
if (isError) {
- throw error
+ throw error;
}
return (
@@ -150,13 +148,13 @@ export const ProductListDataTable = () => {
},
}}
/>
- )
-}
+ );
+};
const ProductActions = ({ product }: { product: ExtendedAdminProduct }) => {
- const { t } = useTranslation()
- const prompt = usePrompt()
- const { mutateAsync } = useDeleteProduct(product.id)
+ const { t } = useTranslation();
+ const prompt = usePrompt();
+ const { mutateAsync } = useDeleteProduct(product.id);
const handleDelete = async () => {
const res = await prompt({
@@ -166,10 +164,10 @@ const ProductActions = ({ product }: { product: ExtendedAdminProduct }) => {
}),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
- })
+ });
if (!res) {
- return
+ return;
}
await mutateAsync(undefined, {
@@ -178,15 +176,15 @@ const ProductActions = ({ product }: { product: ExtendedAdminProduct }) => {
description: t("products.toasts.delete.success.description", {
title: product.title,
}),
- })
+ });
},
onError: (e) => {
toast.error(t("products.toasts.delete.error.header"), {
description: e.message,
- })
+ });
},
- })
- }
+ });
+ };
return (
<ActionMenu
@@ -202,14 +200,14 @@ const ProductActions = ({ product }: { product: ExtendedAdminProduct }) => {
},
]}
/>
- )
-}
+ );
+};
-const columnHelper = createColumnHelper<ExtendedAdminProduct>()
+const columnHelper = createColumnHelper<ExtendedAdminProduct>();
const useColumns = () => {
- const { t } = useTranslation()
- const base = useProductTableColumns()
+ const { t } = useTranslation();
+ const base = useProductTableColumns();
const columns = useMemo(
() => [
@@ -227,7 +225,7 @@ const useColumns = () => {
table.toggleAllPageRowsSelected(!!value)
}
/>
- )
+ );
},
cell: ({ row }) => {
return (
@@ -235,22 +233,22 @@ const useColumns = () => {
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
onClick={(e) => {
- e.stopPropagation()
+ e.stopPropagation();
}}
/>
- )
+ );
},
}),
...base,
columnHelper.display({
id: "actions",
cell: ({ row }) => {
- return <ProductActions product={row.original} />
+ return <ProductActions product={row.original} />;
},
}),
],
- [base, t]
- )
+ [base, t],
+ );
- return columns
-}
+ return columns;
+};
diff --git a/packages/vendor/src/pages/products/create/index.ts b/packages/vendor/src/pages/products/create/index.ts
new file mode 100644
index 000000000..86a2be1b2
--- /dev/null
+++ b/packages/vendor/src/pages/products/create/index.ts
@@ -0,0 +1 @@
+export * from "./product-create-page";
\ No newline at end of file
diff --git a/packages/vendor/src/pages/products/create/index.tsx b/packages/vendor/src/pages/products/create/index.tsx
deleted file mode 100644
index 76f16e2f6..000000000
--- a/packages/vendor/src/pages/products/create/index.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-// Route: /products/create
-import { ProductCreatePage } from "./product-create-page"
-
-export const Component = () => {
- return <ProductCreatePage />
-}
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.tsx
index fde23d112..81009b675 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
@@ -140,7 +140,7 @@ export const ProductCreateForm = ({
await mutateAsync(
{
...payload,
- status: isDraftSubmission ? "draft" : "proposed",
+ status: isDraftSubmission ? "draft" : "published",
images: uploadedMedia,
weight: parseInt(payload.weight || "") || undefined,
length: parseInt(payload.length || "") || undefined,
diff --git a/packages/vendor/src/pages/products/create/product-create-page.tsx b/packages/vendor/src/pages/products/create/product-create-page.tsx
index 2e2c0b0b2..fbff03661 100644
--- a/packages/vendor/src/pages/products/create/product-create-page.tsx
+++ b/packages/vendor/src/pages/products/create/product-create-page.tsx
@@ -1,26 +1,71 @@
-import { Children, ReactNode } from "react"
-import { useTranslation } from "react-i18next"
+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 { RouteFocusModal } from "@components/modals"
-import { useSalesChannels } from "@hooks/api"
-import { useStore } from "@hooks/api/store"
+export const ProductCreate = () => {
+ const { t } = useTranslation();
-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 { useProductCreateContext } from "./context"
+ const {
+ store,
+ isPending: isStorePending,
+ isError: isStoreError,
+ error: storeError,
+ } = useStore({
+ fields: "+default_sales_channel",
+ });
-const Root = ({ children }: { children?: ReactNode }) => {
- const { t } = useTranslation()
+ const {
+ sales_channel,
+ isPending: isSalesChannelPending,
+ isError: isSalesChannelError,
+ error: salesChannelError,
+ } = useSalesChannel(store?.default_sales_channel_id!);
- const { store, isPending: isStorePending } = useStore()
- const { sales_channels, isPending: isSalesChannelPending } =
- useSalesChannels()
+ const {
+ regions,
+ isPending: isRegionsPending,
+ isError: isRegionsError,
+ error: regionsError,
+ } = useRegions({ limit: 9999 });
+
+ const {
+ price_preferences,
+ isPending: isPricePreferencesPending,
+ isError: isPricePreferencesError,
+ error: pricePreferencesError,
+ } = usePricePreferences({
+ limit: 9999,
+ });
const ready =
- !!store && !isStorePending && !!sales_channels && !isSalesChannelPending
+ !!store &&
+ !isStorePending &&
+ !!regions &&
+ !isRegionsPending &&
+ !!sales_channel &&
+ !isSalesChannelPending &&
+ !!price_preferences &&
+ !isPricePreferencesPending;
+
+ if (isStoreError) {
+ throw storeError;
+ }
+
+ if (isRegionsError) {
+ throw regionsError;
+ }
+
+ if (isSalesChannelError) {
+ throw salesChannelError;
+ }
+
+ if (isPricePreferencesError) {
+ throw pricePreferencesError;
+ }
return (
<RouteFocusModal>
@@ -30,24 +75,14 @@ const Root = ({ children }: { children?: ReactNode }) => {
<RouteFocusModal.Description asChild>
<span className="sr-only">{t("products.create.description")}</span>
</RouteFocusModal.Description>
- {ready &&
- (Children.count(children) > 0 ? (
- children
- ) : (
- <ProductCreateForm
- defaultChannel={sales_channels[0] as any}
- store={store}
- />
- ))}
+ {ready && (
+ <ProductCreateForm
+ defaultChannel={sales_channel}
+ store={store}
+ pricePreferences={price_preferences}
+ regions={regions}
+ />
+ )}
</RouteFocusModal>
- )
-}
-
-export const ProductCreatePage = Object.assign(Root, {
- DetailsForm: ProductCreateDetailsForm,
- OrganizeForm: ProductCreateOrganizeForm,
- VariantsForm: ProductCreateVariantsForm,
- InventoryKitForm: ProductCreateInventoryKitForm,
- Form: ProductCreateForm,
- useContext: useProductCreateContext,
-})
+ );
+};
diff --git a/packages/vendor/src/pages/products/exports.ts b/packages/vendor/src/pages/products/exports.ts
deleted file mode 100644
index e6aeb6ae3..000000000
--- a/packages/vendor/src/pages/products/exports.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export { ProductDetailPage } from "./[id]/product-detail-page"
-export { useProductDetailContext } from "./[id]/context"
-export type { ProductDetailContextValue, ProductDetailData } from "./[id]/context"
-
-export { ProductListPage } from "./product-list-page"
-
-export { ProductCreatePage } from "./create/product-create-page"
-export { useProductCreateContext } from "./create/context"
-export type { ProductCreateContextValue } from "./create/context"
diff --git a/packages/vendor/src/pages/products/index.ts b/packages/vendor/src/pages/products/index.ts
new file mode 100644
index 000000000..10c395a82
--- /dev/null
+++ b/packages/vendor/src/pages/products/index.ts
@@ -0,0 +1 @@
+export * from './product-list-page'
\ No newline at end of file
diff --git a/packages/vendor/src/pages/products/index.tsx b/packages/vendor/src/pages/products/index.tsx
deleted file mode 100644
index 70372b037..000000000
--- a/packages/vendor/src/pages/products/index.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-// Route: /products
-import { QueryClient } from "@tanstack/react-query"
-import { HttpTypes } from "@medusajs/types"
-import { productsQueryKeys } from "@hooks/api/products"
-import { fetchQuery } from "@lib/client"
-import { queryClient } from "@lib/query-client"
-
-import { ProductListPage } from "./product-list-page"
-import { PAGE_SIZE } from "./_components/product-list-table"
-
-// Loader for pre-fetching data
-const productsListQuery = () => ({
- queryKey: productsQueryKeys.list({
- limit: PAGE_SIZE,
- offset: 0,
- }),
- queryFn: async () =>
- fetchQuery("/vendor/products", {
- method: "GET",
- query: {
- limit: PAGE_SIZE,
- offset: 0,
- fields: "+thumbnail,*categories,+status",
- },
- }),
-})
-
-export const loader = (client: QueryClient) => {
- return async () => {
- const query = productsListQuery()
-
- return (
- queryClient.getQueryData<HttpTypes.AdminProductListResponse>(
- query.queryKey
- ) ?? (await client.fetchQuery(query))
- )
- }
-}
-
-// Main component
-export const Component = () => {
- return <ProductListPage />
-}
diff --git a/packages/vendor/src/pages/products/product-list-page.tsx b/packages/vendor/src/pages/products/product-list-page.tsx
index 48c0154fc..4824e3ec6 100644
--- a/packages/vendor/src/pages/products/product-list-page.tsx
+++ b/packages/vendor/src/pages/products/product-list-page.tsx
@@ -20,13 +20,10 @@ const Root = ({ children }: { children?: ReactNode }) => {
};
export const ProductListPage = Object.assign(Root, {
- // Backward compat
Table: ProductListTable,
- // Sections
Header: ProductListHeader,
- Actions: ProductListActions,
+ HeaderTitle: ProductListTitle,
+ HeaderActions: ProductListActions,
+ HeaderCreateButton: ProductListCreateButton,
DataTable: ProductListDataTable,
- // Individual elements
- Title: ProductListTitle,
- CreateButton: ProductListCreateButton,
});
diff --git a/packages/vendor/src/pages/promotions/[id]/breadcrumb.tsx b/packages/vendor/src/pages/promotions/[id]/breadcrumb.tsx
new file mode 100644
index 000000000..5862b3242
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/[id]/breadcrumb.tsx
@@ -0,0 +1,16 @@
+import { HttpTypes } from "@medusajs/types";
+import { UIMatch } from "react-router-dom";
+
+import { usePromotion } from "@hooks/api/promotions";
+
+type PromotionDetailBreadcrumbProps = UIMatch<HttpTypes.AdminPromotionResponse>;
+
+export const Breadcrumb = (props: PromotionDetailBreadcrumbProps) => {
+ const { id } = props.params || {};
+ const { promotion } = usePromotion(id!, {
+ initialData: props.data,
+ enabled: Boolean(id),
+ });
+ if (!promotion) return null;
+ return <span>{promotion.code}</span>;
+};
diff --git a/packages/vendor/src/pages/promotions/[id]/index.ts b/packages/vendor/src/pages/promotions/[id]/index.ts
new file mode 100644
index 000000000..341a9d81d
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './promotion-detail-page'
diff --git a/packages/vendor/src/pages/promotions/[id]/index.tsx b/packages/vendor/src/pages/promotions/[id]/index.tsx
deleted file mode 100644
index cc70f80f3..000000000
--- a/packages/vendor/src/pages/promotions/[id]/index.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-// Route: /promotions/:id
-import { HttpTypes } from "@medusajs/types";
-import {
- UIMatch,
- useLoaderData,
- useParams,
- LoaderFunctionArgs,
-} from "react-router-dom";
-
-import { TwoColumnPageSkeleton } from "@components/common/skeleton";
-import { TwoColumnPage } from "@components/layout/pages";
-import { usePromotion, usePromotionRules } from "@hooks/api/promotions";
-import { promotionsQueryKeys } from "@hooks/api/promotions";
-import { fetchQuery } from "@lib/client";
-import { queryClient } from "@lib/query-client";
-
-import { CampaignSection } from "./_components/campaign-section";
-import { PromotionConditionsSection } from "./_components/promotion-conditions-section";
-import { PromotionGeneralSection } from "./_components/promotion-general-section";
-
-// Loader
-const promotionDetailQuery = (id: string) => ({
- queryKey: promotionsQueryKeys.detail(id),
- queryFn: async () =>
- fetchQuery(`/vendor/promotions/${id}`, {
- method: "GET",
- query: { fields: "+status" },
- }),
-});
-
-export const loader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id;
- return queryClient.ensureQueryData(promotionDetailQuery(id!));
-};
-
-// Breadcrumb
-type PromotionDetailBreadcrumbProps = UIMatch<HttpTypes.AdminPromotionResponse>;
-
-export const Breadcrumb = (props: PromotionDetailBreadcrumbProps) => {
- const { id } = props.params || {};
- const { promotion } = usePromotion(id!, {
- initialData: props.data,
- enabled: Boolean(id),
- });
- if (!promotion) return null;
- return <span>{promotion.code}</span>;
-};
-
-// Main component
-export const Component = () => {
- const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
- const { id } = useParams();
- const { promotion, isLoading } = usePromotion(id!, { initialData });
- const query: Record<string, string> = {};
- if (promotion?.type === "buyget") query.promotion_type = promotion.type;
-
- const { rules } = usePromotionRules(id!, "rules", query);
- const { rules: targetRules } = usePromotionRules(id!, "target-rules", query);
- const { rules: buyRules } = usePromotionRules(id!, "buy-rules", query);
-
- if (isLoading || !promotion)
- return (
- <TwoColumnPageSkeleton mainSections={3} sidebarSections={1} showJSON />
- );
-
- return (
- <TwoColumnPage data={promotion} hasOutlet>
- <TwoColumnPage.Main>
- <PromotionGeneralSection promotion={promotion} />
- <PromotionConditionsSection rules={rules || []} ruleType="rules" />
- <PromotionConditionsSection
- rules={targetRules || []}
- ruleType="target-rules"
- />
- {promotion.type === "buyget" && (
- <PromotionConditionsSection
- rules={buyRules || []}
- ruleType="buy-rules"
- />
- )}
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <CampaignSection campaign={promotion.campaign!} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/promotions/[id]/loader.tsx b/packages/vendor/src/pages/promotions/[id]/loader.tsx
new file mode 100644
index 000000000..190a5b083
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/[id]/loader.tsx
@@ -0,0 +1,19 @@
+import { LoaderFunctionArgs } from "react-router-dom";
+
+import { promotionsQueryKeys } from "@hooks/api/promotions";
+import { fetchQuery } from "@lib/client";
+import { queryClient } from "@lib/query-client";
+
+const promotionDetailQuery = (id: string) => ({
+ queryKey: promotionsQueryKeys.detail(id),
+ queryFn: async () =>
+ fetchQuery(`/vendor/promotions/${id}`, {
+ method: "GET",
+ query: { fields: "+status" },
+ }),
+});
+
+export const loader = async ({ params }: LoaderFunctionArgs) => {
+ const id = params.id;
+ return queryClient.ensureQueryData(promotionDetailQuery(id!));
+};
diff --git a/packages/vendor/src/pages/promotions/[id]/promotion-detail-page.tsx b/packages/vendor/src/pages/promotions/[id]/promotion-detail-page.tsx
new file mode 100644
index 000000000..3e058e390
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/[id]/promotion-detail-page.tsx
@@ -0,0 +1,65 @@
+import { Children, ReactNode } from "react";
+import { useLoaderData, useParams } from "react-router-dom";
+
+import { TwoColumnPageSkeleton } from "@components/common/skeleton";
+import { TwoColumnPage } from "@components/layout/pages";
+import { usePromotion, usePromotionRules } from "@hooks/api/promotions";
+
+import { CampaignSection } from "./_components/campaign-section";
+import { PromotionConditionsSection } from "./_components/promotion-conditions-section";
+import { PromotionGeneralSection } from "./_components/promotion-general-section";
+
+import type { loader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const initialData = useLoaderData() as Awaited<ReturnType<typeof loader>>;
+ const { id } = useParams();
+ const { promotion, isLoading } = usePromotion(id!, { initialData });
+ const query: Record<string, string> = {};
+ if (promotion?.type === "buyget") query.promotion_type = promotion.type;
+
+ const { rules } = usePromotionRules(id!, "rules", query);
+ const { rules: targetRules } = usePromotionRules(id!, "target-rules", query);
+ const { rules: buyRules } = usePromotionRules(id!, "buy-rules", query);
+
+ if (isLoading || !promotion)
+ return (
+ <TwoColumnPageSkeleton mainSections={3} sidebarSections={1} showJSON />
+ );
+
+ return (
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage data={promotion} hasOutlet>
+ <TwoColumnPage.Main>
+ <PromotionGeneralSection promotion={promotion} />
+ <PromotionConditionsSection rules={rules || []} ruleType="rules" />
+ <PromotionConditionsSection
+ rules={targetRules || []}
+ ruleType="target-rules"
+ />
+ {promotion.type === "buyget" && (
+ <PromotionConditionsSection
+ rules={buyRules || []}
+ ruleType="buy-rules"
+ />
+ )}
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <CampaignSection campaign={promotion.campaign!} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
+ );
+};
+
+export const PromotionDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: PromotionGeneralSection,
+ MainConditionsSection: PromotionConditionsSection,
+ SidebarCampaignSection: CampaignSection,
+});
diff --git a/packages/vendor/src/pages/promotions/_components/promotion-list-table/index.ts b/packages/vendor/src/pages/promotions/_components/promotion-list-table/index.ts
index aae0291b3..f8afb46ba 100644
--- a/packages/vendor/src/pages/promotions/_components/promotion-list-table/index.ts
+++ b/packages/vendor/src/pages/promotions/_components/promotion-list-table/index.ts
@@ -1 +1,3 @@
export * from "./promotion-list-table"
+export * from "./promotion-list-header"
+export * from "./promotion-list-data-table"
diff --git a/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-data-table.tsx b/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-data-table.tsx
new file mode 100644
index 000000000..e3cbb33ff
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-data-table.tsx
@@ -0,0 +1,164 @@
+import { PencilSquare, Trash } from "@medusajs/icons";
+import { HttpTypes } from "@medusajs/types";
+import { usePrompt } from "@medusajs/ui";
+import { createColumnHelper } from "@tanstack/react-table";
+import { useMemo } from "react";
+import { useTranslation } from "react-i18next";
+import { Outlet, useNavigate } from "react-router-dom";
+
+import { ActionMenu } from "@components/common/action-menu";
+import { _DataTable } from "@components/table/data-table";
+import {
+ useDeletePromotion,
+ usePromotions,
+} from "@hooks/api/promotions";
+import { usePromotionTableColumns } from "@hooks/table/columns/use-promotion-table-columns";
+import { usePromotionTableFilters } from "@hooks/table/filters/use-promotion-table-filters";
+import { usePromotionTableQuery } from "@hooks/table/query/use-promotion-table-query";
+import { useDataTable } from "@hooks/use-data-table";
+
+const PAGE_SIZE = 20;
+
+export const PromotionListDataTable = () => {
+ const { t } = useTranslation();
+
+ const { searchParams, raw } = usePromotionTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+ const {
+ promotions: data,
+ count,
+ isLoading,
+ isError,
+ error,
+ } = usePromotions({
+ fields: "+status",
+ ...searchParams,
+ });
+
+ const promotions = data?.filter((item) => item !== null);
+
+ const filters = usePromotionTableFilters();
+ const columns = useColumns();
+
+ const { table } = useDataTable({
+ data: (promotions ?? []) as HttpTypes.AdminPromotion[],
+ columns: columns as any,
+ count,
+ enablePagination: true,
+ pageSize: PAGE_SIZE,
+ getRowId: (row) => row.id,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <>
+ <_DataTable
+ table={table}
+ columns={columns}
+ count={count}
+ pageSize={PAGE_SIZE}
+ filters={filters}
+ search
+ pagination
+ isLoading={isLoading}
+ queryObject={raw}
+ navigateTo={(row) => `${row.original.id}`}
+ orderBy={[
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ />
+ <Outlet />
+ </>
+ );
+};
+
+const PromotionActions = ({
+ promotion,
+}: {
+ promotion: HttpTypes.AdminPromotion;
+}) => {
+ const { t } = useTranslation();
+ const prompt = usePrompt();
+ const navigate = useNavigate();
+ const { mutateAsync } = useDeletePromotion(promotion.id);
+
+ const handleDelete = async () => {
+ const res = await prompt({
+ title: t("general.areYouSure"),
+ description: t("promotions.deleteWarning", {
+ code: promotion.code!,
+ }),
+ confirmText: t("actions.delete"),
+ cancelText: t("actions.cancel"),
+ verificationInstruction: t("general.typeToConfirm"),
+ verificationText: promotion.code,
+ });
+
+ if (!res) {
+ return;
+ }
+
+ try {
+ await mutateAsync(undefined, {
+ onSuccess: () => {
+ navigate("/promotions", { replace: true });
+ },
+ });
+ } catch {
+ throw new Error(
+ `Promotion with code ${promotion.code} could not be deleted`,
+ );
+ }
+ };
+
+ return (
+ <ActionMenu
+ groups={[
+ {
+ actions: [
+ {
+ icon: <PencilSquare />,
+ label: t("actions.edit"),
+ to: `/promotions/${promotion.id}/edit`,
+ },
+ {
+ icon: <Trash />,
+ label: t("actions.delete"),
+ onClick: handleDelete,
+ },
+ ],
+ },
+ ]}
+ />
+ );
+};
+
+const columnHelper = createColumnHelper<HttpTypes.AdminPromotion>();
+
+const useColumns = () => {
+ const base = usePromotionTableColumns();
+
+ return useMemo(
+ () => [
+ ...base,
+ columnHelper.display({
+ id: "actions",
+ cell: ({ row }) => {
+ return <PromotionActions promotion={row.original} />;
+ },
+ }),
+ ],
+ [base],
+ );
+};
diff --git a/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-header.tsx b/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-header.tsx
new file mode 100644
index 000000000..4bdc750ec
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-header.tsx
@@ -0,0 +1,53 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Link } from "react-router-dom";
+import { Button, Heading } from "@medusajs/ui";
+
+export const PromotionListTitle = () => {
+ const { t } = useTranslation();
+ return <Heading level="h2">{t("promotions.domain")}</Heading>;
+};
+
+export const PromotionListCreateButton = () => {
+ const { t } = useTranslation();
+ return (
+ <Button size="small" variant="secondary" asChild>
+ <Link to="create">{t("actions.create")}</Link>
+ </Button>
+ );
+};
+
+export const PromotionListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <PromotionListCreateButton />
+ )}
+ </div>
+ );
+};
+
+export const PromotionListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <PromotionListTitle />
+ <PromotionListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-table.tsx b/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-table.tsx
index 9f0e820a4..5ddd0b4f6 100644
--- a/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-table.tsx
+++ b/packages/vendor/src/pages/promotions/_components/promotion-list-table/promotion-list-table.tsx
@@ -1,168 +1,20 @@
-import { PencilSquare, Trash } from "@medusajs/icons"
-import { HttpTypes } from "@medusajs/types"
-import { Button, Container, Heading, usePrompt } from "@medusajs/ui"
-import { createColumnHelper } from "@tanstack/react-table"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-import { Link, Outlet, useNavigate } from "react-router-dom"
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-import { ActionMenu } from "@components/common/action-menu"
-import { _DataTable } from "@components/table/data-table"
-import {
- useDeletePromotion,
- usePromotions,
-} from "@hooks/api/promotions"
-import { usePromotionTableColumns } from "@hooks/table/columns/use-promotion-table-columns"
-import { usePromotionTableFilters } from "@hooks/table/filters/use-promotion-table-filters"
-import { usePromotionTableQuery } from "@hooks/table/query/use-promotion-table-query"
-import { useDataTable } from "@hooks/use-data-table"
-
-const PAGE_SIZE = 20
-
-export const PromotionListTable = () => {
- const { t } = useTranslation()
-
- const { searchParams, raw } = usePromotionTableQuery({
- pageSize: PAGE_SIZE,
- })
- const {
- promotions: data,
- count,
- isLoading,
- isError,
- error,
- } = usePromotions({
- fields: "+status",
- ...searchParams,
- })
-
- const promotions = data?.filter((item) => item !== null)
-
- const filters = usePromotionTableFilters()
- const columns = useColumns()
-
- const { table } = useDataTable({
- data: (promotions ?? []) as HttpTypes.AdminPromotion[],
- columns: columns as any,
- count,
- enablePagination: true,
- pageSize: PAGE_SIZE,
- getRowId: (row) => row.id,
- })
-
- if (isError) {
- throw error
- }
+import { PromotionListHeader } from "./promotion-list-header";
+import { PromotionListDataTable } from "./promotion-list-data-table";
+export const PromotionListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading level="h2">{t("promotions.domain")}</Heading>
-
- <Button size="small" variant="secondary" asChild>
- <Link to="create">{t("actions.create")}</Link>
- </Button>
- </div>
-
- <_DataTable
- table={table}
- columns={columns}
- count={count}
- pageSize={PAGE_SIZE}
- filters={filters}
- search
- pagination
- isLoading={isLoading}
- queryObject={raw}
- navigateTo={(row) => `${row.original.id}`}
- orderBy={[
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- />
- <Outlet />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <PromotionListHeader />
+ <PromotionListDataTable />
+ </>
+ )}
</Container>
- )
-}
-
-const PromotionActions = ({ promotion }: { promotion: HttpTypes.AdminPromotion }) => {
- const { t } = useTranslation()
- const prompt = usePrompt()
- const navigate = useNavigate()
- const { mutateAsync } = useDeletePromotion(promotion.id)
-
- const handleDelete = async () => {
- const res = await prompt({
- title: t("general.areYouSure"),
- description: t("promotions.deleteWarning", {
- code: promotion.code!,
- }),
- confirmText: t("actions.delete"),
- cancelText: t("actions.cancel"),
- verificationInstruction: t("general.typeToConfirm"),
- verificationText: promotion.code,
- })
-
- if (!res) {
- return
- }
-
- try {
- await mutateAsync(undefined, {
- onSuccess: () => {
- navigate("/promotions", { replace: true })
- },
- })
- } catch {
- throw new Error(
- `Promotion with code ${promotion.code} could not be deleted`
- )
- }
- }
-
- return (
- <ActionMenu
- groups={[
- {
- actions: [
- {
- icon: <PencilSquare />,
- label: t("actions.edit"),
- to: `/promotions/${promotion.id}/edit`,
- },
- {
- icon: <Trash />,
- label: t("actions.delete"),
- onClick: handleDelete,
- },
- ],
- },
- ]}
- />
- )
-}
-
-const columnHelper = createColumnHelper<HttpTypes.AdminPromotion>()
-
-const useColumns = () => {
- const base = usePromotionTableColumns()
-
- return useMemo(
- () => [
- ...base,
- columnHelper.display({
- id: "actions",
- cell: ({ row }) => {
- return <PromotionActions promotion={row.original} />
- },
- }),
- ],
- [base]
- )
-}
+ );
+};
diff --git a/packages/vendor/src/pages/promotions/index.ts b/packages/vendor/src/pages/promotions/index.ts
new file mode 100644
index 000000000..9ccc26f87
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/index.ts
@@ -0,0 +1 @@
+export * from './promotion-list-page'
diff --git a/packages/vendor/src/pages/promotions/index.tsx b/packages/vendor/src/pages/promotions/index.tsx
deleted file mode 100644
index b19b67203..000000000
--- a/packages/vendor/src/pages/promotions/index.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-// Route: /promotions
-import { SingleColumnPage } from "@components/layout/pages";
-import { PromotionListTable } from "./_components/promotion-list-table";
-
-export const Component = () => {
- return (
- <SingleColumnPage>
- <PromotionListTable />
- </SingleColumnPage>
- );
-};
diff --git a/packages/vendor/src/pages/promotions/promotion-list-page.tsx b/packages/vendor/src/pages/promotions/promotion-list-page.tsx
new file mode 100644
index 000000000..22c80a98e
--- /dev/null
+++ b/packages/vendor/src/pages/promotions/promotion-list-page.tsx
@@ -0,0 +1,29 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ PromotionListTable,
+ PromotionListDataTable,
+ PromotionListHeader,
+ PromotionListActions,
+ PromotionListTitle,
+ PromotionListCreateButton,
+} from "./_components/promotion-list-table";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage>
+ {Children.count(children) > 0 ? children : <PromotionListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const PromotionListPage = Object.assign(Root, {
+ Table: PromotionListTable,
+ Header: PromotionListHeader,
+ HeaderTitle: PromotionListTitle,
+ HeaderActions: PromotionListActions,
+ HeaderCreateButton: PromotionListCreateButton,
+ DataTable: PromotionListDataTable,
+});
diff --git a/packages/vendor/src/pages/settings/index.ts b/packages/vendor/src/pages/settings/index.ts
index 3170af424..ad198a4a8 100644
--- a/packages/vendor/src/pages/settings/index.ts
+++ b/packages/vendor/src/pages/settings/index.ts
@@ -1 +1,6 @@
-export { Settings as Component } from "./settings"
+export * from './seller'
+export * from './shipping-profiles'
+export * from './return-reasons'
+export * from './product-types'
+export * from './product-tags'
+export * from './locations'
\ No newline at end of file
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/index.ts b/packages/vendor/src/pages/settings/locations/[location_id]/index.ts
new file mode 100644
index 000000000..d3bd00fb7
--- /dev/null
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/index.ts
@@ -0,0 +1,3 @@
+export { locationLoader as loader } from './loader'
+export { LocationDetailBreadcrumb as Breadcrumb } from './breadcrumb'
+export * from './location-detail-page'
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/location-detail-page.tsx
similarity index 55%
rename from packages/vendor/src/pages/settings/locations/[location_id]/index.tsx
rename to packages/vendor/src/pages/settings/locations/[location_id]/location-detail-page.tsx
index 5da01e597..0d42db703 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/location-detail-page.tsx
@@ -1,15 +1,17 @@
+import { Children, ReactNode } from "react";
import { useLoaderData, useParams } from "react-router-dom";
-import { useStockLocation } from "@hooks/api/stock-locations";
-import { LocationGeneralSection } from "./_components/location-general-section";
-import { locationLoader } from "./loader";
-
import { TwoColumnPageSkeleton } from "@components/common/skeleton";
import { TwoColumnPage } from "@components/layout/pages";
+import { useStockLocation } from "@hooks/api/stock-locations";
+
+import { LocationGeneralSection } from "./_components/location-general-section";
import LocationsFulfillmentProvidersSection from "./_components/location-fulfillment-providers-section";
import { LOCATION_DETAILS_FIELD } from "./constants";
-const LocationDetail = () => {
+import type { locationLoader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
const initialData = useLoaderData() as Awaited<
ReturnType<typeof locationLoader>
>;
@@ -37,17 +39,26 @@ const LocationDetail = () => {
}
return (
- <TwoColumnPage data={location} hasOutlet>
- <TwoColumnPage.Main>
- <LocationGeneralSection location={location} />
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <LocationsFulfillmentProvidersSection location={location} />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage data={location} hasOutlet>
+ <TwoColumnPage.Main>
+ <LocationGeneralSection location={location} />
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <LocationsFulfillmentProvidersSection location={location} />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
);
};
-export const Component = LocationDetail;
-export { locationLoader as loader } from "./loader";
-export { LocationDetailBreadcrumb as Breadcrumb } from "./breadcrumb";
+export const LocationDetailPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ MainGeneralSection: LocationGeneralSection,
+ SidebarFulfillmentProvidersSection: LocationsFulfillmentProvidersSection,
+});
diff --git a/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx b/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx
index cc081a06d..076ecc490 100644
--- a/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx
+++ b/packages/vendor/src/pages/settings/locations/_components/location-list-item.tsx
@@ -1,14 +1,14 @@
-import { Buildings, PencilSquare, Trash } from "@medusajs/icons"
-import { HttpTypes } from "@medusajs/types"
-import { Container, StatusBadge, Text, toast, usePrompt } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
+import { Buildings, PencilSquare, Trash } from "@medusajs/icons";
+import { Container, StatusBadge, Text, toast, usePrompt } from "@medusajs/ui";
+import { useTranslation } from "react-i18next";
-import { ActionMenu } from "@components/common/action-menu"
+import { ActionMenu } from "@components/common/action-menu";
// import { BadgeListSummary } from "@components/common/badge-list-summary"
-import { LinkButton } from "@components/common/link-button"
-import { useDeleteStockLocation } from "@hooks/api/stock-locations"
-import { getFormattedAddress } from "@lib/addresses"
-import { FulfillmentSetType } from "@pages/settings/locations/_common/constants"
+import { LinkButton } from "@components/common/link-button";
+import { useDeleteStockLocation } from "@hooks/api/stock-locations";
+import { getFormattedAddress } from "@lib/addresses";
+import { FulfillmentSetType } from "@pages/settings/locations/_common/constants";
+import { HttpTypes } from "@mercurjs/types";
// type SalesChannelsProps = {
// salesChannels?: HttpTypes.AdminSalesChannel[] | null
@@ -47,15 +47,15 @@ import { FulfillmentSetType } from "@pages/settings/locations/_common/constants"
// }
type FulfillmentSetProps = {
- fulfillmentSet?: HttpTypes.AdminFulfillmentSet
- type: FulfillmentSetType
-}
+ fulfillmentSet?: HttpTypes.VendorFulfillmentSetResponse["fulfillment_set"];
+ type: FulfillmentSetType;
+};
function FulfillmentSet(props: FulfillmentSetProps) {
- const { t } = useTranslation()
- const { fulfillmentSet, type } = props
+ const { t } = useTranslation();
+ const { fulfillmentSet, type } = props;
- const fulfillmentSetExists = !!fulfillmentSet
+ const fulfillmentSetExists = !!fulfillmentSet;
return (
<div className="flex flex-col px-6 py-4">
@@ -75,19 +75,19 @@ function FulfillmentSet(props: FulfillmentSetProps) {
</div>
</div>
</div>
- )
+ );
}
type LocationProps = {
- location: HttpTypes.AdminStockLocation
-}
+ location: HttpTypes.VendorStockLocationResponse["stock_location"];
+};
function LocationListItem(props: LocationProps) {
- const { location } = props
- const { t } = useTranslation()
- const prompt = usePrompt()
+ const { location } = props;
+ const { t } = useTranslation();
+ const prompt = usePrompt();
- const { mutateAsync: deleteLocation } = useDeleteStockLocation(location.id)
+ const { mutateAsync: deleteLocation } = useDeleteStockLocation(location.id);
const handleDelete = async () => {
const result = await prompt({
@@ -97,10 +97,10 @@ function LocationListItem(props: LocationProps) {
}),
confirmText: t("actions.remove"),
cancelText: t("actions.cancel"),
- })
+ });
if (!result) {
- return
+ return;
}
await deleteLocation(undefined, {
@@ -108,14 +108,14 @@ function LocationListItem(props: LocationProps) {
toast.success(
t("shippingProfile.delete.successToast", {
name: location.name,
- })
- )
+ }),
+ );
},
onError: (e) => {
- toast.error(e.message)
+ toast.error(e.message);
},
- })
- }
+ });
+ };
return (
<Container className="flex flex-col divide-y p-0">
@@ -131,7 +131,15 @@ function LocationListItem(props: LocationProps) {
<Text weight="plus">{location.name}</Text>
<Text className="text-ui-fg-subtle txt-small">
{getFormattedAddress({
- address: location.address,
+ address: {
+ company: location.address?.company,
+ address_1: location.address?.address_1,
+ address_2: location.address?.address_2,
+ city: location.address?.city,
+ postal_code: location.address?.postal_code,
+ province: location.address?.province,
+ country_code: location.address?.country_code,
+ },
}).join(", ")}
</Text>
</div>
@@ -172,17 +180,17 @@ function LocationListItem(props: LocationProps) {
<FulfillmentSet
type={FulfillmentSetType.Pickup}
fulfillmentSet={location.fulfillment_sets?.find(
- (f) => f.type === FulfillmentSetType.Pickup
+ (f) => f.type === FulfillmentSetType.Pickup,
)}
/>
<FulfillmentSet
type={FulfillmentSetType.Shipping}
fulfillmentSet={location.fulfillment_sets?.find(
- (f) => f.type === FulfillmentSetType.Shipping
+ (f) => f.type === FulfillmentSetType.Shipping,
)}
/>
</Container>
- )
+ );
}
-export default LocationListItem
+export default LocationListItem;
diff --git a/packages/vendor/src/pages/settings/locations/index.ts b/packages/vendor/src/pages/settings/locations/index.ts
new file mode 100644
index 000000000..1244311d9
--- /dev/null
+++ b/packages/vendor/src/pages/settings/locations/index.ts
@@ -0,0 +1,2 @@
+export { shippingListLoader as loader } from './loader'
+export * from './location-list-page'
diff --git a/packages/vendor/src/pages/settings/locations/index.tsx b/packages/vendor/src/pages/settings/locations/location-list-page.tsx
similarity index 62%
rename from packages/vendor/src/pages/settings/locations/index.tsx
rename to packages/vendor/src/pages/settings/locations/location-list-page.tsx
index 017d59cd1..72996d7e8 100644
--- a/packages/vendor/src/pages/settings/locations/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/location-list-page.tsx
@@ -1,18 +1,40 @@
import { ShoppingBag } from "@medusajs/icons";
import { Container, Heading } from "@medusajs/ui";
+import { Children, ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { useLoaderData } from "react-router-dom";
+import { SidebarLink } from "@components/common/sidebar-link/sidebar-link";
+import { TwoColumnPage } from "@components/layout/pages";
import { useStockLocations } from "@hooks/api/stock-locations";
+
import LocationListItem from "./_components/location-list-item";
+import { LocationListHeader } from "./_components/location-list-header";
import { LOCATION_LIST_FIELDS } from "./constants";
import { shippingListLoader } from "./loader";
-import { TwoColumnPage } from "@components/layout/pages";
-import { LocationListHeader } from "./_components/location-list-header";
-import { SidebarLink } from "@components/common/sidebar-link/sidebar-link";
+const LinksSection = () => {
+ const { t } = useTranslation();
+
+ return (
+ <Container className="p-0">
+ <div className="flex items-center justify-between px-6 py-4">
+ <Heading level="h2">{t("stockLocations.sidebar.header")}</Heading>
+ </div>
-function LocationList() {
+ <SidebarLink
+ to="/settings/locations/shipping-profiles"
+ labelKey={t("stockLocations.sidebar.shippingProfiles.label")}
+ descriptionKey={t(
+ "stockLocations.sidebar.shippingProfiles.description",
+ )}
+ icon={<ShoppingBag />}
+ />
+ </Container>
+ );
+};
+
+const Root = ({ children }: { children?: ReactNode }) => {
const initialData = useLoaderData() as Awaited<
ReturnType<typeof shippingListLoader>
>;
@@ -25,6 +47,7 @@ function LocationList() {
{
fields: LOCATION_LIST_FIELDS,
},
+ // @ts-expect-error
{ initialData },
);
@@ -33,42 +56,32 @@ function LocationList() {
}
return (
- <TwoColumnPage>
- <TwoColumnPage.Main>
- <LocationListHeader />
- <div className="flex flex-col gap-3 lg:col-span-2">
- {stockLocations.map((location) => (
- <LocationListItem key={location.id} location={location} />
- ))}
- </div>
- </TwoColumnPage.Main>
- <TwoColumnPage.Sidebar>
- <LinksSection />
- </TwoColumnPage.Sidebar>
- </TwoColumnPage>
- );
-}
-
-const LinksSection = () => {
- const { t } = useTranslation();
-
- return (
- <Container className="p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading level="h2">{t("stockLocations.sidebar.header")}</Heading>
- </div>
-
- <SidebarLink
- to="/settings/locations/shipping-profiles"
- labelKey={t("stockLocations.sidebar.shippingProfiles.label")}
- descriptionKey={t(
- "stockLocations.sidebar.shippingProfiles.description",
- )}
- icon={<ShoppingBag />}
- />
- </Container>
+ <>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <TwoColumnPage>
+ <TwoColumnPage.Main>
+ <LocationListHeader />
+ <div className="flex flex-col gap-3 lg:col-span-2">
+ {stockLocations.map((location) => (
+ <LocationListItem key={location.id} location={location} />
+ ))}
+ </div>
+ </TwoColumnPage.Main>
+ <TwoColumnPage.Sidebar>
+ <LinksSection />
+ </TwoColumnPage.Sidebar>
+ </TwoColumnPage>
+ )}
+ </>
);
};
-export const Component = LocationList;
-export { shippingListLoader as loader } from "./loader";
+export const LocationListPage = Object.assign(Root, {
+ Main: TwoColumnPage.Main,
+ Sidebar: TwoColumnPage.Sidebar,
+ Header: LocationListHeader,
+ ListItem: LocationListItem,
+ SidebarLinksSection: LinksSection,
+});
diff --git a/packages/vendor/src/pages/settings/product-tags/[id]/index.ts b/packages/vendor/src/pages/settings/product-tags/[id]/index.ts
new file mode 100644
index 000000000..f00c2b9c6
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-tags/[id]/index.ts
@@ -0,0 +1,3 @@
+export { productTagLoader as loader } from './loader'
+export { ProductTagDetailBreadcrumb as Breadcrumb } from './breadcrumb'
+export * from './product-tag-detail-page'
diff --git a/packages/vendor/src/pages/settings/product-tags/[id]/index.tsx b/packages/vendor/src/pages/settings/product-tags/[id]/product-tag-detail-page.tsx
similarity index 62%
rename from packages/vendor/src/pages/settings/product-tags/[id]/index.tsx
rename to packages/vendor/src/pages/settings/product-tags/[id]/product-tag-detail-page.tsx
index e71d100e5..b2acdd65c 100644
--- a/packages/vendor/src/pages/settings/product-tags/[id]/index.tsx
+++ b/packages/vendor/src/pages/settings/product-tags/[id]/product-tag-detail-page.tsx
@@ -1,13 +1,16 @@
+import { Children, ReactNode } from "react";
import { useLoaderData, useParams } from "react-router-dom";
import { SingleColumnPageSkeleton } from "@components/common/skeleton";
import { SingleColumnPage } from "@components/layout/pages";
import { useProductTag } from "@hooks/api";
+
import { ProductTagGeneralSection } from "./_components/product-tag-general-section";
import { ProductTagProductSection } from "./_components/product-tag-product-section";
-import { productTagLoader } from "./loader";
-const ProductTagDetail = () => {
+import type { productTagLoader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
const { id } = useParams();
const initialData = useLoaderData() as Awaited<
@@ -32,12 +35,19 @@ const ProductTagDetail = () => {
return (
<SingleColumnPage data={product_tag}>
- <ProductTagGeneralSection productTag={product_tag} />
- <ProductTagProductSection productTag={product_tag} />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <ProductTagGeneralSection productTag={product_tag} />
+ <ProductTagProductSection productTag={product_tag} />
+ </>
+ )}
</SingleColumnPage>
);
};
-export const Component = ProductTagDetail;
-export { productTagLoader as loader } from "./loader";
-export { ProductTagDetailBreadcrumb as Breadcrumb } from "./breadcrumb";
+export const ProductTagDetailPage = Object.assign(Root, {
+ GeneralSection: ProductTagGeneralSection,
+ ProductSection: ProductTagProductSection,
+});
diff --git a/packages/vendor/src/pages/settings/product-tags/_components/index.ts b/packages/vendor/src/pages/settings/product-tags/_components/index.ts
new file mode 100644
index 000000000..dace97299
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-tags/_components/index.ts
@@ -0,0 +1,3 @@
+export * from "./product-tag-list-table"
+export * from "./product-tag-list-header"
+export * from "./product-tag-list-data-table"
diff --git a/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-data-table.tsx b/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-data-table.tsx
new file mode 100644
index 000000000..9a19e6d6d
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-data-table.tsx
@@ -0,0 +1,80 @@
+import { keepPreviousData } from "@tanstack/react-query";
+import { useMemo } from "react";
+import { useTranslation } from "react-i18next";
+import { useLoaderData } from "react-router-dom";
+
+import { _DataTable } from "@components/table/data-table";
+import { useProductTags } from "@hooks/api";
+import { useProductTagTableColumns } from "@hooks/table/columns";
+import { useProductTagTableFilters } from "@hooks/table/filters";
+import { useProductTagTableQuery } from "@hooks/table/query";
+import { useDataTable } from "@hooks/use-data-table";
+import { productTagListLoader } from "../../loader";
+
+const PAGE_SIZE = 20;
+
+export const ProductTagListDataTable = () => {
+ const { t } = useTranslation();
+ const { searchParams, raw } = useProductTagTableQuery({
+ pageSize: PAGE_SIZE,
+ });
+
+ const initialData = useLoaderData() as Awaited<
+ ReturnType<typeof productTagListLoader>
+ >;
+
+ const { product_tags, count, isPending, isError, error } = useProductTags(
+ searchParams,
+ {
+ initialData,
+ placeholderData: keepPreviousData,
+ },
+ );
+
+ const columns = useColumns();
+ const filters = useProductTagTableFilters();
+
+ const { table } = useDataTable({
+ data: product_tags,
+ count,
+ columns,
+ getRowId: (row) => row.id,
+ pageSize: PAGE_SIZE,
+ });
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ filters={filters}
+ queryObject={raw}
+ isLoading={isPending}
+ columns={columns}
+ pageSize={PAGE_SIZE}
+ count={count}
+ navigateTo={(row) => row.original.id}
+ search
+ pagination
+ orderBy={[
+ { key: "value", label: t("fields.value") },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ />
+ );
+};
+
+const useColumns = () => {
+ const base = useProductTagTableColumns();
+
+ return useMemo(() => [...base], [base]);
+};
diff --git a/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-header.tsx b/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-header.tsx
new file mode 100644
index 000000000..4ebaeda8e
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-header.tsx
@@ -0,0 +1,36 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Heading } from "@medusajs/ui";
+
+export const ProductTagListTitle = () => {
+ const { t } = useTranslation();
+ return <Heading>{t("productTags.domain")}</Heading>;
+};
+
+export const ProductTagListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? children : null}
+ </div>
+ );
+};
+
+export const ProductTagListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <ProductTagListTitle />
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-table.tsx b/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-table.tsx
index 2053afc51..0ea68332b 100644
--- a/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-table.tsx
+++ b/packages/vendor/src/pages/settings/product-tags/_components/product-tag-list-table.tsx
@@ -1,87 +1,24 @@
-import { Container, Heading } from "@medusajs/ui"
-import { keepPreviousData } from "@tanstack/react-query"
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-import { useLoaderData } from "react-router-dom"
-
-import { _DataTable } from "@components/table/data-table"
-import { useProductTags } from "@hooks/api"
-import { useProductTagTableColumns } from "@hooks/table/columns"
-import { useProductTagTableFilters } from "@hooks/table/filters"
-import { useProductTagTableQuery } from "@hooks/table/query"
-import { useDataTable } from "@hooks/use-data-table"
-import { productTagListLoader } from "../../loader"
-
-const PAGE_SIZE = 20
-
-export const ProductTagListTable = () => {
- const { t } = useTranslation()
- const { searchParams, raw } = useProductTagTableQuery({
- pageSize: PAGE_SIZE,
- })
-
- const initialData = useLoaderData() as Awaited<
- ReturnType<typeof productTagListLoader>
- >
-
- const { product_tags, count, isPending, isError, error } = useProductTags(
- searchParams,
- {
- initialData,
- placeholderData: keepPreviousData,
- }
- )
-
- const columns = useColumns()
- const filters = useProductTagTableFilters()
-
- const { table } = useDataTable({
- data: product_tags,
- count,
- columns,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- })
-
- if (isError) {
- throw error
- }
+import { ProductTagListHeader } from "./product-tag-list-header";
+import { ProductTagListDataTable } from "./product-tag-list-data-table";
+export const ProductTagListTable = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
return (
<Container className="divide-y px-0 py-0">
- <div className="flex items-center justify-between px-6 py-4">
- <Heading>{t("productTags.domain")}</Heading>
- </div>
- <_DataTable
- table={table}
- filters={filters}
- queryObject={raw}
- isLoading={isPending}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- navigateTo={(row) => row.original.id}
- search
- pagination
- orderBy={[
- { key: "value", label: t("fields.value") },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <ProductTagListHeader />
+ <ProductTagListDataTable />
+ </>
+ )}
</Container>
- )
-}
-
-const useColumns = () => {
- const base = useProductTagTableColumns()
-
- return useMemo(() => [...base], [base])
-}
+ );
+};
diff --git a/packages/vendor/src/pages/settings/product-tags/index.ts b/packages/vendor/src/pages/settings/product-tags/index.ts
new file mode 100644
index 000000000..4db394538
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-tags/index.ts
@@ -0,0 +1 @@
+export * from './product-tag-list-page'
diff --git a/packages/vendor/src/pages/settings/product-tags/index.tsx b/packages/vendor/src/pages/settings/product-tags/index.tsx
deleted file mode 100644
index 809cee72d..000000000
--- a/packages/vendor/src/pages/settings/product-tags/index.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { SingleColumnPage } from "@components/layout/pages";
-import { ProductTagListTable } from "./_components/product-tag-list-table";
-
-const ProductTagList = () => {
- return (
- <SingleColumnPage showMetadata={false} showJSON={false} hasOutlet>
- <ProductTagListTable />
- </SingleColumnPage>
- );
-};
-
-export const Component = ProductTagList;
diff --git a/packages/vendor/src/pages/settings/product-tags/product-tag-list-page.tsx b/packages/vendor/src/pages/settings/product-tags/product-tag-list-page.tsx
new file mode 100644
index 000000000..239198430
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-tags/product-tag-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ ProductTagListTable,
+ ProductTagListDataTable,
+ ProductTagListHeader,
+ ProductTagListActions,
+ ProductTagListTitle,
+} from "./_components";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage showMetadata={false} showJSON={false} hasOutlet>
+ {Children.count(children) > 0 ? children : <ProductTagListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const ProductTagListPage = Object.assign(Root, {
+ Table: ProductTagListTable,
+ Header: ProductTagListHeader,
+ HeaderTitle: ProductTagListTitle,
+ HeaderActions: ProductTagListActions,
+ DataTable: ProductTagListDataTable,
+});
diff --git a/packages/vendor/src/pages/settings/product-types/[id]/index.ts b/packages/vendor/src/pages/settings/product-types/[id]/index.ts
new file mode 100644
index 000000000..ee224c7e2
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-types/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './product-type-detail-page'
diff --git a/packages/vendor/src/pages/settings/product-types/[id]/index.tsx b/packages/vendor/src/pages/settings/product-types/[id]/product-type-detail-page.tsx
similarity index 62%
rename from packages/vendor/src/pages/settings/product-types/[id]/index.tsx
rename to packages/vendor/src/pages/settings/product-types/[id]/product-type-detail-page.tsx
index 3b2ded783..ecb96f3d6 100644
--- a/packages/vendor/src/pages/settings/product-types/[id]/index.tsx
+++ b/packages/vendor/src/pages/settings/product-types/[id]/product-type-detail-page.tsx
@@ -1,14 +1,18 @@
+import { Children, ReactNode } from "react";
import { useLoaderData, useParams } from "react-router-dom";
import { SingleColumnPageSkeleton } from "@components/common/skeleton";
import { SingleColumnPage } from "@components/layout/pages";
import { useProductType } from "@hooks/api/product-types";
+
import { ProductTypeGeneralSection } from "./_components/product-type-general-section";
import { ProductTypeProductSection } from "./_components/product-type-product-section";
-import { productTypeLoader } from "./loader";
-const ProductTypeDetail = () => {
+import type { productTypeLoader } from "./loader";
+
+const Root = ({ children }: { children?: ReactNode }) => {
const { id } = useParams();
+
const initialData = useLoaderData() as Awaited<
ReturnType<typeof productTypeLoader>
>;
@@ -31,12 +35,19 @@ const ProductTypeDetail = () => {
return (
<SingleColumnPage data={product_type}>
- <ProductTypeGeneralSection productType={product_type} />
- <ProductTypeProductSection productType={product_type} />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <ProductTypeGeneralSection productType={product_type} />
+ <ProductTypeProductSection productType={product_type} />
+ </>
+ )}
</SingleColumnPage>
);
};
-export const Component = ProductTypeDetail;
-export { productTypeLoader as loader } from "./loader";
-export { ProductTypeDetailBreadcrumb as Breadcrumb } from "./breadcrumb";
+export const ProductTypeDetailPage = Object.assign(Root, {
+ GeneralSection: ProductTypeGeneralSection,
+ ProductSection: ProductTypeProductSection,
+});
diff --git a/packages/vendor/src/pages/settings/product-types/_components/index.ts b/packages/vendor/src/pages/settings/product-types/_components/index.ts
new file mode 100644
index 000000000..b69088eae
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-types/_components/index.ts
@@ -0,0 +1,3 @@
+export * from "./product-type-list-table"
+export * from "./product-type-list-header"
+export * from "./product-type-list-data-table"
diff --git a/packages/vendor/src/pages/settings/product-types/_components/product-type-list-data-table.tsx b/packages/vendor/src/pages/settings/product-types/_components/product-type-list-data-table.tsx
new file mode 100644
index 000000000..ebbd8d63b
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-types/_components/product-type-list-data-table.tsx
@@ -0,0 +1,89 @@
+import { HttpTypes } from "@medusajs/types"
+import { keepPreviousData } from "@tanstack/react-query"
+import { createColumnHelper } from "@tanstack/react-table"
+import { useMemo } from "react"
+import { useTranslation } from "react-i18next"
+
+import { _DataTable } from "@components/table/data-table"
+import { useProductTypes } from "@hooks/api/product-types"
+import { useProductTypeTableColumns } from "@hooks/table/columns/use-product-type-table-columns"
+import { useProductTypeTableFilters } from "@hooks/table/filters/use-product-type-table-filters"
+import { useProductTypeTableQuery } from "@hooks/table/query/use-product-type-table-query"
+import { useDataTable } from "@hooks/use-data-table"
+import { ProductTypeRowActions } from "./product-table-row-actions"
+
+const PAGE_SIZE = 20
+
+export const ProductTypeListDataTable = () => {
+ const { t } = useTranslation()
+
+ const { searchParams, raw } = useProductTypeTableQuery({
+ pageSize: PAGE_SIZE,
+ })
+ const { product_types, count, isLoading, isError, error } = useProductTypes(
+ searchParams,
+ {
+ placeholderData: keepPreviousData,
+ }
+ )
+
+ const filters = useProductTypeTableFilters()
+ const columns = useColumns()
+
+ const { table } = useDataTable({
+ columns,
+ data: product_types,
+ count,
+ getRowId: (row) => row.id,
+ pageSize: PAGE_SIZE,
+ })
+
+ if (isError) {
+ throw error
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ filters={filters}
+ isLoading={isLoading}
+ columns={columns}
+ pageSize={PAGE_SIZE}
+ count={count}
+ orderBy={[
+ { key: "value", label: t("fields.value") },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ navigateTo={({ original }) => original.id}
+ queryObject={raw}
+ pagination
+ search
+ />
+ )
+}
+
+const columnHelper = createColumnHelper<HttpTypes.AdminProductType>()
+
+const useColumns = () => {
+ const base = useProductTypeTableColumns()
+
+ return useMemo(
+ () => [
+ ...base,
+ columnHelper.display({
+ id: "actions",
+ cell: ({ row }) => {
+ return <ProductTypeRowActions productType={row.original} />
+ },
+ }),
+ ],
+ [base]
+ )
+}
diff --git a/packages/vendor/src/pages/settings/product-types/_components/product-type-list-header.tsx b/packages/vendor/src/pages/settings/product-types/_components/product-type-list-header.tsx
new file mode 100644
index 000000000..63a060a50
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-types/_components/product-type-list-header.tsx
@@ -0,0 +1,43 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Heading, Text } from "@medusajs/ui";
+
+export const ProductTypeListTitle = () => {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Heading>{t("productTypes.domain")}</Heading>
+ <Text className="text-ui-fg-subtle" size="small">
+ {t("productTypes.subtitle")}
+ </Text>
+ </div>
+ );
+};
+
+export const ProductTypeListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? children : null}
+ </div>
+ );
+};
+
+export const ProductTypeListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <ProductTypeListTitle />
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/settings/product-types/_components/product-type-list-table.tsx b/packages/vendor/src/pages/settings/product-types/_components/product-type-list-table.tsx
index 96ab720ba..353c883aa 100644
--- a/packages/vendor/src/pages/settings/product-types/_components/product-type-list-table.tsx
+++ b/packages/vendor/src/pages/settings/product-types/_components/product-type-list-table.tsx
@@ -1,106 +1,20 @@
-import { HttpTypes } from "@medusajs/types"
-import { Button, Container, Heading, Text } from "@medusajs/ui"
-import { keepPreviousData } from "@tanstack/react-query"
-import { createColumnHelper } from "@tanstack/react-table"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-import { Link } from "react-router-dom"
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-import { _DataTable } from "@components/table/data-table"
-import { useProductTypes } from "@hooks/api/product-types"
-import { useProductTypeTableColumns } from "@hooks/table/columns/use-product-type-table-columns"
-import { useProductTypeTableFilters } from "@hooks/table/filters/use-product-type-table-filters"
-import { useProductTypeTableQuery } from "@hooks/table/query/use-product-type-table-query"
-import { useDataTable } from "@hooks/use-data-table"
-import { ProductTypeRowActions } from "./product-table-row-actions"
-
-const PAGE_SIZE = 20
-
-export const ProductTypeListTable = () => {
- const { t } = useTranslation()
-
- const { searchParams, raw } = useProductTypeTableQuery({
- pageSize: PAGE_SIZE,
- })
- const { product_types, count, isLoading, isError, error } = useProductTypes(
- searchParams,
- {
- placeholderData: keepPreviousData,
- }
- )
-
- const filters = useProductTypeTableFilters()
- const columns = useColumns()
-
- const { table } = useDataTable({
- columns,
- data: product_types,
- count,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- })
-
- if (isError) {
- throw error
- }
+import { ProductTypeListHeader } from "./product-type-list-header";
+import { ProductTypeListDataTable } from "./product-type-list-data-table";
+export const ProductTypeListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("productTypes.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- {t("productTypes.subtitle")}
- </Text>
- </div>
- {/* TODO: Enable when request product type flow is implemented
- <Button size="small" variant="secondary" asChild>
- <Link to="create">Request Product Type</Link>
- </Button>
- */}
- </div>
- <_DataTable
- table={table}
- filters={filters}
- isLoading={isLoading}
- columns={columns}
- pageSize={PAGE_SIZE}
- count={count}
- orderBy={[
- { key: "value", label: t("fields.value") },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- navigateTo={({ original }) => original.id}
- queryObject={raw}
- pagination
- search
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <ProductTypeListHeader />
+ <ProductTypeListDataTable />
+ </>
+ )}
</Container>
- )
-}
-
-const columnHelper = createColumnHelper<HttpTypes.AdminProductType>()
-
-const useColumns = () => {
- const base = useProductTypeTableColumns()
-
- return useMemo(
- () => [
- ...base,
- columnHelper.display({
- id: "actions",
- cell: ({ row }) => {
- return <ProductTypeRowActions productType={row.original} />
- },
- }),
- ],
- [base]
- )
-}
+ );
+};
diff --git a/packages/vendor/src/pages/settings/product-types/index.ts b/packages/vendor/src/pages/settings/product-types/index.ts
new file mode 100644
index 000000000..05f73dce9
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-types/index.ts
@@ -0,0 +1 @@
+export * from './product-type-list-page'
diff --git a/packages/vendor/src/pages/settings/product-types/index.tsx b/packages/vendor/src/pages/settings/product-types/index.tsx
deleted file mode 100644
index c3ef457f8..000000000
--- a/packages/vendor/src/pages/settings/product-types/index.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { SingleColumnPage } from "@components/layout/pages";
-import { ProductTypeListTable } from "./_components/product-type-list-table";
-
-const ProductTypeList = () => {
- return (
- <SingleColumnPage>
- <ProductTypeListTable />
- </SingleColumnPage>
- );
-};
-
-export const Component = ProductTypeList;
diff --git a/packages/vendor/src/pages/settings/product-types/product-type-list-page.tsx b/packages/vendor/src/pages/settings/product-types/product-type-list-page.tsx
new file mode 100644
index 000000000..4b2bbd37f
--- /dev/null
+++ b/packages/vendor/src/pages/settings/product-types/product-type-list-page.tsx
@@ -0,0 +1,27 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ ProductTypeListTable,
+ ProductTypeListDataTable,
+ ProductTypeListHeader,
+ ProductTypeListActions,
+ ProductTypeListTitle,
+} from "./_components";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage hasOutlet>
+ {Children.count(children) > 0 ? children : <ProductTypeListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const ProductTypeListPage = Object.assign(Root, {
+ Table: ProductTypeListTable,
+ Header: ProductTypeListHeader,
+ HeaderTitle: ProductTypeListTitle,
+ HeaderActions: ProductTypeListActions,
+ DataTable: ProductTypeListDataTable,
+});
diff --git a/packages/vendor/src/pages/settings/profile/_components/profile-general-section.tsx b/packages/vendor/src/pages/settings/profile/_components/profile-general-section.tsx
deleted file mode 100644
index 6d286f624..000000000
--- a/packages/vendor/src/pages/settings/profile/_components/profile-general-section.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import { PencilSquare } from "@medusajs/icons"
-import { Container, Heading, Text } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-
-import { ActionMenu } from "@components/common/action-menu"
-import { ImageAvatar } from "@components/common/image-avatar"
-import { TeamMemberProps } from "@custom-types/user"
-
-type ProfileGeneralSectionProps = {
- user: TeamMemberProps
-}
-
-export const ProfileGeneralSection = ({ user }: ProfileGeneralSectionProps) => {
- const { t } = useTranslation()
-
- const { name, email, photo, phone, bio } = user
-
- return (
- <Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("profile.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- {t("profile.manageYourProfileDetails")}
- </Text>
- </div>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- label: t("actions.edit"),
- to: "edit",
- icon: <PencilSquare />,
- },
- ],
- },
- ]}
- />
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- Photo
- </Text>
- <ImageAvatar src={photo || "/logo.svg"} size={8} rounded />
- </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("fields.name")}
- </Text>
- <Text size="small" leading="compact">
- {name || "-"}
- </Text>
- </div>
- <div className="grid grid-cols-2 items-center px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.email")}
- </Text>
- <Text size="small" leading="compact">
- {email}
- </Text>
- </div>
- <div className="grid grid-cols-2 items-center px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- Phone
- </Text>
- <Text size="small" leading="compact">
- {phone}
- </Text>
- </div>
- <div className="grid grid-cols-2 items-center px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- Bio
- </Text>
- <Text size="small" leading="compact">
- {bio}
- </Text>
- </div>
- </Container>
- )
-}
diff --git a/packages/vendor/src/pages/settings/profile/edit/_components/edit-profile-form.tsx b/packages/vendor/src/pages/settings/profile/edit/_components/edit-profile-form.tsx
deleted file mode 100644
index de6f05ec4..000000000
--- a/packages/vendor/src/pages/settings/profile/edit/_components/edit-profile-form.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod";
-import { Button, Input, Textarea, toast } from "@medusajs/ui";
-import { useFieldArray, useForm } from "react-hook-form";
-import { useTranslation } from "react-i18next";
-import * as zod from "zod";
-import { useCallback } from "react";
-import { HttpTypes } from "@medusajs/types";
-
-import { Form } from "@components/common/form";
-import { RouteDrawer, useRouteModal } from "@components/modals";
-import { KeyboundForm } from "@components/utilities/keybound-form";
-import { useUpdateUser } from "@hooks/api/users";
-import { TeamMemberProps } from "@custom-types/user";
-import { MediaSchema } from "@pages/products/create/constants";
-import { FileType, FileUpload } from "@components/common/file-upload";
-import { uploadFilesQuery } from "@lib/client";
-
-type EditProfileProps = {
- user: TeamMemberProps;
-};
-
-const EditProfileSchema = zod.object({
- name: zod.string().optional(),
- media: zod.array(MediaSchema).optional(),
- phone: zod.string().optional(),
- bio: zod.string().optional(),
-});
-
-const SUPPORTED_FORMATS = [
- "image/jpeg",
- "image/png",
- "image/gif",
- "image/webp",
- "image/heic",
- "image/svg+xml",
-];
-
-const SUPPORTED_FORMATS_FILE_EXTENSIONS = [
- ".jpeg",
- ".png",
- ".gif",
- ".webp",
- ".heic",
- ".svg",
-];
-
-export const EditProfileForm = ({ user }: EditProfileProps) => {
- const { t } = useTranslation();
- const { handleSuccess } = useRouteModal();
-
- const form = useForm<zod.infer<typeof EditProfileSchema>>({
- defaultValues: {
- name: user.name ?? "",
- phone: user.phone ?? "",
- bio: user.bio ?? "",
- media: [],
- },
- resolver: zodResolver(EditProfileSchema),
- });
-
- const { fields } = useFieldArray({
- name: "media",
- control: form.control,
- keyName: "field_id",
- });
-
- const { mutateAsync, isPending } = useUpdateUser(user.id!);
-
- const handleSubmit = form.handleSubmit(async (values) => {
- let uploadedMedia: (HttpTypes.AdminFile & {
- isThumbnail: boolean;
- })[] = [];
- try {
- if (values.media?.length) {
- const fileReqs = [];
- fileReqs.push(
- uploadFilesQuery(values.media).then((r: any) =>
- r.files.map((f: any) => ({
- ...f,
- isThumbnail: false,
- })),
- ),
- );
-
- uploadedMedia = (await Promise.all(fileReqs)).flat();
- }
- } catch (error) {
- if (error instanceof Error) {
- toast.error(error.message);
- }
- }
-
- await mutateAsync(
- {
- name: values.name,
- photo: uploadedMedia[0]?.url || user.photo || "",
- phone: values.phone,
- bio: values.bio,
- },
- {
- onError: (error) => {
- toast.error(error.message);
- return;
- },
- },
- );
-
- toast.success(t("profile.toast.edit"));
- handleSuccess();
- });
-
- const hasInvalidFiles = useCallback(
- (fileList: FileType[]) => {
- const invalidFile = fileList.find(
- (f) => !SUPPORTED_FORMATS.includes(f.file.type),
- );
-
- if (invalidFile) {
- form.setError("media", {
- type: "invalid_file",
- message: t("products.media.invalidFileType", {
- name: invalidFile.file.name,
- types: SUPPORTED_FORMATS_FILE_EXTENSIONS.join(", "),
- }),
- });
-
- return true;
- }
-
- return false;
- },
- [form, t],
- );
-
- const onUploaded = useCallback(
- (files: FileType[]) => {
- form.clearErrors("media");
- if (hasInvalidFiles(files)) {
- return;
- }
-
- form.setValue("media", [{ ...files[0], isThumbnail: false }]);
- },
- [form, hasInvalidFiles],
- );
-
- return (
- <RouteDrawer.Form form={form}>
- <KeyboundForm onSubmit={handleSubmit} className="flex flex-1 flex-col">
- <RouteDrawer.Body>
- <div className="flex flex-col gap-y-8">
- <Form.Field
- name="media"
- control={form.control}
- render={() => {
- return (
- <Form.Item>
- <div className="flex flex-col gap-y-2">
- <div className="flex flex-col gap-y-1">
- <Form.Label>Profile picture</Form.Label>
- </div>
- <Form.Control>
- <FileUpload
- uploadedImage={fields[0]?.url || user.photo || ""}
- multiple={false}
- label={t("products.media.uploadImagesLabel")}
- hint={t("products.media.uploadImagesHint")}
- hasError={!!form.formState.errors.media}
- formats={SUPPORTED_FORMATS}
- onUploaded={onUploaded}
- />
- </Form.Control>
- <Form.ErrorMessage />
- </div>
- </Form.Item>
- );
- }}
- />
- <Form.Field
- control={form.control}
- name="name"
- render={({ field }) => (
- <Form.Item>
- <Form.Label>Name</Form.Label>
- <Form.Control>
- <Input {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="phone"
- render={({ field }) => (
- <Form.Item>
- <Form.Label>Phone</Form.Label>
- <Form.Control>
- <Input {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )}
- />
- <Form.Field
- control={form.control}
- name="bio"
- render={({ field }) => (
- <Form.Item>
- <Form.Label>Bio</Form.Label>
- <Form.Control>
- <Textarea {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )}
- />
- </div>
- </RouteDrawer.Body>
- <RouteDrawer.Footer>
- <div className="flex items-center gap-x-2">
- <RouteDrawer.Close asChild>
- <Button size="small" variant="secondary">
- {t("actions.cancel")}
- </Button>
- </RouteDrawer.Close>
- <Button size="small" type="submit" isLoading={isPending}>
- {t("actions.save")}
- </Button>
- </div>
- </RouteDrawer.Footer>
- </KeyboundForm>
- </RouteDrawer.Form>
- );
-};
diff --git a/packages/vendor/src/pages/settings/profile/edit/index.tsx b/packages/vendor/src/pages/settings/profile/edit/index.tsx
deleted file mode 100644
index df4594342..000000000
--- a/packages/vendor/src/pages/settings/profile/edit/index.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { Heading } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-
-import { RouteDrawer } from "@components/modals"
-import { useUserMe } from "@hooks/api/users"
-import { EditProfileForm } from "./_components/edit-profile-form"
-
-const ProfileEdit = () => {
- const { member, isPending: isLoading, isError, error } = useUserMe()
- const { t } = useTranslation()
-
- if (isError) {
- throw error
- }
-
- return (
- <RouteDrawer>
- <RouteDrawer.Header className="capitalize">
- <RouteDrawer.Title asChild>
- <Heading>{t("profile.edit.header")}</Heading>
- </RouteDrawer.Title>
- </RouteDrawer.Header>
- {!isLoading && member && <EditProfileForm user={member} />}
- </RouteDrawer>
- )
-}
-
-export const Component = ProfileEdit
diff --git a/packages/vendor/src/pages/settings/profile/index.tsx b/packages/vendor/src/pages/settings/profile/index.tsx
deleted file mode 100644
index cc334d48a..000000000
--- a/packages/vendor/src/pages/settings/profile/index.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { useUserMe } from "@hooks/api/users";
-import { ProfileGeneralSection } from "./_components/profile-general-section";
-
-import { SingleColumnPageSkeleton } from "@components/common/skeleton";
-import { SingleColumnPage } from "@components/layout/pages";
-
-const ProfileDetail = () => {
- const { member, isPending: isLoading, isError, error } = useUserMe();
-
- if (isLoading || !member) {
- return <SingleColumnPageSkeleton sections={1} />;
- }
-
- if (isError) {
- throw error;
- }
-
- return (
- <SingleColumnPage>
- <ProfileGeneralSection user={member} />
- </SingleColumnPage>
- );
-};
-
-export const Component = ProfileDetail;
diff --git a/packages/vendor/src/pages/settings/seller/_components/seller-detail-header.tsx b/packages/vendor/src/pages/settings/seller/_components/seller-detail-header.tsx
new file mode 100644
index 000000000..5f64f10c7
--- /dev/null
+++ b/packages/vendor/src/pages/settings/seller/_components/seller-detail-header.tsx
@@ -0,0 +1,68 @@
+import { Children, ReactNode } from "react";
+import { PencilSquare } from "@medusajs/icons";
+import { Heading } from "@medusajs/ui";
+import { useTranslation } from "react-i18next";
+
+import { ActionMenu } from "@components/common/action-menu";
+import { HttpTypes } from "@mercurjs/types";
+
+type SellerProps = {
+ seller: HttpTypes.StoreSellerResponse["seller"];
+};
+
+export const SellerDetailTitle = ({ seller }: SellerProps) => {
+ return (
+ <div className="flex items-center gap-x-4">
+ <Heading>{seller.name}</Heading>
+ </div>
+ );
+};
+
+export const SellerDetailEditButton = () => {
+ const { t } = useTranslation();
+ return (
+ <ActionMenu
+ groups={[
+ {
+ actions: [
+ {
+ icon: <PencilSquare />,
+ label: t("actions.edit"),
+ to: "edit",
+ },
+ ],
+ },
+ ]}
+ />
+ );
+};
+
+export const SellerDetailActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center gap-x-2">
+ {Children.count(children) > 0 ? children : <SellerDetailEditButton />}
+ </div>
+ );
+};
+
+export const SellerDetailHeader = ({
+ seller,
+ children,
+}: SellerProps & { children?: ReactNode }) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <SellerDetailTitle seller={seller} />
+ <SellerDetailActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/settings/seller/_components/seller-general-section.tsx b/packages/vendor/src/pages/settings/seller/_components/seller-general-section.tsx
index ed0fd1918..d1e98886b 100644
--- a/packages/vendor/src/pages/settings/seller/_components/seller-general-section.tsx
+++ b/packages/vendor/src/pages/settings/seller/_components/seller-general-section.tsx
@@ -1,134 +1,128 @@
-import { PencilSquare } from "@medusajs/icons";
-import { Container, Heading, Text } from "@medusajs/ui";
+import { Children, ReactNode } from "react";
+import { Container, Text } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
-import { ActionMenu } from "@components/common/action-menu";
import ImageAvatar from "@components/common/image-avatar/image-avatar";
import { HttpTypes } from "@mercurjs/types";
-type StoreGeneralSectionProps = {
+import { SellerDetailHeader } from "./seller-detail-header";
+
+type SellerGeneralSectionProps = {
seller: HttpTypes.StoreSellerResponse["seller"];
+ children?: ReactNode;
};
-export const SellerGeneralSection = ({ seller }: StoreGeneralSectionProps) => {
+export const SellerGeneralSection = ({
+ seller,
+ children,
+}: SellerGeneralSectionProps) => {
const { t } = useTranslation();
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div className="flex items-center gap-x-4">
- <Heading>{seller.name}</Heading>
- </div>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- icon: <PencilSquare />,
- label: t("actions.edit"),
- to: "edit",
- },
- ],
- },
- ]}
- />
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("store.logo", "Logo")}
- </Text>
- {seller.logo ? (
- <ImageAvatar src={seller.logo} size={12} />
- ) : (
- <Text size="small" leading="compact">
- {"-"}
- </Text>
- )}
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("store.coverImage", "Cover image")}
- </Text>
- {seller.cover_image ? (
- <ImageAvatar src={seller.cover_image} size={12} />
- ) : (
- <Text size="small" leading="compact">
- {"-"}
- </Text>
- )}
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.handle")}
- </Text>
- <Text size="small" leading="compact">
- {seller.handle || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.email")}
- </Text>
- <Text size="small" leading="compact">
- {seller.email || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.phone")}
- </Text>
- <Text size="small" leading="compact">
- {seller.phone || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.address")}
- </Text>
- <Text size="small" leading="compact">
- {seller.address_1 || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.address2")}
- </Text>
- <Text size="small" leading="compact">
- {seller.address_2 || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.city")}
- </Text>
- <Text size="small" leading="compact">
- {seller.city || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.state")}
- </Text>
- <Text size="small" leading="compact">
- {seller.province || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.postalCode")}
- </Text>
- <Text size="small" leading="compact">
- {seller.postal_code || "-"}
- </Text>
- </div>
- <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
- <Text size="small" leading="compact" weight="plus">
- {t("fields.country")}
- </Text>
- <Text size="small" leading="compact">
- {seller.country_code || "-"}
- </Text>
- </div>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <SellerDetailHeader seller={seller} />
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("store.logo", "Logo")}
+ </Text>
+ {seller.logo ? (
+ <ImageAvatar src={seller.logo} size={12} />
+ ) : (
+ <Text size="small" leading="compact">
+ {"-"}
+ </Text>
+ )}
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("store.coverImage", "Cover image")}
+ </Text>
+ {seller.cover_image ? (
+ <ImageAvatar src={seller.cover_image} size={12} />
+ ) : (
+ <Text size="small" leading="compact">
+ {"-"}
+ </Text>
+ )}
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.handle")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.handle || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.email")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.email || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.phone")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.phone || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.address")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.address_1 || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.address2")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.address_2 || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.city")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.city || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.state")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.province || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.postalCode")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.postal_code || "-"}
+ </Text>
+ </div>
+ <div className="text-ui-fg-subtle grid grid-cols-2 px-6 py-4">
+ <Text size="small" leading="compact" weight="plus">
+ {t("fields.country")}
+ </Text>
+ <Text size="small" leading="compact">
+ {seller.country_code || "-"}
+ </Text>
+ </div>
+ </>
+ )}
</Container>
);
};
diff --git a/packages/vendor/src/pages/settings/seller/index.ts b/packages/vendor/src/pages/settings/seller/index.ts
new file mode 100644
index 000000000..6da7c54ed
--- /dev/null
+++ b/packages/vendor/src/pages/settings/seller/index.ts
@@ -0,0 +1 @@
+export * from './seller-detail-page'
diff --git a/packages/vendor/src/pages/settings/seller/index.tsx b/packages/vendor/src/pages/settings/seller/index.tsx
deleted file mode 100644
index 34b950139..000000000
--- a/packages/vendor/src/pages/settings/seller/index.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { SingleColumnPageSkeleton } from "@components/common/skeleton";
-import { SingleColumnPage } from "@components/layout/pages";
-import { SellerGeneralSection } from "./_components/seller-general-section";
-import { useMe } from "@/hooks/api";
-
-const SellerDetail = () => {
- const { seller, isPending, isError, error } = useMe();
-
- if (isPending || !seller) {
- return <SingleColumnPageSkeleton sections={2} />;
- }
-
- if (isError) {
- throw error;
- }
-
- return (
- <SingleColumnPage data={seller} hasOutlet>
- <SellerGeneralSection seller={seller} />
- </SingleColumnPage>
- );
-};
-
-export const Component = SellerDetail;
diff --git a/packages/vendor/src/pages/settings/seller/seller-detail-page.tsx b/packages/vendor/src/pages/settings/seller/seller-detail-page.tsx
new file mode 100644
index 000000000..1010e5fb7
--- /dev/null
+++ b/packages/vendor/src/pages/settings/seller/seller-detail-page.tsx
@@ -0,0 +1,43 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPageSkeleton } from "@components/common/skeleton";
+import { SingleColumnPage } from "@components/layout/pages";
+import { useMe } from "@/hooks/api";
+
+import { SellerGeneralSection } from "./_components/seller-general-section";
+import {
+ SellerDetailHeader,
+ SellerDetailTitle,
+ SellerDetailActions,
+ SellerDetailEditButton,
+} from "./_components/seller-detail-header";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ const { seller, isPending, isError, error } = useMe();
+
+ if (isPending || !seller) {
+ return <SingleColumnPageSkeleton sections={2} />;
+ }
+
+ if (isError) {
+ throw error;
+ }
+
+ return (
+ <SingleColumnPage data={seller} hasOutlet>
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <SellerGeneralSection seller={seller} />
+ )}
+ </SingleColumnPage>
+ );
+};
+
+export const SellerDetailPage = Object.assign(Root, {
+ GeneralSection: SellerGeneralSection,
+ Header: SellerDetailHeader,
+ HeaderTitle: SellerDetailTitle,
+ HeaderActions: SellerDetailActions,
+ HeaderEditButton: SellerDetailEditButton,
+});
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/[id]/index.ts b/packages/vendor/src/pages/settings/shipping-profiles/[id]/index.ts
new file mode 100644
index 000000000..44dcad56b
--- /dev/null
+++ b/packages/vendor/src/pages/settings/shipping-profiles/[id]/index.ts
@@ -0,0 +1,2 @@
+export * from './loader'
+export * from './shipping-profile-detail-page'
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/[id]/index.tsx b/packages/vendor/src/pages/settings/shipping-profiles/[id]/shipping-profile-detail-page.tsx
similarity index 67%
rename from packages/vendor/src/pages/settings/shipping-profiles/[id]/index.tsx
rename to packages/vendor/src/pages/settings/shipping-profiles/[id]/shipping-profile-detail-page.tsx
index a5365ee4a..c292931cd 100644
--- a/packages/vendor/src/pages/settings/shipping-profiles/[id]/index.tsx
+++ b/packages/vendor/src/pages/settings/shipping-profiles/[id]/shipping-profile-detail-page.tsx
@@ -1,13 +1,15 @@
+import { Children, ReactNode } from "react";
import { useLoaderData, useParams } from "react-router-dom";
import { SingleColumnPageSkeleton } from "@components/common/skeleton";
+import { SingleColumnPage } from "@components/layout/pages";
import { useShippingProfile } from "@hooks/api/shipping-profiles";
+
import { ShippingProfileGeneralSection } from "./_components/shipping-profile-general-section";
-import { SingleColumnPage } from "@components/layout/pages";
-import { shippingProfileLoader } from "./loader";
+import type { shippingProfileLoader } from "./loader";
-const ShippingProfileDetail = () => {
+const Root = ({ children }: { children?: ReactNode }) => {
const { shipping_profile_id } = useParams();
const initialData = useLoaderData() as Awaited<
@@ -32,11 +34,15 @@ const ShippingProfileDetail = () => {
return (
<SingleColumnPage data={shipping_profile}>
- <ShippingProfileGeneralSection profile={shipping_profile} />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <ShippingProfileGeneralSection profile={shipping_profile} />
+ )}
</SingleColumnPage>
);
};
-export const Component = ShippingProfileDetail;
-export { shippingProfileLoader as loader } from "./loader";
-export { ShippingProfileDetailBreadcrumb as Breadcrumb } from "./breadcrumb";
+export const ShippingProfileDetailPage = Object.assign(Root, {
+ GeneralSection: ShippingProfileGeneralSection,
+});
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/_components/index.ts b/packages/vendor/src/pages/settings/shipping-profiles/_components/index.ts
new file mode 100644
index 000000000..697fb6ce9
--- /dev/null
+++ b/packages/vendor/src/pages/settings/shipping-profiles/_components/index.ts
@@ -0,0 +1,3 @@
+export * from "./shipping-profile-list-table"
+export * from "./shipping-profile-list-header"
+export * from "./shipping-profile-list-data-table"
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-data-table.tsx b/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-data-table.tsx
new file mode 100644
index 000000000..798d51ff6
--- /dev/null
+++ b/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-data-table.tsx
@@ -0,0 +1,67 @@
+import { keepPreviousData } from "@tanstack/react-query"
+import { useTranslation } from "react-i18next"
+
+import { _DataTable } from "@components/table/data-table"
+import { useShippingProfiles } from "@hooks/api"
+import { useDataTable } from "@hooks/use-data-table"
+import { useShippingProfileTableColumns } from "./use-shipping-profile-table-columns"
+import { useShippingProfileTableFilters } from "./use-shipping-profile-table-filters"
+import { useShippingProfileTableQuery } from "./use-shipping-profile-table-query"
+
+const PAGE_SIZE = 20
+
+export const ShippingProfileListDataTable = () => {
+ const { t } = useTranslation()
+
+ const { raw, searchParams } = useShippingProfileTableQuery({
+ pageSize: PAGE_SIZE,
+ })
+
+ const { shipping_profiles, count, isLoading, isError, error } =
+ useShippingProfiles(searchParams, {
+ placeholderData: keepPreviousData,
+ })
+
+ const columns = useShippingProfileTableColumns()
+ const filters = useShippingProfileTableFilters()
+
+ const { table } = useDataTable({
+ data: shipping_profiles ?? [],
+ columns,
+ count,
+ enablePagination: true,
+ getRowId: (row, index) => row?.id ?? `row-${index}`,
+ pageSize: PAGE_SIZE,
+ })
+
+ if (isError) {
+ throw error
+ }
+
+ return (
+ <_DataTable
+ table={table}
+ pageSize={PAGE_SIZE}
+ count={count}
+ columns={columns}
+ filters={filters}
+ orderBy={[
+ { key: "name", label: t("fields.name") },
+ { key: "type", label: t("fields.type") },
+ {
+ key: "created_at",
+ label: t("fields.createdAt"),
+ },
+ {
+ key: "updated_at",
+ label: t("fields.updatedAt"),
+ },
+ ]}
+ isLoading={isLoading}
+ navigateTo={(row) => row.id}
+ queryObject={raw}
+ search
+ pagination
+ />
+ )
+}
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-header.tsx b/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-header.tsx
new file mode 100644
index 000000000..ef293ac58
--- /dev/null
+++ b/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-header.tsx
@@ -0,0 +1,60 @@
+import { Children, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Link } from "react-router-dom";
+import { Button, Heading, Text } from "@medusajs/ui";
+
+export const ShippingProfileListTitle = () => {
+ const { t } = useTranslation();
+ return (
+ <div>
+ <Heading>{t("shippingProfile.domain")}</Heading>
+ <Text className="text-ui-fg-subtle" size="small">
+ {t("shippingProfile.subtitle")}
+ </Text>
+ </div>
+ );
+};
+
+export const ShippingProfileListCreateButton = () => {
+ const { t } = useTranslation();
+ return (
+ <Button size="small" variant="secondary" asChild>
+ <Link to="create">{t("actions.create")}</Link>
+ </Button>
+ );
+};
+
+export const ShippingProfileListActions = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-center gap-x-2">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <ShippingProfileListCreateButton />
+ )}
+ </div>
+ );
+};
+
+export const ShippingProfileListHeader = ({
+ children,
+}: {
+ children?: ReactNode;
+}) => {
+ return (
+ <div className="flex items-center justify-between px-6 py-4">
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <ShippingProfileListTitle />
+ <ShippingProfileListActions />
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-table.tsx b/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-table.tsx
index b17f58b0c..d1f7c82ef 100644
--- a/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-table.tsx
+++ b/packages/vendor/src/pages/settings/shipping-profiles/_components/shipping-profile-list-table.tsx
@@ -1,84 +1,20 @@
-import { Button, Container, Heading, Text } from "@medusajs/ui"
-import { Link } from "react-router-dom"
+import { Children, ReactNode } from "react";
+import { Container } from "@medusajs/ui";
-import { keepPreviousData } from "@tanstack/react-query"
-import { useTranslation } from "react-i18next"
-import { _DataTable } from "@components/table/data-table"
-import { useShippingProfiles } from "@hooks/api"
-import { useDataTable } from "@hooks/use-data-table"
-import { useShippingProfileTableColumns } from "./use-shipping-profile-table-columns"
-import { useShippingProfileTableFilters } from "./use-shipping-profile-table-filters"
-import { useShippingProfileTableQuery } from "./use-shipping-profile-table-query"
-
-const PAGE_SIZE = 20
-
-export const ShippingProfileListTable = () => {
- const { t } = useTranslation()
-
- const { raw, searchParams } = useShippingProfileTableQuery({
- pageSize: PAGE_SIZE,
- })
-
- const { shipping_profiles, count, isLoading, isError, error } =
- useShippingProfiles(searchParams, {
- placeholderData: keepPreviousData,
- })
-
- const columns = useShippingProfileTableColumns()
- const filters = useShippingProfileTableFilters()
-
- const { table } = useDataTable({
- data: shipping_profiles ?? [],
- columns,
- count,
- enablePagination: true,
- getRowId: (row, index) => row?.id ?? `row-${index}`,
- pageSize: PAGE_SIZE,
- })
-
- if (isError) {
- throw error
- }
+import { ShippingProfileListHeader } from "./shipping-profile-list-header";
+import { ShippingProfileListDataTable } from "./shipping-profile-list-data-table";
+export const ShippingProfileListTable = ({ children }: { children?: ReactNode }) => {
return (
<Container className="divide-y p-0">
- <div className="flex items-center justify-between px-6 py-4">
- <div>
- <Heading>{t("shippingProfile.domain")}</Heading>
- <Text className="text-ui-fg-subtle" size="small">
- {t("shippingProfile.subtitle")}
- </Text>
- </div>
- <div>
- <Button size="small" variant="secondary" asChild>
- <Link to="create">{t("actions.create")}</Link>
- </Button>
- </div>
- </div>
- <_DataTable
- table={table}
- pageSize={PAGE_SIZE}
- count={count}
- columns={columns}
- filters={filters}
- orderBy={[
- { key: "name", label: t("fields.name") },
- { key: "type", label: t("fields.type") },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- isLoading={isLoading}
- navigateTo={(row) => row.id}
- queryObject={raw}
- search
- pagination
- />
+ {Children.count(children) > 0 ? (
+ children
+ ) : (
+ <>
+ <ShippingProfileListHeader />
+ <ShippingProfileListDataTable />
+ </>
+ )}
</Container>
- )
-}
+ );
+};
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/index.ts b/packages/vendor/src/pages/settings/shipping-profiles/index.ts
new file mode 100644
index 000000000..7982ce03f
--- /dev/null
+++ b/packages/vendor/src/pages/settings/shipping-profiles/index.ts
@@ -0,0 +1 @@
+export * from './shipping-profile-list-page'
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/index.tsx b/packages/vendor/src/pages/settings/shipping-profiles/index.tsx
deleted file mode 100644
index 2db3d6336..000000000
--- a/packages/vendor/src/pages/settings/shipping-profiles/index.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { SingleColumnPage } from "@components/layout/pages";
-import { ShippingProfileListTable } from "./_components/shipping-profile-list-table";
-
-const ShippingProfileList = () => {
- return (
- <SingleColumnPage>
- <ShippingProfileListTable />
- </SingleColumnPage>
- );
-};
-
-export const Component = ShippingProfileList;
diff --git a/packages/vendor/src/pages/settings/shipping-profiles/shipping-profile-list-page.tsx b/packages/vendor/src/pages/settings/shipping-profiles/shipping-profile-list-page.tsx
new file mode 100644
index 000000000..e38c0a8ab
--- /dev/null
+++ b/packages/vendor/src/pages/settings/shipping-profiles/shipping-profile-list-page.tsx
@@ -0,0 +1,29 @@
+import { Children, ReactNode } from "react";
+
+import { SingleColumnPage } from "@components/layout/pages";
+
+import {
+ ShippingProfileListTable,
+ ShippingProfileListDataTable,
+ ShippingProfileListHeader,
+ ShippingProfileListActions,
+ ShippingProfileListTitle,
+ ShippingProfileListCreateButton,
+} from "./_components";
+
+const Root = ({ children }: { children?: ReactNode }) => {
+ return (
+ <SingleColumnPage hasOutlet>
+ {Children.count(children) > 0 ? children : <ShippingProfileListTable />}
+ </SingleColumnPage>
+ );
+};
+
+export const ShippingProfileListPage = Object.assign(Root, {
+ Table: ShippingProfileListTable,
+ Header: ShippingProfileListHeader,
+ HeaderTitle: ShippingProfileListTitle,
+ HeaderActions: ShippingProfileListActions,
+ HeaderCreateButton: ShippingProfileListCreateButton,
+ DataTable: ShippingProfileListDataTable,
+});
diff --git a/packages/vendor/src/pages/settings/users/[id]/_components/user-general-section.tsx b/packages/vendor/src/pages/settings/users/[id]/_components/user-general-section.tsx
deleted file mode 100644
index c74b146d4..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/_components/user-general-section.tsx
+++ /dev/null
@@ -1,88 +0,0 @@
-import { PencilSquare, Trash } from "@medusajs/icons"
-import { Container, Heading, Text, toast, usePrompt } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-import { useNavigate } from "react-router-dom"
-import { ActionMenu } from "@components/common/action-menu"
-import { useDeleteUser } from "@hooks/api/users"
-import { TeamMemberProps } from "@custom-types/user"
-
-type UserGeneralSectionProps = {
- member: TeamMemberProps
-}
-
-export const UserGeneralSection = ({ member }: UserGeneralSectionProps) => {
- const { t } = useTranslation()
- const navigate = useNavigate()
- const prompt = usePrompt()
-
- const { mutateAsync } = useDeleteUser(member.id)
-
- const handleDeleteUser = async () => {
- const res = await prompt({
- title: t("general.areYouSure"),
- description: t("users.deleteUserWarning", {
- name: member.name ?? member.email,
- }),
- verificationText: member.name ?? member.email,
- verificationInstruction: t("general.typeToConfirm"),
- confirmText: t("actions.delete"),
- cancelText: t("actions.cancel"),
- })
-
- if (!res) {
- return
- }
-
- await mutateAsync(undefined, {
- onSuccess: () => {
- toast.success(
- t("users.deleteUserSuccess", {
- name: member.email,
- })
- )
- navigate("..")
- },
- 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>{member.email}</Heading>
- <ActionMenu
- groups={[
- {
- actions: [
- {
- label: t("actions.edit"),
- to: "edit",
- icon: <PencilSquare />,
- },
- ],
- },
- {
- actions: [
- {
- label: t("actions.delete"),
- onClick: handleDeleteUser,
- icon: <Trash />,
- },
- ],
- },
- ]}
- />
- </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("fields.name")}
- </Text>
- <Text size="small" leading="compact">
- {member.name ?? "-"}
- </Text>
- </div>
- </Container>
- )
-}
diff --git a/packages/vendor/src/pages/settings/users/[id]/breadcrumb.tsx b/packages/vendor/src/pages/settings/users/[id]/breadcrumb.tsx
deleted file mode 100644
index 3eafe4cc9..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/breadcrumb.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { HttpTypes } from "@medusajs/types"
-import { UIMatch } from "react-router-dom"
-import { useUser } from "@hooks/api/users"
-
-type UserDetailBreadcrumbProps = UIMatch<HttpTypes.AdminUserResponse>
-
-export const UserDetailBreadcrumb = (props: UserDetailBreadcrumbProps) => {
- const { id } = props.params || {}
-
- const { user } = useUser(id!, undefined, {
- initialData: props.data,
- enabled: Boolean(id),
- })
-
- if (!user) {
- return null
- }
-
- const name = [user.first_name, user.last_name].filter(Boolean).join(" ")
-
- const display = name || user.email
-
- return <span>{display}</span>
-}
diff --git a/packages/vendor/src/pages/settings/users/[id]/edit/_components/edit-user-form.tsx b/packages/vendor/src/pages/settings/users/[id]/edit/_components/edit-user-form.tsx
deleted file mode 100644
index 50241eb1a..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/edit/_components/edit-user-form.tsx
+++ /dev/null
@@ -1,80 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { Button, Input } from "@medusajs/ui"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import * as zod from "zod"
-
-import { Form } from "@components/common/form"
-import { RouteDrawer, useRouteModal } from "@components/modals"
-import { KeyboundForm } from "@components/utilities/keybound-form"
-import { useUpdateUser } from "@hooks/api/users"
-import { TeamMemberProps } from "@custom-types/user"
-
-type EditUserFormProps = {
- member: TeamMemberProps
-}
-
-const EditUserFormSchema = zod.object({
- name: zod.string().min(1),
-})
-
-export const EditUserForm = ({ member }: EditUserFormProps) => {
- const { t } = useTranslation()
- const { handleSuccess } = useRouteModal()
-
- const form = useForm<zod.infer<typeof EditUserFormSchema>>({
- defaultValues: {
- name: member.name || "",
- },
- resolver: zodResolver(EditUserFormSchema),
- })
-
- const { mutateAsync, isPending } = useUpdateUser(member.id)
-
- const handleSubmit = form.handleSubmit(async (values) => {
- await mutateAsync(values, {
- onSuccess: () => {
- handleSuccess()
- },
- })
- })
-
- return (
- <RouteDrawer.Form form={form}>
- <KeyboundForm
- onSubmit={handleSubmit}
- className="flex flex-1 flex-col overflow-hidden"
- >
- <RouteDrawer.Body className="flex max-w-full flex-1 flex-col gap-y-8 overflow-y-auto">
- <Form.Field
- control={form.control}
- name="name"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label>Name</Form.Label>
- <Form.Control>
- <Input {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- </RouteDrawer.Body>
- <RouteDrawer.Footer>
- <div className="flex items-center justify-end gap-x-2">
- <RouteDrawer.Close asChild>
- <Button size="small" variant="secondary">
- {t("actions.cancel")}
- </Button>
- </RouteDrawer.Close>
- <Button size="small" type="submit" isLoading={isPending}>
- {t("actions.save")}
- </Button>
- </div>
- </RouteDrawer.Footer>
- </KeyboundForm>
- </RouteDrawer.Form>
- )
-}
diff --git a/packages/vendor/src/pages/settings/users/[id]/edit/index.tsx b/packages/vendor/src/pages/settings/users/[id]/edit/index.tsx
deleted file mode 100644
index 9278a17b8..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/edit/index.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import { Heading } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-import { useParams } from "react-router-dom"
-import { RouteDrawer } from "@components/modals"
-import { useUser } from "@hooks/api/users"
-import { EditUserForm } from "./_components/edit-user-form"
-
-const UserEdit = () => {
- const { t } = useTranslation()
- const { id } = useParams()
- const { member, isPending: isLoading, isError, error } = useUser(id!)
-
- if (isError) {
- throw error
- }
-
- return (
- <RouteDrawer>
- <RouteDrawer.Header>
- <Heading>{t("users.editUser")}</Heading>
- </RouteDrawer.Header>
- {!isLoading && member && <EditUserForm member={member} />}
- </RouteDrawer>
- )
-}
-
-export const Component = UserEdit
diff --git a/packages/vendor/src/pages/settings/users/[id]/index.tsx b/packages/vendor/src/pages/settings/users/[id]/index.tsx
deleted file mode 100644
index 1faf285d4..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/index.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import { useParams } from "react-router-dom"
-
-import { useUser } from "@hooks/api/users"
-import { UserGeneralSection } from "./_components/user-general-section"
-
-import { SingleColumnPageSkeleton } from "@components/common/skeleton"
-import { SingleColumnPage } from "@components/layout/pages"
-import { useDashboardExtension } from "@/extensions"
-
-const UserDetail = () => {
- const { id } = useParams()
- const { member, isPending: isLoading, isError, error } = useUser(id!)
-
- const { getWidgets } = useDashboardExtension()
-
- if (isLoading || !member) {
- return <SingleColumnPageSkeleton />
- }
-
- if (isError) {
- throw error
- }
-
- return (
- <SingleColumnPage
- data={member}
- widgets={{
- after: getWidgets("user.details.after"),
- before: getWidgets("user.details.before"),
- }}
- >
- <UserGeneralSection member={member} />
- </SingleColumnPage>
- )
-}
-
-export const Component = UserDetail
-export { userLoader as loader } from "./loader"
-export { UserDetailBreadcrumb as Breadcrumb } from "./breadcrumb"
diff --git a/packages/vendor/src/pages/settings/users/[id]/loader.ts b/packages/vendor/src/pages/settings/users/[id]/loader.ts
deleted file mode 100644
index 6847477ed..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/loader.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { LoaderFunctionArgs } from "react-router-dom"
-
-import { productsQueryKeys } from "@hooks/api/products"
-import { fetchQuery } from "@lib/client"
-import { queryClient } from "@lib/query-client"
-
-const userDetailQuery = (id: string) => ({
- queryKey: productsQueryKeys.detail(id),
- queryFn: async () => fetchQuery(`/vendor/members/${id}`, { method: "GET" }),
-})
-
-export const userLoader = async ({ params }: LoaderFunctionArgs) => {
- const id = params.id
- const query = userDetailQuery(id!)
-
- return queryClient.ensureQueryData(query)
-}
diff --git a/packages/vendor/src/pages/settings/users/[id]/metadata/index.tsx b/packages/vendor/src/pages/settings/users/[id]/metadata/index.tsx
deleted file mode 100644
index e798804b1..000000000
--- a/packages/vendor/src/pages/settings/users/[id]/metadata/index.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import { useParams } from "react-router-dom"
-import { MetadataForm } from "@components/forms/metadata-form"
-import { RouteDrawer } from "@components/modals"
-import { useUpdateUser, useUser } from "@hooks/api"
-type FetchError = Error & { status?: number }
-
-const UserMetadata = () => {
- const { id } = useParams()
-
- const { user, isPending, isError, error } = useUser(id!)
- const { mutateAsync, isPending: isMutating } = useUpdateUser(id!)
-
- if (isError) {
- throw error
- }
-
- const handleUpdate = async (
- params: { metadata?: Record<string, any> | null },
- callbacks: { onSuccess: () => void; onError: (error: FetchError) => void }
- ) => {
- return mutateAsync(
- { metadata: params.metadata ?? undefined },
- callbacks
- )
- }
-
- return (
- <RouteDrawer>
- <MetadataForm
- isPending={isPending}
- isMutating={isMutating}
- hook={handleUpdate}
- metadata={user?.metadata}
- />
- </RouteDrawer>
- )
-}
-
-export const Component = UserMetadata
diff --git a/packages/vendor/src/pages/settings/users/_components/user-list-table.tsx b/packages/vendor/src/pages/settings/users/_components/user-list-table.tsx
deleted file mode 100644
index ba876d0d4..000000000
--- a/packages/vendor/src/pages/settings/users/_components/user-list-table.tsx
+++ /dev/null
@@ -1,131 +0,0 @@
-import { Container, createDataTableColumnHelper } from "@medusajs/ui"
-import { keepPreviousData } from "@tanstack/react-query"
-import { useMemo } from "react"
-import { useTranslation } from "react-i18next"
-import { useNavigate } from "react-router-dom"
-
-import { PencilSquare } from "@medusajs/icons"
-import { DataTable } from "@components/data-table"
-// import { useDataTableDateFilters } from "@components/data-table/helpers/general/use-data-table-date-filters"
-import { useUsers } from "@hooks/api/users"
-import { useQueryParams } from "@hooks/use-query-params"
-import { TeamMemberProps } from "@custom-types/user"
-
-const PAGE_SIZE = 20
-
-export const UserListTable = () => {
- const { q, order, offset } = useQueryParams(["q", "order", "offset"])
- const { members, isPending, isError, error } = useUsers(
- {
- limit: 9999,
- order,
- },
- {
- placeholderData: keepPreviousData,
- }
- )
-
- const processedMembers = useMemo(() => {
- if (q) {
- return members?.filter((member) =>
- member.email.toLowerCase().includes(q.toLowerCase())
- )
- }
- return members
- }, [members, q])
-
- const count = processedMembers?.length ?? 0
- const membersOffset = offset ? parseInt(offset) : 0
-
- const columns = useColumns()
- // const filters = useFilters()
-
- const { t } = useTranslation()
-
- if (isError) {
- throw error
- }
-
- return (
- <Container className="divide-y p-0">
- <DataTable
- data={
- processedMembers?.slice(membersOffset, membersOffset + PAGE_SIZE) ??
- []
- }
- columns={columns}
- // filters={filters}
- getRowId={(row) => row.id}
- rowCount={count}
- pageSize={PAGE_SIZE}
- heading={t("users.domain")}
- rowHref={(row) => `${row.id}`}
- isLoading={isPending}
- action={{
- label: t("users.invite"),
- to: "invite",
- }}
- emptyState={{
- empty: {
- heading: t("users.list.empty.heading"),
- description: t("users.list.empty.description"),
- },
- filtered: {
- heading: t("users.list.filtered.heading"),
- description: t("users.list.filtered.description"),
- },
- }}
- />
- </Container>
- )
-}
-
-const columnHelper = createDataTableColumnHelper<TeamMemberProps>()
-
-const useColumns = () => {
- const { t } = useTranslation()
- const navigate = useNavigate()
-
- return useMemo(
- () => [
- columnHelper.accessor("email", {
- header: "Email",
- cell: ({ row }) => {
- return row.original.email
- },
- enableSorting: true,
- sortAscLabel: t("filters.sorting.alphabeticallyAsc"),
- sortDescLabel: t("filters.sorting.alphabeticallyDesc"),
- }),
- columnHelper.accessor("name", {
- header: "Name",
- cell: ({ row }) => {
- return row.original.name || "-"
- },
- enableSorting: true,
- sortAscLabel: t("filters.sorting.alphabeticallyAsc"),
- sortDescLabel: t("filters.sorting.alphabeticallyDesc"),
- }),
- columnHelper.action({
- actions: [
- {
- label: t("actions.edit"),
- icon: <PencilSquare />,
- onClick: (ctx) => {
- navigate(`${ctx.row.original.id}/edit`)
- },
- },
- ],
- }),
- ],
- [t, navigate]
- )
-}
-
-// const useFilters = () => {
-// const dateFilters = useDataTableDateFilters()
-
-// return useMemo(() => {
-// return dateFilters
-// }, [dateFilters])
-// }
diff --git a/packages/vendor/src/pages/settings/users/index.tsx b/packages/vendor/src/pages/settings/users/index.tsx
deleted file mode 100644
index b8c9d24b2..000000000
--- a/packages/vendor/src/pages/settings/users/index.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { SingleColumnPage } from "@components/layout/pages"
-import { useDashboardExtension } from "@/extensions"
-import { UserListTable } from "./_components/user-list-table"
-
-const UserList = () => {
- const { getWidgets } = useDashboardExtension()
-
- return (
- <SingleColumnPage
- widgets={{
- after: getWidgets("user.list.after"),
- before: getWidgets("user.list.before"),
- }}
- >
- <UserListTable />
- </SingleColumnPage>
- )
-}
-
-export const Component = UserList
diff --git a/packages/vendor/src/pages/settings/users/invite/_components/invite-user-form.tsx b/packages/vendor/src/pages/settings/users/invite/_components/invite-user-form.tsx
deleted file mode 100644
index 9f54f63ce..000000000
--- a/packages/vendor/src/pages/settings/users/invite/_components/invite-user-form.tsx
+++ /dev/null
@@ -1,263 +0,0 @@
-import { zodResolver } from "@hookform/resolvers/zod"
-import { HttpTypes } from "@medusajs/types"
-import {
- Alert,
- Button,
- Container,
- Heading,
- Input,
- StatusBadge,
- Text,
- Tooltip,
-} from "@medusajs/ui"
-import { createColumnHelper } from "@tanstack/react-table"
-// import copy from 'copy-to-clipboard';
-import { format } from "date-fns"
-import { useMemo } from "react"
-import { useForm } from "react-hook-form"
-import { useTranslation } from "react-i18next"
-import * as zod from "zod"
-
-import { Form } from "@components/common/form"
-import { RouteFocusModal } from "@components/modals/index.ts"
-import { _DataTable } from "@components/table/data-table"
-import { KeyboundForm } from "@components/utilities/keybound-form/keybound-form.tsx"
-import { useCreateInvite, useInvites } from "@hooks/api/invites"
-import { useUserInviteTableQuery } from "@hooks/table/query/use-user-invite-table-query"
-import { useDataTable } from "@hooks/use-data-table"
-import { isFetchError } from "@lib/is-fetch-error"
-
-const InviteUserSchema = zod.object({
- email: zod.string().email(),
-})
-
-const PAGE_SIZE = 10
-const PREFIX = "usr_invite"
-
-export const InviteUserForm = () => {
- const { t } = useTranslation()
-
- const form = useForm<zod.infer<typeof InviteUserSchema>>({
- defaultValues: {
- email: "",
- },
- resolver: zodResolver(InviteUserSchema),
- })
-
- const { raw, searchParams } = useUserInviteTableQuery({
- prefix: PREFIX,
- pageSize: PAGE_SIZE,
- })
-
- const {
- invites,
- isPending: isLoading,
- isError,
- error,
- } = useInvites({
- limit: 9999,
- order: searchParams.order,
- })
-
- const processedInvites = useMemo(() => {
- if (searchParams?.q) {
- return invites?.filter((invite) =>
- invite.email
- .toLowerCase()
- .includes(searchParams?.q?.toLowerCase() ?? "")
- )
- }
- return invites
- }, [invites, searchParams])
-
- const offset = searchParams.offset ?? 0
-
- const columns = useColumns()
-
- const { table } = useDataTable({
- data: processedInvites?.slice(offset, offset + PAGE_SIZE) ?? [],
- columns,
- count: processedInvites?.length ?? 0,
- enablePagination: true,
- getRowId: (row) => row.id,
- pageSize: PAGE_SIZE,
- prefix: PREFIX,
- })
-
- const { mutateAsync, isPending } = useCreateInvite()
-
- const handleSubmit = form.handleSubmit(async (values) => {
- try {
- await mutateAsync({ email: values.email })
- form.reset()
- } catch (error) {
- if (isFetchError(error) && error.status === 400) {
- form.setError("root", {
- type: "manual",
- message: error.message,
- })
- return
- }
- }
- })
-
- if (isError) {
- throw error
- }
-
- return (
- <RouteFocusModal.Form form={form}>
- <KeyboundForm
- onSubmit={handleSubmit}
- className="flex h-full flex-col overflow-hidden"
- >
- <RouteFocusModal.Header />
- <RouteFocusModal.Body className="flex flex-1 flex-col overflow-hidden">
- <div className="flex flex-1 flex-col items-center overflow-y-auto">
- <div className="flex w-full max-w-[720px] flex-col gap-y-8 px-2 py-16">
- <div>
- <Heading>{t("users.inviteUser")}</Heading>
- <Text size="small" className="text-ui-fg-subtle">
- {t("users.inviteUserHint")}
- </Text>
- </div>
-
- {form.formState.errors.root && (
- <Alert
- variant="error"
- dismissible={false}
- className="text-balance"
- >
- {form.formState.errors.root.message}
- </Alert>
- )}
-
- <div className="flex flex-col gap-y-4">
- <div className="grid grid-cols-2 gap-4">
- <Form.Field
- control={form.control}
- name="email"
- render={({ field }) => {
- return (
- <Form.Item>
- <Form.Label>{t("fields.email")}</Form.Label>
- <Form.Control>
- <Input {...field} />
- </Form.Control>
- <Form.ErrorMessage />
- </Form.Item>
- )
- }}
- />
- </div>
- <div className="flex items-center justify-end">
- <Button
- size="small"
- variant="secondary"
- type="submit"
- isLoading={isPending}
- >
- {t("users.sendInvite")}
- </Button>
- </div>
- </div>
- <div className="flex flex-col gap-y-4">
- <Heading level="h2">{t("users.pendingInvites")}</Heading>
- <Container className="overflow-hidden p-0">
- <_DataTable
- table={table}
- columns={columns}
- count={processedInvites?.length ?? 0}
- pageSize={PAGE_SIZE}
- pagination
- search="autofocus"
- isLoading={isLoading}
- queryObject={raw}
- prefix={PREFIX}
- orderBy={[
- {
- key: "email",
- label: t("fields.email"),
- },
- {
- key: "created_at",
- label: t("fields.createdAt"),
- },
- {
- key: "updated_at",
- label: t("fields.updatedAt"),
- },
- ]}
- />
- </Container>
- </div>
- </div>
- </div>
- </RouteFocusModal.Body>
- </KeyboundForm>
- </RouteFocusModal.Form>
- )
-}
-
-const columnHelper = createColumnHelper<HttpTypes.AdminInvite>()
-
-const useColumns = () => {
- const { t } = useTranslation()
-
- return useMemo(
- () => [
- columnHelper.accessor("email", {
- header: t("fields.email"),
- cell: ({ getValue }) => {
- return getValue()
- },
- }),
- columnHelper.accessor("accepted", {
- header: t("fields.status"),
- cell: ({ getValue, row }) => {
- const accepted = getValue()
-
- const expired = new Date(row.original.expires_at) < new Date()
- if (accepted) {
- return (
- <Tooltip
- content={t("users.acceptedOnDate", {
- date: format(
- new Date(row.original.updated_at),
- "dd MMM, yyyy"
- ),
- })}
- >
- <StatusBadge color="green">
- {t("users.inviteStatus.accepted")}
- </StatusBadge>
- </Tooltip>
- )
- }
- if (expired) {
- return (
- <Tooltip
- content={t("users.expiredOnDate", {
- date: format(
- new Date(row.original.expires_at),
- "dd MMM, yyyy"
- ),
- })}
- >
- <StatusBadge color="red">
- {t("users.inviteStatus.expired")}
- </StatusBadge>
- </Tooltip>
- )
- }
- return (
- <StatusBadge color="orange">
- {t("users.inviteStatus.pending")}
- </StatusBadge>
- )
- },
- }),
- ],
- [t]
- )
-}
diff --git a/packages/vendor/src/pages/settings/users/invite/index.tsx b/packages/vendor/src/pages/settings/users/invite/index.tsx
deleted file mode 100644
index c3968f7a4..000000000
--- a/packages/vendor/src/pages/settings/users/invite/index.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { RouteFocusModal } from "@components/modals"
-import { InviteUserForm } from "./_components/invite-user-form"
-
-const UserInvite = () => {
- return (
- <RouteFocusModal>
- <InviteUserForm />
- </RouteFocusModal>
- )
-}
-
-export const Component = UserInvite
diff --git a/packages/vendor/tsup.config.ts b/packages/vendor/tsup.config.ts
index 5e16e3a32..52a65f83b 100644
--- a/packages/vendor/tsup.config.ts
+++ b/packages/vendor/tsup.config.ts
@@ -1,14 +1,9 @@
import { defineConfig } from "tsup";
-import { resolve } from "path";
-import { fileURLToPath } from "url";
-import { dirname } from "path";
-
-const __dirname = dirname(fileURLToPath(import.meta.url));
export default defineConfig({
clean: true,
dts: true,
- entry: ["src/index.ts", "src/index.css"],
+ entry: ["src/index.ts", "src/index.css", 'src/pages/index.ts'],
format: ["esm"],
external: ["react", "react-dom", "virtual:mercur/config", "virtual:mercur/routes", "virtual:mercur/components", "virtual:mercur/menu-items", "virtual:mercur/i18n"],
});