This repository was archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathcart.jsx
executable file
·124 lines (119 loc) · 4.09 KB
/
cart.jsx
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as React from "react"
import { Link } from "gatsby"
import { Layout } from "../components/layout"
import { StoreContext } from "../context/store-context"
import { LineItem } from "../components/line-item"
import { formatPrice } from "../utils/format-price"
import {
table,
wrap,
totals,
grandTotal,
summary,
checkoutButton,
collapseColumn,
labelColumn,
imageHeader,
productHeader,
emptyStateContainer,
emptyStateHeading,
emptyStateLink,
title,
} from "./cart.module.css"
import { Seo } from "../components/seo"
export default function CartPage() {
const { checkout, loading } = React.useContext(StoreContext)
const emptyCart = checkout.lineItems.length === 0
const handleCheckout = () => {
window.open(checkout.webUrl)
}
return (
<Layout>
<div className={wrap}>
{emptyCart ? (
<div className={emptyStateContainer}>
<h1 className={emptyStateHeading}>Your cart is empty</h1>
<p>
Looks like you haven’t found anything yet. We understand that
sometimes it’s hard to choose — maybe this helps:
</p>
<Link to="/search?s=BEST_SELLING" className={emptyStateLink}>
View trending products
</Link>
</div>
) : (
<>
<h1 className={title}>Your cart</h1>
<table className={table}>
<thead>
<tr>
<th className={imageHeader}>Image</th>
<th className={productHeader}>Product</th>
<th className={collapseColumn}>Price</th>
<th>Qty.</th>
<th className={[totals, collapseColumn].join(" ")}>Total</th>
</tr>
</thead>
<tbody>
{checkout.lineItems.map((item) => (
<LineItem item={item} key={item.id} />
))}
<tr className={summary}>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={labelColumn}>Subtotal</td>
<td className={totals}>
{formatPrice(
checkout.subtotalPriceV2.currencyCode,
checkout.subtotalPriceV2.amount
)}
</td>
</tr>
<tr className={summary}>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={labelColumn}>Taxes</td>
<td className={totals}>
{formatPrice(
checkout.totalTaxV2.currencyCode,
checkout.totalTaxV2.amount
)}
</td>
</tr>
<tr className={summary}>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={labelColumn}>Shipping</td>
<td className={totals}>Calculated at checkout</td>
</tr>
<tr className={grandTotal}>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={collapseColumn}></td>
<td className={labelColumn}>Total Price</td>
<td className={totals}>
{formatPrice(
checkout.totalPriceV2.currencyCode,
checkout.totalPriceV2.amount
)}
</td>
</tr>
</tbody>
</table>
<button
onClick={handleCheckout}
disabled={loading}
className={checkoutButton}
>
Checkout
</button>
</>
)}
</div>
</Layout>
)
}
export const Head = () => <Seo />