@springmicro/cart 0.7.11 → 0.7.13
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 +2106 -2095
- package/dist/index.umd.cjs +50 -50
- package/package.json +3 -3
- package/src/checkout/ReviewCartAndCalculateTaxes.tsx +13 -6
- package/src/checkout/index.tsx +15 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springmicro/cart",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.13",
|
|
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.7.
|
|
27
|
+
"@springmicro/utils": "^0.7.13",
|
|
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": "0f3da8c5a1c587c6457114172bb297adefdf3e08"
|
|
53
53
|
}
|
|
@@ -215,18 +215,23 @@ export default function ReviewAndCalculateTaxes({
|
|
|
215
215
|
invoiceId
|
|
216
216
|
)
|
|
217
217
|
.then(async (data) => {
|
|
218
|
-
dev && console.log("Checkout submitted");
|
|
218
|
+
dev && console.log("Checkout submitted.", data);
|
|
219
|
+
|
|
219
220
|
if (data instanceof Response) {
|
|
220
221
|
setFormError(true);
|
|
221
222
|
const { detail: errorData } = await data.json();
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
|
|
224
|
+
if (!errorData.valid) {
|
|
225
|
+
dev && console.log("Precheck invalid", errorData);
|
|
226
|
+
setPrecheckErrors(errorData.errors);
|
|
227
|
+
}
|
|
226
228
|
} else {
|
|
229
|
+
dev && console.log("Checkout returned status code 200");
|
|
230
|
+
|
|
227
231
|
// success
|
|
228
232
|
setSuccessData(data);
|
|
229
233
|
onPlacement && onPlacement();
|
|
234
|
+
|
|
230
235
|
// Get the current URL
|
|
231
236
|
const currentUrl = new URL(window.location.href);
|
|
232
237
|
// Set the query parameter 'showReceipt' to '1'
|
|
@@ -349,7 +354,9 @@ export default function ReviewAndCalculateTaxes({
|
|
|
349
354
|
|
|
350
355
|
// const res = await submitFunc(values);
|
|
351
356
|
submitFunc(values)
|
|
352
|
-
.then((v) => {
|
|
357
|
+
.then((v) => {
|
|
358
|
+
dev && console.log("Submit success", v);
|
|
359
|
+
})
|
|
353
360
|
.catch((e) => {
|
|
354
361
|
dev && console.log("Submit errors", e);
|
|
355
362
|
});
|
package/src/checkout/index.tsx
CHANGED
|
@@ -27,6 +27,8 @@ export default function Checkout({
|
|
|
27
27
|
hideFields = [],
|
|
28
28
|
disableFields = [],
|
|
29
29
|
dev,
|
|
30
|
+
invoiceId,
|
|
31
|
+
order: _order,
|
|
30
32
|
}: {
|
|
31
33
|
apiBaseUrl: string;
|
|
32
34
|
taxProvider: string;
|
|
@@ -38,10 +40,13 @@ export default function Checkout({
|
|
|
38
40
|
hideFields?: string[];
|
|
39
41
|
disableFields?: string[];
|
|
40
42
|
dev?: boolean;
|
|
43
|
+
invoiceId?;
|
|
44
|
+
order?;
|
|
41
45
|
}) {
|
|
42
46
|
const store = useStore(cartStore);
|
|
43
|
-
const
|
|
44
|
-
|
|
47
|
+
const localCart = useMemo(() => JSON.parse(store), [store]);
|
|
48
|
+
|
|
49
|
+
const cart = invoiceId ? { items: _order.basket } : localCart; // todo fix calculation
|
|
45
50
|
|
|
46
51
|
const [products, setProducts] = useState({});
|
|
47
52
|
const [prices, setPrices] = useState({});
|
|
@@ -51,7 +56,7 @@ export default function Checkout({
|
|
|
51
56
|
const discount = 0;
|
|
52
57
|
|
|
53
58
|
const [status, setStatus] = useState(0);
|
|
54
|
-
const [order, setOrder] = useState(
|
|
59
|
+
const [order, setOrder] = useState(_order); // starts undefined on a typical checkout. If an order is provided, it's likely an invoice.
|
|
55
60
|
const [successData, setSuccessData] = useState(null);
|
|
56
61
|
|
|
57
62
|
useEffect(() => {
|
|
@@ -204,7 +209,7 @@ export default function Checkout({
|
|
|
204
209
|
* Review taxes and shipping
|
|
205
210
|
*
|
|
206
211
|
* status === 2
|
|
207
|
-
* Order has been
|
|
212
|
+
* Order has been placed. Invoice for printing.
|
|
208
213
|
*
|
|
209
214
|
*/}
|
|
210
215
|
|
|
@@ -233,10 +238,15 @@ export default function Checkout({
|
|
|
233
238
|
dev={dev}
|
|
234
239
|
hideFields={hideFields}
|
|
235
240
|
disableFields={disableFields}
|
|
241
|
+
invoiceId={invoiceId}
|
|
236
242
|
/>
|
|
237
243
|
)}
|
|
238
244
|
{status === 2 && order !== undefined && (
|
|
239
|
-
<Invoice
|
|
245
|
+
<Invoice
|
|
246
|
+
order={order}
|
|
247
|
+
successData={successData}
|
|
248
|
+
invoiceId={invoiceId}
|
|
249
|
+
/>
|
|
240
250
|
)}
|
|
241
251
|
</div>
|
|
242
252
|
</div>
|