Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
import type { Import } from '@spree/admin-sdk'
import { IMPORT_STATUSES } from '@spree/core'
import { defineTable } from '@spree/dashboard-core'
import { RelativeTime, ResourceNameCell, StatusBadge } from '@spree/dashboard-ui'
import { UploadIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
import { importTypeLabel } from '../lib/import-types'
defineTable<Import>('imports', {
title: i18n.t('admin.pages.settings.imports.title'),
docsPath: 'manage-products/import-products',
description: i18n.t('admin.table_descriptions.imports'),
searchParam: 'search',
searchPlaceholder: i18n.t('admin.pages.settings.imports.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <UploadIcon className="size-8 text-muted-foreground" />,
emptyMessage: i18n.t('admin.pages.settings.imports.empty_title'),
columns: [
{
key: 'number',
label: i18n.t('admin.pages.settings.imports.table.number'),
sortable: true,
default: true,
render: (imp) => <ResourceNameCell id={imp.id} dataAttr="data-import-id" name={imp.number} />,
},
{
key: 'type',
label: i18n.t('admin.pages.settings.imports.table.type'),
sortable: true,
default: true,
render: (imp) => importTypeLabel(imp.type),
},
{
key: 'status',
label: i18n.t('admin.pages.settings.imports.table.status'),
sortable: true,
filterable: true,
filterType: 'enum',
filterOptions: IMPORT_STATUSES.map((status) => ({
value: status,
label: i18n.t(`admin.imports.status.${status}`),
})),
default: true,
render: (imp) => (
<StatusBadge status={imp.status} label={i18n.t(`admin.imports.status.${imp.status}`)} />
),
},
{
// Marketplaces only: a store with no sellers renders an em dash on every
// row, so the column is available but off by default.
key: 'seller_name',
label: i18n.t('admin.pages.settings.imports.table.seller'),
filterable: true,
render: (imp) =>
imp.seller_name ?? (
<span className="text-muted-foreground">
{i18n.t('admin.pages.settings.imports.table.first_party')}
</span>
),
},
{
key: 'rows',
label: i18n.t('admin.pages.settings.imports.table.rows'),
default: true,
render: (imp) => {
if (imp.rows_count === 0) return <span className="text-muted-foreground">—</span>
return (
<span>
{imp.completed_rows_count}/{imp.rows_count}
{imp.failed_rows_count > 0 && (
<span className="ml-1 text-destructive">
·{' '}
{i18n.t('admin.pages.settings.imports.table.failed_count', {
failed: imp.failed_rows_count,
})}
</span>
)}
</span>
)
},
},
{
key: 'created_at',
label: i18n.t('admin.fields.created_at.label'),
sortable: true,
default: true,
render: (imp) => <RelativeTime iso={imp.created_at} />,
},
],
})