From a0b92866f237daa3f8318e6b2378c2e564a29419 Mon Sep 17 00:00:00 2001 From: Robert Field Date: Wed, 1 May 2024 11:31:22 +0100 Subject: [PATCH] feat: add product list example --- packages/react-shopper-hooks/example/App.tsx | 43 ++++++++++++++----- .../example/CartExample.tsx | 16 ++++--- .../example/ProductListExample.tsx | 17 ++++++++ 3 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 packages/react-shopper-hooks/example/ProductListExample.tsx diff --git a/packages/react-shopper-hooks/example/App.tsx b/packages/react-shopper-hooks/example/App.tsx index 6d80f9ad..e181cb80 100644 --- a/packages/react-shopper-hooks/example/App.tsx +++ b/packages/react-shopper-hooks/example/App.tsx @@ -4,27 +4,48 @@ import CartExample from "./CartExample" import { CartProvider } from "../src/cart" import { gateway as EPCCGateway } from "@moltin/sdk" import { StoreProvider } from "../src/store" +import { ElasticPathProvider } from "../src" +import { QueryClient } from "@tanstack/react-query" +import { ProductListExample } from "./ProductListExample" + +const client = EPCCGateway({ + name: "my_store", + client_id: import.meta.env.VITE_APP_EPCC_CLIENT_ID, + client_secret: import.meta.env.VITE_APP_EPCC_CLIENT_SECRET, + host: import.meta.env.VITE_APP_EPCC_HOST, +}) + +const queryClient = new QueryClient() function App() { - const client = EPCCGateway({ - name: "my_store", - client_id: import.meta.env.VITE_APP_EPCC_CLIENT_ID, - client_secret: import.meta.env.VITE_APP_EPCC_CLIENT_SECRET, - host: import.meta.env.VITE_APP_EPCC_HOST, - }) + const [activeItem, setActiveItem] = React.useState<"cart" | "products">( + "cart", + ) return (

React Shopper Hooks

+
+ + +
- - - - - + + + + {activeItem === "cart" && } + {activeItem === "products" && } + + +
) } +function TanstackWrapper() {} + export default App diff --git a/packages/react-shopper-hooks/example/CartExample.tsx b/packages/react-shopper-hooks/example/CartExample.tsx index b2a8e046..5b30d9cb 100644 --- a/packages/react-shopper-hooks/example/CartExample.tsx +++ b/packages/react-shopper-hooks/example/CartExample.tsx @@ -1,16 +1,19 @@ import React from "react" -import { useCart } from "../src/cart" +import { useCart, useCartAddBundleItem, useCartClear } from "../src/cart" export default function CartExample(): JSX.Element { - const { state, addBundleProductToCart, emptyCart } = useCart() + const { state } = useCart() + const { mutate: addBundleProductToCart } = useCartAddBundleItem() + const { mutate: emptyCart } = useCartClear() return ( <>