@springmicro/cart 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +21 -21
- package/README.md +64 -64
- package/dist/index.js +0 -0
- package/dist/index.umd.cjs +0 -0
- package/package.json +3 -3
- package/springmicro-cart-0.3.4.tgz +0 -0
- package/src/AddToCartForm.tsx +16 -16
- package/src/CartButton.tsx +249 -249
- package/src/ProductCard.css +106 -106
- package/src/ProductCard.tsx +165 -165
- package/src/checkout/ReviewCartAndCalculateTaxes.css +93 -93
- package/src/checkout/ReviewCartAndCalculateTaxes.tsx +370 -370
- package/src/checkout/components/AddCard.tsx +267 -267
- package/src/checkout/components/Address.tsx +261 -261
- package/src/checkout/components/CartList.tsx +151 -151
- package/src/checkout/components/CartProductCard.css +67 -67
- package/src/checkout/components/CartProductCard.tsx +90 -90
- package/src/checkout/components/Invoice.tsx +145 -145
- package/src/checkout/components/ProviderLogos.tsx +93 -93
- package/src/checkout/components/StatusBar.tsx +32 -32
- package/src/checkout/index.tsx +165 -165
- package/src/index.css +5 -5
- package/src/index.ts +36 -36
- package/src/types.d.ts +56 -56
- package/src/utils/api.ts +67 -67
- package/src/utils/cartAuthHandler.ts +50 -50
- package/src/utils/index.ts +28 -28
- package/src/utils/storage.ts +133 -133
- package/tsconfig.json +24 -24
- package/tsconfig.node.json +11 -11
- package/vite.config.ts +25 -25
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import { Box, Button, Tooltip, Typography } from "@mui/material";
|
|
2
|
-
import { CartProductCard } from "./CartProductCard";
|
|
3
|
-
|
|
4
|
-
function formatPrice(cents) {
|
|
5
|
-
if (typeof cents === "string") return cents;
|
|
6
|
-
return `$${(cents / 100).toFixed(2)}`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function CartList({
|
|
10
|
-
status,
|
|
11
|
-
cart,
|
|
12
|
-
subtotal,
|
|
13
|
-
tax,
|
|
14
|
-
shipping,
|
|
15
|
-
discount,
|
|
16
|
-
prices,
|
|
17
|
-
disableMissingImage,
|
|
18
|
-
disableProductLink,
|
|
19
|
-
formik,
|
|
20
|
-
formDisabled,
|
|
21
|
-
formError,
|
|
22
|
-
}) {
|
|
23
|
-
return (
|
|
24
|
-
<form
|
|
25
|
-
style={{ flexGrow: 1 }}
|
|
26
|
-
onSubmit={(e) => {
|
|
27
|
-
e.preventDefault();
|
|
28
|
-
formik.handleSubmit(e);
|
|
29
|
-
}}
|
|
30
|
-
>
|
|
31
|
-
<Box
|
|
32
|
-
sx={{
|
|
33
|
-
display: "flex",
|
|
34
|
-
justifyContent: "center",
|
|
35
|
-
flexGrow: 1,
|
|
36
|
-
mb: { xs: 4, xl: undefined },
|
|
37
|
-
}}
|
|
38
|
-
>
|
|
39
|
-
<Box
|
|
40
|
-
sx={{
|
|
41
|
-
display: "flex",
|
|
42
|
-
flexDirection: "column",
|
|
43
|
-
maxWidth: 650,
|
|
44
|
-
alignItems: "center",
|
|
45
|
-
boxShadow: "0px 2px 5px 2px #dfdfdfff",
|
|
46
|
-
margin: "4px",
|
|
47
|
-
padding: "2rem 0",
|
|
48
|
-
borderRadius: "8px",
|
|
49
|
-
flexGrow: 1,
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
<Typography style={{ fontSize: "30px", fontWeight: "bold" }}>
|
|
53
|
-
Checkout
|
|
54
|
-
</Typography>
|
|
55
|
-
<Box
|
|
56
|
-
sx={{
|
|
57
|
-
width: "50%",
|
|
58
|
-
display: "flex",
|
|
59
|
-
justifyContent: "space-between",
|
|
60
|
-
}}
|
|
61
|
-
>
|
|
62
|
-
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
63
|
-
Subtotal: {formatPrice(subtotal)}
|
|
64
|
-
</Typography>
|
|
65
|
-
{tax.error ? (
|
|
66
|
-
<Tooltip
|
|
67
|
-
disableInteractive
|
|
68
|
-
title={`Tax could not be calculated. Error: ${tax.error}`}
|
|
69
|
-
>
|
|
70
|
-
<Typography
|
|
71
|
-
sx={{
|
|
72
|
-
fontSize: "20px",
|
|
73
|
-
bgcolor: "#ff000040",
|
|
74
|
-
borderRadius: 2,
|
|
75
|
-
p: 1,
|
|
76
|
-
textDecoration: "underline dotted",
|
|
77
|
-
cursor: "help",
|
|
78
|
-
}}
|
|
79
|
-
>
|
|
80
|
-
Taxes: {formatPrice(tax.tax_amount)}
|
|
81
|
-
</Typography>
|
|
82
|
-
</Tooltip>
|
|
83
|
-
) : (
|
|
84
|
-
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
85
|
-
Taxes: {formatPrice(tax.tax_amount)}
|
|
86
|
-
</Typography>
|
|
87
|
-
)}
|
|
88
|
-
</Box>
|
|
89
|
-
{(discount != 0 || shipping != 0) && (
|
|
90
|
-
<Box
|
|
91
|
-
sx={{
|
|
92
|
-
width: "50%",
|
|
93
|
-
display: "flex",
|
|
94
|
-
justifyContent: "space-between",
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
98
|
-
{shipping && <>Shipping: {formatPrice(shipping)}</>}
|
|
99
|
-
</Typography>
|
|
100
|
-
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
101
|
-
{discount && <>Discount: {formatPrice(discount)}</>}
|
|
102
|
-
</Typography>
|
|
103
|
-
</Box>
|
|
104
|
-
)}
|
|
105
|
-
<Box>
|
|
106
|
-
<Typography style={{ fontSize: "26px" }}>
|
|
107
|
-
Total:{" "}
|
|
108
|
-
{typeof subtotal === "number"
|
|
109
|
-
? formatPrice(
|
|
110
|
-
subtotal +
|
|
111
|
-
(tax.tax_amount === "TBD" ? 0 : tax.tax_amount) +
|
|
112
|
-
shipping -
|
|
113
|
-
discount
|
|
114
|
-
)
|
|
115
|
-
: subtotal}
|
|
116
|
-
</Typography>
|
|
117
|
-
</Box>
|
|
118
|
-
{formError && (
|
|
119
|
-
<Typography color="red">
|
|
120
|
-
Could not confirm payment. Your card info may have been entered
|
|
121
|
-
incorrectly.
|
|
122
|
-
</Typography>
|
|
123
|
-
)}
|
|
124
|
-
{status === 1 && (
|
|
125
|
-
<Button
|
|
126
|
-
variant="contained"
|
|
127
|
-
sx={{ mt: 2 }}
|
|
128
|
-
type="submit"
|
|
129
|
-
disabled={formDisabled}
|
|
130
|
-
color={formError ? "error" : undefined}
|
|
131
|
-
>
|
|
132
|
-
Confirm Order
|
|
133
|
-
</Button>
|
|
134
|
-
)}
|
|
135
|
-
<Box className="checkout-list">
|
|
136
|
-
{cart.items.map((p, i) => (
|
|
137
|
-
<CartProductCard
|
|
138
|
-
product={p}
|
|
139
|
-
i={i}
|
|
140
|
-
price={prices[p.price_id]}
|
|
141
|
-
disableProductLink={disableProductLink}
|
|
142
|
-
disableMissingImage={disableMissingImage}
|
|
143
|
-
disableModification={status != 0}
|
|
144
|
-
/>
|
|
145
|
-
))}
|
|
146
|
-
</Box>
|
|
147
|
-
</Box>
|
|
148
|
-
</Box>
|
|
149
|
-
</form>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
1
|
+
import { Box, Button, Tooltip, Typography } from "@mui/material";
|
|
2
|
+
import { CartProductCard } from "./CartProductCard";
|
|
3
|
+
|
|
4
|
+
function formatPrice(cents) {
|
|
5
|
+
if (typeof cents === "string") return cents;
|
|
6
|
+
return `$${(cents / 100).toFixed(2)}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function CartList({
|
|
10
|
+
status,
|
|
11
|
+
cart,
|
|
12
|
+
subtotal,
|
|
13
|
+
tax,
|
|
14
|
+
shipping,
|
|
15
|
+
discount,
|
|
16
|
+
prices,
|
|
17
|
+
disableMissingImage,
|
|
18
|
+
disableProductLink,
|
|
19
|
+
formik,
|
|
20
|
+
formDisabled,
|
|
21
|
+
formError,
|
|
22
|
+
}) {
|
|
23
|
+
return (
|
|
24
|
+
<form
|
|
25
|
+
style={{ flexGrow: 1 }}
|
|
26
|
+
onSubmit={(e) => {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
formik.handleSubmit(e);
|
|
29
|
+
}}
|
|
30
|
+
>
|
|
31
|
+
<Box
|
|
32
|
+
sx={{
|
|
33
|
+
display: "flex",
|
|
34
|
+
justifyContent: "center",
|
|
35
|
+
flexGrow: 1,
|
|
36
|
+
mb: { xs: 4, xl: undefined },
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<Box
|
|
40
|
+
sx={{
|
|
41
|
+
display: "flex",
|
|
42
|
+
flexDirection: "column",
|
|
43
|
+
maxWidth: 650,
|
|
44
|
+
alignItems: "center",
|
|
45
|
+
boxShadow: "0px 2px 5px 2px #dfdfdfff",
|
|
46
|
+
margin: "4px",
|
|
47
|
+
padding: "2rem 0",
|
|
48
|
+
borderRadius: "8px",
|
|
49
|
+
flexGrow: 1,
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<Typography style={{ fontSize: "30px", fontWeight: "bold" }}>
|
|
53
|
+
Checkout
|
|
54
|
+
</Typography>
|
|
55
|
+
<Box
|
|
56
|
+
sx={{
|
|
57
|
+
width: "50%",
|
|
58
|
+
display: "flex",
|
|
59
|
+
justifyContent: "space-between",
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
63
|
+
Subtotal: {formatPrice(subtotal)}
|
|
64
|
+
</Typography>
|
|
65
|
+
{tax.error ? (
|
|
66
|
+
<Tooltip
|
|
67
|
+
disableInteractive
|
|
68
|
+
title={`Tax could not be calculated. Error: ${tax.error}`}
|
|
69
|
+
>
|
|
70
|
+
<Typography
|
|
71
|
+
sx={{
|
|
72
|
+
fontSize: "20px",
|
|
73
|
+
bgcolor: "#ff000040",
|
|
74
|
+
borderRadius: 2,
|
|
75
|
+
p: 1,
|
|
76
|
+
textDecoration: "underline dotted",
|
|
77
|
+
cursor: "help",
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
Taxes: {formatPrice(tax.tax_amount)}
|
|
81
|
+
</Typography>
|
|
82
|
+
</Tooltip>
|
|
83
|
+
) : (
|
|
84
|
+
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
85
|
+
Taxes: {formatPrice(tax.tax_amount)}
|
|
86
|
+
</Typography>
|
|
87
|
+
)}
|
|
88
|
+
</Box>
|
|
89
|
+
{(discount != 0 || shipping != 0) && (
|
|
90
|
+
<Box
|
|
91
|
+
sx={{
|
|
92
|
+
width: "50%",
|
|
93
|
+
display: "flex",
|
|
94
|
+
justifyContent: "space-between",
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
98
|
+
{shipping && <>Shipping: {formatPrice(shipping)}</>}
|
|
99
|
+
</Typography>
|
|
100
|
+
<Typography sx={{ fontSize: "20px", p: 1 }}>
|
|
101
|
+
{discount && <>Discount: {formatPrice(discount)}</>}
|
|
102
|
+
</Typography>
|
|
103
|
+
</Box>
|
|
104
|
+
)}
|
|
105
|
+
<Box>
|
|
106
|
+
<Typography style={{ fontSize: "26px" }}>
|
|
107
|
+
Total:{" "}
|
|
108
|
+
{typeof subtotal === "number"
|
|
109
|
+
? formatPrice(
|
|
110
|
+
subtotal +
|
|
111
|
+
(tax.tax_amount === "TBD" ? 0 : tax.tax_amount) +
|
|
112
|
+
shipping -
|
|
113
|
+
discount
|
|
114
|
+
)
|
|
115
|
+
: subtotal}
|
|
116
|
+
</Typography>
|
|
117
|
+
</Box>
|
|
118
|
+
{formError && (
|
|
119
|
+
<Typography color="red">
|
|
120
|
+
Could not confirm payment. Your card info may have been entered
|
|
121
|
+
incorrectly.
|
|
122
|
+
</Typography>
|
|
123
|
+
)}
|
|
124
|
+
{status === 1 && (
|
|
125
|
+
<Button
|
|
126
|
+
variant="contained"
|
|
127
|
+
sx={{ mt: 2 }}
|
|
128
|
+
type="submit"
|
|
129
|
+
disabled={formDisabled}
|
|
130
|
+
color={formError ? "error" : undefined}
|
|
131
|
+
>
|
|
132
|
+
Confirm Order
|
|
133
|
+
</Button>
|
|
134
|
+
)}
|
|
135
|
+
<Box className="checkout-list">
|
|
136
|
+
{cart.items.map((p, i) => (
|
|
137
|
+
<CartProductCard
|
|
138
|
+
product={p}
|
|
139
|
+
i={i}
|
|
140
|
+
price={prices[p.price_id]}
|
|
141
|
+
disableProductLink={disableProductLink}
|
|
142
|
+
disableMissingImage={disableMissingImage}
|
|
143
|
+
disableModification={status != 0}
|
|
144
|
+
/>
|
|
145
|
+
))}
|
|
146
|
+
</Box>
|
|
147
|
+
</Box>
|
|
148
|
+
</Box>
|
|
149
|
+
</form>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
.product-card {
|
|
2
|
-
width: 500px;
|
|
3
|
-
/* display: flex;
|
|
4
|
-
flex-direction: row;
|
|
5
|
-
justify-content: space-between; */
|
|
6
|
-
display: grid;
|
|
7
|
-
grid-template-columns: 1fr 40px;
|
|
8
|
-
gap: 0.5rem;
|
|
9
|
-
border-radius: 8px;
|
|
10
|
-
padding: 1rem;
|
|
11
|
-
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0);
|
|
12
|
-
transition: all 0.3s 0.1s;
|
|
13
|
-
cursor: pointer;
|
|
14
|
-
min-height: 48px;
|
|
15
|
-
flex-shrink: 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.product-card:hover {
|
|
19
|
-
box-shadow: 0px 2px 5px 2px #dfdfdfff;
|
|
20
|
-
transition: all 0.3s 0s;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.left-section {
|
|
24
|
-
display: flex;
|
|
25
|
-
flex-direction: row;
|
|
26
|
-
gap: 1rem;
|
|
27
|
-
flex-grow: 1;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.left-section > img,
|
|
31
|
-
.missing-image {
|
|
32
|
-
min-height: 100%;
|
|
33
|
-
max-height: 100px;
|
|
34
|
-
aspect-ratio: 1;
|
|
35
|
-
border-radius: 6px;
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.missing-image {
|
|
40
|
-
background-color: rgb(222, 222, 222);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.two-row {
|
|
44
|
-
display: flex;
|
|
45
|
-
flex-direction: column;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.two-row :nth-child(1) {
|
|
49
|
-
font-size: 20px;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.two-row :nth-child(2) {
|
|
53
|
-
font-size: 14px;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.two-row > * {
|
|
57
|
-
margin: 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.remove-button {
|
|
61
|
-
color: #ff000040 !important;
|
|
62
|
-
transition: all 0.2s !important;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.product-card:hover .remove-button {
|
|
66
|
-
color: red !important;
|
|
67
|
-
}
|
|
1
|
+
.product-card {
|
|
2
|
+
width: 500px;
|
|
3
|
+
/* display: flex;
|
|
4
|
+
flex-direction: row;
|
|
5
|
+
justify-content: space-between; */
|
|
6
|
+
display: grid;
|
|
7
|
+
grid-template-columns: 1fr 40px;
|
|
8
|
+
gap: 0.5rem;
|
|
9
|
+
border-radius: 8px;
|
|
10
|
+
padding: 1rem;
|
|
11
|
+
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0);
|
|
12
|
+
transition: all 0.3s 0.1s;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
min-height: 48px;
|
|
15
|
+
flex-shrink: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.product-card:hover {
|
|
19
|
+
box-shadow: 0px 2px 5px 2px #dfdfdfff;
|
|
20
|
+
transition: all 0.3s 0s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.left-section {
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: row;
|
|
26
|
+
gap: 1rem;
|
|
27
|
+
flex-grow: 1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.left-section > img,
|
|
31
|
+
.missing-image {
|
|
32
|
+
min-height: 100%;
|
|
33
|
+
max-height: 100px;
|
|
34
|
+
aspect-ratio: 1;
|
|
35
|
+
border-radius: 6px;
|
|
36
|
+
overflow: hidden;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.missing-image {
|
|
40
|
+
background-color: rgb(222, 222, 222);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.two-row {
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.two-row :nth-child(1) {
|
|
49
|
+
font-size: 20px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.two-row :nth-child(2) {
|
|
53
|
+
font-size: 14px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.two-row > * {
|
|
57
|
+
margin: 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.remove-button {
|
|
61
|
+
color: #ff000040 !important;
|
|
62
|
+
transition: all 0.2s !important;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.product-card:hover .remove-button {
|
|
66
|
+
color: red !important;
|
|
67
|
+
}
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import "./CartProductCard.css";
|
|
2
|
-
import { Tooltip, IconButton, Typography } from "@mui/material";
|
|
3
|
-
import CloseIcon from "@mui/icons-material/Close";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { CartProduct } from "../../types";
|
|
6
|
-
import { removeFromCart } from "../../utils/storage";
|
|
7
|
-
|
|
8
|
-
export function CartProductCard({
|
|
9
|
-
product,
|
|
10
|
-
i,
|
|
11
|
-
price,
|
|
12
|
-
disableProductLink = false,
|
|
13
|
-
disableMissingImage = false,
|
|
14
|
-
disableModification = false,
|
|
15
|
-
}: {
|
|
16
|
-
product: CartProduct;
|
|
17
|
-
i: number;
|
|
18
|
-
price: any;
|
|
19
|
-
disableProductLink?: boolean;
|
|
20
|
-
disableMissingImage?: boolean;
|
|
21
|
-
disableModification?: boolean;
|
|
22
|
-
}) {
|
|
23
|
-
const [hoverDelete, setHoverDelete] = React.useState(false);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<a
|
|
27
|
-
className="product-card"
|
|
28
|
-
href={
|
|
29
|
-
disableProductLink || hoverDelete
|
|
30
|
-
? undefined
|
|
31
|
-
: `/product/${product.product_id}`
|
|
32
|
-
}
|
|
33
|
-
>
|
|
34
|
-
<div className="left-section">
|
|
35
|
-
{product.image ? (
|
|
36
|
-
<img />
|
|
37
|
-
) : (
|
|
38
|
-
!disableMissingImage && <div className="missing-image" />
|
|
39
|
-
)}
|
|
40
|
-
<div className="two-row">
|
|
41
|
-
<Typography>{product.name}</Typography>
|
|
42
|
-
<Typography>
|
|
43
|
-
{price
|
|
44
|
-
? `$${(price.unit_amount / 100).toFixed(2)}${
|
|
45
|
-
price.recurring
|
|
46
|
-
? `/${
|
|
47
|
-
price.recurring.interval_count > 1
|
|
48
|
-
? `${price.recurring.interval_count} `
|
|
49
|
-
: ""
|
|
50
|
-
}${price.recurring.interval}${
|
|
51
|
-
price.recurring.interval_count > 1 ? "s" : ""
|
|
52
|
-
}`
|
|
53
|
-
: ""
|
|
54
|
-
}`
|
|
55
|
-
: "Loading price..."}
|
|
56
|
-
</Typography>
|
|
57
|
-
</div>
|
|
58
|
-
</div>
|
|
59
|
-
<div
|
|
60
|
-
style={{
|
|
61
|
-
display: "flex",
|
|
62
|
-
flexGrow: 1,
|
|
63
|
-
justifyContent: "center",
|
|
64
|
-
alignItems: "center",
|
|
65
|
-
}}
|
|
66
|
-
>
|
|
67
|
-
{!disableModification && (
|
|
68
|
-
<Tooltip
|
|
69
|
-
title="Remove from cart"
|
|
70
|
-
onMouseEnter={() => {
|
|
71
|
-
setHoverDelete(true);
|
|
72
|
-
}}
|
|
73
|
-
onMouseLeave={() => {
|
|
74
|
-
setHoverDelete(false);
|
|
75
|
-
}}
|
|
76
|
-
>
|
|
77
|
-
<IconButton
|
|
78
|
-
className="remove-button"
|
|
79
|
-
onClick={() => {
|
|
80
|
-
removeFromCart(i);
|
|
81
|
-
}}
|
|
82
|
-
>
|
|
83
|
-
<CloseIcon />
|
|
84
|
-
</IconButton>
|
|
85
|
-
</Tooltip>
|
|
86
|
-
)}
|
|
87
|
-
</div>
|
|
88
|
-
</a>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
1
|
+
import "./CartProductCard.css";
|
|
2
|
+
import { Tooltip, IconButton, Typography } from "@mui/material";
|
|
3
|
+
import CloseIcon from "@mui/icons-material/Close";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { CartProduct } from "../../types";
|
|
6
|
+
import { removeFromCart } from "../../utils/storage";
|
|
7
|
+
|
|
8
|
+
export function CartProductCard({
|
|
9
|
+
product,
|
|
10
|
+
i,
|
|
11
|
+
price,
|
|
12
|
+
disableProductLink = false,
|
|
13
|
+
disableMissingImage = false,
|
|
14
|
+
disableModification = false,
|
|
15
|
+
}: {
|
|
16
|
+
product: CartProduct;
|
|
17
|
+
i: number;
|
|
18
|
+
price: any;
|
|
19
|
+
disableProductLink?: boolean;
|
|
20
|
+
disableMissingImage?: boolean;
|
|
21
|
+
disableModification?: boolean;
|
|
22
|
+
}) {
|
|
23
|
+
const [hoverDelete, setHoverDelete] = React.useState(false);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<a
|
|
27
|
+
className="product-card"
|
|
28
|
+
href={
|
|
29
|
+
disableProductLink || hoverDelete
|
|
30
|
+
? undefined
|
|
31
|
+
: `/product/${product.product_id}`
|
|
32
|
+
}
|
|
33
|
+
>
|
|
34
|
+
<div className="left-section">
|
|
35
|
+
{product.image ? (
|
|
36
|
+
<img />
|
|
37
|
+
) : (
|
|
38
|
+
!disableMissingImage && <div className="missing-image" />
|
|
39
|
+
)}
|
|
40
|
+
<div className="two-row">
|
|
41
|
+
<Typography>{product.name}</Typography>
|
|
42
|
+
<Typography>
|
|
43
|
+
{price
|
|
44
|
+
? `$${(price.unit_amount / 100).toFixed(2)}${
|
|
45
|
+
price.recurring
|
|
46
|
+
? `/${
|
|
47
|
+
price.recurring.interval_count > 1
|
|
48
|
+
? `${price.recurring.interval_count} `
|
|
49
|
+
: ""
|
|
50
|
+
}${price.recurring.interval}${
|
|
51
|
+
price.recurring.interval_count > 1 ? "s" : ""
|
|
52
|
+
}`
|
|
53
|
+
: ""
|
|
54
|
+
}`
|
|
55
|
+
: "Loading price..."}
|
|
56
|
+
</Typography>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
<div
|
|
60
|
+
style={{
|
|
61
|
+
display: "flex",
|
|
62
|
+
flexGrow: 1,
|
|
63
|
+
justifyContent: "center",
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{!disableModification && (
|
|
68
|
+
<Tooltip
|
|
69
|
+
title="Remove from cart"
|
|
70
|
+
onMouseEnter={() => {
|
|
71
|
+
setHoverDelete(true);
|
|
72
|
+
}}
|
|
73
|
+
onMouseLeave={() => {
|
|
74
|
+
setHoverDelete(false);
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<IconButton
|
|
78
|
+
className="remove-button"
|
|
79
|
+
onClick={() => {
|
|
80
|
+
removeFromCart(i);
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
<CloseIcon />
|
|
84
|
+
</IconButton>
|
|
85
|
+
</Tooltip>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
</a>
|
|
89
|
+
);
|
|
90
|
+
}
|