From 3dcfd0f74dc85ac396c07f32d429973a92aa56d8 Mon Sep 17 00:00:00 2001 From: SpanacheNarcis <43211787+SpanacheNarcis@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:00:40 +0200 Subject: [PATCH 1/7] Implementare fleg (#1) * Implementare fleg * Implementing SGR (#2) --- CHANGELOG.md | 1132 ----------------------- docs/README.md | 2 +- manifest.json | 8 +- react/Summary.tsx | 95 +- react/components/MinicartIconButton.tsx | 56 +- react/legacy/utils/fetchWithRetry.ts | 18 + react/package.json | 29 +- react/typings/packages-sku-ids.d.ts | 25 + react/yarn.lock | 64 +- 9 files changed, 242 insertions(+), 1187 deletions(-) create mode 100644 react/legacy/utils/fetchWithRetry.ts create mode 100644 react/typings/packages-sku-ids.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e7c11c90..4386bc4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,1135 +6,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] - -## [2.67.1] - 2023-05-05 -### Fixed -- Fixes of i18n on readme.md accorrding to task LOC-10558. - -## [2.67.0] - 2023-05-02 -### Added -- Send `vtex:viewCart` event to analytics when minicart is opened - -## [2.66.0] - 2023-01-19 - -### Added -- Provide `originalTotal` prop (sum of item list prices) to `checkout-summary` extension point - -## [2.65.0] - 2022-12-23 - -### Added -- Indonesian and Thai translations. -### Fixed -- Portuguese, Spanish and Italian translations. - -## [2.64.0] - 2022-12-22 - -### Added -- Schema to the `checkout button`, this makes it possible to define via admin where the user will be directed after the click - -## [2.63.5] - 2022-07-28 - -### Fixed -- Quantity update by using item index instead of uniqueid - -## [2.63.4] - 2022-05-24 - -### Fixed - -- Do not emit `cartChanged` pixel event if orderForm is still updating (denoted by the most recent item's `additionalInfo` property being `undefined`) - -## [2.63.3] - 2022-03-03 -### Fixed -- Brackets in `minicart-checkout-button` (documentation). - -## [2.63.2] - 2022-02-17 - -### Added -- Prop `finishShoppingButtonLink` of `minicart-checkout-button`. - -## [2.63.1] - 2022-02-15 - -### Fixed -- Bug Fixed on pixelHelper if validation. - -## [2.63.0] - 2022-02-08 - -### Added -- Norwegian variant translation. - -## [2.62.1] - 2021-11-17 - -### Changed -- Spanish translation - -### Added -- Hungarian and Arabic translation. - -### Fixed -- Crowdin configuration file - -## [2.62.0] - 2021-09-23 - -### Added -- New `block` variation - -## [2.61.1] - 2021-09-13 -### Added -- New condition in `getNameWithoutVariant` at `pixelHelper.ts` to check if item.name is the same as item.skuName. - -## [2.61.0] - 2021-09-06 -### Added -- New `popupWithLink` variation. - -## [2.60.0] - 2021-06-29 - -## [2.60.0] - 2021-06-29 -### Added -- Pass paymentData as prop to Summary component - -## [2.59.1] - 2021-06-08 -### Fixed -- GTM events to follow Google's defined patterns - -## [2.59.0] - 2021-04-22 -### Added -- I18n Jp and No. - -### Changed -- I18n Ro. -- Crowdin configuration file. - -## [2.58.0] - 2021-04-20 - -### Added -- New property `allowedOutdatedData` to `handleQuantityChange` and `handleRemove` events. - -## [2.57.0] - 2021-03-17 -### Added -- Property `priceIsInt` in pixel events, so it's possible to properly identify when to divide price by 100 in pixel apps. - -## [2.56.0] - 2021-01-07 -### Added -- `classes` prop to all exported components. - -### Changed -- `vtex.css-handles` dependency is now on major `1.x`. - -## [2.55.0] - 2020-12-17 - -### Added - -- I18n Ro and Cs. - -### Fixed - -- Crowdin configuration file. - -## [2.54.2] - 2020-12-04 - -### Fixed -- Ignore assemblies values on `itemCountMode`. - -## [2.54.1] - 2020-10-20 - -### Added -- `totalAvailable` and `distinctAvailable` values for `itemCountMode`. - -## [2.54.0] - 2020-10-20 [YANKED] -### Added -- `totalAvailable` and `distinctAvailable` values for `itemCountMode`. - -### Fixed -- Use navigate when redirecting to checkout - -## [2.53.0] - 2020-10-06 - -### Fix -- Mini cart not rendering variation link when in mobile version. - -## [2.52.0] - 2020-10-05 -### Added -- Translations for `bg`, `ca`, `da`, `de`, `el`, `fi`, `fr`, `it`, `ko`, `nl`, `pl`, `ru`, `sk`, `sl`, `sv`, and `uk`. - -## [2.51.2] - 2020-10-01 -### Fixed -- Fix broken links in the app documentation - -## [2.51.1] - 2020-09-09 -### Changed -- Memoize change and remove callbacks to avoid re-rendering product list items - unnecessarily. - -## [2.51.0] - 2020-09-08 -### Added -- `customPixelEventId` prop. - -## [2.50.0] - 2020-06-24 -### Added -- `MinicartIcon` prop to `minicart.v2`. - -## [2.49.0] - 2020-06-22 -### Added -- Added `itemCountMode` prop in `minicart.v2`. - -## [2.48.0] - 2020-06-03 -### Changed -- Default empty state layout. - -## [2.47.0] - 2020-06-02 -### Added -- New property `productId` to `addToCart`, `removeFromCart` and `cartChanged` events. - -## [2.46.2] - 2020-05-28 - -### Fixed - -- Missing `rootPath` in `goToCheckout` function. - -## [2.46.1] - 2020-05-04 -### Fixed -- Build failing to find entry point for `minicart` block. - -## [2.46.0] - 2020-04-29 -### Added -- `backdropMode` on `minicart.v2`. - -### Security -- Bump dependency versions. - -## [2.45.0] - 2020-03-25 -### Added -- `referenceId` to `addToCart` and `cartChanged` pixel event payloads. - -## [2.44.0] - 2020-03-11 -### Added -- Updated `CODEOWNERS` file with responsible teams for each directory. -- Updated `.all-contributorsrc`. -- Add `quantityDisplay` prop in `minicart.v2`. - -## [2.43.5] - 2020-02-18 -### Changed -- Import queries and mutation directly. - -## [2.43.4] - 2020-02-13 -### Fixed -- Faulty verification at BaseContent component. - -## [2.43.3] - 2020-02-13 -### Fixed -- Transparency effect in 'drawer' variant. - -## [2.43.2] - 2020-02-12 -### Fixed -- [Legacy] Correctly add SKUs that might have attachments. - -## [2.43.1] - 2020-02-05 -### Removed -- `OrderItemsProvider` inside `ProductList`. - -## [2.43.0] - 2020-02-03 -### Added -- `cartId` pixel event. - -## [2.42.1] - 2020-01-31 -### Fixed -- Duplicated components being rendered due to a faulty verification at BaseContent component. - -## [2.42.0] - 2020-01-30 -### Added -- `Advanced configuration` section in the documentation. - -## [2.41.2] - 2020-01-30 -### Fixed -- Design improvements. - -## [2.41.1] - 2020-01-30 -### Fixed -- Popup minicart behavior when `openOnHover` is set to `true`. - -## [2.41.0] - 2020-01-29 -### Changed -- Use `render-runtime` `navigate` function to proceed to cart in order to benefit from apollo cache. - -## [2.40.0] - 2020-01-27 -### Added -- `BaseContent` can now render any `children` blocks passed to it. -- `minicart-checkout-button` interface. -- New `minicartCheckoutButton` CSS handle. - -### Changed -- Default blocks implementation to use these new features. - -## [2.39.0] - 2020-01-22 -### Added -- `labelDiscountText` CSS handle to `minicart`. - -## [2.38.0] - 2020-01-13 -### Added -- New fields `detailUrl` and `imageUrl` to items in `addToCart`, `removeFromCart` and `cartChanged` events. - -## [2.37.1] - 2020-01-09 -### Fixed -- Missing `h-100` token on `minicart-base-content`. - -## [2.37.0] - 2020-01-09 -### Added -- New pixel event `cartChanged` when an item is removed or added. - -### Fixed -- Remove variant name from product name in `removeFromCart` event. Making the name consistent across events. - -## [2.36.0] - 2020-01-06 -### Changed -- Lazy load minicart.v2 content -- Render minicart button on SSR - -## [2.35.0] - 2019-12-20 -### Added -- New CSS handles. - -## [2.34.1] - 2019-12-20 - -## [2.34.0] - 2019-12-20 - -## [2.33.0] - 2019-12-19 -### Added -- New `minicart-empty-state` interface. - -## [2.32.1] - 2019-12-17 -### Fixed -- Update some dependencies, fix tests. - -## [2.32.0] - 2019-12-09 -### Changed -- Link to Cart now varies depending on the version of `vtex.checkout` installed in the account. - -## [2.31.1] - 2019-12-05 -### Changed -- `MinicartLegacy.js` renamed back to `index.js`. - -## [2.31.0] - 2019-12-03 -### Added -- New `minicart.v2`, `minicart-base-content`, `minicart-product-list` and `minicart-summary` interfaces. -- Support for a flexible minicart implementation using these new blocks. - -## [2.30.0] - 2019-11-21 -### Added -- New `openOnHover` prop. - -## [2.29.0] - 2019-11-19 -### Added -- New `iconsProps` prop. - -## [2.28.1] - 2019-11-13 -### Fixed -- New items that must be added in the local state are filtered using "id" and "seller". - -## [2.28.0] - 2019-11-11 -### Added -- Expose `iconLabel` to be edited in Site Editor. - -## [2.27.2] - 2019-10-22 -### Fixed -- Add missing data necessary to pixel events. - -## [2.27.1] - 2019-10-14 -### Fixed -- Use ButtonWithIcon component, removing deprecation warning. - -## [2.27.0] - 2019-10-14 -### Added -- New CSS handles to all components. - -## [2.26.1] - 2019-09-20 -### Fixed -- Removed unused `react-device-detect` dependency. - -## [2.26.0] - 2019-09-03 -### Added -- Allow `sandbox` block on footer. - -## [2.25.0] - 2019-08-30 -### Changed -- Add render type to lazy - -## [2.24.4] - 2019-08-29 - -## [2.24.3] - 2019-08-19 - -### Fixed - -- `addToCart` mutation would add items to the minicart even though they were already there. - -## [2.24.2] - 2019-08-09 -### Fixed -- Removed overflow-hidden token inserted when only one item on minicart. - -## [2.24.1] - 2019-07-31 -### Fixed -- Problem when modifying cart in checkout screen and item still being displayed on minicart after coming back to store screen. - -## [2.24.0] - 2019-07-29 - -### Added -- Added `linkButton` field for the finish shopping button - -## [2.23.2] - 2019-07-26 -### Changed -- Use `sellingPriceWithAssemblies` field to display item price. - -## [2.23.1] - 2019-07-22 - -### Fixed - -- Pixel events of `addToCart` and `removeFromCart`. - -## [2.23.0] - 2019-07-18 - -### Changed - -- Add a new prop that controls if the minicart should show the total price of the items in the cart if the price is bigger than 0. - -## [2.22.1] - 2019-07-17 - -### Fixed - -- Offline Minicart adding repeated items when user navigates. -- Some synchronization issues on offline scenarios. -- Local items being deleted even when the server returned an error. - -### Changed - -- Pass prop `isPartial` to the product summary extension point. - -## [2.22.0] - 2019-07-16 - -### Changed - -- Add a new prop that controls if the minicart should show the total quantity of items or just the quantity of different items. - -## [2.21.2] - 2019-07-01 - -### Fixed - -- Protect against undefined totalizers case. - -## [2.21.1] - 2019-06-27 - -### Fixed - -- Build assets with new builder hub. - -## [2.21.0] - 2019-06-14 - -### Changed - -- Add rootPath prefix to checkout redirect. - -## [2.20.0] - 2019-05-27 - -### Changed - -- Migrate to pixel-manager v1. - -## [2.19.0] - 2019-05-23 - -### Changed - -- Use an overlay div instead of `react-outside-click-handler` on Popup. - -## [2.18.3] - 2019-05-20 - -### Fixed - -- Fix total purchase value when the product is unavailable for shipping in the selected address. - -## [2.18.2] - 2019-05-15 - -## [2.18.1] - 2019-05-15 - -### Changed - -- Separate local state resolvers into separate functions and add tests. -- Add Lint to repo, fix basic issues. - -### Fixed - -- Fixed the case when an item is added offline and the user closes and then accesses the store again still offline. - -## [2.18.0] - 2019-05-14 - -### Changed - -- `isOpen` state is now coming from Apollo Local State. - -## [2.17.1] - 2019-05-08 - -### Fixed - -- Export MiniCart schema and create test case for it. (Releasing again.) - -## [2.17.0] - 2019-05-08 - -### Added - -- Add offline minicart logic allowing users to add an item to the cart when there is no network connection. - -## [2.16.4] - 2019-05-07 - -### Fixed - -- Export MiniCart schema and create test case for it. - -## [2.16.3] - 2019-05-01 - -### Fixed - -- Fix bug on Popup mode where clicks inside the minicart were closing it. - -## [2.16.2] - 2019-04-30 - -### Changed - -- Use `react-portal` to add Popup and Sidebar on the top level of the body. - -## [2.16.1] - 2019-04-30 - -### Fixed - -- Fix props passed to `addToCart` event. - -## [2.16.0] - 2019-04-24 - -### Changed - -- Scope messages by domain - -## [2.15.0] - 2019-04-17 - -### Added - -- Add the `removeFromCart` event. - -## [2.14.7] - 2019-04-12 - -### Fixed - -- Fixes `Cannot read property 'replace' of null` bug on `toHttps`. - -## [2.14.6] - 2019-04-04 - -### Fixed - -- Implement multiple status to simulate request queue and be able to continuously sync local state and server. - -## [2.14.5] - 2019-04-01 - -### Changed - -- Stringify and parse local state order form to prevent bugs in apollo link state. - -### Fixed - -- Make items mutations be based on index and nothing related to sku id. - -## [2.14.4] - 2019-03-28 - -### Changed - -- Remove unused `itemMetadata` fields from orderForm and minicart queries. - -## [2.14.3] - 2019-03-28 - -### Fixed - -- Correctly get orderForm from server mutation on replay mutation method. - -## [2.14.2] - 2019-03-26 - -### Fixed - -- Add toast when request to checkout fails. - -## [2.14.1] - 2019-03-22 - -### Fixed - -- Add default fields to all items to prevent bugs when adding item to cart with missing field. - -## [2.14.0] - 2019-03-21 - -### Added - -- Use the new Apollo Local State API to manage the orderForm and the minicart items to a faster UX. - -## [2.13.1] - 2019-03-14 - -### Changed - -- Use most generic languages files. - -## [2.13.0] - 2019-03-13 - -### Changed - -- Use `inlinePrice` product summary type. - -## [2.12.1] - 2019-03-01 - -### Changed - -- Using `store-icons` instead of `dreamstore-icons` - -### Fixed - -- Fix Tests. - -## [2.12.0] - 2019-02-27 - -### Changed - -- Use assembly resolvers of `store-graphql` - -### Fixed - -- Fix `package.json` dependencies. - -### Added - -- Setup tests and snapshot test. - -## [2.11.9] - 2019-02-25 - -### Fixed - -- `classNames` not found. - -## [2.11.8] - 2019-02-25 - -### Removed - -- `showRemoveButton`, `showSku`, `enableQuantitySelector` and `maxQuantity` props that were not used. -- `Image` component that was not used. - -## [2.11.7] - 2019-02-21 - -### Fixed - -- Total discount was not showing, even when enabled. - -## [2.11.6] - 2019-02-18 - -### Fixed - -- Fix warnings. - -## [2.11.5] - 2019-02-15 - -### Fixed - -- Minicart flick when scroll is being displayed. - -## [2.11.4] - 2019-02-15 - -### Fixed - -- Revert the `link-state` configuration. - -## [2.11.3] - 2019-02-14 - -## [2.11.2] - 2019-02-14 - -## [2.11.1] - 2019-02-13 - -### Fixed - -- Remove block elements inside inline elements. -- Using html5 tags to a more semantic structure. - -## [2.11.0] - 2019-02-13 - -### Added - -- Styles section on docs. -- Improve tokens description on docs. -- Implement an optimistic strategy using apollo-link-state so the minicart operations feel faster. - -## [2.10.5] - 2019-02-08 - -### Added - -- Create a API docs - -### Changed - -- Minor refact on blocks language. - -## [2.10.4] - 2019-02-08 - -### Changed - -- Pass composition item to product summary - -### Fixed - -- Small margin adjustments for shipping cost view - -## [2.10.3] - 2019-02-07 - -### Fixed - -- Add shipping fee string id to context.json - -## [2.10.2] - 2019-02-05 - -### Fixed - -- Protect against `itemMetadata` null - -## [2.10.1] - 2019-02-01 - -## [2.10.0] - 2019-01-31 - -### Changed - -- Add icons from `vtex.dreamstore-icons`. - -## [2.9.1] - 2019-01-29 - -### Fixed - -- Remove inherit component from `blocks.json` - -### Changed - -- Send to product-summary the "choice type" of each assembly option (SINGLE, TOGGLE or MULTIPLE) - -## [2.9.0] - 2019-01-25 - -### Added - -Add possibility of showing shipping cost above footer - -### Changed - -Rename `large` prop to `isSizeLarge` for better description - -## [2.8.0] - 2019-01-22 - -## [2.7.3] - 2019-01-18 - -## [2.7.2] - 2019-01-18 - -### Changed - -- Adjust the way to import render-runtime components - -## [2.7.1] - 2019-01-18 - -## [2.7.0] - 2019-01-18 - -### Changed - -- Bump vtex.styleguide to 9.x. - -## [2.6.0] - 2019-01-18 - -### Changed - -- Update React builder to 3.x - -## [2.5.0] - 2019-01-16 - -### Fixed - -- Create isSingleChoiceOption function and calculate parent item price correctly. - -## [2.4.3] - 2019-01-15 - -### Fixed - -- Fixed price overlapping in the mobile view. - -## [2.4.2] - 2019-01-15 - -### Fixed - -- Fix icon vertical aligment in the header in mobile view. - -## [2.4.1] - 2019-01-14 - -### Fixed - -- Remove `undefined` css classes. -- Change `store/product` to `store.product` on Link. - -## [2.4.0] - 2019-01-09 - -### Changed - -- Bye `pages.json`! Welcome `store-builder`. - -## [2.3.2] - 2019-01-09 - -### Fixed - -- Replace URL just for legacy file manager url format. - -## [2.3.1] - 2019-01-04 - -### Fixed - -- Icon aligment. - -## [2.3.0] - 2018-12-26 - -### Added - -- Create `groupItemsWithParents` function, add tests. Group parent items with its attachments. - -## [2.2.0] - 2018-12-17 - -### Added - -- Support to messages builder. - -### Fixed - -- Remove unnecessary declarations on `manifes.json`. - -## [2.1.5] - 2018-12-14 - -### Changed - -- Bump major version of `vtex.styleguide` and `vtex.store-components`. -- Add design tokens on selling price label. - -## [2.1.4] - 2018-12-14 - -### Fixed - -- Fix minimum items length to scrolling in minicart. - -## [2.1.3] - 2018-12-14 - -### Changed - -- CSS module classes' name to be in CamelCase. - -## [2.1.2] - 2018-12-12 - -### Fixed - -- Don't render the discount label when there is no discount. - -## [2.1.1] - 2018-12-12 - -### Fixed - -- Items sort by insertion order. - -## [2.1.0] - 2018-12-12 - -### Added - -- Support to CSS Modules - -## [2.0.6] - 2018-12-04 - -### Fixed - -- Mixed Content error, insecure http image -- Poor image quality - -## [2.0.5] - 2018-12-03 - -### Changed - -- Set cart badge color to bg-emphasis - -## [2.0.4] - 2018-12-03 - -### Fixed - -- Vertically center number on mini cart badge - -## [2.0.3] - 2018-12-02 - -### Fixed - -- Replace delete button after click with spinner, Fix price loading and add error when something goes wrong when removing from cart. - -## [2.0.2] - 2018-12-02 - -### Changed - -- Use of `vtex.use-svg` lib to display icons. - -## [2.0.1] - 2018-12-02 - -### Fixed - -- Fix scrim not covering entire screen. - -## [2.0.0] - 2018-11-26 - -### Changed - -- Update the `MiniCartContent` component to use the `ProductSummary` from the `vtex.product-summary` instead `MiniCartItem`. -- Update the size of `Sidebar` to 80% of original value. -- Add shadow scrim. - -### Fixed - -- Replace typography and color classes with design tokens. - -## [1.3.0] - 2018-11-21 - -### Changed - -- Use icons from the dreamstore icon pack. - -## [1.2.3] - 2018-11-07 - -### Changed - -- Close the `SideBar` after clicking some product's link. - -## [1.2.2] - 2018-10-18 - -### Changed - -- Update the `SideBar` component to use the `Animation` from the `store-components`. - -## [1.2.1] - 2018-10-18 - -### Changed - -- `Sidebar` header to use border instead of shadow, according to the design. - -## [1.2.0] - 2018-10-18 - -### Changed - -- Redesign of the `MiniCartContent` footer layout, now there are three rows aligned on the right side of the footer. - -## [1.1.6] - 2018-10-05 - -### Fixed - -- Empty message position of the `MiniCartContent` to be vertically centered in the pop-up mode. - -## [1.1.5] - 2018-09-24 - -### Changed - -- Hide label in screens thinner than the laptop resolution. - -## [1.1.4] - 2018-09-20 - -### Fixed - -- Fixes being able to scroll the body on mobile with the `Sidebar` open. - -## [1.1.3] - 2018-09-14 - -### Changed - -- Refactor the `global.css`. - -## [1.1.2] - 2018-09-05 - -### Changed - -- `MiniCart` to receive the icon's classnames. -- `CartIcon` to fill the parents color. - -## [1.1.1] - 2018-08-31 - -### Changed - -- `Sidebar` header design colors. - -### Fixed - -- `MiniCart` bagde position. - -## [1.1.0] - 2018-08-31 - -### Changed - -- Update the `Styleguide` version. -- Update the `store-components` version. - -## [1.0.6] - 2018-08-30 - -## [1.0.5] - 2018-08-30 - -## [1.0.4] - 2018-08-30 - -### Added - -- `NumericStepper` from styleguide into the `MiniCartItem`. - -### Fixed - -- Change `MiniCartItem` quantity. - -## [1.0.3] - 2018-08-24 - -### Added - -- Add CSS class to `MiniCart` label. - -## [1.0.2] - 2018-08-20 - -### Fixed - -- Fix box position to be compatible with the new header design - -## [1.0.1] - 2018-08-17 - -### Fixed - -- Discount label text. - -## [1.0.0] - 2018-08-17 - -### Added - -- props `iconLabel`, `iconSize`, `iconColor` to `Minicart` component - -## [0.9.2] - 2018-08-10 - -### Fixed - -- `MiniCart` overflow hidden property which was affecting all the screens with at most 400px of width. - -## [0.9.1] - 2018-08-09 - -### Added - -- Content Loader while the `MiniCartItem`'s image isn't loaded. - -### Fixed - -- `MiniCartItem`'s name width. - -## [0.9.0] - 2018-08-08 - -### Fixed - -- `MiniCartContent` prop-types. -- Remove item. - -### Added - -- Animation into the `SideBar`. - -## [0.8.0] - 2018-08-02 - -### Added - -- OrderFormContext component - -### Changed - -- Removed Graphql queries and mutation -- Open sidebar independent of configuration if on mobile. - -## [0.7.2] - 2018-07-25 - -## [0.7.1] - 2018-07-11 - -### Changed - -- `Popup` to appear when the `MiniCart` button is clicked instead of on hover. - -### Fixed - -- `maxQuantity` undefined warning. -- Loading mixed (insecure) display content warning. - -## [0.7.0] - 2018-7-6 - -### Added - -- Minicart SideBar type. - -### Fixed - -- Fix duplicate items showing when changing the quantity. - -## [0.6.0] - 2018-6-20 - -### Added - -- Quantity Selector into the `MiniCartItem` - -## [0.5.1] - 2018-6-14 - -### Changed - -- Hide the quantity badge when the quantity is less then 0 - -## [0.5.0] - 2018-6-11 - -### Added - -- Add internationalization into minicart schema - -## [0.4.0] - 2018-05-24 - -### Changed - -- The mini cart components to use the store components. -- PropTypes to reuse the mini cart's one. -- Update folder structure - -## [0.3.2] - 2018-05-19 - -### Fixed - -- Fix minicart render error when cannot fetch the orderForm from graphql. - -## [0.3.1] - 2018-05-13 - -### Fixed - -- Fix minicart locales - -## [0.3.0] - 2018-05-11 - -### Added - -- Add badge to show the quantity of items in the mini cart. -- Add arrow indicator to mini cart content. - -### Changed - -- Add event listener on minicart that will be used to update minicart badge. - -## [0.2.1] - 2018-05-10 - -### Fixed - -- Refetch order form data when a new product is added to the mini cart. - -## [0.2.0] - 2018-05-10 - -### Added - -- Add a spinner when remove button is pressed. - -## [0.1.0] - 2018-05-09 - -### Added - -- Add feature that allows to remove a minicart item. - -## [0.0.1] - 2018-05-09 - -### Added - -- Publish first version of the app. diff --git a/docs/README.md b/docs/README.md index 93d4da7c..f9223fd8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,7 +18,7 @@ The Minicart is a block that displays a summary list of all items added to the s ```json "dependencies": { - "vtex.minicart": "2.x" + "auchan.minicart": "0.x" } ``` diff --git a/manifest.json b/manifest.json index 9c9eaf24..eac0563c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { - "vendor": "vtex", + "vendor": "auchan", "name": "minicart", "title": "Mini Cart", - "version": "2.67.1", + "version": "0.0.1", "builders": { "messages": "1.x", "store": "0.x", @@ -14,6 +14,8 @@ "postreleasy": "vtex publish --verbose" }, "dependencies": { + "auchan.product-list": "0.x", + "auchan.checkout-summary": "0.x", "vtex.product-summary": "2.x", "vtex.store-resources": "0.x", "vtex.store-components": "3.x", @@ -26,10 +28,8 @@ "vtex.css-handles": "1.x", "vtex.order-manager": "0.x", "vtex.order-items": "0.x", - "vtex.product-list": "0.x", "vtex.device-detector": "0.x", "vtex.store-drawer": "0.x", - "vtex.checkout-summary": "0.x", "vtex.checkout-resources": "0.x", "vtex.flex-layout": "0.x", "vtex.rich-text": "0.x", diff --git a/react/Summary.tsx b/react/Summary.tsx index 5d2a9123..0e070dfa 100644 --- a/react/Summary.tsx +++ b/react/Summary.tsx @@ -1,8 +1,10 @@ -import React, { FC } from 'react' +import React, { FC, useEffect, useMemo, useState } from 'react' import { ExtensionPoint } from 'vtex.render-runtime' import { OrderForm as OrderFormComponent } from 'vtex.order-manager' import { useCssHandles, CssHandlesTypes } from 'vtex.css-handles' +import { fetchWithRetry } from './legacy/utils/fetchWithRetry' + const CSS_HANDLES = ['minicartSummary'] as const interface Props { @@ -16,6 +18,95 @@ const Summary: FC = ({ classes }) => { orderForm: { totalizers, value, items, paymentData }, } = useOrderForm() + const [packagesSkuIds, setPackagesSkuIds] = useState([]) + const [sgrSkuIds, setSgrSkuIds] = useState([]) + + useEffect(() => { + let isSubscribed = true + + fetchWithRetry('/_v/private/api/cart-bags-manager/app-settings', 3).then( + (res: PackagesSkuIds) => { + if (res && isSubscribed) { + try { + const { bagsSettings, sgrSettings } = res?.data ?? {} + + setPackagesSkuIds(Object.values(bagsSettings)) + + const allSkuIds: string[] = [] + + Object.values(sgrSettings).forEach(sgrType => { + if (sgrType?.skuIds) { + allSkuIds.push(...sgrType.skuIds) + } + }) + + setSgrSkuIds(allSkuIds) + } catch (error) { + console.error('Error in packages feature.', error) + } + } + } + ) + + return () => { + isSubscribed = false + } + }, []) + + const flegValue = useMemo(() => { + if (!packagesSkuIds.length) { + return + } + return items.reduce((total: number, item: OrderFormItem) => { + if (packagesSkuIds.includes(item.id)) { + return ( + total + ((item?.listPrice as number) ?? 0) * (item?.quantity ?? 1) + ) + } + return total + }, 0) + }, [items, packagesSkuIds]) + + const sgrValue = useMemo(() => { + if (!sgrSkuIds.length) { + return + } + return items.reduce((total: number, item: OrderFormItem) => { + if (sgrSkuIds.includes(item.id)) { + return ( + total + ((item?.listPrice as number) ?? 0) * (item?.quantity ?? 1) + ) + } + return total + }, 0) + }, [items, sgrSkuIds]) + + let newTotalizers = totalizers + + newTotalizers = JSON.parse(JSON.stringify(totalizers)) + const totalizerItems = newTotalizers.find((t: any) => t.id === 'Items') + + if (flegValue && typeof flegValue === 'number') { + newTotalizers.push({ + id: 'Packaging', + name: 'Taxa ambalare', + value: flegValue, + __typename: 'Totalizer', + }) + + totalizerItems.value -= flegValue ?? 0 + } + + if (sgrValue && typeof sgrValue === 'number') { + newTotalizers.push({ + id: 'SGR', + name: 'Garantie', + value: sgrValue, + __typename: 'Totalizer', + }) + totalizerItems.value -= sgrValue ?? 0 + } + const { handles } = useCssHandles(CSS_HANDLES, { classes }) const originalValue = @@ -30,7 +121,7 @@ const Summary: FC = ({ classes }) => {
{ // Filter only main products, remove assembly items from the count - const items = allItems.filter(item => item.parentItemIndex === null) + const items = allItems.filter( + item => + item.parentItemIndex === null && + item.productId && + !packagesSkuIds.includes(item.productId) && + !sgrSkuIds.includes(item.productId) + ) if (countMode === 'distinctAvailable') { return items.reduce((itemQuantity: number, item) => { @@ -61,7 +70,46 @@ const MinicartIconButton: React.FC = props => { const { handles } = useMinicartCssHandles() const { open, openBehavior, openOnHoverProp } = useMinicartState() const dispatch = useMinicartDispatch() - const quantity = countCartItems(itemCountMode, orderForm.items) + const [packagesSkuIds, setPackagesSkuIds] = useState([]) + const [sgrSkuIds, setSgrSkuIds] = useState([]) + + useEffect(() => { + let isSubscribed = true + + fetchWithRetry('/_v/private/api/cart-bags-manager/app-settings', 3).then( + (res: PackagesSkuIds) => { + if (res && isSubscribed) { + try { + const { bagsSettings, sgrSettings } = res?.data ?? {} + + setPackagesSkuIds(Object.values(bagsSettings)) + + const allSkuIds: string[] = [] + + Object.values(sgrSettings).forEach(sgrType => { + if (sgrType?.skuIds) { + allSkuIds.push(...sgrType.skuIds) + } + }) + + setSgrSkuIds(allSkuIds) + } catch (error) { + console.error('Error in packages feature.', error) + } + } + } + ) + + return () => { + isSubscribed = false + } + }, []) + const quantity = countCartItems( + itemCountMode, + orderForm.items, + packagesSkuIds, + sgrSkuIds + ) const itemQuantity = loading ? 0 : quantity const { url: checkoutUrl } = useCheckoutURL() const goToCheckout = useCheckout() diff --git a/react/legacy/utils/fetchWithRetry.ts b/react/legacy/utils/fetchWithRetry.ts new file mode 100644 index 00000000..c2d9fa5a --- /dev/null +++ b/react/legacy/utils/fetchWithRetry.ts @@ -0,0 +1,18 @@ +interface FetchWithRetry { + (url: string, retries: number): Promise +} + +export const fetchWithRetry: FetchWithRetry = (url: string, retries: number) => + fetch(url) + .then(res => { + if (res.ok) { + return res.json() + } + + if (retries > 0) { + return fetchWithRetry(url, retries - 1) + } + + throw new Error(`Failed to fetch: ${url}`) + }) + .catch(error => console.error(error.message)) diff --git a/react/package.json b/react/package.json index 016b114f..c4031c5d 100644 --- a/react/package.json +++ b/react/package.json @@ -1,6 +1,6 @@ { - "name": "vtex.minicart", - "version": "2.67.1", + "name": "auchan.minicart", + "version": "0.0.1", "description": "A MiniCart Component.", "scripts": { "pretest": "yarn", @@ -17,30 +17,31 @@ "@vtex/test-tools": "^3.1.0", "@vtex/tsconfig": "^0.4.4", "apollo-cache-inmemory": "^1.6.5", + "auchan.checkout-summary": "https://narcissgr--auchanqa.myvtex.com/_v/private/typings/linked/v1/auchan.checkout-summary@0.0.1+build1702379716/public/@types/auchan.checkout-summary", + "auchan.minicart": "https://narcissgr--auchanqa.myvtex.com/_v/private/typings/linked/v1/auchan.minicart@0.0.1+build1702379665/public/@types/auchan.minicart", + "auchan.product-list": "https://narcissgr--auchanqa.myvtex.com/_v/private/typings/linked/v1/auchan.product-list@0.0.1+build1702379804/public/@types/auchan.product-list", "babel-eslint": "^10.1.0", "typescript": "3.9.7", - "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.0/public/@types/vtex.checkout-graphql", + "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.3/public/@types/vtex.checkout-graphql", "vtex.checkout-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.49.0/public/@types/vtex.checkout-resources", - "vtex.checkout-summary": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-summary@0.22.0/public/@types/vtex.checkout-summary", "vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@1.0.0/public/@types/vtex.css-handles", "vtex.device-detector": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.device-detector@0.2.6/public/@types/vtex.device-detector", - "vtex.flex-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.0/public/@types/vtex.flex-layout", - "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.21/public/@types/vtex.order-items", + "vtex.flex-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.3/public/@types/vtex.flex-layout", + "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.23/public/@types/vtex.order-items", "vtex.order-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.12.0/public/@types/vtex.order-manager", "vtex.pixel-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.9.0/public/@types/vtex.pixel-manager", - "vtex.product-list": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-list@0.37.1/public/@types/vtex.product-list", - "vtex.product-summary": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.82.0/public/@types/vtex.product-summary", + "vtex.product-summary": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.87.0/public/@types/vtex.product-summary", "vtex.react-portal": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.react-portal@0.4.1/public/@types/vtex.react-portal", - "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.133.0/public/@types/vtex.render-runtime", + "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.134.2/public/@types/vtex.render-runtime", "vtex.responsive-values": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.responsive-values@0.4.2/public/@types/vtex.responsive-values", "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.16.0/public/@types/vtex.rich-text", "vtex.sandbox": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.sandbox@0.5.1/public/@types/vtex.sandbox", - "vtex.store-components": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.167.0/public/@types/vtex.store-components", - "vtex.store-drawer": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.2/public/@types/vtex.store-drawer", - "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.161.2/public/@types/vtex.store-graphql", + "vtex.store-components": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.170.0/public/@types/vtex.store-components", + "vtex.store-drawer": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.3/public/@types/vtex.store-drawer", + "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.170.1/public/@types/vtex.store-graphql", "vtex.store-icons": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons", - "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.89.0/public/@types/vtex.store-resources", - "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.3/public/@types/vtex.styleguide" + "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.93.0/public/@types/vtex.store-resources", + "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.9/public/@types/vtex.styleguide" }, "dependencies": { "apollo-client": "2.6.4", diff --git a/react/typings/packages-sku-ids.d.ts b/react/typings/packages-sku-ids.d.ts new file mode 100644 index 00000000..ff982f0b --- /dev/null +++ b/react/typings/packages-sku-ids.d.ts @@ -0,0 +1,25 @@ +interface PackagesSkuIds { + data: { + bagsSettings: { + bioFlegBagId: string + insulationBagId: string + plasticBagId: string + paperBagId: string + } + sgrSettings: { + aluminumCanProducts: { + label: string + skuIds: string[] + } + glassBottleProducts: { + label: string + skuIds: string[] + } + plasticBottleProducts: { + label: string + skuIds: string[] + } + } + } + error: null | string +} diff --git a/react/yarn.lock b/react/yarn.lock index 8f664e74..73748184 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -5008,9 +5008,9 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.0/public/@types/vtex.checkout-graphql": - version "0.66.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.0/public/@types/vtex.checkout-graphql#62e6165824dcf5786dc3675b8bb8fdf276b22089" +"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.3/public/@types/vtex.checkout-graphql": + version "0.66.3" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.3/public/@types/vtex.checkout-graphql#a0a8bc4e91627678877ea3b8b59f003aa5887002" "vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.49.0/public/@types/vtex.checkout-resources": version "0.49.0" @@ -5028,13 +5028,17 @@ verror@1.10.0: version "0.2.6" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.device-detector@0.2.6/public/@types/vtex.device-detector#3219242fa5c2f14023d33c3549c2d8de93c76d1f" -"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.0/public/@types/vtex.flex-layout": - version "0.21.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.0/public/@types/vtex.flex-layout#aa4a7225567408a4299a9d030c99dcb71555628a" +"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.3/public/@types/vtex.flex-layout": + version "0.21.3" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.3/public/@types/vtex.flex-layout#407f0e310545ff006f08afb35f5d38ace4546435" -"vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.21/public/@types/vtex.order-items": - version "0.13.21" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.21/public/@types/vtex.order-items#b88b2d267bc1b2877cae92e657b3934d4f01a960" +"vtex.minicart@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.minicart@2.67.1/public/@types/vtex.minicart": + version "2.67.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.minicart@2.67.1/public/@types/vtex.minicart#d0c160a87d987c8a2a48890bb76f28b17ba7c0db" + +"vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.23/public/@types/vtex.order-items": + version "0.13.23" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.23/public/@types/vtex.order-items#282f1dffe38cfb96ad1c225ebb252bfa0e5b1912" "vtex.order-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.12.0/public/@types/vtex.order-manager": version "0.12.0" @@ -5048,17 +5052,17 @@ verror@1.10.0: version "0.37.1" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-list@0.37.1/public/@types/vtex.product-list#9b4faad9194f5aa2a74e3848eb560b11c5b98513" -"vtex.product-summary@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.82.0/public/@types/vtex.product-summary": - version "2.82.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.82.0/public/@types/vtex.product-summary#21ae1d2f6582c4a2a17aa978030a65d7ac735441" +"vtex.product-summary@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.85.0/public/@types/vtex.product-summary": + version "2.85.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.85.0/public/@types/vtex.product-summary#152bccd364a354ef4ca6436049184693e1c71ace" "vtex.react-portal@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.react-portal@0.4.1/public/@types/vtex.react-portal": version "0.4.1" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.react-portal@0.4.1/public/@types/vtex.react-portal#781ce4b53ba576a6365306531d8be0f1ad114769" -"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.133.0/public/@types/vtex.render-runtime": - version "8.133.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.133.0/public/@types/vtex.render-runtime#8a94831937320c3649655e190a02a9297f3379ae" +"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.134.2/public/@types/vtex.render-runtime": + version "8.134.2" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.134.2/public/@types/vtex.render-runtime#ae69e2b2a471291c6c6b155e17510150fbfc2d0e" "vtex.responsive-values@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.responsive-values@0.4.2/public/@types/vtex.responsive-values": version "0.4.2" @@ -5072,29 +5076,29 @@ verror@1.10.0: version "0.5.1" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.sandbox@0.5.1/public/@types/vtex.sandbox#be4a4153a0864282fdfbe0d63501daa3978fe6dc" -"vtex.store-components@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.167.0/public/@types/vtex.store-components": - version "3.167.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.167.0/public/@types/vtex.store-components#1abbb57f3a78dd19dbcd4a473012ac44e23fa7ff" +"vtex.store-components@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.169.5/public/@types/vtex.store-components": + version "3.169.5" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.169.5/public/@types/vtex.store-components#b58f7ecc96f1450c577cc8eefe3059003829e2a4" -"vtex.store-drawer@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.2/public/@types/vtex.store-drawer": - version "0.16.2" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.2/public/@types/vtex.store-drawer#3e3a0e07babcf623922f1eb0c85185bcd12b8002" +"vtex.store-drawer@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.3/public/@types/vtex.store-drawer": + version "0.16.3" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.3/public/@types/vtex.store-drawer#c9fc58f76b5fa7a1c6ce35acc371448b262b1450" -"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.161.2/public/@types/vtex.store-graphql": - version "2.161.2" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.161.2/public/@types/vtex.store-graphql#6348bb2c1fe66a47a2a0f5f600cbf84a4a43d144" +"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.170.1/public/@types/vtex.store-graphql": + version "2.170.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.170.1/public/@types/vtex.store-graphql#7e087ac00c2abf0a2e06ef5551110d0de5b7fe58" "vtex.store-icons@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons": version "0.18.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons#0ee94d549aa283ce3a13ab987c13eac4fdfd1bba" -"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.89.0/public/@types/vtex.store-resources": - version "0.89.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.89.0/public/@types/vtex.store-resources#a240ccd479d5c667e137ff5338f95361176ad09d" +"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.93.0/public/@types/vtex.store-resources": + version "0.93.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.93.0/public/@types/vtex.store-resources#f7d82498aa2871d25df89c54f8fff2f5a7ac22f7" -"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.3/public/@types/vtex.styleguide": - version "9.146.3" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.3/public/@types/vtex.styleguide#05558160f29cd8f4aefe419844a4bd66e2b3fdbb" +"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.9/public/@types/vtex.styleguide": + version "9.146.9" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.9/public/@types/vtex.styleguide#d1601fedfb665c6173334753171717da64e670bc" w3c-hr-time@^1.0.1: version "1.0.2" From cda3c9d05f5988b5ec7847ba30b4f561c7fc9f55 Mon Sep 17 00:00:00 2001 From: Claudiu Ionita Date: Wed, 13 Dec 2023 17:48:04 +0200 Subject: [PATCH 2/7] fix missing items total bug --- react/Summary.tsx | 10 +++++++--- react/package.json | 3 --- react/yarn.lock | 24 ++++++------------------ 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/react/Summary.tsx b/react/Summary.tsx index 0e070dfa..799284dd 100644 --- a/react/Summary.tsx +++ b/react/Summary.tsx @@ -84,7 +84,7 @@ const Summary: FC = ({ classes }) => { let newTotalizers = totalizers newTotalizers = JSON.parse(JSON.stringify(totalizers)) - const totalizerItems = newTotalizers.find((t: any) => t.id === 'Items') + const totalizerItems = newTotalizers.find((t: { id: string }) => t.id === 'Items') if (flegValue && typeof flegValue === 'number') { newTotalizers.push({ @@ -94,7 +94,9 @@ const Summary: FC = ({ classes }) => { __typename: 'Totalizer', }) - totalizerItems.value -= flegValue ?? 0 + if (totalizerItems) { + totalizerItems.value -= flegValue ?? 0 + } } if (sgrValue && typeof sgrValue === 'number') { @@ -104,7 +106,9 @@ const Summary: FC = ({ classes }) => { value: sgrValue, __typename: 'Totalizer', }) - totalizerItems.value -= sgrValue ?? 0 + if (totalizerItems) { + totalizerItems.value -= sgrValue ?? 0 + } } const { handles } = useCssHandles(CSS_HANDLES, { classes }) diff --git a/react/package.json b/react/package.json index c4031c5d..83c1e5a4 100644 --- a/react/package.json +++ b/react/package.json @@ -17,9 +17,6 @@ "@vtex/test-tools": "^3.1.0", "@vtex/tsconfig": "^0.4.4", "apollo-cache-inmemory": "^1.6.5", - "auchan.checkout-summary": "https://narcissgr--auchanqa.myvtex.com/_v/private/typings/linked/v1/auchan.checkout-summary@0.0.1+build1702379716/public/@types/auchan.checkout-summary", - "auchan.minicart": "https://narcissgr--auchanqa.myvtex.com/_v/private/typings/linked/v1/auchan.minicart@0.0.1+build1702379665/public/@types/auchan.minicart", - "auchan.product-list": "https://narcissgr--auchanqa.myvtex.com/_v/private/typings/linked/v1/auchan.product-list@0.0.1+build1702379804/public/@types/auchan.product-list", "babel-eslint": "^10.1.0", "typescript": "3.9.7", "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.66.3/public/@types/vtex.checkout-graphql", diff --git a/react/yarn.lock b/react/yarn.lock index 73748184..50935a8c 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -5016,10 +5016,6 @@ verror@1.10.0: version "0.49.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.49.0/public/@types/vtex.checkout-resources#a7d7620fce143e5dc7a9075ce2fc74727ab132c4" -"vtex.checkout-summary@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-summary@0.22.0/public/@types/vtex.checkout-summary": - version "0.22.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-summary@0.22.0/public/@types/vtex.checkout-summary#c6d3dbd76be90cd18c4a6e03a00284dc4f12f352" - "vtex.css-handles@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@1.0.0/public/@types/vtex.css-handles": version "1.0.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@1.0.0/public/@types/vtex.css-handles#336b23ef3a9bcb2b809529ba736783acd405d081" @@ -5032,10 +5028,6 @@ verror@1.10.0: version "0.21.3" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.21.3/public/@types/vtex.flex-layout#407f0e310545ff006f08afb35f5d38ace4546435" -"vtex.minicart@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.minicart@2.67.1/public/@types/vtex.minicart": - version "2.67.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.minicart@2.67.1/public/@types/vtex.minicart#d0c160a87d987c8a2a48890bb76f28b17ba7c0db" - "vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.23/public/@types/vtex.order-items": version "0.13.23" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.23/public/@types/vtex.order-items#282f1dffe38cfb96ad1c225ebb252bfa0e5b1912" @@ -5048,13 +5040,9 @@ verror@1.10.0: version "1.9.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.9.0/public/@types/vtex.pixel-manager#eb61e263c4f8024430ef1a19d28bcf608db3d481" -"vtex.product-list@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-list@0.37.1/public/@types/vtex.product-list": - version "0.37.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-list@0.37.1/public/@types/vtex.product-list#9b4faad9194f5aa2a74e3848eb560b11c5b98513" - -"vtex.product-summary@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.85.0/public/@types/vtex.product-summary": - version "2.85.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.85.0/public/@types/vtex.product-summary#152bccd364a354ef4ca6436049184693e1c71ace" +"vtex.product-summary@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.87.0/public/@types/vtex.product-summary": + version "2.87.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.product-summary@2.87.0/public/@types/vtex.product-summary#e0e58da094d5851e020782b1e1791425361350b3" "vtex.react-portal@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.react-portal@0.4.1/public/@types/vtex.react-portal": version "0.4.1" @@ -5076,9 +5064,9 @@ verror@1.10.0: version "0.5.1" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.sandbox@0.5.1/public/@types/vtex.sandbox#be4a4153a0864282fdfbe0d63501daa3978fe6dc" -"vtex.store-components@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.169.5/public/@types/vtex.store-components": - version "3.169.5" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.169.5/public/@types/vtex.store-components#b58f7ecc96f1450c577cc8eefe3059003829e2a4" +"vtex.store-components@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.170.0/public/@types/vtex.store-components": + version "3.170.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.170.0/public/@types/vtex.store-components#1f5673bc0b974862ed0a0c0e61cefefff1d472c6" "vtex.store-drawer@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.16.3/public/@types/vtex.store-drawer": version "0.16.3" From e72779b6bbe6c1fa9e4ae8b15c090889414382dc Mon Sep 17 00:00:00 2001 From: Narcis Spanache Date: Mon, 8 Jan 2024 09:51:53 +0200 Subject: [PATCH 3/7] changing version to use vtex release comand --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index eac0563c..e8974a82 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "vendor": "auchan", "name": "minicart", "title": "Mini Cart", - "version": "0.0.1", + "version": "0.0.0", "builders": { "messages": "1.x", "store": "0.x", From c3f8b7680bd2b9f281285f311dc3771d9ddc4d55 Mon Sep 17 00:00:00 2001 From: Narcis Spanache Date: Mon, 8 Jan 2024 09:52:09 +0200 Subject: [PATCH 4/7] Release v0.0.1 --- CHANGELOG.md | 2 ++ manifest.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4386bc4d..29771019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,5 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.0.1] - 2024-01-08 diff --git a/manifest.json b/manifest.json index e8974a82..eac0563c 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "vendor": "auchan", "name": "minicart", "title": "Mini Cart", - "version": "0.0.0", + "version": "0.0.1", "builders": { "messages": "1.x", "store": "0.x", From 1d30f5faa655584336abc8b04146dd5b100209ce Mon Sep 17 00:00:00 2001 From: tanasievlad246 Date: Thu, 12 Dec 2024 15:36:30 +0200 Subject: [PATCH 5/7] Added check for items remaining in the cart, if they are bags or shipping, to refresh the cart, to fix the empty cart with summary values bug --- react/Summary.tsx | 125 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 97 insertions(+), 28 deletions(-) diff --git a/react/Summary.tsx b/react/Summary.tsx index 799284dd..85bdf471 100644 --- a/react/Summary.tsx +++ b/react/Summary.tsx @@ -1,4 +1,4 @@ -import React, { FC, useEffect, useMemo, useState } from 'react' +import React, { FC, useCallback, useEffect, useMemo, useState } from 'react' import { ExtensionPoint } from 'vtex.render-runtime' import { OrderForm as OrderFormComponent } from 'vtex.order-manager' import { useCssHandles, CssHandlesTypes } from 'vtex.css-handles' @@ -12,11 +12,29 @@ interface Props { } const Summary: FC = ({ classes }) => { - const { useOrderForm } = OrderFormComponent + const { useOrderForm } = OrderFormComponent; + const orderFormContext = useOrderForm(); const { orderForm: { totalizers, value, items, paymentData }, - } = useOrderForm() + } = orderFormContext; + + const refreshCart = useCallback(async () => { + await orderFormContext.setOrderForm({ + ...orderFormContext.orderForm, + items: [] // This forces a refresh + }) + }, [orderFormContext]) + + + const [finalTotalizers, setFinalTotalizers] = useState(totalizers); + const [isUpdating, setIsUpdating] = useState(false); + + useEffect(() => { + setIsUpdating(true); + const timeoutId = setTimeout(() => setIsUpdating(false), 100); + return () => clearTimeout(timeoutId); + }, [items]); const [packagesSkuIds, setPackagesSkuIds] = useState([]) const [sgrSkuIds, setSgrSkuIds] = useState([]) @@ -81,35 +99,49 @@ const Summary: FC = ({ classes }) => { }, 0) }, [items, sgrSkuIds]) - let newTotalizers = totalizers - newTotalizers = JSON.parse(JSON.stringify(totalizers)) - const totalizerItems = newTotalizers.find((t: { id: string }) => t.id === 'Items') - if (flegValue && typeof flegValue === 'number') { - newTotalizers.push({ - id: 'Packaging', - name: 'Taxa ambalare', - value: flegValue, - __typename: 'Totalizer', - }) + useEffect(() => { + if (isUpdating) { + return + } - if (totalizerItems) { - totalizerItems.value -= flegValue ?? 0 + if (!items?.length) { + setFinalTotalizers([]) + return } - } - - if (sgrValue && typeof sgrValue === 'number') { - newTotalizers.push({ - id: 'SGR', - name: 'Garantie', - value: sgrValue, - __typename: 'Totalizer', - }) - if (totalizerItems) { - totalizerItems.value -= sgrValue ?? 0 + + let newTotalizers = JSON.parse(JSON.stringify(totalizers)) + + newTotalizers = JSON.parse(JSON.stringify(totalizers)) + const totalizerItems = newTotalizers.find((t: { id: string }) => t.id === 'Items') + + if (flegValue && typeof flegValue === 'number') { + newTotalizers.push({ + id: 'Packaging', + name: 'Taxa ambalare', + value: flegValue, + __typename: 'Totalizer', + }) + + if (totalizerItems) { + totalizerItems.value -= flegValue ?? 0 + } + } + + if (sgrValue && typeof sgrValue === 'number') { + newTotalizers.push({ + id: 'SGR', + name: 'Garantie', + value: sgrValue, + __typename: 'Totalizer', + }) + if (totalizerItems) { + totalizerItems.value -= sgrValue ?? 0 + } } - } + setFinalTotalizers(newTotalizers) + }, [totalizers, flegValue, sgrValue, items, value, paymentData, isUpdating]) const { handles } = useCssHandles(CSS_HANDLES, { classes }) @@ -121,11 +153,48 @@ const Summary: FC = ({ classes }) => { 0 ) ?? 0 + const isPackagingItem = useCallback((item: OrderFormItem) => { + const packagingIdentifiers = [ + 'PUNGA HARTIE E-COMMERCE', + 'PUNGA BIO FLEG', + 'Punga transparenta e commerce' + ] + + return packagingIdentifiers.some(identifier => + item.name.toUpperCase().includes(identifier.toUpperCase()) + ) + }, [totalizers, items]) + + useEffect(() => { + let timeoutId: any; + const hasOnlyPackagingAndShipping = () => { + const hasOnlyPackagingItems = items.every(isPackagingItem) + + const hasOnlyShippingTotalizer = totalizers.length === 1 && + totalizers[0].id === 'Shipping' + + const hasShippingAndPackaging = totalizers.length === 2 && + totalizers.some((t: any) => t.id === 'Shipping') && + totalizers.some((t: any) => t.id === 'Items') && + items.every(isPackagingItem) + return hasOnlyPackagingItems && (hasOnlyShippingTotalizer || hasShippingAndPackaging) + } + + if (hasOnlyPackagingAndShipping()) { + timeoutId = setTimeout(() => { + refreshCart() + }, 100) + + } + + return () => clearTimeout(timeoutId) + }, [totalizers, value, items, paymentData, refreshCart, isPackagingItem]) + return (
Date: Fri, 13 Dec 2024 12:04:52 +0200 Subject: [PATCH 6/7] Added changes that fix attachments being duplicated on minicart qty change, refactored totalizers computing logic and added extra catch to calculate totlizers for summary component --- react/ProductList.tsx | 23 +++++++------- react/Summary.tsx | 72 ++++++++----------------------------------- 2 files changed, 24 insertions(+), 71 deletions(-) diff --git a/react/ProductList.tsx b/react/ProductList.tsx index 67297ce3..32e75274 100644 --- a/react/ProductList.tsx +++ b/react/ProductList.tsx @@ -9,16 +9,13 @@ import { mapCartItemToPixel } from './modules/pixelHelper' const CSS_HANDLES = ['minicartProductListContainer'] as const -const options = { - allowedOutdatedData: ['paymentData'], -} - interface Props { renderAsChildren: boolean - classes?: CssHandlesTypes.CustomClasses + classes?: CssHandlesTypes.CustomClasses, + splitItem?: boolean } -const ProductList: FC = ({ renderAsChildren, classes }) => { +const ProductList: FC = ({ renderAsChildren, splitItem = true, classes }) => { const { orderForm: { items }, } = useOrderForm() @@ -26,6 +23,11 @@ const ProductList: FC = ({ renderAsChildren, classes }) => { const { push } = usePixel() const { handles } = useCssHandles(CSS_HANDLES, { classes }) + const options = { + allowedOutdatedData: ['paymentData'], + splitItem, + } + const handleQuantityChange = useCallback( (_: string, quantity: number, item: OrderFormItemWithIndex) => { if (quantity === item.quantity) { @@ -58,7 +60,7 @@ const ProductList: FC = ({ renderAsChildren, classes }) => { updateQuantity({ index: item.index, quantity }, options) }, - [push, updateQuantity] + [options, push, updateQuantity] ) const handleRemove = useCallback( @@ -70,7 +72,7 @@ const ProductList: FC = ({ renderAsChildren, classes }) => { }) removeItem({ uniqueId }, options) }, - [push, removeItem] + [options, push, removeItem] ) return ( @@ -82,9 +84,8 @@ const ProductList: FC = ({ renderAsChildren, classes }) => { in the minicart being closed (when openOnHover = true). */ onMouseLeave={e => e.stopPropagation()} - className={`${handles.minicartProductListContainer} ${ - renderAsChildren ? 'w-100 h-100' : '' - } overflow-y-auto ph4 ph6-l`} + className={`${handles.minicartProductListContainer} ${renderAsChildren ? 'w-100 h-100' : '' + } overflow-y-auto ph4 ph6-l`} > = ({ classes }) => { const { useOrderForm } = OrderFormComponent; + const { useOrderQueue, QueueStatus } = OrderQueue; const orderFormContext = useOrderForm(); const { orderForm: { totalizers, value, items, paymentData }, } = orderFormContext; - - const refreshCart = useCallback(async () => { - await orderFormContext.setOrderForm({ - ...orderFormContext.orderForm, - items: [] // This forces a refresh - }) - }, [orderFormContext]) - + const { listen } = useOrderQueue(); const [finalTotalizers, setFinalTotalizers] = useState(totalizers); - const [isUpdating, setIsUpdating] = useState(false); - - useEffect(() => { - setIsUpdating(true); - const timeoutId = setTimeout(() => setIsUpdating(false), 100); - return () => clearTimeout(timeoutId); - }, [items]); const [packagesSkuIds, setPackagesSkuIds] = useState([]) const [sgrSkuIds, setSgrSkuIds] = useState([]) @@ -99,13 +86,15 @@ const Summary: FC = ({ classes }) => { }, 0) }, [items, sgrSkuIds]) - + listen(QueueStatus.FULFILLED, () => { + computeTotalizers() + }); useEffect(() => { - if (isUpdating) { - return - } + computeTotalizers() + }, [items, flegValue, sgrValue, totalizers]) + const computeTotalizers = () => { if (!items?.length) { setFinalTotalizers([]) return @@ -113,7 +102,6 @@ const Summary: FC = ({ classes }) => { let newTotalizers = JSON.parse(JSON.stringify(totalizers)) - newTotalizers = JSON.parse(JSON.stringify(totalizers)) const totalizerItems = newTotalizers.find((t: { id: string }) => t.id === 'Items') if (flegValue && typeof flegValue === 'number') { @@ -140,8 +128,9 @@ const Summary: FC = ({ classes }) => { totalizerItems.value -= sgrValue ?? 0 } } + setFinalTotalizers(newTotalizers) - }, [totalizers, flegValue, sgrValue, items, value, paymentData, isUpdating]) + } const { handles } = useCssHandles(CSS_HANDLES, { classes }) @@ -153,43 +142,6 @@ const Summary: FC = ({ classes }) => { 0 ) ?? 0 - const isPackagingItem = useCallback((item: OrderFormItem) => { - const packagingIdentifiers = [ - 'PUNGA HARTIE E-COMMERCE', - 'PUNGA BIO FLEG', - 'Punga transparenta e commerce' - ] - - return packagingIdentifiers.some(identifier => - item.name.toUpperCase().includes(identifier.toUpperCase()) - ) - }, [totalizers, items]) - - useEffect(() => { - let timeoutId: any; - const hasOnlyPackagingAndShipping = () => { - const hasOnlyPackagingItems = items.every(isPackagingItem) - - const hasOnlyShippingTotalizer = totalizers.length === 1 && - totalizers[0].id === 'Shipping' - - const hasShippingAndPackaging = totalizers.length === 2 && - totalizers.some((t: any) => t.id === 'Shipping') && - totalizers.some((t: any) => t.id === 'Items') && - items.every(isPackagingItem) - return hasOnlyPackagingItems && (hasOnlyShippingTotalizer || hasShippingAndPackaging) - } - - if (hasOnlyPackagingAndShipping()) { - timeoutId = setTimeout(() => { - refreshCart() - }, 100) - - } - - return () => clearTimeout(timeoutId) - }, [totalizers, value, items, paymentData, refreshCart, isPackagingItem]) - return (
Date: Fri, 13 Dec 2024 12:11:25 +0200 Subject: [PATCH 7/7] Check if only bags or sgr is left in the items array to recompute totalizers for summary --- react/Summary.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/react/Summary.tsx b/react/Summary.tsx index c6331689..23448142 100644 --- a/react/Summary.tsx +++ b/react/Summary.tsx @@ -87,7 +87,14 @@ const Summary: FC = ({ classes }) => { }, [items, sgrSkuIds]) listen(QueueStatus.FULFILLED, () => { - computeTotalizers() + const onlySgrOrBags = items.every( + (item: any) => + sgrSkuIds.includes(item.id) || packagesSkuIds.includes(item.id) + ) + + if (onlySgrOrBags) { + computeTotalizers() + } }); useEffect(() => {