Skip to content

Commit 021a9d3

Browse files
authored
chore(dashboard): fix type and lint errors (5/n) (#15213)
1 parent 27dc6d7 commit 021a9d3

22 files changed

Lines changed: 91 additions & 84 deletions

File tree

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/adjust-inventory/adjust-inventory-drawer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { InventoryTypes } from "@medusajs/types"
21
import { Heading } from "@medusajs/ui"
32
import { useTranslation } from "react-i18next"
43
import { useParams } from "react-router-dom"
@@ -19,8 +18,7 @@ export const AdjustInventoryDrawer = () => {
1918
} = useInventoryItem(id!)
2019

2120
const inventoryLevel = inventoryItem?.location_levels!.find(
22-
(level: InventoryTypes.InventoryLevelDTO) =>
23-
level.location_id === location_id
21+
(level) => level.location_id === location_id
2422
)
2523

2624
const { stock_location, isLoading: isLoadingLocation } = useStockLocation(

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { zodResolver } from "@hookform/resolvers/zod"
2-
import { HttpTypes, InventoryLevelDTO, StockLocationDTO } from "@medusajs/types"
2+
import {
3+
AdminInventoryLevel,
4+
AdminStockLocation,
5+
HttpTypes,
6+
} from "@medusajs/types"
37
import { Button, Input, Text, toast } from "@medusajs/ui"
48
import { useForm, useWatch } from "react-hook-form"
59
import { useTranslation } from "react-i18next"
@@ -13,8 +17,8 @@ import { castNumber } from "../../../../../../lib/cast-number"
1317

1418
type AdjustInventoryFormProps = {
1519
item: HttpTypes.AdminInventoryItem
16-
level: InventoryLevelDTO
17-
location: StockLocationDTO
20+
level: AdminInventoryLevel
21+
location: AdminStockLocation
1822
}
1923

2024
const AttributeGridRow = ({

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button, Input, toast } from "@medusajs/ui"
44
import { RouteDrawer, useRouteModal } from "../../../../../../components/modals"
55

66
import { zodResolver } from "@hookform/resolvers/zod"
7-
import { InventoryTypes } from "@medusajs/types"
7+
import { AdminInventoryItem } from "@medusajs/types"
88
import { useForm } from "react-hook-form"
99
import { useTranslation } from "react-i18next"
1010
import { z } from "zod"
@@ -15,7 +15,7 @@ import { KeyboundForm } from "../../../../../../components/utilities/keybound-fo
1515
import { useUpdateInventoryItem } from "../../../../../../hooks/api/inventory"
1616

1717
type EditInventoryItemAttributeFormProps = {
18-
item: InventoryTypes.InventoryItemDTO
18+
item: AdminInventoryItem
1919
}
2020

2121
const EditInventoryItemAttributesSchema = z.object({
@@ -29,7 +29,7 @@ const EditInventoryItemAttributesSchema = z.object({
2929
origin_country: z.string().optional(),
3030
})
3131

32-
const getDefaultValues = (item: InventoryTypes.InventoryItemDTO) => {
32+
const getDefaultValues = (item: AdminInventoryItem) => {
3333
return {
3434
height: item.height ?? undefined,
3535
width: item.width ?? undefined,

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button, Input, toast } from "@medusajs/ui"
44
import { RouteDrawer, useRouteModal } from "../../../../../../components/modals"
55

66
import { zodResolver } from "@hookform/resolvers/zod"
7-
import { InventoryTypes } from "@medusajs/types"
7+
import { AdminInventoryItem } from "@medusajs/types"
88
import { useForm } from "react-hook-form"
99
import { useTranslation } from "react-i18next"
1010
import { z } from "zod"
@@ -13,15 +13,15 @@ import { KeyboundForm } from "../../../../../../components/utilities/keybound-fo
1313
import { useUpdateInventoryItem } from "../../../../../../hooks/api/inventory"
1414

1515
type EditInventoryItemFormProps = {
16-
item: InventoryTypes.InventoryItemDTO
16+
item: AdminInventoryItem
1717
}
1818

1919
const EditInventoryItemSchema = z.object({
2020
title: z.string().optional(),
2121
sku: z.string().min(1),
2222
})
2323

24-
const getDefaultValues = (item: InventoryTypes.InventoryItemDTO) => {
24+
const getDefaultValues = (item: AdminInventoryItem) => {
2525
return {
2626
title: item.title ?? undefined,
2727
sku: item.sku ?? undefined,

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-variants/variants-section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const InventoryItemVariantsSection = ({
4545
{variant.options.map((o) => o.value).join(" ⋅ ")}
4646
</span>
4747
</div>
48-
<div className="size-7 flex items-center justify-center">
48+
<div className="flex size-7 items-center justify-center">
4949
<TriangleRightMini className="text-ui-fg-muted rtl:rotate-180" />
5050
</div>
5151
</div>
@@ -60,7 +60,7 @@ export const InventoryItemVariantsSection = ({
6060
<Link
6161
to={link}
6262
key={variant.id}
63-
className="outline-none focus-within:shadow-borders-interactive-with-focus rounded-md [&:hover>div]:bg-ui-bg-component-hover"
63+
className="focus-within:shadow-borders-interactive-with-focus [&:hover>div]:bg-ui-bg-component-hover rounded-md outline-none"
6464
>
6565
{Inner}
6666
</Link>

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/location-levels-table/use-location-list-table-columns.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InventoryTypes, StockLocationDTO } from "@medusajs/types"
1+
import { AdminInventoryLevel } from "@medusajs/types"
22
import { PencilSquare, Trash } from "@medusajs/icons"
33

44
import { useMemo } from "react"
@@ -13,25 +13,15 @@ import { sdk } from "../../../../../lib/client"
1313
import { queryClient } from "../../../../../lib/query-client"
1414
import { useNavigate } from "react-router-dom"
1515

16-
/**
17-
* Adds missing properties to the InventoryLevelDTO type.
18-
*/
19-
interface ExtendedLocationLevel extends InventoryTypes.InventoryLevelDTO {
20-
stock_locations: StockLocationDTO[]
21-
reserved_quantity: number
22-
stocked_quantity: number
23-
available_quantity: number
24-
}
25-
26-
const columnHelper = createDataTableColumnHelper<ExtendedLocationLevel>()
16+
const columnHelper = createDataTableColumnHelper<AdminInventoryLevel>()
2717

2818
export const useLocationListTableColumns = () => {
2919
const { t } = useTranslation()
3020
const navigate = useNavigate()
3121

3222
const prompt = usePrompt()
3323

34-
const handleDelete = async (level: ExtendedLocationLevel) => {
24+
const handleDelete = async (level: AdminInventoryLevel) => {
3525
const res = await prompt({
3626
title: t("general.areYouSure"),
3727
description: t("inventory.deleteWarning"),
@@ -66,13 +56,13 @@ export const useLocationListTableColumns = () => {
6656
queryKey: inventoryItemLevelsQueryKeys.detail(level.inventory_item_id),
6757
})
6858
} catch (e) {
69-
toast.error(e.message)
59+
toast.error(e instanceof Error ? e.message : t("errorBoundary.defaultTitle"))
7060
}
7161
}
7262

7363
return useMemo(
7464
() => [
75-
columnHelper.accessor("stock_locations.0.name", {
65+
columnHelper.accessor("stock_locations.0.name" as any, {
7666
header: t("fields.location"),
7767
cell: ({ getValue }) => {
7868
const locationName = getValue()
@@ -147,7 +137,7 @@ export const useLocationListTableColumns = () => {
147137
icon: <PencilSquare />,
148138
label: t("actions.edit"),
149139

150-
onClick: (row) => {
140+
onClick: () => {
151141
navigate(`locations/${level.location_id}`)
152142
},
153143
},

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/use-reservation-list-table-columns.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { useMemo } from "react"
44
import { useTranslation } from "react-i18next"
55
import { CreatedAtCell } from "../../../../../components/table/table-cells/common/created-at-cell"
66
import { PlaceholderCell } from "../../../../../components/table/table-cells/common/placeholder-cell"
7-
import { TextCell, TextHeader } from "../../../../../components/table/table-cells/common/text-cell"
7+
import {
8+
TextCell,
9+
TextHeader,
10+
} from "../../../../../components/table/table-cells/common/text-cell"
811
import { ReservationActions } from "./reservation-actions"
912

1013
/**
@@ -26,9 +29,7 @@ export const useReservationTableColumn = ({ sku }: { sku: string }) => {
2629
id: "sku",
2730
header: () => <TextHeader text={t("fields.sku")} />,
2831
cell: () => {
29-
return (
30-
<TextCell text={sku} />
31-
)
32+
return <TextCell text={sku} />
3233
},
3334
}),
3435
columnHelper.accessor("line_item.order_id", {
@@ -40,9 +41,7 @@ export const useReservationTableColumn = ({ sku }: { sku: string }) => {
4041
return <PlaceholderCell />
4142
}
4243

43-
return (
44-
<TextCell text={orderId} />
45-
)
44+
return <TextCell text={orderId} />
4645
},
4746
}),
4847
columnHelper.accessor("description", {
@@ -54,9 +53,7 @@ export const useReservationTableColumn = ({ sku }: { sku: string }) => {
5453
return <PlaceholderCell />
5554
}
5655

57-
return (
58-
<TextCell text={description} />
59-
)
56+
return <TextCell text={description} />
6057
},
6158
}),
6259
columnHelper.accessor("location.name", {
@@ -68,9 +65,7 @@ export const useReservationTableColumn = ({ sku }: { sku: string }) => {
6865
return <PlaceholderCell />
6966
}
7067

71-
return (
72-
<TextCell text={location} />
73-
)
68+
return <TextCell text={location} />
7469
},
7570
}),
7671
columnHelper.accessor("created_at", {

packages/admin/dashboard/src/routes/inventory/inventory-list/components/inventory-actions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { PencilSquare, Trash } from "@medusajs/icons"
22

33
import { ActionMenu } from "../../../../components/common/action-menu"
4-
import { InventoryItemDTO } from "@medusajs/types"
4+
import { AdminInventoryItem } from "@medusajs/types"
55
import { useDeleteInventoryItem } from "../../../../hooks/api/inventory"
66
import { usePrompt } from "@medusajs/ui"
77
import { useTranslation } from "react-i18next"
88

9-
export const InventoryActions = ({ item }: { item: InventoryItemDTO }) => {
9+
export const InventoryActions = ({ item }: { item: AdminInventoryItem }) => {
1010
const { t } = useTranslation()
1111
const prompt = usePrompt()
1212
const { mutateAsync } = useDeleteInventoryItem(item.id)

packages/admin/dashboard/src/routes/inventory/inventory-list/components/inventory-list-table.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { InventoryTypes } from "@medusajs/types"
21
import { Button, Container, Heading, Text } from "@medusajs/ui"
32

43
import { RowSelectionState } from "@tanstack/react-table"
@@ -39,7 +38,7 @@ export const InventoryListTable = () => {
3938
const columns = useInventoryTableColumns()
4039

4140
const { table } = useDataTable({
42-
data: (inventory_items ?? []) as InventoryTypes.InventoryItemDTO[],
41+
data: inventory_items,
4342
columns,
4443
count,
4544
enablePagination: true,

packages/admin/dashboard/src/routes/inventory/inventory-list/components/use-inventory-table-columns.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InventoryTypes, ProductVariantDTO } from "@medusajs/types"
1+
import { AdminInventoryItem } from "@medusajs/types"
22

33
import { Checkbox } from "@medusajs/ui"
44
import { createColumnHelper } from "@tanstack/react-table"
@@ -7,16 +7,7 @@ import { useTranslation } from "react-i18next"
77
import { PlaceholderCell } from "../../../../components/table/table-cells/common/placeholder-cell"
88
import { InventoryActions } from "./inventory-actions"
99

10-
/**
11-
* Adds missing properties to the InventoryItemDTO type.
12-
*/
13-
interface ExtendedInventoryItem extends InventoryTypes.InventoryItemDTO {
14-
variants?: ProductVariantDTO[] | null
15-
stocked_quantity?: number
16-
reserved_quantity?: number
17-
}
18-
19-
const columnHelper = createColumnHelper<ExtendedInventoryItem>()
10+
const columnHelper = createColumnHelper<AdminInventoryItem>()
2011

2112
export const useInventoryTableColumns = () => {
2213
const { t } = useTranslation()

0 commit comments

Comments
 (0)