@cimplify/sdk 0.38.0 → 0.38.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/dist/mock/cli.mjs +238 -63
- package/dist/mock/library.js +238 -63
- package/dist/mock/library.mjs +238 -63
- package/dist/mock/msw.js +238 -63
- package/dist/mock/msw.mjs +238 -63
- package/dist/react.js +12 -2
- package/dist/react.mjs +12 -2
- package/package.json +1 -1
- package/templates/storefront/package.json +3 -1
- package/templates/storefront/src/App.tsx +44 -8
- package/templates/storefront/src/main.tsx +9 -2
- package/templates/storefront/src/styles.css +7 -1
- package/templates/storefront/vite.config.ts +3 -5
|
@@ -1,18 +1,45 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
1
2
|
import { Routes, Route, NavLink, useNavigate } from "react-router-dom";
|
|
2
|
-
import { CataloguePage, CartPage, CheckoutPage,
|
|
3
|
-
import type { Product } from "@cimplify/sdk";
|
|
3
|
+
import { CataloguePage, CartPage, CheckoutPage, useCimplifyClient } from "@cimplify/sdk/react";
|
|
4
|
+
import type { Product, Category } from "@cimplify/sdk";
|
|
4
5
|
|
|
5
|
-
function CartPill() {
|
|
6
|
-
|
|
7
|
-
const total = cim?.cart?.totalItems ?? 0;
|
|
8
|
-
return <span className="cimplify-storefront__cart-pill">Cart · {total}</span>;
|
|
6
|
+
function CartPill({ count }: { count: number }) {
|
|
7
|
+
return <span className="cimplify-storefront__cart-pill">Cart · {count}</span>;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
function Catalogue() {
|
|
12
11
|
const navigate = useNavigate();
|
|
12
|
+
const { client } = useCimplifyClient();
|
|
13
|
+
const [products, setProducts] = useState<Product[] | undefined>(undefined);
|
|
14
|
+
const [categories, setCategories] = useState<Category[] | undefined>(undefined);
|
|
15
|
+
const [loading, setLoading] = useState(true);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let cancelled = false;
|
|
19
|
+
void (async () => {
|
|
20
|
+
try {
|
|
21
|
+
const [p, c] = await Promise.all([
|
|
22
|
+
client.catalogue.getProducts({ limit: 50 }),
|
|
23
|
+
client.catalogue.getCategories(),
|
|
24
|
+
]);
|
|
25
|
+
if (cancelled) return;
|
|
26
|
+
if (p.ok) setProducts(p.value.items);
|
|
27
|
+
if (c.ok) setCategories(c.value);
|
|
28
|
+
} finally {
|
|
29
|
+
if (!cancelled) setLoading(false);
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
return () => {
|
|
33
|
+
cancelled = true;
|
|
34
|
+
};
|
|
35
|
+
}, [client]);
|
|
36
|
+
|
|
37
|
+
if (loading) return <p>Loading shop…</p>;
|
|
13
38
|
return (
|
|
14
39
|
<CataloguePage
|
|
15
40
|
title="Shop"
|
|
41
|
+
products={products}
|
|
42
|
+
categories={categories}
|
|
16
43
|
onProductClick={(p: Product) => navigate(`/products/${p.id}`)}
|
|
17
44
|
/>
|
|
18
45
|
);
|
|
@@ -52,14 +79,23 @@ function OrderConfirmation() {
|
|
|
52
79
|
}
|
|
53
80
|
|
|
54
81
|
export function App() {
|
|
82
|
+
const [cartCount, setCartCount] = useState(0);
|
|
83
|
+
const { client } = useCimplifyClient();
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
void client.cart.getCount().then((r) => {
|
|
87
|
+
if (r.ok) setCartCount(r.value);
|
|
88
|
+
});
|
|
89
|
+
}, [client]);
|
|
90
|
+
|
|
55
91
|
return (
|
|
56
92
|
<div className="cimplify-storefront">
|
|
57
93
|
<header className="cimplify-storefront__nav">
|
|
58
|
-
<NavLink to="/"><h1>
|
|
94
|
+
<NavLink to="/"><h1>cimplify-store</h1></NavLink>
|
|
59
95
|
<nav>
|
|
60
96
|
<NavLink to="/" end>Shop</NavLink>
|
|
61
97
|
<NavLink to="/cart">Cart</NavLink>
|
|
62
|
-
<CartPill />
|
|
98
|
+
<CartPill count={cartCount} />
|
|
63
99
|
</nav>
|
|
64
100
|
</header>
|
|
65
101
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import ReactDOM from "react-dom/client";
|
|
3
3
|
import { BrowserRouter } from "react-router-dom";
|
|
4
|
+
import { createCimplifyClient } from "@cimplify/sdk";
|
|
4
5
|
import { CimplifyProvider } from "@cimplify/sdk/react";
|
|
5
6
|
import { App } from "./App";
|
|
6
7
|
|
|
@@ -8,12 +9,18 @@ import "@cimplify/sdk/styles.css";
|
|
|
8
9
|
import "./styles.css";
|
|
9
10
|
|
|
10
11
|
const baseUrl = import.meta.env.VITE_CIMPLIFY_API_URL ?? "http://127.0.0.1:8787";
|
|
11
|
-
const
|
|
12
|
+
const publicKey = import.meta.env.VITE_CIMPLIFY_PUBLIC_KEY ?? "mock-dev";
|
|
13
|
+
|
|
14
|
+
const client = createCimplifyClient({
|
|
15
|
+
baseUrl,
|
|
16
|
+
publicKey,
|
|
17
|
+
suppressPublicKeyWarning: true,
|
|
18
|
+
});
|
|
12
19
|
|
|
13
20
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
14
21
|
<React.StrictMode>
|
|
15
22
|
<BrowserRouter>
|
|
16
|
-
<CimplifyProvider
|
|
23
|
+
<CimplifyProvider client={client}>
|
|
17
24
|
<App />
|
|
18
25
|
</CimplifyProvider>
|
|
19
26
|
</BrowserRouter>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
1
3
|
html, body {
|
|
2
4
|
margin: 0;
|
|
3
5
|
padding: 0;
|
|
@@ -7,7 +9,6 @@ html, body {
|
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
* { box-sizing: border-box; }
|
|
10
|
-
|
|
11
12
|
a { color: inherit; text-decoration: none; }
|
|
12
13
|
|
|
13
14
|
.cimplify-storefront {
|
|
@@ -57,3 +58,8 @@ a { color: inherit; text-decoration: none; }
|
|
|
57
58
|
border-top: 1px solid #e2e8f0;
|
|
58
59
|
background: white;
|
|
59
60
|
}
|
|
61
|
+
|
|
62
|
+
.cimplify-storefront__main svg {
|
|
63
|
+
max-width: 64px;
|
|
64
|
+
max-height: 64px;
|
|
65
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { defineConfig } from "vite";
|
|
2
2
|
import react from "@vitejs/plugin-react";
|
|
3
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
3
4
|
|
|
4
5
|
export default defineConfig({
|
|
5
|
-
plugins: [react()],
|
|
6
|
-
server: {
|
|
7
|
-
port: 5173,
|
|
8
|
-
open: true,
|
|
9
|
-
},
|
|
6
|
+
plugins: [react(), tailwindcss()],
|
|
7
|
+
server: { port: 5173, open: false, strictPort: false },
|
|
10
8
|
});
|