1 import { createColumnHelper } from "@tanstack/react-table"
2
3 import { AdminCampaign } from "@medusajs/types"
4 import { useMemo } from "react"
5 import { useTranslation } from "react-i18next"
6 import { DateCell } from "../../../components/table/table-cells/common/date-cell"
7 import {
8 TextCell,
9 TextHeader,
10 } from "../../../components/table/table-cells/common/text-cell"
11 import {
12 DescriptionCell,
13 DescriptionHeader,
14 } from "../../../components/table/table-cells/sales-channel/description-cell"
15 import {
16 NameCell,
17 NameHeader,
18 } from "../../../components/table/table-cells/sales-channel/name-cell"
19
20 const columnHelper = createColumnHelper<AdminCampaign>()
21
22 export const useCampaignTableColumns = () => {
23 const { t } = useTranslation()
24
25 return useMemo(
26 () => [
27 columnHelper.accessor("name", {
28 header: () => <NameHeader />,
29 cell: ({ getValue }) => <NameCell name={getValue()} />,
30 }),
31 columnHelper.accessor("description", {
32 header: () => <DescriptionHeader />,
33 cell: ({ getValue }) => <DescriptionCell description={getValue()} />,
34 }),
35 columnHelper.accessor("campaign_identifier", {
36 header: () => <TextHeader text={t("campaigns.fields.identifier")} />,
37 cell: ({ getValue }) => {
38 const value = getValue()
39 return <TextCell text={value} />
40 },
41 }),
42 columnHelper.accessor("starts_at", {
43 header: () => <TextHeader text={t("campaigns.fields.start_date")} />,
44 cell: ({ getValue }) => {
45 const value = getValue()
46
47 if (!value) {
48 return
49 }
50
51 const date = new Date(value)
52
53 return <DateCell date={date} />
54 },
55 }),
56 columnHelper.accessor("ends_at", {
57 header: () => <TextHeader text={t("campaigns.fields.end_date")} />,
58 cell: ({ getValue }) => {
59 const value = getValue()
60
61 if (!value) {
62 return
63 }
64
65 const date = new Date(value)
66
67 return <DateCell date={date} />
68 },
69 }),
70 ],
71 [t]
72 )
73 }