|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { createColumnHelper } from "@tanstack/react-table" |
|
3
|
import { useMemo } from "react" |
|
4
|
import { useTranslation } from "react-i18next" |
|
5
|
|
|
6
|
import { |
|
7
|
CodeCell, |
|
8
|
CodeHeader, |
|
9
|
} from "../../../components/table/table-cells/common/code-cell" |
|
10
|
import { |
|
11
|
TextCell, |
|
12
|
TextHeader, |
|
13
|
} from "../../../components/table/table-cells/common/text-cell" |
|
14
|
import { StatusCell } from "../../../components/table/table-cells/promotion/status-cell" |
|
15
|
|
|
16
|
const columnHelper = createColumnHelper<HttpTypes.AdminPromotion>() |
|
17
|
|
|
18
|
export const usePromotionTableColumns = () => { |
|
19
|
const { t } = useTranslation() |
|
20
|
|
|
21
|
return useMemo( |
|
22
|
() => [ |
|
23
|
columnHelper.display({ |
|
24
|
id: "code", |
|
25
|
header: () => <CodeHeader text={t("fields.code")} />, |
|
26
|
cell: ({ row }) => <CodeCell code={row.original.code!} />, |
|
27
|
}), |
|
28
|
|
|
29
|
columnHelper.display({ |
|
30
|
id: "method", |
|
31
|
header: () => <TextHeader text={t("promotions.fields.method")} />, |
|
32
|
cell: ({ row }) => { |
|
33
|
const text = row.original.is_automatic |
|
34
|
? t("promotions.form.method.automatic.title") |
|
35
|
: t("promotions.form.method.code.title") |
|
36
|
|
|
37
|
return <TextCell text={text} /> |
|
38
|
}, |
|
39
|
}), |
|
40
|
|
|
41
|
columnHelper.display({ |
|
42
|
id: "status", |
|
43
|
header: () => <TextHeader text={t("fields.status")} />, |
|
44
|
cell: ({ row }) => <StatusCell promotion={row.original} />, |
|
45
|
}), |
|
46
|
], |
|
47
|
[t] |
|
48
|
) |
|
49
|
} |