From b7631b6eb156321657d3e9c7477450e139da35a0 Mon Sep 17 00:00:00 2001 From: Graham Rogers Date: Thu, 8 Aug 2024 10:56:26 -0600 Subject: [PATCH] sync v2 --- .eslintrc.js | 1 + README.md | 147 +++++++++--------- package.json | 4 +- src/api/graphql.ts | 12 +- src/api/mutations.ts | 63 +++++++- src/api/queries.ts | 25 ++- .../InputButtonGroup/InputButtonGroup.tsx | 3 + src/components/ProductItem/ProductItem.tsx | 12 +- .../WishlistButton/WishlistButton.stories.mdx | 39 +++++ .../WishlistButton/WishlistButton.test.tsx | 26 ++++ .../WishlistButton/WishlistButton.tsx | 78 ++++++++++ src/components/WishlistButton/index.ts | 11 ++ src/context/cart.tsx | 16 +- src/context/index.ts | 10 +- src/context/store.tsx | 10 +- src/context/widgetConfig.tsx | 133 ++++++++++++++++ src/context/wishlist.tsx | 124 +++++++++++++++ src/icons/emptyHeart.svg | 3 + src/icons/filledHeart.svg | 3 + src/styles/index.css | 47 ++++-- src/styles/tokens.css | 2 + src/types/globals.d.ts | 5 +- src/types/interface.ts | 32 ++++ src/types/widgetConfig.interface.ts | 95 +++++++++++ src/utils/handleUrlFilters.ts | 22 ++- 25 files changed, 805 insertions(+), 118 deletions(-) create mode 100644 src/components/WishlistButton/WishlistButton.stories.mdx create mode 100644 src/components/WishlistButton/WishlistButton.test.tsx create mode 100644 src/components/WishlistButton/WishlistButton.tsx create mode 100644 src/components/WishlistButton/index.ts create mode 100644 src/context/widgetConfig.tsx create mode 100644 src/context/wishlist.tsx create mode 100644 src/icons/emptyHeart.svg create mode 100644 src/icons/filledHeart.svg create mode 100644 src/types/widgetConfig.interface.ts diff --git a/.eslintrc.js b/.eslintrc.js index 6de23f1..5f845db 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -77,6 +77,7 @@ module.exports = { document: true, window: true, API_URL: true, + WIDGET_CONFIG_URL: true, API_KEY: true, SANDBOX_KEY: true, TEST_URL: true, diff --git a/README.md b/README.md index a48c7a5..426ff96 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Node and NPM setup: https://docs.npmjs.com/downloading-and-installing-node-js-an Within the root of the project (~/storefront-product-listing-page): -``` +```sh npm install ``` @@ -44,7 +44,7 @@ npm install Install storybook: https://storybook.js.org/docs/react/get-started/install -``` +```sh npm run storybook ``` @@ -52,25 +52,25 @@ npm run storybook build tailwind styles and run locally -``` +```sh npm run tailwind:build npm run dev ``` note: for styles to update you must run `npm run tailwind:build` -And open `localhost:8080/v1/index.html` in your favorite browser. +And open `localhost:8080/v2/index.html` in your favorite browser. ### Unit Testing -``` +```sh npm run test ``` ### Build -``` -npm run tailwind:build //builds tailwind styles +```sh +npm run tailwind:build # builds tailwind styles npm run build ``` @@ -80,7 +80,7 @@ search.js will be built to ./dist/ import the script: -``` +```html ``` @@ -90,71 +90,81 @@ Most of these will be passed with the extension if you have your storefront setu #### Store Variables needed: -``` - ENVIRONMENT_ID - WEBSITE_CODE - STORE_CODE - STORE_VIEW_CODE - CUSTOMER_GROUP_CODE - API_KEY - SANDBOX_KEY // input this key into webpack.dev.js & webpack.prod.js +```sh +ENVIRONMENT_ID +WEBSITE_CODE +STORE_CODE +STORE_VIEW_CODE +CUSTOMER_GROUP_CODE +API_KEY +SANDBOX_KEY # input this key into webpack.dev.js & webpack.prod.js ``` - To set up sandbox keys please see here: https://experienceleague.adobe.com/docs/commerce-merchant-services/catalog-service/installation.html?lang=en #### insert into store details config -``` +```ts const storeDetails = { - environmentId: 'ENVIRONMENT_ID', - websiteCode: 'WEBSITE_CODE', - storeCode: 'STORE_CODE', - storeViewCode: 'STORE_VIEW_CODE', - config: { - minQueryLength: '2', - pageSize: 8, - perPageConfig: { - pageSizeOptions: '12,24,36', - defaultPageSizeOption: '24', - }, - currencySymbol: '$', - currencyRate: '1', - displaySearchBox: true, - displayOutOfStock: true, - allowAllProducts: false, - currentCategoryUrlPath?: string; - categoryName: '', // name of category to display - displaySearchBox: false, // display search box - displayOutOfStock: '', // "1" will return from php escapeJs and boolean is returned if called from data-service-graphql - displayMode: '', // "" for search || "PAGE" for category search - locale: '', //add locale for translations - priceSlider: false, //enable slider for price - EXPERIMENTAL, default is false - imageCarousel: false, //enable multiple image carousel - EXPERIMENTAL, default is false - listview: false; //add listview as an option - EXPERIMENTAL, default is false - optimizeImages: true, // optimize images with Fastly - imageBaseWidth: 200, - resolveCartId?: resolveCartId // Luma specific addToCart method. Enabled with the extension - refreshCart?: refreshCart // Luma specific addToCart method. Enabled with the extension - addToCart?: (sku, options, quantity)=>{} // custom add to cart callback function. Called on addToCart action - }, - context: { - customerGroup: 'CUSTOMER_GROUP_CODE', - }, - apiKey: 'API_KEY', - }; + environmentId: 'ENVIRONMENT_ID', + websiteCode: 'WEBSITE_CODE', + storeCode: 'STORE_CODE', + storeViewCode: 'STORE_VIEW_CODE', + config: { + minQueryLength: '2', + pageSize: 8, + perPageConfig: { + pageSizeOptions: '12,24,36', + defaultPageSizeOption: '24', + }, + currencySymbol: '$', + currencyRate: '1', + allowAllProducts: false, + currentCategoryUrlPath: "string", + /* name of category to display */ + categoryName: '', + /* display search box */ + displaySearchBox: false, + /* '1' will return from php escapeJs and boolean is returned if called from data-service-graphql */ + displayOutOfStock: '', + /* "" for search || "PAGE" for category search */ + displayMode: '', + /* add locale for translations */ + locale: '', + /* enable slider for price - EXPERIMENTAL, default is false */ + priceSlider: false, + /* enable multiple image carousel - EXPERIMENTAL, default is false */ + imageCarousel: false, + /* add listview as an option - EXPERIMENTAL, default is false */ + listview: false, + /* optimize images with Fastly */ + optimizeImages: true, + imageBaseWidth: 200, + /* Luma specific addToCart method. Enabled with the extension */ + resolveCartId: resolveCartId(), + /* Luma specific addToCart method. Enabled with the extension */ + refreshCart: refreshCart(), + /* custom add to cart callback function. Called on addToCart action */ + addToCart: (sku, options, quantity) => {}, + }, + context: { + customerGroup: 'CUSTOMER_GROUP_CODE', + }, + apiKey: 'API_KEY', +}; ``` Append LiveSearchPLP to the storefront window: -``` +```js const root = document.querySelector('div.search-plp-root'); setTimeout(async () => { - while (typeof window.LiveSearchPLP !== 'function') { - console.log('waiting for window.LiveSearchPLP to be available'); - await new Promise((resolve) => setTimeout(resolve, 500)); - } - window.LiveSearchPLP({ storeDetails, root }); + while (typeof window.LiveSearchPLP !== 'function') { + console.log('waiting for window.LiveSearchPLP to be available'); + await new Promise((resolve) => setTimeout(resolve, 500)); + } + window.LiveSearchPLP({ storeDetails, root }); }, 1000); ``` @@ -172,7 +182,7 @@ So how do we use CSS variables to style our components? Great question 😄 Let's say as if I want to style an element with the theme's primary color. Normally, in CSS we would have done the following: -``` +```tsx