|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { useMemo } from "react" |
|
3
|
import { useTranslation } from "react-i18next" |
|
4
|
|
|
5
|
import { createDataTableColumnHelper, Tooltip } from "@medusajs/ui" |
|
6
|
import { DataTableStatusCell } from "../../components/data-table-status-cell/data-table-status-cell" |
|
7
|
import { useDataTableDateColumns } from "../general/use-data-table-date-columns" |
|
8
|
|
|
9
|
const columnHelper = createDataTableColumnHelper<HttpTypes.AdminSalesChannel>() |
|
10
|
|
|
11
|
export const useSalesChannelTableColumns = () => { |
|
12
|
const { t } = useTranslation() |
|
13
|
const dateColumns = useDataTableDateColumns<HttpTypes.AdminSalesChannel>() |
|
14
|
|
|
15
|
return useMemo( |
|
16
|
() => [ |
|
17
|
columnHelper.accessor("name", { |
|
18
|
header: () => t("fields.name"), |
|
19
|
enableSorting: true, |
|
20
|
sortLabel: t("fields.name"), |
|
21
|
sortAscLabel: t("filters.sorting.alphabeticallyAsc"), |
|
22
|
sortDescLabel: t("filters.sorting.alphabeticallyDesc"), |
|
23
|
}), |
|
24
|
columnHelper.accessor("description", { |
|
25
|
header: () => t("fields.description"), |
|
26
|
cell: ({ getValue }) => { |
|
27
|
return ( |
|
28
|
<Tooltip content={getValue()}> |
|
29
|
<div className="flex h-full w-full items-center overflow-hidden"> |
|
30
|
<span className="truncate">{getValue()}</span> |
|
31
|
</div> |
|
32
|
</Tooltip> |
|
33
|
) |
|
34
|
}, |
|
35
|
enableSorting: true, |
|
36
|
sortLabel: t("fields.description"), |
|
37
|
sortAscLabel: t("filters.sorting.alphabeticallyAsc"), |
|
38
|
sortDescLabel: t("filters.sorting.alphabeticallyDesc"), |
|
39
|
maxSize: 250, |
|
40
|
minSize: 100, |
|
41
|
}), |
|
42
|
columnHelper.accessor("is_disabled", { |
|
43
|
header: () => t("fields.status"), |
|
44
|
enableSorting: true, |
|
45
|
sortLabel: t("fields.status"), |
|
46
|
sortAscLabel: t("filters.sorting.alphabeticallyAsc"), |
|
47
|
sortDescLabel: t("filters.sorting.alphabeticallyDesc"), |
|
48
|
cell: ({ getValue }) => { |
|
49
|
const value = getValue() |
|
50
|
return ( |
|
51
|
<DataTableStatusCell color={value ? "grey" : "green"}> |
|
52
|
{value ? t("general.disabled") : t("general.enabled")} |
|
53
|
</DataTableStatusCell> |
|
54
|
) |
|
55
|
}, |
|
56
|
}), |
|
57
|
...dateColumns, |
|
58
|
], |
|
59
|
[t, dateColumns] |
|
60
|
) |
|
61
|
} |