import Button from "../../fundamentals/button" import { Column } from "@tanstack/react-table" import { DecoratedInventoryItemDTO } from "@medusajs/medusa" import ImagePlaceholder from "../../fundamentals/image-placeholder" import { InventoryLevelDTO } from "@medusajs/types" import Tooltip from "../../atoms/tooltip" import { useMemo } from "react" import { useNavigate } from "react-router-dom" import { useTranslation } from "react-i18next" const useInventoryTableColumn = ({ location_id, }: { location_id: string }): [Column[]] => { const { t } = useTranslation() const columns = useMemo( () => [ { Header: t("inventory-table-item", "Item"), accessor: "title", Cell: ({ row: { original } }) => { return (
{original.variants[0]?.product?.thumbnail ? ( ) : ( )}
{original.variants[0]?.product?.title || ""}
) }, }, { Header: t("inventory-table-variant", "Variant"), Cell: ({ row: { original } }) => { return
{original?.variants[0]?.title || "-"}
}, }, { Header: t("inventory-table-sku", "SKU"), accessor: "sku", Cell: ({ cell: { value } }) => value, }, { Header: t("inventory-table-reserved", "Reserved"), accessor: "reserved_quantity", Cell: ({ row: { original } }) => { const navigate = useNavigate() return (
{ navigate( `/a/inventory/reservations?inventory_item_id%5B0%5D=${ original.id }${location_id ? `&location_id=${location_id}` : ""}` ) }} > Go to reservations } >
{original.location_levels.reduce( (acc: number, next: InventoryLevelDTO) => acc + next.reserved_quantity, 0 )}
) }, }, { Header: t("inventory-table-in-stock", "In stock"), accessor: "stocked_quantity", Cell: ({ row: { original } }) => { return (
{original.location_levels.reduce( (acc: number, next: InventoryLevelDTO) => acc + next.stocked_quantity, 0 )}
) }, }, ], [location_id] ) return [columns] as const } export default useInventoryTableColumn