-
-
Notifications
You must be signed in to change notification settings - Fork 380
/
index.tsx
108 lines (100 loc) · 3.37 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { useStore } from "@lib/context/store-context"
import { LineItem, Region } from "@medusajs/medusa"
import { Table, Text, clx } from "@medusajs/ui"
import LineItemOptions from "@modules/common/components/line-item-options"
import LineItemPrice from "@modules/common/components/line-item-price"
import LineItemUnitPrice from "@modules/common/components/line-item-unit-price"
import CartItemSelect from "@modules/cart/components/cart-item-select"
import Trash from "@modules/common/icons/trash"
import Thumbnail from "@modules/products/components/thumbnail"
import Link from "next/link"
type ItemProps = {
item: Omit<LineItem, "beforeInsert">
region: Region
type?: "full" | "preview"
}
const Item = ({ item, region, type = "full" }: ItemProps) => {
const { updateItem, deleteItem } = useStore()
const { handle } = item.variant.product
return (
<Table.Row className="w-full">
<Table.Cell className="!pl-0 p-4 w-24">
<Link
href={`/products/${handle}`}
className={clx("flex", {
"w-16": type === "preview",
"small:w-24 w-12": type === "full",
})}
>
<Thumbnail thumbnail={item.thumbnail} size="square" />
</Link>
</Table.Cell>
<Table.Cell className="text-left">
<Text className="txt-medium-plus text-ui-fg-base">{item.title}</Text>
<LineItemOptions variant={item.variant} />
</Table.Cell>
{type === "full" && (
<Table.Cell>
<div className="flex gap-2">
<button
className="flex items-center gap-x-"
onClick={() => deleteItem(item.id)}
>
<Trash size={18} />
</button>
<CartItemSelect
value={item.quantity}
onChange={(value) =>
updateItem({
lineId: item.id,
quantity: parseInt(value.target.value),
})
}
className="w-14 h-10 p-4"
>
{Array.from(
[
...Array(
item.variant.inventory_quantity > 0
? item.variant.inventory_quantity
: 10
),
].keys()
)
.slice(0, 10)
.map((i) => {
const value = i + 1
return (
<option value={value} key={i}>
{value}
</option>
)
})}
</CartItemSelect>
</div>
</Table.Cell>
)}
{type === "full" && (
<Table.Cell className="hidden small:table-cell">
<LineItemUnitPrice item={item} region={region} style="tight" />
</Table.Cell>
)}
<Table.Cell className="!pr-0">
<span
className={clx("!pr-0", {
"flex flex-col items-end h-full justify-center": type === "preview",
})}
>
{type === "preview" && (
<span className="flex gap-x-1 ">
<Text className="text-ui-fg-muted">{item.quantity}x </Text>
<LineItemUnitPrice item={item} region={region} style="tight" />
</span>
)}
<LineItemPrice item={item} region={region} style="tight" />
</span>
</Table.Cell>
</Table.Row>
)
}
export default Item