import { PriceList } from "@medusajs/medusa" import { isArray } from "lodash" import { useMemo } from "react" import { Column } from "react-table" import { useTranslation } from "react-i18next" import Actionables from "../../molecules/actionables" import Table from "../../molecules/table" import usePriceListActions from "./use-price-list-actions" import { formatPriceListGroups, getPriceListStatus } from "./utils" export const usePriceListTableColumns = () => { const { t } = useTranslation() const columns = useMemo[]>( () => [ { Header: t("price-list-table-name", "Name"), accessor: "name", Cell: ({ cell: { value } }) => ( {value} ), }, { Header: t("price-list-table-description", "Description"), accessor: "description", Cell: ({ cell: { value } }) => {value}, }, { Header: t("price-list-table-status", "Status"), accessor: "status", Cell: ({ row: { original } }) => ( {getPriceListStatus(original)} ), }, { Header: t("price-list-table-groups", "Groups"), accessor: "customer_groups", Cell: ({ cell: { value } }) => { const groups: string[] = isArray(value) ? value.map((v) => v.name) : [] const [group, other] = formatPriceListGroups(groups) return ( {group} {other && ( {" "} {t("price-list-table-other-more", "+ {{other}} more", { other, })} )} ) }, }, { accessor: "created_at", Cell: ({ row: { original: priceList } }) => { const { getActions } = usePriceListActions(priceList) return ( e.stopPropagation()} className="flex w-full justify-end" >
) }, }, ], [] ) return [columns] as const }