@springmicro/cart 0.5.17 → 0.6.1
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/dist/index.js +213 -152
- package/dist/index.umd.cjs +21 -21
- package/package.json +3 -3
- package/src/checkout/ReviewCartAndCalculateTaxes.tsx +69 -1
- package/src/checkout/index.tsx +7 -0
- package/springmicro-cart-0.3.4.tgz +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springmicro/cart",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.1",
|
|
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.
|
|
27
|
+
"@springmicro/utils": "0.6.1",
|
|
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": "
|
|
52
|
+
"gitHead": "232d9b1996bd1dbd66a020beee58eeefca8a40a2"
|
|
53
53
|
}
|
|
@@ -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";
|
|
@@ -122,6 +122,7 @@ export default function ReviewAndCalculateTaxes({
|
|
|
122
122
|
defaultValues = {},
|
|
123
123
|
dev,
|
|
124
124
|
}) {
|
|
125
|
+
console.log({ products, prices });
|
|
125
126
|
const [formDisabled, setFormDisabled] = useState(true);
|
|
126
127
|
const [formError, setFormError] = useState(undefined);
|
|
127
128
|
const theme = useTheme();
|
|
@@ -379,6 +380,11 @@ export default function ReviewAndCalculateTaxes({
|
|
|
379
380
|
sx={{ flexGrow: 1, display: "flex", flexDirection: "column", gap: 2 }}
|
|
380
381
|
>
|
|
381
382
|
{CollectExtraInfo && <CollectExtraInfo formik={formik} />}
|
|
383
|
+
<CheckoutActionFields
|
|
384
|
+
formik={formik}
|
|
385
|
+
prices={prices}
|
|
386
|
+
products={products}
|
|
387
|
+
/>
|
|
382
388
|
<AddCard
|
|
383
389
|
cardRequired={cardRequired}
|
|
384
390
|
onSubmit={createOrderAndGetTaxes}
|
|
@@ -396,3 +402,65 @@ export default function ReviewAndCalculateTaxes({
|
|
|
396
402
|
</Box>
|
|
397
403
|
);
|
|
398
404
|
}
|
|
405
|
+
|
|
406
|
+
function CheckoutActionFields({ formik, products, prices }) {
|
|
407
|
+
const checkoutFields = [
|
|
408
|
+
...Object.keys(products).flatMap((productKey) =>
|
|
409
|
+
(products[productKey].actions ?? []).flatMap(
|
|
410
|
+
(action) => action.checkout_fields ?? []
|
|
411
|
+
)
|
|
412
|
+
),
|
|
413
|
+
// TODO Add this once prices have checkout fields
|
|
414
|
+
...Object.keys(prices).flatMap((priceKey) =>
|
|
415
|
+
(prices[priceKey].actions ?? []).flatMap(
|
|
416
|
+
(action) => action.checkout_fields ?? []
|
|
417
|
+
)
|
|
418
|
+
),
|
|
419
|
+
|
|
420
|
+
// Overwrites the checkout field to use the last one provided. This allows prices to overwrite product checkout fields if necessary.
|
|
421
|
+
].reduce((old, field) => ({ ...old, [field.name]: field }), {});
|
|
422
|
+
|
|
423
|
+
console.log("Checkout fields", checkoutFields);
|
|
424
|
+
const handleInputFocus = (e) => {
|
|
425
|
+
const focusedEl = (e.target as HTMLElement).getAttribute("name");
|
|
426
|
+
if (focusedEl) {
|
|
427
|
+
formik.setValues({
|
|
428
|
+
...formik.values,
|
|
429
|
+
focus: focusedEl,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const handleInputChange = (e) => {
|
|
435
|
+
formik.handleChange(e);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
return (
|
|
439
|
+
<Box sx={{ display: "flex", flexDirection: "column", mx: 3, gap: 2 }}>
|
|
440
|
+
{Object.keys(checkoutFields).map((key) => {
|
|
441
|
+
const {
|
|
442
|
+
name,
|
|
443
|
+
label,
|
|
444
|
+
type = "string", // todo
|
|
445
|
+
required = true, // can be a string
|
|
446
|
+
} = checkoutFields[key];
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<TextField
|
|
450
|
+
fullWidth
|
|
451
|
+
name={name}
|
|
452
|
+
label={label}
|
|
453
|
+
required={required === true || required === "true"}
|
|
454
|
+
onBlur={formik.handleBlur}
|
|
455
|
+
onChange={handleInputChange}
|
|
456
|
+
onFocus={handleInputFocus}
|
|
457
|
+
variant="outlined"
|
|
458
|
+
value={formik.values[name]}
|
|
459
|
+
error={Boolean(formik.touched[name] && formik.errors[name])}
|
|
460
|
+
helperText={formik.touched[name] && formik.errors[name]}
|
|
461
|
+
/>
|
|
462
|
+
);
|
|
463
|
+
})}
|
|
464
|
+
</Box>
|
|
465
|
+
);
|
|
466
|
+
}
|
package/src/checkout/index.tsx
CHANGED
|
@@ -8,6 +8,13 @@ import ReviewAndCalculateTaxes from "./ReviewCartAndCalculateTaxes";
|
|
|
8
8
|
import Invoice from "./components/Invoice";
|
|
9
9
|
import { FormikConfig } from "formik";
|
|
10
10
|
|
|
11
|
+
export type CheckoutFieldsType = {
|
|
12
|
+
name: string;
|
|
13
|
+
label?: string; // Defaults to a formated version of the name
|
|
14
|
+
required?: boolean; // Defaults to true
|
|
15
|
+
type?: "string"; // Defaults to "string" (text)
|
|
16
|
+
};
|
|
17
|
+
|
|
11
18
|
export default function Checkout({
|
|
12
19
|
apiBaseUrl,
|
|
13
20
|
taxProvider,
|
|
Binary file
|