Skip to content

Commit ecdf528

Browse files
committed
Merge branch 'test' into fix/mm2-1209/fix-ts-errors
2 parents 7c70e52 + cab7ef2 commit ecdf528

File tree

50 files changed

+1107
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1107
-377
lines changed

src/components/authentication/protected-route/protected-route.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TalkjsProvider } from "../../../providers/talkjs-provider"
77

88
export const ProtectedRoute = () => {
99
const { seller, isPending, error } = useMe()
10-
const isSuspended = seller?.store_status === "SUSPENDED"
1110

1211
const location = useLocation()
1312
if (isPending) {
@@ -32,11 +31,6 @@ export const ProtectedRoute = () => {
3231
<TalkjsProvider>
3332
<SidebarProvider>
3433
<SearchProvider>
35-
{isSuspended && (
36-
<div className="w-full bg-red-600 text-white p-1 text-center text-sm">
37-
Your store is <b>suspended</b>. Please contact support.
38-
</div>
39-
)}
4034
<Outlet />
4135
</SearchProvider>
4236
</SidebarProvider>

src/components/data-grid/components/data-grid-toggleable-number-cell.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const OuterComponent = ({
7979
newValue.quantity = ""
8080
}
8181

82-
if (update && newValue.quantity === "") {
82+
if (update) {
8383
newValue.quantity = 0
8484
}
8585

@@ -101,7 +101,7 @@ const OuterComponent = ({
101101

102102
return (
103103
<ConditionalTooltip
104-
showTooltip={localValue.disabledToggle && tooltip}
104+
showTooltip={localValue.disabledToggle && !!tooltip}
105105
content={tooltip}
106106
>
107107
<div className="absolute inset-y-0 left-4 z-[3] flex w-fit items-center justify-center">
@@ -155,12 +155,6 @@ const Inner = ({
155155
const ensuredValue = updatedValue !== undefined ? updatedValue : ""
156156
const newValue = { ...localValue, quantity: ensuredValue }
157157

158-
/**
159-
* If the value is not empty, then the location should be enabled.
160-
*
161-
* Else, if the value is empty and the location is enabled, then the
162-
* location should be disabled, unless toggling the location is disabled.
163-
*/
164158
if (ensuredValue !== "") {
165159
newValue.checked = true
166160
} else if (newValue.checked && newValue.disabledToggle === false) {
@@ -186,7 +180,7 @@ const Inner = ({
186180
{...props}
187181
ref={combinedRefs}
188182
className="txt-compact-small w-full flex-1 cursor-default appearance-none bg-transparent pl-8 text-right outline-none"
189-
value={localValue?.quantity}
183+
value={localValue?.quantity ?? undefined}
190184
onValueChange={handleInputChange}
191185
formatValueOnBlur
192186
onBlur={() => {
@@ -195,7 +189,6 @@ const Inner = ({
195189
handleOnChange()
196190
}}
197191
onFocus={onFocus}
198-
decimalsLimit={0}
199192
autoComplete="off"
200193
tabIndex={-1}
201194
placeholder={!localValue.checked ? placeholder : undefined}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { HttpTypes } from "@medusajs/types"
2+
import { ColumnDef } from "@tanstack/react-table"
3+
import { TFunction } from "i18next"
4+
import { FieldPath, FieldValues } from "react-hook-form"
5+
import { DataGridReadonlyCell } from "../components/data-grid-readonly-cell"
6+
import { DataGridTogglableNumberCell } from "../components/data-grid-toggleable-number-cell"
7+
import { FieldContext } from "../types"
8+
import { createDataGridHelper } from "./create-data-grid-column-helper"
9+
10+
type CreateDataGridLocationStockColumnsProps<
11+
TData,
12+
TFieldValues extends FieldValues,
13+
> = {
14+
stockLocations: HttpTypes.AdminStockLocation[]
15+
isReadyOnly?: (context: FieldContext<TData>) => boolean
16+
getFieldName: (
17+
context: FieldContext<TData>,
18+
stockLocationIndex: number
19+
) => FieldPath<TFieldValues> | null
20+
t: TFunction
21+
}
22+
23+
export const createDataGridLocationStockColumns = <
24+
TData,
25+
TFieldValues extends FieldValues,
26+
>({
27+
stockLocations,
28+
isReadyOnly,
29+
getFieldName,
30+
t,
31+
}: CreateDataGridLocationStockColumnsProps<TData, TFieldValues>): ColumnDef<
32+
TData,
33+
unknown
34+
>[] => {
35+
const columnHelper = createDataGridHelper<TData, TFieldValues>()
36+
37+
return [
38+
...(stockLocations.map((stockLocation, index) => {
39+
const translatedStockLocationName = t("fields.stockTemplate", {
40+
stockLocation: index + 1,
41+
})
42+
43+
return columnHelper.column({
44+
id: `stock_locations.${stockLocation.id}`,
45+
name: translatedStockLocationName,
46+
field: (context) => {
47+
const isReadyOnlyValue = isReadyOnly?.(context)
48+
if (isReadyOnlyValue) {
49+
return null
50+
}
51+
return getFieldName(context, index)
52+
},
53+
type: "togglable-number",
54+
header: () => (
55+
<div className="flex w-full items-center justify-between gap-3">
56+
<span className="truncate" title={translatedStockLocationName}>
57+
{translatedStockLocationName}
58+
</span>
59+
</div>
60+
),
61+
cell: (context) => {
62+
if (isReadyOnly?.(context)) {
63+
return <DataGridReadonlyCell context={context} />
64+
}
65+
66+
return (
67+
<DataGridTogglableNumberCell
68+
context={context}
69+
disabledToggleTooltip={t("inventory.stock.disabledToggleTooltip")}
70+
placeholder={t("inventory.stock.placeholder")}
71+
/>
72+
)
73+
},
74+
})
75+
}) ?? []),
76+
]
77+
}

src/components/data-grid/helpers/create-data-grid-price-columns.tsx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DataGridCurrencyCell } from "../components/data-grid-currency-cell"
77
import { DataGridReadonlyCell } from "../components/data-grid-readonly-cell"
88
import { FieldContext } from "../types"
99
import { createDataGridHelper } from "./create-data-grid-column-helper"
10+
import { formatCurrency } from "../../../lib/format-currency"
1011

1112
type CreateDataGridPriceColumnsProps<
1213
TData,
@@ -20,6 +21,7 @@ type CreateDataGridPriceColumnsProps<
2021
value: string
2122
) => FieldPath<TFieldValues> | null
2223
t: TFunction
24+
showCurrentPriceCell?: boolean
2325
}
2426

2527
export const createDataGridPriceColumns = <
@@ -31,14 +33,15 @@ export const createDataGridPriceColumns = <
3133
isReadyOnly,
3234
getFieldName,
3335
t,
36+
showCurrentPriceCell = false,
3437
}: CreateDataGridPriceColumnsProps<TData, TFieldValues>): ColumnDef<
3538
TData,
3639
unknown
3740
>[] => {
3841
const columnHelper = createDataGridHelper<TData, TFieldValues>()
3942

4043
return [
41-
...(currencies?.map((currency) => {
44+
...(currencies?.flatMap((currency) => {
4245
const preference = pricePreferences?.find(
4346
(p) => p.attribute === "currency_code" && p.value === currency
4447
)
@@ -47,7 +50,11 @@ export const createDataGridPriceColumns = <
4750
regionOrCurrency: currency.toUpperCase(),
4851
})
4952

50-
return columnHelper.column({
53+
const translatedCurrentCurrencyName = t("fields.currentPriceTemplate", {
54+
regionOrCurrency: currency.toUpperCase(),
55+
})
56+
57+
const editableCol = columnHelper.column({
5158
id: `currency_prices.${currency}`,
5259
name: t("fields.priceTemplate", {
5360
regionOrCurrency: currency.toUpperCase(),
@@ -78,6 +85,51 @@ export const createDataGridPriceColumns = <
7885
return <DataGridCurrencyCell code={currency} context={context} />
7986
},
8087
})
88+
89+
const currentPriceCol = showCurrentPriceCell
90+
? columnHelper.column({
91+
id: `currency_current_price.${currency}`,
92+
name: translatedCurrentCurrencyName,
93+
field: () => null,
94+
type: "number",
95+
header: () => (
96+
<div className="flex w-full items-center justify-between gap-3">
97+
<span
98+
className="truncate"
99+
title={translatedCurrentCurrencyName}
100+
>
101+
{translatedCurrentCurrencyName}
102+
</span>
103+
</div>
104+
),
105+
cell: (context) => {
106+
const prices = (
107+
context.row.original as HttpTypes.AdminProductVariant
108+
).prices
109+
110+
const currentPrice = prices?.find(
111+
({ currency_code }) => currency_code === currency
112+
)
113+
114+
const amount = currentPrice?.amount
115+
116+
return (
117+
<DataGridReadonlyCell context={context}>
118+
{typeof amount === "number"
119+
? formatCurrency(amount, currency.toUpperCase())
120+
: isReadyOnly?.(context)
121+
? ""
122+
: "—"}
123+
</DataGridReadonlyCell>
124+
)
125+
},
126+
})
127+
: null
128+
129+
return [editableCol, currentPriceCol].filter(Boolean) as ColumnDef<
130+
TData,
131+
unknown
132+
>[]
81133
}) ?? []),
82134
]
83135
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./create-data-grid-column-helper"
22
export * from "./create-data-grid-price-columns"
3+
export * from "./create-data-grid-location-stock-columns"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { clx, Container, Heading } from "@medusajs/ui"
2+
import React, { useLayoutEffect, useRef, useState } from "react"
3+
4+
import { _DataTable } from "../table/data-table/data-table"
5+
import { TableSkeleton } from "../common/skeleton"
6+
7+
type InnerDataTableProps<TData> = Parameters<typeof _DataTable<TData>>[0]
8+
9+
type DataTableWithStickyFooterProps<TData> = InnerDataTableProps<TData> & {
10+
heading: string | React.ReactNode
11+
className?: string
12+
marginPx?: number
13+
}
14+
15+
export function DataTableWithStickyFooter<TData>({
16+
heading,
17+
className,
18+
marginPx = 16,
19+
isLoading,
20+
...dataTableProps
21+
}: DataTableWithStickyFooterProps<TData>) {
22+
const [containerMaxHeight, setContainerMaxHeight] = useState<number | null>(
23+
null
24+
)
25+
26+
const containerRef = useRef<HTMLDivElement | null>(null)
27+
28+
function handleCalcMaxHeight() {
29+
const container = containerRef.current
30+
if (!container) {
31+
return
32+
}
33+
34+
const rect = container?.getBoundingClientRect()
35+
const availableVerticalSpace = Math.max(
36+
0,
37+
window.innerHeight - rect.top - marginPx
38+
)
39+
setContainerMaxHeight(availableVerticalSpace)
40+
}
41+
42+
useLayoutEffect(() => {
43+
handleCalcMaxHeight()
44+
45+
window.addEventListener("resize", handleCalcMaxHeight)
46+
window.addEventListener("scroll", handleCalcMaxHeight)
47+
48+
return () => {
49+
window.removeEventListener("resize", handleCalcMaxHeight)
50+
window.removeEventListener("scroll", handleCalcMaxHeight)
51+
}
52+
}, [])
53+
54+
return (
55+
<Container
56+
ref={containerRef}
57+
className={clx("divide-y p-0 flex flex-col", className)}
58+
style={{
59+
maxHeight: containerMaxHeight ? `${containerMaxHeight}px` : undefined,
60+
}}
61+
>
62+
{isLoading ? (
63+
<TableSkeleton layout="fit" />
64+
) : (
65+
<>
66+
<div className="flex items-center justify-between px-6 py-4">
67+
<Heading>{heading}</Heading>
68+
</div>
69+
<_DataTable
70+
{...(dataTableProps as InnerDataTableProps<TData>)}
71+
layout="fill"
72+
isLoading={false}
73+
/>
74+
</>
75+
)}
76+
</Container>
77+
)
78+
}

0 commit comments

Comments
 (0)