1 import { Container } from "@medusajs/ui"
2 import { keepPreviousData } from "@tanstack/react-query"
3 import { useTranslation } from "react-i18next"
4
5 import { DataTable } from "../../../components/data-table"
6 import { useStockLocations } from "../../../hooks/api/stock-locations"
7 import { LOCATION_LIST_FIELDS } from "./constants"
8 import { useLocationListTableColumns } from "./use-location-list-table-columns"
9 import { useLocationListTableQuery } from "./use-location-list-table-query"
10
11 const PAGE_SIZE = 20
12 const PREFIX = "loc"
13
14 export const LocationListTable = () => {
15 const { t } = useTranslation()
16
17 const searchParams = useLocationListTableQuery({
18 pageSize: PAGE_SIZE,
19 prefix: PREFIX,
20 })
21
22 const {
23 stock_locations: stockLocations = [],
24 count,
25 isError,
26 error,
27 isLoading,
28 } = useStockLocations(
29 {
30 fields: LOCATION_LIST_FIELDS,
31 ...searchParams,
32 },
33 {
34 placeholderData: keepPreviousData,
35 }
36 )
37
38 const columns = useLocationListTableColumns()
39
40 if (isError) {
41 throw error
42 }
43
44 return (
45 <Container className="flex flex-col divide-y p-0">
46 <DataTable
47 data={stockLocations}
48 columns={columns}
49 rowCount={count}
50 pageSize={PAGE_SIZE}
51 getRowId={(row) => row.id}
52 heading={t("stockLocations.domain")}
53 subHeading={t("stockLocations.list.description")}
54 emptyState={{
55 empty: {
56 heading: t("stockLocations.list.noRecordsMessage"),
57 description: t("stockLocations.list.noRecordsMessageEmpty"),
58 },
59 filtered: {
60 heading: t("stockLocations.list.noRecordsMessage"),
61 description: t("stockLocations.list.noRecordsMessageFiltered"),
62 },
63 }}
64 actions={[
65 {
66 label: t("actions.create"),
67 to: "create",
68 },
69 ]}
70 isLoading={isLoading}
71 rowHref={(row) => `/settings/locations/${row.id}`}
72 enableSearch={true}
73 prefix={PREFIX}
74 layout="fill"
75 />
76 </Container>
77 )
78 }