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.5 KB
Raw Blame
import { STOCK_LOCATION_KINDS } from '@spree/core'
import { ActiveBadge, ResourceNameCell } from '@spree/dashboard-ui'
import { WarehouseIcon } from '@spree/dashboard-ui/icons'
import i18n from 'i18next'
import type { PanelStockLocation } from '../api-client'
import { defineTable } from '../lib/table-registry'

defineTable<PanelStockLocation>('stock-locations', {
  docsPath: 'settings/locations',
  description: i18n.t('admin.stock_locations.description'),
  title: i18n.t('admin.settings_nav.items.stock_locations'),
  searchParam: 'search',
  searchPlaceholder: i18n.t('admin.stock_locations.search_placeholder'),
  defaultSort: { field: 'name', direction: 'asc' },
  emptyIcon: <WarehouseIcon className="size-8 text-muted-foreground" />,
  emptyMessage: i18n.t('admin.stock_locations.empty'),
  columns: [
    {
      key: 'name',
      label: i18n.t('admin.fields.name.label'),
      sortable: true,
      default: true,
      render: (sl) => (
        <ResourceNameCell
          id={sl.id}
          dataAttr="data-stock-location-id"
          name={sl.name}
          secondary={sl.admin_name}
        />
      ),
    },
    {
      key: 'kind',
      label: i18n.t('admin.stock_locations.columns.type'),
      sortable: true,
      filterable: true,
      default: true,
      filterType: 'enum',
      filterOptions: STOCK_LOCATION_KINDS.map((kind) => ({
        value: kind,
        label: i18n.t(`admin.stock_locations.kinds.${kind}`),
      })),
      quickFilter: true,
      render: (sl) => {
        const key = `admin.stock_locations.kinds.${sl.kind}`
        const label = i18n.exists(key) ? i18n.t(key) : sl.kind.replace('_', ' ')
        return <span className="capitalize">{label}</span>
      },
    },
    {
      key: 'city',
      label: i18n.t('admin.stock_locations.columns.location'),
      default: true,
      render: (sl) => {
        const parts = [sl.city, sl.state_text || sl.state_code, sl.country_code]
          .filter(Boolean)
          .join(', ')
        return parts || '—'
      },
    },
    {
      key: 'pickup_enabled',
      label: i18n.t('admin.stock_locations.columns.pickup'),
      sortable: true,
      filterable: true,
      default: true,
      filterType: 'boolean',
      render: (sl) => (
        <ActiveBadge
          active={sl.pickup_enabled}
          activeLabel={i18n.t('admin.stock_locations.badges.enabled')}
          dashWhenInactive
        />
      ),
    },
    {
      key: 'returns_enabled',
      label: i18n.t('admin.stock_locations.columns.returns'),
      sortable: true,
      filterable: true,
      default: true,
      filterType: 'boolean',
      render: (sl) => (
        <ActiveBadge
          active={sl.returns_enabled ?? true}
          activeLabel={i18n.t('admin.stock_locations.badges.enabled')}
          dashWhenInactive
        />
      ),
    },
    {
      key: 'active',
      label: i18n.t('admin.fields.active.label'),
      sortable: true,
      filterable: true,
      default: true,
      filterType: 'boolean',
      render: (sl) => (
        <ActiveBadge
          active={sl.active}
          activeLabel={i18n.t('admin.fields.active.label')}
          inactiveLabel={i18n.t('admin.stock_locations.badges.inactive')}
        />
      ),
    },
    {
      key: 'default',
      label: i18n.t('admin.stock_locations.columns.default'),
      default: true,
      filterable: true,
      filterType: 'boolean',
      render: (sl) => (
        <ActiveBadge
          active={sl.default}
          activeLabel={i18n.t('admin.stock_locations.badges.default')}
          dashWhenInactive
        />
      ),
    },
  ],
})