Skip to content

armgit / spree

Public Imported from GitHub
0

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.

3.3 KB
Raw Blame
import type { Seller } from '@spree/admin-sdk'
import { SELLER_STATUSES } from '@spree/core'
import { defineTable, progressPercentage } from '@spree/dashboard-core'
import { Progress, RelativeTime, StatusBadge } from '@spree/dashboard-ui'
import { StoreIcon } from '@spree/dashboard-ui/icons'
import { Link } from '@tanstack/react-router'
import i18n from 'i18next'

defineTable<Seller>('sellers', {
  docsPath: 'sellers/managing-sellers',
  description: i18n.t('admin.table_descriptions.sellers'),
  title: i18n.t('admin.nav.sellers'),
  searchParam: 'search',
  searchPlaceholder: i18n.t('admin.sellers.search_placeholder'),
  defaultSort: { field: 'name', direction: 'asc' },
  emptyIcon: <StoreIcon className="size-8 text-muted-foreground" />,
  emptyMessage: i18n.t('admin.sellers.empty'),
  columns: [
    {
      key: 'name',
      label: i18n.t('admin.fields.name.label'),
      sortable: true,
      default: true,
      render: (seller) => (
        <Link
          to={'/$storeId/sellers/$sellerId' as string}
          params={{ sellerId: seller.id }}
          className="font-medium text-foreground no-underline"
        >
          {seller.name}
        </Link>
      ),
    },
    {
      key: 'status',
      label: i18n.t('admin.fields.status.label'),
      sortable: true,
      filterable: true,
      filterType: 'enum',
      filterOptions: SELLER_STATUSES.map((status) => ({
        value: status,
        label: i18n.t(`admin.sellers.status.${status}`),
      })),
      quickFilter: true,
      default: true,
      render: (seller) => (
        <StatusBadge
          status={seller.status}
          label={i18n.t(`admin.sellers.status.${seller.status}`)}
        />
      ),
    },
    {
      key: 'contact_email',
      label: i18n.t('admin.fields.contact_email.label'),
      sortable: true,
      filterable: true,
      default: true,
      render: (seller) => seller.contact_email ?? <span className="text-muted-foreground">—</span>,
    },
    {
      key: 'onboarding',
      label: i18n.t('admin.sellers.onboarding_column'),
      default: true,
      // "n of m done" over a bar, as the operator's list has always shown
      // it. Nothing to show for a marketplace that asks for nothing.
      render: (seller) => {
        const progress = seller.onboarding_progress
        if (progress.total === 0) return <span className="text-muted-foreground">—</span>

        return (
          <div className="flex min-w-32 flex-col gap-1">
            <span className="text-muted-foreground text-xs">
              {i18n.t('admin.sellers.onboarding.progress', {
                done: progress.done,
                total: progress.total,
              })}
            </span>
            <Progress value={progressPercentage(progress)} />
          </div>
        )
      },
    },
    {
      key: 'products_count',
      label: i18n.t('admin.sellers.products_column'),
      default: true,
      render: (seller) => seller.products_count,
    },
    {
      key: 'users_count',
      label: i18n.t('admin.sellers.team_column'),
      render: (seller) => seller.users_count,
    },
    {
      key: 'created_at',
      label: i18n.t('admin.fields.created_at.label'),
      sortable: true,
      default: true,
      render: (seller) => <RelativeTime iso={seller.created_at} />,
    },
  ],
})