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.

2.0 KB
Raw Blame
import type { Channel } from '@spree/admin-sdk'
import { defineTable } from '@spree/dashboard-core'
import { ActiveBadge, ResourceNameCell } from '@spree/dashboard-ui'
import { RadioTowerIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'

defineTable<Channel>('channels', {
  title: i18n.t('admin.pages.channels.title'),
  docsPath: 'settings/sales-channels',
  description: i18n.t('admin.table_descriptions.channels'),
  searchParam: 'search',
  searchPlaceholder: i18n.t('admin.common.search_placeholder'),
  defaultSort: { field: 'name', direction: 'asc' },
  emptyIcon: <RadioTowerIcon className="size-8 text-muted-foreground" />,
  emptyMessage: i18n.t('admin.pages.channels.empty_message'),
  columns: [
    {
      key: 'name',
      label: i18n.t('admin.fields.name.label'),
      sortable: true,
      default: true,
      render: (channel) => (
        <ResourceNameCell
          id={channel.id}
          dataAttr="data-channel-id"
          name={channel.name}
          secondary={channel.code}
        />
      ),
    },
    {
      key: 'code',
      label: i18n.t('admin.fields.channel.code.label'),
      sortable: true,
      default: true,
      className: 'text-sm text-muted-foreground',
      render: (channel) => channel.code,
    },
    {
      key: 'active',
      label: i18n.t('admin.fields.status.label'),
      sortable: false,
      filterable: true,
      filterType: 'boolean',
      default: true,
      render: (channel) => (
        <ActiveBadge
          active={channel.active}
          activeLabel={i18n.t('admin.common.active')}
          inactiveLabel={i18n.t('admin.common.inactive')}
        />
      ),
    },
    {
      key: 'default',
      label: i18n.t('admin.fields.channel.default.label'),
      sortable: true,
      filterable: true,
      filterType: 'boolean',
      default: true,
      render: (channel) => (
        <ActiveBadge
          active={channel.default}
          activeLabel={i18n.t('admin.common.yes')}
          dashWhenInactive
        />
      ),
    },
  ],
})