1 import { HttpTypes } from "@medusajs/types"
2 import { StatusBadge } from "@medusajs/ui"
3
4 import { ListSummary } from "../../../components/common/list-summary"
5 import { PlaceholderCell } from "../../../components/table/table-cells/common/placeholder-cell"
6 import { defineCellRenderer } from "../../../lib/table/cell-renderers"
7 import { FulfillmentSetType } from "../common/constants"
8
9 /**
10 * Stock-location-specific cell renderers, registered in the GLOBAL registry so
11 * consuming apps can override them. Imported for its side effect by the
12 * configurable location table.
13 */
14
15 const fulfillmentRenderer = (setType: FulfillmentSetType) => ({
16 render: (_value: any, row: any, _column: any, t: any) => {
17 const location = row as HttpTypes.AdminStockLocation
18 const exists = !!location.fulfillment_sets?.find((f) => f.type === setType)
19
20 return (
21 <StatusBadge color={exists ? "green" : "grey"}>
22 {t(exists ? "statuses.enabled" : "statuses.disabled")}
23 </StatusBadge>
24 )
25 },
26 })
27
28 defineCellRenderer(
29 "stock_location_shipping",
30 fulfillmentRenderer(FulfillmentSetType.Shipping)
31 )
32 defineCellRenderer(
33 "stock_location_pickup",
34 fulfillmentRenderer(FulfillmentSetType.Pickup)
35 )
36
37 defineCellRenderer("stock_location_sales_channels", {
38 render: (_value, row) => {
39 const location = row as HttpTypes.AdminStockLocation
40 const salesChannels = location.sales_channels
41
42 if (!salesChannels?.length) {
43 return <PlaceholderCell />
44 }
45
46 return (
47 <div className="flex items-center">
48 <ListSummary inline n={1} list={salesChannels.map((s) => s.name)} />
49 </div>
50 )
51 },
52 })