|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { createDataTableColumnHelper, StatusBadge } from "@medusajs/ui" |
|
3
|
import { useTranslation } from "react-i18next" |
|
4
|
import { useMemo } from "react" |
|
5
|
|
|
6
|
import { PlaceholderCell } from "../../../components/table/table-cells/common/placeholder-cell" |
|
7
|
import { getFormattedAddress } from "../../../lib/addresses" |
|
8
|
import { FulfillmentSetType } from "../common/constants" |
|
9
|
import { ListSummary } from "../../../components/common/list-summary" |
|
10
|
import { LocationListTableActions } from "./location-list-table-actions" |
|
11
|
|
|
12
|
const columnHelper = createDataTableColumnHelper<HttpTypes.AdminStockLocation>() |
|
13
|
|
|
14
|
export const useLocationListTableColumns = () => { |
|
15
|
const { t } = useTranslation() |
|
16
|
|
|
17
|
return useMemo( |
|
18
|
() => [ |
|
19
|
columnHelper.accessor("name", { |
|
20
|
header: t("fields.name"), |
|
21
|
cell: ({ getValue }) => { |
|
22
|
const name = getValue() |
|
23
|
if (!name) { |
|
24
|
return <PlaceholderCell /> |
|
25
|
} |
|
26
|
|
|
27
|
return ( |
|
28
|
<span className="text-ui-fg-subtle text-small truncate"> |
|
29
|
{name} |
|
30
|
</span> |
|
31
|
) |
|
32
|
}, |
|
33
|
}), |
|
34
|
columnHelper.accessor("address", { |
|
35
|
header: t("fields.address"), |
|
36
|
cell: ({ getValue, row }) => { |
|
37
|
const address = getValue() |
|
38
|
const location = row.original |
|
39
|
|
|
40
|
if (!address) { |
|
41
|
return <PlaceholderCell /> |
|
42
|
} |
|
43
|
|
|
44
|
return ( |
|
45
|
<div className="flex flex-col"> |
|
46
|
<span className="text-ui-fg-subtle text-small truncate"> |
|
47
|
{getFormattedAddress({ |
|
48
|
address: location.address as HttpTypes.AdminOrderAddress, |
|
49
|
}).join(", ")} |
|
50
|
</span> |
|
51
|
</div> |
|
52
|
) |
|
53
|
}, |
|
54
|
}), |
|
55
|
columnHelper.accessor("fulfillment_sets", { |
|
56
|
id: "shipping_fulfillment", |
|
57
|
header: t("stockLocations.fulfillmentSets.shipping.header"), |
|
58
|
cell: ({ getValue }) => { |
|
59
|
const fulfillmentSets = getValue() |
|
60
|
const shippingSet = fulfillmentSets?.find( |
|
61
|
(f) => f.type === FulfillmentSetType.Shipping |
|
62
|
) |
|
63
|
const fulfillmentSetExists = !!shippingSet |
|
64
|
|
|
65
|
return ( |
|
66
|
<StatusBadge color={fulfillmentSetExists ? "green" : "grey"}> |
|
67
|
{t( |
|
68
|
fulfillmentSetExists ? "statuses.enabled" : "statuses.disabled" |
|
69
|
)} |
|
70
|
</StatusBadge> |
|
71
|
) |
|
72
|
}, |
|
73
|
}), |
|
74
|
columnHelper.accessor("fulfillment_sets", { |
|
75
|
id: "pickup_fulfillment", |
|
76
|
header: t("stockLocations.fulfillmentSets.pickup.header"), |
|
77
|
cell: ({ getValue }) => { |
|
78
|
const fulfillmentSets = getValue() |
|
79
|
const pickupSet = fulfillmentSets?.find( |
|
80
|
(f) => f.type === FulfillmentSetType.Pickup |
|
81
|
) |
|
82
|
const fulfillmentSetExists = !!pickupSet |
|
83
|
|
|
84
|
return ( |
|
85
|
<StatusBadge color={fulfillmentSetExists ? "green" : "grey"}> |
|
86
|
{t( |
|
87
|
fulfillmentSetExists ? "statuses.enabled" : "statuses.disabled" |
|
88
|
)} |
|
89
|
</StatusBadge> |
|
90
|
) |
|
91
|
}, |
|
92
|
}), |
|
93
|
columnHelper.accessor("sales_channels", { |
|
94
|
header: t("stockLocations.salesChannels.label"), |
|
95
|
cell: ({ getValue }) => { |
|
96
|
const salesChannels = getValue() |
|
97
|
|
|
98
|
if (!salesChannels?.length) { |
|
99
|
return <PlaceholderCell /> |
|
100
|
} |
|
101
|
|
|
102
|
return ( |
|
103
|
<div className="flex items-center"> |
|
104
|
<ListSummary |
|
105
|
inline |
|
106
|
n={1} |
|
107
|
list={salesChannels.map((s) => s.name)} |
|
108
|
/> |
|
109
|
</div> |
|
110
|
) |
|
111
|
}, |
|
112
|
}), |
|
113
|
columnHelper.display({ |
|
114
|
id: "action", |
|
115
|
cell: ({ row }) => <LocationListTableActions location={row.original} />, |
|
116
|
}), |
|
117
|
], |
|
118
|
[t] |
|
119
|
) |
|
120
|
} |