@springmicro/cart 0.7.4 → 0.7.6
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/package.json +3 -3
- package/src/AddToCartForm.tsx +16 -16
- package/src/ProductCard.css +106 -106
- package/src/checkout/ReviewCartAndCalculateTaxes.css +93 -93
- package/src/checkout/components/CartProductCard.css +67 -67
- package/src/checkout/components/Invoice.tsx +145 -145
- package/src/checkout/components/ProviderLogos.tsx +93 -93
- package/src/index.css +5 -5
- package/src/utils/cartAuthHandler.ts +50 -50
- package/tsconfig.json +24 -24
- package/tsconfig.node.json +11 -11
- package/vite.config.ts +25 -25
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { defaultCartValue } from ".";
|
|
2
|
-
import { ApiCartResponse, Cart } from "../types";
|
|
3
|
-
import { Storage } from "unstorage";
|
|
4
|
-
|
|
5
|
-
export function cartAuthHandler(
|
|
6
|
-
cartState: [Cart, React.Dispatch<React.SetStateAction<Cart>>],
|
|
7
|
-
storage: {
|
|
8
|
-
api: Storage<any>;
|
|
9
|
-
local: Storage<any>;
|
|
10
|
-
} | null,
|
|
11
|
-
userId: number | string | undefined,
|
|
12
|
-
prevUserId: number | string | undefined
|
|
13
|
-
) {
|
|
14
|
-
const [cart, setCart] = cartState;
|
|
15
|
-
if (storage === null) return () => {}; // storage can be null.
|
|
16
|
-
|
|
17
|
-
if (userId === prevUserId) return;
|
|
18
|
-
|
|
19
|
-
if (userId === undefined) {
|
|
20
|
-
// logout
|
|
21
|
-
setCart(defaultCartValue);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// login
|
|
26
|
-
if (cart.items.length > 0) {
|
|
27
|
-
setCart((c) => ({
|
|
28
|
-
...c,
|
|
29
|
-
authentication: {
|
|
30
|
-
loggedIn: true,
|
|
31
|
-
user_id: userId,
|
|
32
|
-
},
|
|
33
|
-
}));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
storage.api
|
|
37
|
-
.getItem(`${userId}`)
|
|
38
|
-
.then((c2: ApiCartResponse) => {
|
|
39
|
-
if (!c2) return;
|
|
40
|
-
|
|
41
|
-
setCart({
|
|
42
|
-
items: JSON.parse(c2.cart),
|
|
43
|
-
authentication: {
|
|
44
|
-
loggedIn: true,
|
|
45
|
-
user_id: c2.user_id,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
})
|
|
49
|
-
.catch(() => {});
|
|
50
|
-
}
|
|
1
|
+
import { defaultCartValue } from ".";
|
|
2
|
+
import { ApiCartResponse, Cart } from "../types";
|
|
3
|
+
import { Storage } from "unstorage";
|
|
4
|
+
|
|
5
|
+
export function cartAuthHandler(
|
|
6
|
+
cartState: [Cart, React.Dispatch<React.SetStateAction<Cart>>],
|
|
7
|
+
storage: {
|
|
8
|
+
api: Storage<any>;
|
|
9
|
+
local: Storage<any>;
|
|
10
|
+
} | null,
|
|
11
|
+
userId: number | string | undefined,
|
|
12
|
+
prevUserId: number | string | undefined
|
|
13
|
+
) {
|
|
14
|
+
const [cart, setCart] = cartState;
|
|
15
|
+
if (storage === null) return () => {}; // storage can be null.
|
|
16
|
+
|
|
17
|
+
if (userId === prevUserId) return;
|
|
18
|
+
|
|
19
|
+
if (userId === undefined) {
|
|
20
|
+
// logout
|
|
21
|
+
setCart(defaultCartValue);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// login
|
|
26
|
+
if (cart.items.length > 0) {
|
|
27
|
+
setCart((c) => ({
|
|
28
|
+
...c,
|
|
29
|
+
authentication: {
|
|
30
|
+
loggedIn: true,
|
|
31
|
+
user_id: userId,
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
storage.api
|
|
37
|
+
.getItem(`${userId}`)
|
|
38
|
+
.then((c2: ApiCartResponse) => {
|
|
39
|
+
if (!c2) return;
|
|
40
|
+
|
|
41
|
+
setCart({
|
|
42
|
+
items: JSON.parse(c2.cart),
|
|
43
|
+
authentication: {
|
|
44
|
+
loggedIn: true,
|
|
45
|
+
user_id: c2.user_id,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
})
|
|
49
|
+
.catch(() => {});
|
|
50
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"jsx": "react-jsx",
|
|
16
|
-
|
|
17
|
-
/* Linting */
|
|
18
|
-
"strict": false,
|
|
19
|
-
"noFallthroughCasesInSwitch": true,
|
|
20
|
-
"noImplicitAny": false
|
|
21
|
-
},
|
|
22
|
-
"include": ["src"],
|
|
23
|
-
"references": [{ "path": "./tsconfig.node.json" }]
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": false,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
"noImplicitAny": false
|
|
21
|
+
},
|
|
22
|
+
"include": ["src"],
|
|
23
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
24
|
+
}
|
package/tsconfig.node.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"composite": true,
|
|
4
|
-
"skipLibCheck": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"strict": true
|
|
9
|
-
},
|
|
10
|
-
"include": ["vite.config.ts"]
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"composite": true,
|
|
4
|
+
"skipLibCheck": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"strict": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["vite.config.ts"]
|
|
11
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import react from "@vitejs/plugin-react";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { defineConfig } from "vite";
|
|
4
|
-
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
|
|
5
|
-
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
plugins: [react(), cssInjectedByJsPlugin()],
|
|
8
|
-
build: {
|
|
9
|
-
lib: {
|
|
10
|
-
entry: resolve(__dirname, "src/index.ts"),
|
|
11
|
-
name: "@springmicro/cart",
|
|
12
|
-
fileName: "index",
|
|
13
|
-
},
|
|
14
|
-
rollupOptions: {
|
|
15
|
-
external: ["react", "react-dom", "nanoid"],
|
|
16
|
-
output: {
|
|
17
|
-
globals: {
|
|
18
|
-
react: "React",
|
|
19
|
-
"react-dom": "ReactDOM",
|
|
20
|
-
nanoid: "Nanoid",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [react(), cssInjectedByJsPlugin()],
|
|
8
|
+
build: {
|
|
9
|
+
lib: {
|
|
10
|
+
entry: resolve(__dirname, "src/index.ts"),
|
|
11
|
+
name: "@springmicro/cart",
|
|
12
|
+
fileName: "index",
|
|
13
|
+
},
|
|
14
|
+
rollupOptions: {
|
|
15
|
+
external: ["react", "react-dom", "nanoid"],
|
|
16
|
+
output: {
|
|
17
|
+
globals: {
|
|
18
|
+
react: "React",
|
|
19
|
+
"react-dom": "ReactDOM",
|
|
20
|
+
nanoid: "Nanoid",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|