@springmicro/cart 0.6.0 → 0.6.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@springmicro/cart",
3
3
  "private": false,
4
- "version": "0.6.0",
4
+ "version": "0.6.2",
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.6.0",
27
+ "@springmicro/utils": "0.6.2",
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": "37c816671357a3b1af66ad231880216fbda2fb72"
52
+ "gitHead": "f0aee01ae9b45595f59d70a5fdf9cae8933edb24"
53
53
  }
Binary file
@@ -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
+ }
File without changes
@@ -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, Button } from "@mui/material";
2
+ import { Box, useTheme, useMediaQuery, Button, TextField } 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";
@@ -77,6 +77,7 @@ async function getTax(apiBaseUrl, taxProvider, items, v, products, dev) {
77
77
  const taxable_items = items.filter(
78
78
  (i) => i.unit_amount > 0 && products[i.product_id].type !== "DONATION"
79
79
  );
80
+ dev && console.log("Taxable items", taxable_items);
80
81
  if (taxable_items.length === 0) return { tax_amount: 0 };
81
82
 
82
83
  const res = await fetch(
@@ -122,6 +123,7 @@ export default function ReviewAndCalculateTaxes({
122
123
  defaultValues = {},
123
124
  dev,
124
125
  }) {
126
+ dev && console.log({ products, prices });
125
127
  const [formDisabled, setFormDisabled] = useState(true);
126
128
  const [formError, setFormError] = useState(undefined);
127
129
  const theme = useTheme();
@@ -379,6 +381,11 @@ export default function ReviewAndCalculateTaxes({
379
381
  sx={{ flexGrow: 1, display: "flex", flexDirection: "column", gap: 2 }}
380
382
  >
381
383
  {CollectExtraInfo && <CollectExtraInfo formik={formik} />}
384
+ <CheckoutActionFields
385
+ formik={formik}
386
+ prices={prices}
387
+ products={products}
388
+ />
382
389
  <AddCard
383
390
  cardRequired={cardRequired}
384
391
  onSubmit={createOrderAndGetTaxes}
@@ -396,3 +403,65 @@ export default function ReviewAndCalculateTaxes({
396
403
  </Box>
397
404
  );
398
405
  }
406
+
407
+ function CheckoutActionFields({ formik, products, prices }) {
408
+ const checkoutFields = [
409
+ ...Object.keys(products).flatMap((productKey) =>
410
+ (products[productKey].actions ?? []).flatMap(
411
+ (action) => action.checkout_fields ?? []
412
+ )
413
+ ),
414
+ // TODO Add this once prices have checkout fields
415
+ ...Object.keys(prices).flatMap((priceKey) =>
416
+ (prices[priceKey].actions ?? []).flatMap(
417
+ (action) => action.checkout_fields ?? []
418
+ )
419
+ ),
420
+
421
+ // Overwrites the checkout field to use the last one provided. This allows prices to overwrite product checkout fields if necessary.
422
+ ].reduce((old, field) => ({ ...old, [field.name]: field }), {});
423
+
424
+ // console.log("Checkout fields", checkoutFields);
425
+ const handleInputFocus = (e) => {
426
+ const focusedEl = (e.target as HTMLElement).getAttribute("name");
427
+ if (focusedEl) {
428
+ formik.setValues({
429
+ ...formik.values,
430
+ focus: focusedEl,
431
+ });
432
+ }
433
+ };
434
+
435
+ const handleInputChange = (e) => {
436
+ formik.handleChange(e);
437
+ };
438
+
439
+ return (
440
+ <Box sx={{ display: "flex", flexDirection: "column", mx: 3, gap: 2 }}>
441
+ {Object.keys(checkoutFields).map((key) => {
442
+ const {
443
+ name,
444
+ label,
445
+ type = "string", // todo
446
+ required = true, // can be a string
447
+ } = checkoutFields[key];
448
+
449
+ return (
450
+ <TextField
451
+ fullWidth
452
+ name={name}
453
+ label={label}
454
+ required={required === true || required === "true"}
455
+ onBlur={formik.handleBlur}
456
+ onChange={handleInputChange}
457
+ onFocus={handleInputFocus}
458
+ variant="outlined"
459
+ value={formik.values[name]}
460
+ error={Boolean(formik.touched[name] && formik.errors[name])}
461
+ helperText={formik.touched[name] && formik.errors[name]}
462
+ />
463
+ );
464
+ })}
465
+ </Box>
466
+ );
467
+ }
File without changes
File without changes
@@ -21,7 +21,6 @@ export function CartList({
21
21
  formDisabled,
22
22
  formErrorState,
23
23
  }) {
24
- console.log("DISABLED", formDisabled);
25
24
  const [status, setStatus] = statusState;
26
25
  const [formError, setFormError] = formErrorState;
27
26
  return (