|
3 | 3 | import { LineItem, Region } from "@medusajs/medusa"
|
4 | 4 | import { Table, Text, clx } from "@medusajs/ui"
|
5 | 5 |
|
| 6 | +import { I18nProviderClient, useCurrentLocale } from "../../../../locales/client" |
| 7 | + |
6 | 8 | import CartItemSelect from "@modules/cart/components/cart-item-select"
|
7 | 9 | import DeleteButton from "@modules/common/components/delete-button"
|
8 | 10 | import LineItemOptions from "@modules/common/components/line-item-options"
|
@@ -46,78 +48,91 @@ const Item = ({ item, region, type = "full" }: ItemProps) => {
|
46 | 48 | }
|
47 | 49 |
|
48 | 50 | return (
|
49 |
| - <Table.Row className="w-full" data-testid="product-row"> |
50 |
| - <Table.Cell className="!pl-0 p-4 w-24"> |
51 |
| - <LocalizedClientLink |
52 |
| - href={`/products/${handle}`} |
53 |
| - className={clx("flex", { |
54 |
| - "w-16": type === "preview", |
55 |
| - "small:w-24 w-12": type === "full", |
56 |
| - })} |
57 |
| - > |
58 |
| - <Thumbnail thumbnail={item.thumbnail} size="square" /> |
59 |
| - </LocalizedClientLink> |
60 |
| - </Table.Cell> |
61 |
| - |
62 |
| - <Table.Cell className="text-left"> |
63 |
| - <Text className="txt-medium-plus text-ui-fg-base" data-testid="product-title">{item.title}</Text> |
64 |
| - <LineItemOptions variant={item.variant} data-testid="product-variant" /> |
65 |
| - </Table.Cell> |
66 |
| - |
67 |
| - {type === "full" && ( |
68 |
| - <Table.Cell> |
69 |
| - <div className="flex gap-2 items-center w-28"> |
70 |
| - <DeleteButton id={item.id} data-testid="product-delete-button" /> |
71 |
| - <CartItemSelect |
72 |
| - value={item.quantity} |
73 |
| - onChange={(value) => changeQuantity(parseInt(value.target.value))} |
74 |
| - className="w-14 h-10 p-4" |
75 |
| - data-testid="product-select-button" |
76 |
| - > |
77 |
| - {Array.from( |
78 |
| - { |
79 |
| - length: Math.min( |
80 |
| - item.variant.inventory_quantity > 0 |
81 |
| - ? item.variant.inventory_quantity |
82 |
| - : 10, |
83 |
| - 10 |
84 |
| - ), |
85 |
| - }, |
86 |
| - (_, i) => ( |
87 |
| - <option value={i + 1} key={i}> |
88 |
| - {i + 1} |
89 |
| - </option> |
90 |
| - ) |
91 |
| - )} |
92 |
| - </CartItemSelect> |
93 |
| - {updating && <Spinner />} |
94 |
| - </div> |
95 |
| - <ErrorMessage error={error} data-testid="product-error-message" /> |
| 51 | + <I18nProviderClient locale={useCurrentLocale()}> |
| 52 | + <Table.Row className="w-full" data-testid="product-row"> |
| 53 | + <Table.Cell className="!pl-0 p-4 w-24"> |
| 54 | + <LocalizedClientLink |
| 55 | + href={`/products/${handle}`} |
| 56 | + className={clx("flex", { |
| 57 | + "w-16": type === "preview", |
| 58 | + "small:w-24 w-12": type === "full", |
| 59 | + })} |
| 60 | + > |
| 61 | + <Thumbnail thumbnail={item.thumbnail} size="square" /> |
| 62 | + </LocalizedClientLink> |
96 | 63 | </Table.Cell>
|
97 |
| - )} |
98 | 64 |
|
99 |
| - {type === "full" && ( |
100 |
| - <Table.Cell className="hidden small:table-cell"> |
101 |
| - <LineItemUnitPrice item={item} region={region} style="tight" /> |
| 65 | + <Table.Cell className="text-left"> |
| 66 | + <Text |
| 67 | + className="txt-medium-plus text-ui-fg-base" |
| 68 | + data-testid="product-title" |
| 69 | + > |
| 70 | + {item.title} |
| 71 | + </Text> |
| 72 | + <LineItemOptions |
| 73 | + variant={item.variant} |
| 74 | + data-testid="product-variant" |
| 75 | + /> |
102 | 76 | </Table.Cell>
|
103 |
| - )} |
104 | 77 |
|
105 |
| - <Table.Cell className="!pr-0"> |
106 |
| - <span |
107 |
| - className={clx("!pr-0", { |
108 |
| - "flex flex-col items-end h-full justify-center": type === "preview", |
109 |
| - })} |
110 |
| - > |
111 |
| - {type === "preview" && ( |
112 |
| - <span className="flex gap-x-1 "> |
113 |
| - <Text className="text-ui-fg-muted">{item.quantity}x </Text> |
114 |
| - <LineItemUnitPrice item={item} region={region} style="tight" /> |
115 |
| - </span> |
116 |
| - )} |
117 |
| - <LineItemPrice item={item} region={region} style="tight" /> |
118 |
| - </span> |
119 |
| - </Table.Cell> |
120 |
| - </Table.Row> |
| 78 | + {type === "full" && ( |
| 79 | + <Table.Cell> |
| 80 | + <div className="flex gap-2 items-center w-28"> |
| 81 | + <DeleteButton id={item.id} data-testid="product-delete-button" /> |
| 82 | + <CartItemSelect |
| 83 | + value={item.quantity} |
| 84 | + onChange={(value) => |
| 85 | + changeQuantity(parseInt(value.target.value)) |
| 86 | + } |
| 87 | + className="w-14 h-10 p-4" |
| 88 | + data-testid="product-select-button" |
| 89 | + > |
| 90 | + {Array.from( |
| 91 | + { |
| 92 | + length: Math.min( |
| 93 | + item.variant.inventory_quantity > 0 |
| 94 | + ? item.variant.inventory_quantity |
| 95 | + : 10, |
| 96 | + 10 |
| 97 | + ), |
| 98 | + }, |
| 99 | + (_, i) => ( |
| 100 | + <option value={i + 1} key={i}> |
| 101 | + {i + 1} |
| 102 | + </option> |
| 103 | + ) |
| 104 | + )} |
| 105 | + </CartItemSelect> |
| 106 | + {updating && <Spinner />} |
| 107 | + </div> |
| 108 | + <ErrorMessage error={error} data-testid="product-error-message" /> |
| 109 | + </Table.Cell> |
| 110 | + )} |
| 111 | + |
| 112 | + {type === "full" && ( |
| 113 | + <Table.Cell className="hidden small:table-cell"> |
| 114 | + <LineItemUnitPrice item={item} region={region} style="tight" /> |
| 115 | + </Table.Cell> |
| 116 | + )} |
| 117 | + |
| 118 | + <Table.Cell className="!pr-0"> |
| 119 | + <span |
| 120 | + className={clx("!pr-0", { |
| 121 | + "flex flex-col items-end h-full justify-center": |
| 122 | + type === "preview", |
| 123 | + })} |
| 124 | + > |
| 125 | + {type === "preview" && ( |
| 126 | + <span className="flex gap-x-1 "> |
| 127 | + <Text className="text-ui-fg-muted">{item.quantity}x </Text> |
| 128 | + <LineItemUnitPrice item={item} region={region} style="tight" /> |
| 129 | + </span> |
| 130 | + )} |
| 131 | + <LineItemPrice item={item} region={region} style="tight" /> |
| 132 | + </span> |
| 133 | + </Table.Cell> |
| 134 | + </Table.Row> |
| 135 | + </I18nProviderClient> |
121 | 136 | )
|
122 | 137 | }
|
123 | 138 |
|
|
0 commit comments