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.

chore(magento2-connector): align admin status section with Medusa detail-section patterns (#1704)

Viktor Holik33542a1c854a
diff --git a/packages/plugins/magento2-connector/src/admin/routes/settings/magento/components/magento-status-section.tsx b/packages/plugins/magento2-connector/src/admin/routes/settings/magento/components/magento-status-section.tsx
index ff2f2cf8b..dd8f965cb 100644
--- a/packages/plugins/magento2-connector/src/admin/routes/settings/magento/components/magento-status-section.tsx
+++ b/packages/plugins/magento2-connector/src/admin/routes/settings/magento/components/magento-status-section.tsx
@@ -1,10 +1,11 @@
-import { Container, Heading, StatusBadge, Text } from "@medusajs/ui"
-import { SectionRow } from "@mercurjs/dashboard-shared"
+import { Badge, Container, Heading, StatusBadge, Text, Tooltip } from "@medusajs/ui"
+import { SectionRow, Skeleton, useDate } from "@mercurjs/dashboard-shared"
import { useMagentoStatus } from "../../../../hooks/api/magento"
+import type { MagentoStatus, MagentoWebhookDeliveryStatus } from "../../../../lib/client"
+import { DELIVERY_STATE_COLOR, DELIVERY_STATE_LABEL } from "../lib/delivery-state"
-const formatDate = (value: string | null) =>
- value ? new Date(value).toLocaleString() : "Never"
+const DELIVERY_STATES: MagentoWebhookDeliveryStatus[] = ["delivered", "failed", "pending", "dead"]
export const MagentoStatusSection = () => {
const { connection: status, isPending, isError, error } = useMagentoStatus({
@@ -15,9 +16,6 @@ export const MagentoStatusSection = () => {
throw error
}
- const connected =
- !!status?.payment_provider.installed && (status?.webhooks.active ?? 0) > 0
-
return (
<Container className="divide-y p-0" data-testid="magento-status-section">
<div className="flex items-center justify-between px-6 py-4">
@@ -27,55 +25,86 @@ export const MagentoStatusSection = () => {
Connection between this marketplace and your Magento 2 storefront.
</Text>
</div>
- {isPending || !status ? (
- <StatusBadge color="grey">Checking</StatusBadge>
- ) : connected ? (
- <StatusBadge color="green">Connected</StatusBadge>
- ) : (
- <StatusBadge color="orange">Not configured</StatusBadge>
- )}
+ <ConnectionBadge status={isPending ? undefined : status} />
</div>
+ {isPending || !status ? <StatusRowsSkeleton /> : <StatusRows status={status} />}
+ </Container>
+ )
+}
+
+const ConnectionBadge = ({ status }: { status?: MagentoStatus }) => {
+ if (!status) {
+ return <StatusBadge color="grey">Checking</StatusBadge>
+ }
+
+ return status.payment_provider.installed && status.webhooks.active > 0 ? (
+ <StatusBadge color="green">Connected</StatusBadge>
+ ) : (
+ <StatusBadge color="orange">Not configured</StatusBadge>
+ )
+}
+
+const StatusRows = ({ status }: { status: MagentoStatus }) => {
+ const { getFullDate, getRelativeDate } = useDate()
+ const { deliveries } = status
+
+ const deliveryCounts = DELIVERY_STATES.map((state) => ({
+ state,
+ count: deliveries[state],
+ })).filter(({ state, count }) => count > 0 || state === "delivered")
+
+ return (
+ <>
<SectionRow
title="Payment provider"
value={
- status ? (
- status.payment_provider.installed ? (
- <StatusBadge color="green">{status.payment_provider.id}</StatusBadge>
- ) : (
- <StatusBadge color="red">Missing from payment module</StatusBadge>
- )
+ status.payment_provider.installed ? (
+ <Badge size="2xsmall">{status.payment_provider.id}</Badge>
) : (
- "-"
+ <StatusBadge color="red">Not registered</StatusBadge>
)
}
/>
<SectionRow
title="Webhooks"
- value={status ? `${status.webhooks.active} active of ${status.webhooks.total}` : "-"}
+ value={`${status.webhooks.active} of ${status.webhooks.total} active`}
/>
<SectionRow
- title={`Deliveries (last ${status?.deliveries.window_hours ?? 24}h)`}
- value={
- status
- ? [
- `${status.deliveries.delivered} delivered`,
- status.deliveries.failed ? `${status.deliveries.failed} retrying` : null,
- status.deliveries.dead ? `${status.deliveries.dead} gave up` : null,
- status.deliveries.pending ? `${status.deliveries.pending} queued` : null,
- ]
- .filter(Boolean)
- .join(" · ")
- : "-"
- }
+ title={`Deliveries (last ${deliveries.window_hours}h)`}
+ value={deliveryCounts.map(({ state, count }) => (
+ <StatusBadge key={state} color={DELIVERY_STATE_COLOR[state]}>
+ {count} {DELIVERY_STATE_LABEL[state].toLowerCase()}
+ </StatusBadge>
+ ))}
/>
<SectionRow
title="Last delivery"
- value={status ? formatDate(status.deliveries.last_delivered_at) : "-"}
- />
- <SectionRow
- title="Orders from Magento (24h)"
- value={status ? String(status.orders.last_24h) : "-"}
+ value={
+ deliveries.last_delivered_at ? (
+ <Tooltip
+ content={getFullDate({ date: deliveries.last_delivered_at, includeTime: true })}
+ >
+ <Text size="small" leading="compact">
+ {getRelativeDate(deliveries.last_delivered_at)}
+ </Text>
+ </Tooltip>
+ ) : (
+ "Never"
+ )
+ }
/>
- </Container>
+ <SectionRow title="Orders from Magento (24h)" value={String(status.orders.last_24h)} />
+ </>
)
}
+
+const StatusRowsSkeleton = () => (
+ <>
+ {Array.from({ length: 5 }, (_, i) => (
+ <div key={i} className="grid grid-cols-2 items-center gap-4 px-6 py-4">
+ <Skeleton className="h-5 w-32" />
+ <Skeleton className="h-5 w-24" />
+ </div>
+ ))}
+ </>
+)