|
1
|
import { createColumnHelper } from "@tanstack/react-table" |
|
2
|
import { useMemo } from "react" |
|
3
|
import { useTranslation } from "react-i18next" |
|
4
|
import { TextCell } from "../../../components/table/table-cells/common/text-cell" |
|
5
|
import { HttpTypes } from "@medusajs/types" |
|
6
|
import { Badge } from "@medusajs/ui" |
|
7
|
|
|
8
|
const columnHelper = createColumnHelper<HttpTypes.AdminProductOption>() |
|
9
|
|
|
10
|
export const useProductOptionTableColumns = () => { |
|
11
|
const { t } = useTranslation() |
|
12
|
|
|
13
|
return useMemo( |
|
14
|
() => [ |
|
15
|
columnHelper.accessor("title", { |
|
16
|
header: t("fields.title"), |
|
17
|
cell: ({ getValue }) => <TextCell text={getValue()} />, |
|
18
|
}), |
|
19
|
columnHelper.accessor("values", { |
|
20
|
header: t("fields.values"), |
|
21
|
cell: ({ getValue }) => { |
|
22
|
const values = getValue() |
|
23
|
const count = values?.length || 0 |
|
24
|
const displayText = |
|
25
|
count > 0 |
|
26
|
? t(`general.${count === 1 ? "values_one" : "values_other"}`, { |
|
27
|
count, |
|
28
|
}) |
|
29
|
: "-" |
|
30
|
|
|
31
|
return <TextCell text={displayText} /> |
|
32
|
}, |
|
33
|
}), |
|
34
|
columnHelper.accessor("is_exclusive", { |
|
35
|
header: t("fields.status"), |
|
36
|
cell: ({ getValue }) => { |
|
37
|
const isExclusive = getValue() |
|
38
|
return ( |
|
39
|
<Badge size="xsmall" color={isExclusive ? "grey" : "blue"}> |
|
40
|
{t(`general.${isExclusive ? "exclusive" : "global"}`)} |
|
41
|
</Badge> |
|
42
|
) |
|
43
|
}, |
|
44
|
}), |
|
45
|
], |
|
46
|
[t] |
|
47
|
) |
|
48
|
} |