@springmicro/cart 0.5.14 → 0.5.16

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@springmicro/cart",
3
3
  "private": false,
4
- "version": "0.5.14",
4
+ "version": "0.5.16",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@nanostores/persistent": "^0.10.1",
25
25
  "@nanostores/query": "^0.3.3",
26
26
  "@nanostores/react": "^0.7.2",
27
- "@springmicro/utils": "0.5.14",
27
+ "@springmicro/utils": "0.5.16",
28
28
  "dotenv": "^16.4.5",
29
29
  "nanostores": "^0.10.3",
30
30
  "react": "^18.2.0",
@@ -49,5 +49,5 @@
49
49
  "vite-plugin-css-injected-by-js": "^3.5.1",
50
50
  "yup": "^1.4.0"
51
51
  },
52
- "gitHead": "0c889259d325d955a7981f8e8975edc42c8b9cf8"
52
+ "gitHead": "9adcb0aba821c9e30cb9c1c8d737e2426f7f29c6"
53
53
  }
@@ -1,16 +1,16 @@
1
- import { CartProduct } from "./types";
2
- import { addToCart } from "./utils/storage";
3
-
4
- type Props = {
5
- item: CartProduct;
6
- children: any;
7
- };
8
-
9
- export default function AddToCartForm({ item, children }: Props) {
10
- function addItemToCart(e: any) {
11
- e.preventDefault();
12
- addToCart(item);
13
- }
14
-
15
- return <form onSubmit={addItemToCart}>{children}</form>;
16
- }
1
+ import { CartProduct } from "./types";
2
+ import { addToCart } from "./utils/storage";
3
+
4
+ type Props = {
5
+ item: CartProduct;
6
+ children: any;
7
+ };
8
+
9
+ export default function AddToCartForm({ item, children }: Props) {
10
+ function addItemToCart(e: any) {
11
+ e.preventDefault();
12
+ addToCart(item);
13
+ }
14
+
15
+ return <form onSubmit={addItemToCart}>{children}</form>;
16
+ }
@@ -140,7 +140,9 @@ function CartModal({
140
140
  );
141
141
  if (pricesToGet.length === 0) return;
142
142
 
143
- const url = `${apiBaseUrl}/api/ecommerce/price?filter={'ids':[${pricesToGet.join(",")}]}`;
143
+ const url = `${apiBaseUrl}/api/ecommerce/price?filter={'ids':[${pricesToGet.join(
144
+ ","
145
+ )}]}`;
144
146
  fetch(url, {
145
147
  method: "GET",
146
148
  headers: {
@@ -212,12 +214,18 @@ function CartModal({
212
214
  {prices === null
213
215
  ? "Price not found."
214
216
  : price
215
- ? `$${(price.unit_amount / 100).toFixed(2)}${
216
- price.recurring
217
- ? `/${price.recurring.interval_count > 1 ? `${price.recurring.interval_count} ` : ""}${price.recurring.interval}${price.recurring.interval_count > 1 ? "s" : ""}`
218
- : ""
219
- }`
220
- : "Loading price..."}
217
+ ? `$${(price.unit_amount / 100).toFixed(2)}${
218
+ price.recurring
219
+ ? `/${
220
+ price.recurring.interval_count > 1
221
+ ? `${price.recurring.interval_count} `
222
+ : ""
223
+ }${price.recurring.interval}${
224
+ price.recurring.interval_count > 1 ? "s" : ""
225
+ }`
226
+ : ""
227
+ }`
228
+ : "Loading price..."}
221
229
  </h3>
222
230
  </Box>
223
231
  <Tooltip title="Remove from cart">
@@ -1,106 +1,106 @@
1
- .card {
2
- display: flex;
3
- gap: 0.5rem;
4
- flex-direction: column;
5
- border-radius: 8px;
6
- padding: 1rem;
7
- box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0);
8
- transition: all 0.3s 0.1s;
9
- cursor: pointer;
10
- }
11
-
12
- .card:hover {
13
- box-shadow: 0px 2px 5px 2px #dfdfdfff;
14
- transition: all 0.3s 0s;
15
- }
16
-
17
- .card-section {
18
- display: flex;
19
- gap: 8px;
20
- flex-direction: column;
21
- align-items: center;
22
- }
23
-
24
- .image-container {
25
- width: 100%;
26
- background-color: #ccc;
27
- border-radius: 4px;
28
- aspect-ratio: 1.5;
29
- }
30
-
31
- .button-section {
32
- display: flex;
33
- justify-content: space-around;
34
- flex-direction: row;
35
- flex-wrap: wrap;
36
- margin: 4px 2rem 0px;
37
- gap: 0.5rem;
38
- }
39
-
40
- .addtocartbutton {
41
- color: white;
42
- background-color: rgb(39, 138, 230);
43
- padding: 4px 16px 6px;
44
- border-radius: 8px;
45
- outline: none;
46
- transition: all 0.3s;
47
- }
48
-
49
- .addtocartbutton.red {
50
- background-color: rgb(230, 39, 39);
51
- }
52
-
53
- .addtocartbutton.disabled {
54
- background-color: rgb(170, 170, 170);
55
- cursor: not-allowed;
56
- }
57
- .addtocartbutton.disabled:hover {
58
- background-color: rgb(170, 170, 170);
59
- }
60
-
61
- .addtocartbutton:hover {
62
- background-color: rgb(36, 124, 207);
63
- }
64
-
65
- .hover-button > .hover-section {
66
- display: none;
67
- position: absolute;
68
- width: 325px;
69
- margin-left: calc(-113.75px);
70
- padding: 1rem;
71
- color: black;
72
- }
73
-
74
- .hover-button:hover > .hover-section {
75
- display: flex;
76
- justify-content: center;
77
- }
78
-
79
- .hover-data {
80
- border-radius: 8px;
81
- padding: 1rem;
82
- box-shadow: 0px 2px 5px 2px rgb(173, 173, 173);
83
- background-color: white;
84
- }
85
-
86
- .hover-data > div {
87
- display: flex;
88
- flex-direction: column;
89
- background-color: rgb(203, 203, 203);
90
- gap: 1px;
91
- }
92
-
93
- .tieredpricingbutton {
94
- display: flex;
95
- flex-direction: column;
96
- justify-content: flex-start;
97
- align-items: flex-start;
98
- text-align: left;
99
- padding: 4px 0.5rem 8px;
100
- background-color: white;
101
- transition: all 0.3s;
102
- }
103
-
104
- .tieredpricingbutton:hover {
105
- background-color: rgb(233, 233, 233);
106
- }
1
+ .card {
2
+ display: flex;
3
+ gap: 0.5rem;
4
+ flex-direction: column;
5
+ border-radius: 8px;
6
+ padding: 1rem;
7
+ box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0);
8
+ transition: all 0.3s 0.1s;
9
+ cursor: pointer;
10
+ }
11
+
12
+ .card:hover {
13
+ box-shadow: 0px 2px 5px 2px #dfdfdfff;
14
+ transition: all 0.3s 0s;
15
+ }
16
+
17
+ .card-section {
18
+ display: flex;
19
+ gap: 8px;
20
+ flex-direction: column;
21
+ align-items: center;
22
+ }
23
+
24
+ .image-container {
25
+ width: 100%;
26
+ background-color: #ccc;
27
+ border-radius: 4px;
28
+ aspect-ratio: 1.5;
29
+ }
30
+
31
+ .button-section {
32
+ display: flex;
33
+ justify-content: space-around;
34
+ flex-direction: row;
35
+ flex-wrap: wrap;
36
+ margin: 4px 2rem 0px;
37
+ gap: 0.5rem;
38
+ }
39
+
40
+ .addtocartbutton {
41
+ color: white;
42
+ background-color: rgb(39, 138, 230);
43
+ padding: 4px 16px 6px;
44
+ border-radius: 8px;
45
+ outline: none;
46
+ transition: all 0.3s;
47
+ }
48
+
49
+ .addtocartbutton.red {
50
+ background-color: rgb(230, 39, 39);
51
+ }
52
+
53
+ .addtocartbutton.disabled {
54
+ background-color: rgb(170, 170, 170);
55
+ cursor: not-allowed;
56
+ }
57
+ .addtocartbutton.disabled:hover {
58
+ background-color: rgb(170, 170, 170);
59
+ }
60
+
61
+ .addtocartbutton:hover {
62
+ background-color: rgb(36, 124, 207);
63
+ }
64
+
65
+ .hover-button > .hover-section {
66
+ display: none;
67
+ position: absolute;
68
+ width: 325px;
69
+ margin-left: calc(-113.75px);
70
+ padding: 1rem;
71
+ color: black;
72
+ }
73
+
74
+ .hover-button:hover > .hover-section {
75
+ display: flex;
76
+ justify-content: center;
77
+ }
78
+
79
+ .hover-data {
80
+ border-radius: 8px;
81
+ padding: 1rem;
82
+ box-shadow: 0px 2px 5px 2px rgb(173, 173, 173);
83
+ background-color: white;
84
+ }
85
+
86
+ .hover-data > div {
87
+ display: flex;
88
+ flex-direction: column;
89
+ background-color: rgb(203, 203, 203);
90
+ gap: 1px;
91
+ }
92
+
93
+ .tieredpricingbutton {
94
+ display: flex;
95
+ flex-direction: column;
96
+ justify-content: flex-start;
97
+ align-items: flex-start;
98
+ text-align: left;
99
+ padding: 4px 0.5rem 8px;
100
+ background-color: white;
101
+ transition: all 0.3s;
102
+ }
103
+
104
+ .tieredpricingbutton:hover {
105
+ background-color: rgb(233, 233, 233);
106
+ }
File without changes
@@ -1,93 +1,93 @@
1
- .two-col {
2
- display: flex;
3
- /* grid-template-columns: 1fr 1fr; */
4
- margin-top: 2rem;
5
- align-items: flex-start;
6
- }
7
-
8
- .two-col > * {
9
- width: 50%;
10
- }
11
-
12
- .checkout-list {
13
- display: flex;
14
- flex-direction: column;
15
- align-items: center;
16
- gap: 1rem;
17
- padding: 8px 4px;
18
- margin-top: 1rem;
19
- max-height: 50vh;
20
- overflow: auto;
21
- }
22
-
23
- @keyframes cardanimate {
24
- 0% {
25
- box-shadow: 0px 2px 5px 2px #dfdfdfff;
26
- }
27
- 50% {
28
- box-shadow: 0px 0px 0px 0px #ffffff00;
29
- }
30
- 100% {
31
- box-shadow: 0px 2px 5px 2px #dfdfdfff;
32
- }
33
- }
34
-
35
- .skeleton-card {
36
- min-height: 318px;
37
- border-radius: 8px;
38
- box-shadow: 0px 2px 5px 2px #dfdfdfff;
39
- animation: cardanimate 1.25s linear infinite;
40
- }
41
-
42
- #status-bar {
43
- display: flex;
44
- flex-direction: row;
45
- gap: 1rem;
46
- align-items: center;
47
- margin-left: -29px;
48
- margin-bottom: 1rem;
49
- margin-top: 2rem;
50
- font-size: 18px;
51
- font-weight: 600;
52
- }
53
-
54
- .status-bar {
55
- width: 200px;
56
- height: 6px;
57
- background: linear-gradient(
58
- 90deg,
59
- rgb(40, 130, 213) 0%,
60
- rgb(40, 130, 213) 50%,
61
- lightgrey 50%,
62
- lightgrey 100%
63
- );
64
- background-position: 100% 0;
65
- transition: color 0.3s 0s; /* active -> inactive */
66
- background-size: 200% 100%;
67
- border-radius: 16px;
68
- }
69
-
70
- .status-bar.active {
71
- background-position: 0 0;
72
- transition: background-position 0.75s; /* inactive -> active */
73
- }
74
-
75
- .status-text {
76
- color: lightgrey;
77
- transition: color 0.3s 0s; /* active -> inactive */
78
- }
79
-
80
- .status-text.active {
81
- color: rgb(40, 130, 213);
82
- transition: color 0.5s 0.65s; /* inactive -> active */
83
- }
84
-
85
- .shopping-button {
86
- color: white;
87
- background-color: rgb(39, 138, 230);
88
- padding: 4px 16px 6px;
89
- border-radius: 8px;
90
- outline: none;
91
- transition: all 0.3s;
92
- text-decoration: none;
93
- }
1
+ .two-col {
2
+ display: flex;
3
+ /* grid-template-columns: 1fr 1fr; */
4
+ margin-top: 2rem;
5
+ align-items: flex-start;
6
+ }
7
+
8
+ .two-col > * {
9
+ width: 50%;
10
+ }
11
+
12
+ .checkout-list {
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: center;
16
+ gap: 1rem;
17
+ padding: 8px 4px;
18
+ margin-top: 1rem;
19
+ max-height: 50vh;
20
+ overflow: auto;
21
+ }
22
+
23
+ @keyframes cardanimate {
24
+ 0% {
25
+ box-shadow: 0px 2px 5px 2px #dfdfdfff;
26
+ }
27
+ 50% {
28
+ box-shadow: 0px 0px 0px 0px #ffffff00;
29
+ }
30
+ 100% {
31
+ box-shadow: 0px 2px 5px 2px #dfdfdfff;
32
+ }
33
+ }
34
+
35
+ .skeleton-card {
36
+ min-height: 318px;
37
+ border-radius: 8px;
38
+ box-shadow: 0px 2px 5px 2px #dfdfdfff;
39
+ animation: cardanimate 1.25s linear infinite;
40
+ }
41
+
42
+ #status-bar {
43
+ display: flex;
44
+ flex-direction: row;
45
+ gap: 1rem;
46
+ align-items: center;
47
+ margin-left: -29px;
48
+ margin-bottom: 1rem;
49
+ margin-top: 2rem;
50
+ font-size: 18px;
51
+ font-weight: 600;
52
+ }
53
+
54
+ .status-bar {
55
+ width: 200px;
56
+ height: 6px;
57
+ background: linear-gradient(
58
+ 90deg,
59
+ rgb(40, 130, 213) 0%,
60
+ rgb(40, 130, 213) 50%,
61
+ lightgrey 50%,
62
+ lightgrey 100%
63
+ );
64
+ background-position: 100% 0;
65
+ transition: color 0.3s 0s; /* active -> inactive */
66
+ background-size: 200% 100%;
67
+ border-radius: 16px;
68
+ }
69
+
70
+ .status-bar.active {
71
+ background-position: 0 0;
72
+ transition: background-position 0.75s; /* inactive -> active */
73
+ }
74
+
75
+ .status-text {
76
+ color: lightgrey;
77
+ transition: color 0.3s 0s; /* active -> inactive */
78
+ }
79
+
80
+ .status-text.active {
81
+ color: rgb(40, 130, 213);
82
+ transition: color 0.5s 0.65s; /* inactive -> active */
83
+ }
84
+
85
+ .shopping-button {
86
+ color: white;
87
+ background-color: rgb(39, 138, 230);
88
+ padding: 4px 16px 6px;
89
+ border-radius: 8px;
90
+ outline: none;
91
+ transition: all 0.3s;
92
+ text-decoration: none;
93
+ }
@@ -1,5 +1,5 @@
1
1
  import "./ReviewCartAndCalculateTaxes.css";
2
- import { Box, useTheme, useMediaQuery } from "@mui/material";
2
+ import { Box, useTheme, useMediaQuery, Button } from "@mui/material";
3
3
  import { setOrder as cartSetOrder } from "../utils/storage";
4
4
  import { AddCard, CCFocus, CreditCardValues } from "./components/AddCard";
5
5
  import { CartList } from "./components/CartList";
@@ -133,6 +133,7 @@ export default function ReviewAndCalculateTaxes({
133
133
 
134
134
  async function createOrderAndGetTaxes(values) {
135
135
  setFormError(undefined);
136
+ setFormDisabled(true);
136
137
  // status === 0 when this is clicked.
137
138
  // Creates an order and calculates tax.
138
139
  Promise.all([
@@ -153,9 +154,11 @@ export default function ReviewAndCalculateTaxes({
153
154
  setTax(taxData);
154
155
  setOrder(order);
155
156
  setStatus(1);
157
+ setFormDisabled(false);
156
158
  })
157
159
  .catch(() => {
158
160
  setFormError(true);
161
+ setFormDisabled(false);
159
162
  });
160
163
  }
161
164
 
@@ -196,9 +199,12 @@ export default function ReviewAndCalculateTaxes({
196
199
  .catch((e) => {
197
200
  dev && console.log("Checkout error", e);
198
201
  setFormError(true);
202
+ setFormDisabled(false);
199
203
  });
200
204
  }
201
205
 
206
+ const cardRequired = typeof subtotal === "string" || subtotal > 0;
207
+
202
208
  /**
203
209
  *
204
210
  * AddCard formik data
@@ -262,21 +268,18 @@ export default function ReviewAndCalculateTaxes({
262
268
  const formik = useFormik({
263
269
  initialValues,
264
270
  validationSchema: Yup.object(
265
- address
266
- ? {
267
- ...validationSchemaBase,
268
- ...validationSchemaAddress,
269
- }
270
- : validationSchemaBase
271
+ cardRequired
272
+ ? address
273
+ ? {
274
+ ...validationSchemaBase,
275
+ ...validationSchemaAddress,
276
+ }
277
+ : validationSchemaBase
278
+ : {}
271
279
  ),
272
280
  onSubmit: async (v, helpers) => {
273
281
  dev && console.log("Formik submit");
274
- setFormDisabled(true);
275
282
  const values = { ...v };
276
- if (formDisabled) {
277
- setFormDisabled(false);
278
- throw new Error("Attempted to submit an invalid form.");
279
- }
280
283
 
281
284
  const submitFunc = status === 0 ? createOrderAndGetTaxes : confirmOrder;
282
285
 
@@ -305,9 +308,6 @@ export default function ReviewAndCalculateTaxes({
305
308
  .then((v) => {})
306
309
  .catch((e) => {
307
310
  dev && console.log("Submit errors", e);
308
- })
309
- .finally(() => {
310
- setFormDisabled(false);
311
311
  });
312
312
  } else {
313
313
  setFormDisabled(false);
@@ -340,7 +340,8 @@ export default function ReviewAndCalculateTaxes({
340
340
  dev &&
341
341
  (Object.keys(formik.errors).length > 0
342
342
  ? console.log("Formik errors", formik.errors)
343
- : "No formik errors");
343
+ : console.log("No formik errors"));
344
+
344
345
  setFormDisabled(Object.keys(formik.errors).length > 0);
345
346
  }, [formik.errors]);
346
347
 
@@ -379,6 +380,7 @@ export default function ReviewAndCalculateTaxes({
379
380
  >
380
381
  {CollectExtraInfo && <CollectExtraInfo formik={formik} />}
381
382
  <AddCard
383
+ cardRequired={cardRequired}
382
384
  onSubmit={createOrderAndGetTaxes}
383
385
  stacked={stacked}
384
386
  formData={{