@springmicro/cart 0.3.0 → 0.3.4
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 +2327 -2322
- package/dist/index.umd.cjs +61 -61
- package/package.json +5 -3
- 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/CheckoutList.css +93 -93
- package/src/checkout/CheckoutList.tsx +272 -264
- package/src/checkout/components/Address.tsx +265 -265
- package/src/checkout/components/Billing.tsx +353 -353
- package/src/checkout/components/CartProductCard.css +67 -67
- package/src/checkout/components/CartProductCard.tsx +80 -80
- package/src/checkout/components/Order.tsx +95 -93
- package/src/checkout/components/ProviderLogos.tsx +93 -93
- package/src/checkout/components/index.tsx +104 -104
- package/src/index.css +5 -5
- package/src/index.ts +35 -35
- 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
- package/springmicro-cart-0.2.3.tgz +0 -0
|
@@ -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: transparent !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: transparent !important;
|
|
62
|
+
transition: all 0.2s !important;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.product-card:hover .remove-button {
|
|
66
|
+
color: red !important;
|
|
67
|
+
}
|
|
@@ -1,80 +1,80 @@
|
|
|
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
|
-
}: {
|
|
14
|
-
product: CartProduct;
|
|
15
|
-
i: number;
|
|
16
|
-
price: any;
|
|
17
|
-
disableProductLink?: boolean;
|
|
18
|
-
}) {
|
|
19
|
-
const [hoverDelete, setHoverDelete] = React.useState(false);
|
|
20
|
-
console.log(product);
|
|
21
|
-
return (
|
|
22
|
-
<a
|
|
23
|
-
className="product-card"
|
|
24
|
-
href={
|
|
25
|
-
disableProductLink || hoverDelete
|
|
26
|
-
? undefined
|
|
27
|
-
: `/product/${product.product_id}`
|
|
28
|
-
}
|
|
29
|
-
>
|
|
30
|
-
<div className="left-section">
|
|
31
|
-
{product.image ? <img /> : <div className="missing-image"></div>}
|
|
32
|
-
<div className="two-row">
|
|
33
|
-
<Typography>{product.name}</Typography>
|
|
34
|
-
<Typography>
|
|
35
|
-
{price
|
|
36
|
-
? `$${(price.unit_amount / 100).toFixed(2)}${
|
|
37
|
-
price.recurring
|
|
38
|
-
? `/${
|
|
39
|
-
price.recurring.interval_count > 1
|
|
40
|
-
? `${price.recurring.interval_count} `
|
|
41
|
-
: ""
|
|
42
|
-
}${price.recurring.interval}${
|
|
43
|
-
price.recurring.interval_count > 1 ? "s" : ""
|
|
44
|
-
}`
|
|
45
|
-
: ""
|
|
46
|
-
}`
|
|
47
|
-
: "Loading price..."}
|
|
48
|
-
</Typography>
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
<div
|
|
52
|
-
style={{
|
|
53
|
-
display: "flex",
|
|
54
|
-
flexGrow: 1,
|
|
55
|
-
justifyContent: "center",
|
|
56
|
-
alignItems: "center",
|
|
57
|
-
}}
|
|
58
|
-
>
|
|
59
|
-
<Tooltip
|
|
60
|
-
title="Remove from cart"
|
|
61
|
-
onMouseEnter={() => {
|
|
62
|
-
setHoverDelete(true);
|
|
63
|
-
}}
|
|
64
|
-
onMouseLeave={() => {
|
|
65
|
-
setHoverDelete(false);
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
<IconButton
|
|
69
|
-
className="remove-button"
|
|
70
|
-
onClick={() => {
|
|
71
|
-
removeFromCart(i);
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
<CloseIcon />
|
|
75
|
-
</IconButton>
|
|
76
|
-
</Tooltip>
|
|
77
|
-
</div>
|
|
78
|
-
</a>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
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
|
+
}: {
|
|
14
|
+
product: CartProduct;
|
|
15
|
+
i: number;
|
|
16
|
+
price: any;
|
|
17
|
+
disableProductLink?: boolean;
|
|
18
|
+
}) {
|
|
19
|
+
const [hoverDelete, setHoverDelete] = React.useState(false);
|
|
20
|
+
console.log(product);
|
|
21
|
+
return (
|
|
22
|
+
<a
|
|
23
|
+
className="product-card"
|
|
24
|
+
href={
|
|
25
|
+
disableProductLink || hoverDelete
|
|
26
|
+
? undefined
|
|
27
|
+
: `/product/${product.product_id}`
|
|
28
|
+
}
|
|
29
|
+
>
|
|
30
|
+
<div className="left-section">
|
|
31
|
+
{product.image ? <img /> : <div className="missing-image"></div>}
|
|
32
|
+
<div className="two-row">
|
|
33
|
+
<Typography>{product.name}</Typography>
|
|
34
|
+
<Typography>
|
|
35
|
+
{price
|
|
36
|
+
? `$${(price.unit_amount / 100).toFixed(2)}${
|
|
37
|
+
price.recurring
|
|
38
|
+
? `/${
|
|
39
|
+
price.recurring.interval_count > 1
|
|
40
|
+
? `${price.recurring.interval_count} `
|
|
41
|
+
: ""
|
|
42
|
+
}${price.recurring.interval}${
|
|
43
|
+
price.recurring.interval_count > 1 ? "s" : ""
|
|
44
|
+
}`
|
|
45
|
+
: ""
|
|
46
|
+
}`
|
|
47
|
+
: "Loading price..."}
|
|
48
|
+
</Typography>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
<div
|
|
52
|
+
style={{
|
|
53
|
+
display: "flex",
|
|
54
|
+
flexGrow: 1,
|
|
55
|
+
justifyContent: "center",
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<Tooltip
|
|
60
|
+
title="Remove from cart"
|
|
61
|
+
onMouseEnter={() => {
|
|
62
|
+
setHoverDelete(true);
|
|
63
|
+
}}
|
|
64
|
+
onMouseLeave={() => {
|
|
65
|
+
setHoverDelete(false);
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
<IconButton
|
|
69
|
+
className="remove-button"
|
|
70
|
+
onClick={() => {
|
|
71
|
+
removeFromCart(i);
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<CloseIcon />
|
|
75
|
+
</IconButton>
|
|
76
|
+
</Tooltip>
|
|
77
|
+
</div>
|
|
78
|
+
</a>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -1,93 +1,95 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
Container,
|
|
4
|
-
Typography,
|
|
5
|
-
Table,
|
|
6
|
-
TableBody,
|
|
7
|
-
TableCell,
|
|
8
|
-
TableContainer,
|
|
9
|
-
TableHead,
|
|
10
|
-
TableRow,
|
|
11
|
-
Paper,
|
|
12
|
-
} from "@mui/material";
|
|
13
|
-
|
|
14
|
-
const Order = ({ order, invoiceId }) => {
|
|
15
|
-
// Formatter for currency in USD
|
|
16
|
-
const formatter = new Intl.NumberFormat("en-US", {
|
|
17
|
-
style: "currency",
|
|
18
|
-
currency: "USD",
|
|
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
|
-
<TableCell>
|
|
48
|
-
<TableCell>
|
|
49
|
-
<TableCell>
|
|
50
|
-
<TableCell>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<TableCell>{item.
|
|
59
|
-
<TableCell>{item.
|
|
60
|
-
<TableCell>
|
|
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
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
Container,
|
|
4
|
+
Typography,
|
|
5
|
+
Table,
|
|
6
|
+
TableBody,
|
|
7
|
+
TableCell,
|
|
8
|
+
TableContainer,
|
|
9
|
+
TableHead,
|
|
10
|
+
TableRow,
|
|
11
|
+
Paper,
|
|
12
|
+
} from "@mui/material";
|
|
13
|
+
|
|
14
|
+
const Order = ({ order, invoiceId }) => {
|
|
15
|
+
// Formatter for currency in USD
|
|
16
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
17
|
+
style: "currency",
|
|
18
|
+
currency: "USD",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log("ORDER", order);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Container>
|
|
25
|
+
<Typography variant="h4" gutterBottom>
|
|
26
|
+
{invoiceId ? `Invoice #${invoiceId}` : "Order"}
|
|
27
|
+
</Typography>
|
|
28
|
+
<Typography variant="subtitle1">Reference: {order.reference}</Typography>
|
|
29
|
+
<Typography variant="subtitle1">
|
|
30
|
+
Date: {new Date(order.date).toLocaleDateString()}
|
|
31
|
+
</Typography>
|
|
32
|
+
<Typography variant="subtitle1">Status: {order.status}</Typography>
|
|
33
|
+
{order.customer ? (
|
|
34
|
+
<Typography variant="subtitle1">
|
|
35
|
+
{order.customer.first_name} {order.customer.last_name}
|
|
36
|
+
</Typography>
|
|
37
|
+
) : (
|
|
38
|
+
<Typography variant="subtitle1">
|
|
39
|
+
Customer ID: {order.customer_id}
|
|
40
|
+
</Typography>
|
|
41
|
+
)}
|
|
42
|
+
|
|
43
|
+
<TableContainer component={Paper} sx={{ my: 2 }}>
|
|
44
|
+
<Table>
|
|
45
|
+
<TableHead>
|
|
46
|
+
<TableRow>
|
|
47
|
+
<TableCell>Item ID</TableCell>
|
|
48
|
+
<TableCell>Name</TableCell>
|
|
49
|
+
<TableCell>Description</TableCell>
|
|
50
|
+
<TableCell>Quantity</TableCell>
|
|
51
|
+
<TableCell>Unit Price</TableCell>
|
|
52
|
+
<TableCell>Total Price</TableCell>
|
|
53
|
+
</TableRow>
|
|
54
|
+
</TableHead>
|
|
55
|
+
<TableBody>
|
|
56
|
+
{order.basket.map((item) => (
|
|
57
|
+
<TableRow key={item.item_id}>
|
|
58
|
+
<TableCell>{item.item_id}</TableCell>
|
|
59
|
+
<TableCell>{item.name}</TableCell>
|
|
60
|
+
<TableCell>{item.description || "-"}</TableCell>
|
|
61
|
+
<TableCell>{item.quantity}</TableCell>
|
|
62
|
+
<TableCell>
|
|
63
|
+
{formatter.format(item.unit_price_cents / 100)}
|
|
64
|
+
</TableCell>
|
|
65
|
+
<TableCell>
|
|
66
|
+
{formatter.format(
|
|
67
|
+
(item.quantity * item.unit_price_cents) / 100
|
|
68
|
+
)}
|
|
69
|
+
</TableCell>
|
|
70
|
+
</TableRow>
|
|
71
|
+
))}
|
|
72
|
+
</TableBody>
|
|
73
|
+
</Table>
|
|
74
|
+
</TableContainer>
|
|
75
|
+
|
|
76
|
+
<Typography variant="h6" gutterBottom>
|
|
77
|
+
Subtotal (excl. taxes): {formatter.format(order.subtotal / 100)}
|
|
78
|
+
</Typography>
|
|
79
|
+
<Typography variant="h6" gutterBottom>
|
|
80
|
+
Taxes: {formatter.format(order.taxes / 100)}
|
|
81
|
+
</Typography>
|
|
82
|
+
<Typography variant="h6" gutterBottom>
|
|
83
|
+
Delivery Fees:{" "}
|
|
84
|
+
{formatter.format(
|
|
85
|
+
order.delivery_fees ? order.delivery_fees / 100 : 0.0
|
|
86
|
+
)}
|
|
87
|
+
</Typography>
|
|
88
|
+
<Typography variant="h5" gutterBottom sx={{ mb: 4 }}>
|
|
89
|
+
Total: {formatter.format(order.total / 100)}
|
|
90
|
+
</Typography>
|
|
91
|
+
</Container>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default Order;
|