@cimplify/sdk 0.44.6 → 0.44.8

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.
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
 
3
- import { useRouter } from "next/navigation";
4
3
  import Image from "next/image";
5
4
  import { ProductPage as SdkProductPage, useCart } from "@cimplify/sdk/react";
6
5
  import type { Product, ProductWithDetails } from "@cimplify/sdk";
@@ -23,7 +22,6 @@ export function ProductDetail({
23
22
  product: ProductWithDetails;
24
23
  related: Product[];
25
24
  }) {
26
- const router = useRouter();
27
25
  const { addItem } = useCart();
28
26
 
29
27
  return (
@@ -33,7 +31,6 @@ export function ProductDetail({
33
31
  showRelated={false}
34
32
  onAddToCart={async (p, qty, options) => {
35
33
  await addItem(p, qty, options);
36
- router.push("/cart");
37
34
  }}
38
35
  renderImage={({ src, alt, className }) => (
39
36
  <Image
@@ -0,0 +1,14 @@
1
+ "use client";
2
+
3
+ import { useRouter } from "next/navigation";
4
+ import { CartDrawer as SdkCartDrawer } from "@cimplify/sdk/react";
5
+
6
+ /**
7
+ * Side-drawer cart. Auto-opens when an item is added (via
8
+ * `<CartDrawerProvider>` in `providers.tsx`). The header's cart pill
9
+ * also calls `useCartDrawer().open()` to reveal it on click.
10
+ */
11
+ export function CartDrawer() {
12
+ const router = useRouter();
13
+ return <SdkCartDrawer onCheckout={() => router.push("/checkout")} />;
14
+ }
@@ -1,22 +1,26 @@
1
1
  "use client";
2
2
 
3
- import Link from "next/link";
3
+ import { useCartDrawer } from "@cimplify/sdk/react";
4
4
  import { useCartCount } from "@/lib/cart";
5
5
 
6
6
  /**
7
7
  * Cart pill — dynamic island. Reads the live cart count via the SDK and
8
- * renders a link to `/cart`. Wrap in `<Suspense fallback={<CartPillSkeleton/>}>`
9
- * so the cached header chrome streams without blocking on the cart fetch.
8
+ * opens the side cart drawer on click (instead of navigating to /cart).
9
+ * Wrap in `<Suspense fallback={<CartPillSkeleton/>}>` so the cached
10
+ * header chrome streams without blocking on the cart fetch.
10
11
  */
11
12
  export function CartPill() {
12
13
  const { count } = useCartCount();
14
+ const { open } = useCartDrawer();
13
15
  return (
14
- <Link
15
- href="/cart"
16
- className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-foreground text-background text-xs font-semibold tracking-wide transition-transform hover:scale-105"
16
+ <button
17
+ type="button"
18
+ onClick={open}
19
+ aria-label={`Open cart, ${count} ${count === 1 ? "item" : "items"}`}
20
+ className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-foreground text-background text-xs font-semibold tracking-wide transition-transform hover:scale-105 cursor-pointer"
17
21
  >
18
22
  Cart · {count}
19
- </Link>
23
+ </button>
20
24
  );
21
25
  }
22
26
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useMemo, type ReactNode } from "react";
4
4
  import { createCimplifyClient } from "@cimplify/sdk";
5
- import { CimplifyProvider } from "@cimplify/sdk/react";
5
+ import { CimplifyProvider, CartDrawerProvider } from "@cimplify/sdk/react";
6
6
 
7
7
  /**
8
8
  * Boots the Cimplify SDK client once on the client-side and exposes it via
@@ -27,5 +27,9 @@ export function Providers({ children }: { children: ReactNode }) {
27
27
  });
28
28
  }, []);
29
29
 
30
- return <CimplifyProvider client={client}>{children}</CimplifyProvider>;
30
+ return (
31
+ <CimplifyProvider client={client}>
32
+ <CartDrawerProvider>{children}</CartDrawerProvider>
33
+ </CimplifyProvider>
34
+ );
31
35
  }
@@ -1,27 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useState } from "react";
4
- import { useCimplifyClient } from "@cimplify/sdk/react";
3
+ import { useCart } from "@cimplify/sdk/react";
5
4
 
6
5
  /**
7
- * Tiny hook for the live cart-count pill in the header. Re-fetches on
8
- * mount and exposes a refresh callback. The SDK's `useCart` hook is
9
- * fine-grained but heavier — this is enough for a header badge.
6
+ * Reactive cart count for the header pill. Subscribes to the SDK cart
7
+ * state — updates immediately on add / remove / quantity change.
10
8
  */
11
- export function useCartCount(): { count: number; refresh: () => void } {
12
- const { client } = useCimplifyClient();
13
- const [count, setCount] = useState(0);
14
-
15
- const refresh = () => {
16
- void client.cart.getCount().then((r) => {
17
- if (r.ok) setCount(r.value);
18
- });
19
- };
20
-
21
- useEffect(() => {
22
- refresh();
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [client]);
25
-
26
- return { count, refresh };
9
+ export function useCartCount(): { count: number } {
10
+ const { itemCount } = useCart();
11
+ return { count: itemCount };
27
12
  }
@@ -73,7 +73,6 @@ export function ProductModal() {
73
73
  onAddToCart={async (p, qty, options) => {
74
74
  await addItem(p, qty, options);
75
75
  close();
76
- router.push("/cart");
77
76
  }}
78
77
  renderImage={({ src, alt, className }) => (
79
78
  <Image
@@ -1,27 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useState } from "react";
4
- import { useCimplifyClient } from "@cimplify/sdk/react";
3
+ import { useCart } from "@cimplify/sdk/react";
5
4
 
6
5
  /**
7
- * Tiny hook for the live cart-count pill in the header. Re-fetches on
8
- * mount and exposes a refresh callback. The SDK's `useCart` hook is
9
- * fine-grained but heavier — this is enough for a header badge.
6
+ * Reactive cart count for the header pill. Subscribes to the SDK cart
7
+ * state — updates immediately on add / remove / quantity change.
10
8
  */
11
- export function useCartCount(): { count: number; refresh: () => void } {
12
- const { client } = useCimplifyClient();
13
- const [count, setCount] = useState(0);
14
-
15
- const refresh = () => {
16
- void client.cart.getCount().then((r) => {
17
- if (r.ok) setCount(r.value);
18
- });
19
- };
20
-
21
- useEffect(() => {
22
- refresh();
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [client]);
25
-
26
- return { count, refresh };
9
+ export function useCartCount(): { count: number } {
10
+ const { itemCount } = useCart();
11
+ return { count: itemCount };
27
12
  }
@@ -73,7 +73,6 @@ export function ProductModal() {
73
73
  onAddToCart={async (p, qty, options) => {
74
74
  await addItem(p, qty, options);
75
75
  close();
76
- router.push("/cart");
77
76
  }}
78
77
  renderImage={({ src, alt, className }) => (
79
78
  <Image
@@ -1,27 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useState } from "react";
4
- import { useCimplifyClient } from "@cimplify/sdk/react";
3
+ import { useCart } from "@cimplify/sdk/react";
5
4
 
6
5
  /**
7
- * Tiny hook for the live cart-count pill in the header. Re-fetches on
8
- * mount and exposes a refresh callback. The SDK's `useCart` hook is
9
- * fine-grained but heavier — this is enough for a header badge.
6
+ * Reactive cart count for the header pill. Subscribes to the SDK cart
7
+ * state — updates immediately on add / remove / quantity change.
10
8
  */
11
- export function useCartCount(): { count: number; refresh: () => void } {
12
- const { client } = useCimplifyClient();
13
- const [count, setCount] = useState(0);
14
-
15
- const refresh = () => {
16
- void client.cart.getCount().then((r) => {
17
- if (r.ok) setCount(r.value);
18
- });
19
- };
20
-
21
- useEffect(() => {
22
- refresh();
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [client]);
25
-
26
- return { count, refresh };
9
+ export function useCartCount(): { count: number } {
10
+ const { itemCount } = useCart();
11
+ return { count: itemCount };
27
12
  }
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
 
3
- import { useRouter } from "next/navigation";
4
3
  import Image from "next/image";
5
4
  import { ProductPage as SdkProductPage, useCart } from "@cimplify/sdk/react";
6
5
  import type { Product, ProductWithDetails } from "@cimplify/sdk";
@@ -23,7 +22,6 @@ export function ProductDetail({
23
22
  product: ProductWithDetails;
24
23
  related: Product[];
25
24
  }) {
26
- const router = useRouter();
27
25
  const { addItem } = useCart();
28
26
 
29
27
  return (
@@ -33,7 +31,6 @@ export function ProductDetail({
33
31
  showRelated={false}
34
32
  onAddToCart={async (p, qty, options) => {
35
33
  await addItem(p, qty, options);
36
- router.push("/cart");
37
34
  }}
38
35
  renderImage={({ src, alt, className }) => (
39
36
  <Image
@@ -1,27 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useState } from "react";
4
- import { useCimplifyClient } from "@cimplify/sdk/react";
3
+ import { useCart } from "@cimplify/sdk/react";
5
4
 
6
5
  /**
7
- * Tiny hook for the live cart-count pill in the header. Re-fetches on
8
- * mount and exposes a refresh callback. The SDK's `useCart` hook is
9
- * fine-grained but heavier — this is enough for a header badge.
6
+ * Reactive cart count for the header pill. Subscribes to the SDK cart
7
+ * state — updates immediately on add / remove / quantity change.
10
8
  */
11
- export function useCartCount(): { count: number; refresh: () => void } {
12
- const { client } = useCimplifyClient();
13
- const [count, setCount] = useState(0);
14
-
15
- const refresh = () => {
16
- void client.cart.getCount().then((r) => {
17
- if (r.ok) setCount(r.value);
18
- });
19
- };
20
-
21
- useEffect(() => {
22
- refresh();
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [client]);
25
-
26
- return { count, refresh };
9
+ export function useCartCount(): { count: number } {
10
+ const { itemCount } = useCart();
11
+ return { count: itemCount };
27
12
  }
@@ -73,7 +73,6 @@ export function ProductModal() {
73
73
  onAddToCart={async (p, qty, options) => {
74
74
  await addItem(p, qty, options);
75
75
  close();
76
- router.push("/cart");
77
76
  }}
78
77
  renderImage={({ src, alt, className }) => (
79
78
  <Image
@@ -1,27 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { useEffect, useState } from "react";
4
- import { useCimplifyClient } from "@cimplify/sdk/react";
3
+ import { useCart } from "@cimplify/sdk/react";
5
4
 
6
5
  /**
7
- * Tiny hook for the live cart-count pill in the header. Re-fetches on
8
- * mount and exposes a refresh callback. The SDK's `useCart` hook is
9
- * fine-grained but heavier — this is enough for a header badge.
6
+ * Reactive cart count for the header pill. Subscribes to the SDK cart
7
+ * state — updates immediately on add / remove / quantity change.
10
8
  */
11
- export function useCartCount(): { count: number; refresh: () => void } {
12
- const { client } = useCimplifyClient();
13
- const [count, setCount] = useState(0);
14
-
15
- const refresh = () => {
16
- void client.cart.getCount().then((r) => {
17
- if (r.ok) setCount(r.value);
18
- });
19
- };
20
-
21
- useEffect(() => {
22
- refresh();
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [client]);
25
-
26
- return { count, refresh };
9
+ export function useCartCount(): { count: number } {
10
+ const { itemCount } = useCart();
11
+ return { count: itemCount };
27
12
  }