@salesforce/retail-react-app 1.0.0-preview.0
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/.eslintignore +7 -0
- package/.eslintrc.js +25 -0
- package/.prettierignore +4 -0
- package/.prettierrc.yaml +7 -0
- package/CHANGELOG.md +173 -0
- package/LICENSE +14 -0
- package/README.md +48 -0
- package/app/assets/svg/account.svg +3 -0
- package/app/assets/svg/alert.svg +3 -0
- package/app/assets/svg/basket.svg +3 -0
- package/app/assets/svg/brand-logo.svg +10 -0
- package/app/assets/svg/cc-amex.svg +7 -0
- package/app/assets/svg/cc-cvv.svg +8 -0
- package/app/assets/svg/cc-discover.svg +14 -0
- package/app/assets/svg/cc-mastercard.svg +8 -0
- package/app/assets/svg/cc-visa.svg +11 -0
- package/app/assets/svg/check-circle.svg +3 -0
- package/app/assets/svg/check.svg +3 -0
- package/app/assets/svg/chevron-down.svg +3 -0
- package/app/assets/svg/chevron-left.svg +3 -0
- package/app/assets/svg/chevron-right.svg +3 -0
- package/app/assets/svg/chevron-up.svg +3 -0
- package/app/assets/svg/close.svg +3 -0
- package/app/assets/svg/dashboard.svg +4 -0
- package/app/assets/svg/figma-logo.svg +14 -0
- package/app/assets/svg/file.svg +3 -0
- package/app/assets/svg/filter.svg +3 -0
- package/app/assets/svg/flag-ca.svg +5 -0
- package/app/assets/svg/flag-cn.svg +19 -0
- package/app/assets/svg/flag-fr.svg +19 -0
- package/app/assets/svg/flag-gb.svg +16 -0
- package/app/assets/svg/flag-it.svg +29 -0
- package/app/assets/svg/flag-jp.svg +10 -0
- package/app/assets/svg/flag-us.svg +7 -0
- package/app/assets/svg/github-logo.svg +40 -0
- package/app/assets/svg/hamburger.svg +8 -0
- package/app/assets/svg/heart-solid.svg +7 -0
- package/app/assets/svg/heart.svg +3 -0
- package/app/assets/svg/info.svg +3 -0
- package/app/assets/svg/like.svg +4 -0
- package/app/assets/svg/location.svg +3 -0
- package/app/assets/svg/lock.svg +3 -0
- package/app/assets/svg/paypal.svg +19 -0
- package/app/assets/svg/plug.svg +3 -0
- package/app/assets/svg/plus.svg +3 -0
- package/app/assets/svg/receipt.svg +3 -0
- package/app/assets/svg/search.svg +8 -0
- package/app/assets/svg/signout.svg +3 -0
- package/app/assets/svg/social-facebook.svg +3 -0
- package/app/assets/svg/social-instagram.svg +3 -0
- package/app/assets/svg/social-pinterest.svg +4 -0
- package/app/assets/svg/social-twitter.svg +3 -0
- package/app/assets/svg/social-youtube.svg +3 -0
- package/app/assets/svg/user.svg +3 -0
- package/app/assets/svg/visibility-off.svg +5 -0
- package/app/assets/svg/visibility.svg +3 -0
- package/app/components/_app/index.jsx +401 -0
- package/app/components/_app/index.test.js +85 -0
- package/app/components/_app/partials/above-header.jsx +10 -0
- package/app/components/_app-config/index.jsx +125 -0
- package/app/components/_app-config/index.test.js +77 -0
- package/app/components/_error/index.jsx +142 -0
- package/app/components/_error/index.test.js +25 -0
- package/app/components/action-card/index.jsx +75 -0
- package/app/components/address-display/index.jsx +30 -0
- package/app/components/basic-tile/index.jsx +65 -0
- package/app/components/basic-tile/index.test.js +23 -0
- package/app/components/breadcrumb/index.jsx +67 -0
- package/app/components/breadcrumb/index.test.js +30 -0
- package/app/components/confirmation-modal/index.jsx +111 -0
- package/app/components/confirmation-modal/index.test.js +98 -0
- package/app/components/drawer-menu/index.jsx +405 -0
- package/app/components/drawer-menu/index.test.js +33 -0
- package/app/components/dynamic-image/index.jsx +56 -0
- package/app/components/field/index.jsx +161 -0
- package/app/components/footer/index.jsx +269 -0
- package/app/components/footer/index.test.js +22 -0
- package/app/components/forms/address-fields.jsx +49 -0
- package/app/components/forms/credit-card-fields.jsx +149 -0
- package/app/components/forms/form-action-buttons.jsx +55 -0
- package/app/components/forms/login-fields.jsx +31 -0
- package/app/components/forms/password-requirements.jsx +99 -0
- package/app/components/forms/post-checkout-registration-fields.jsx +43 -0
- package/app/components/forms/profile-fields.jsx +36 -0
- package/app/components/forms/promo-code-fields.jsx +43 -0
- package/app/components/forms/registration-fields.jsx +42 -0
- package/app/components/forms/reset-password-fields.jsx +31 -0
- package/app/components/forms/state-province-options.jsx +75 -0
- package/app/components/forms/update-password-fields.jsx +49 -0
- package/app/components/forms/useAddressFields.jsx +196 -0
- package/app/components/forms/useCreditCardFields.jsx +146 -0
- package/app/components/forms/useLoginFields.jsx +52 -0
- package/app/components/forms/useProfileFields.jsx +95 -0
- package/app/components/forms/usePromoCodeFields.jsx +39 -0
- package/app/components/forms/useRegistrationFields.jsx +136 -0
- package/app/components/forms/useResetPasswordFields.jsx +40 -0
- package/app/components/forms/useUpdatePasswordFields.jsx +89 -0
- package/app/components/header/index.jsx +290 -0
- package/app/components/header/index.test.js +217 -0
- package/app/components/hero/index.jsx +84 -0
- package/app/components/hero/index.test.js +40 -0
- package/app/components/icons/index.jsx +158 -0
- package/app/components/icons/index.test.js +20 -0
- package/app/components/image-gallery/index.jsx +176 -0
- package/app/components/image-gallery/index.test.js +485 -0
- package/app/components/item-variant/index.jsx +33 -0
- package/app/components/item-variant/item-attributes.jsx +107 -0
- package/app/components/item-variant/item-image.jsx +73 -0
- package/app/components/item-variant/item-name.jsx +28 -0
- package/app/components/item-variant/item-price.jsx +117 -0
- package/app/components/link/index.jsx +32 -0
- package/app/components/link/index.test.js +72 -0
- package/app/components/links-list/index.jsx +89 -0
- package/app/components/links-list/index.test.js +62 -0
- package/app/components/list-menu/index.jsx +280 -0
- package/app/components/list-menu/index.test.js +44 -0
- package/app/components/loading-spinner/index.jsx +46 -0
- package/app/components/locale-selector/index.jsx +124 -0
- package/app/components/locale-selector/index.test.js +37 -0
- package/app/components/locale-text/index.jsx +97 -0
- package/app/components/locale-text/index.test.js +36 -0
- package/app/components/login/index.jsx +96 -0
- package/app/components/nested-accordion/index.jsx +185 -0
- package/app/components/nested-accordion/index.test.js +98 -0
- package/app/components/offline-banner/index.jsx +40 -0
- package/app/components/offline-banner/index.test.js +15 -0
- package/app/components/offline-boundary/index.jsx +104 -0
- package/app/components/offline-boundary/index.test.js +123 -0
- package/app/components/order-summary/index.jsx +331 -0
- package/app/components/page-action-placeholder/index.jsx +50 -0
- package/app/components/pagination/index.jsx +134 -0
- package/app/components/pagination/index.test.js +25 -0
- package/app/components/product-item/index.jsx +146 -0
- package/app/components/product-item/index.test.js +38 -0
- package/app/components/product-scroller/index.jsx +172 -0
- package/app/components/product-scroller/index.test.js +98 -0
- package/app/components/product-tile/index.jsx +195 -0
- package/app/components/product-tile/index.test.js +96 -0
- package/app/components/product-view/index.jsx +538 -0
- package/app/components/product-view/index.test.js +224 -0
- package/app/components/product-view-modal/index.jsx +48 -0
- package/app/components/product-view-modal/index.test.js +72 -0
- package/app/components/promo-code/index.jsx +162 -0
- package/app/components/promo-popover/index.jsx +83 -0
- package/app/components/quantity-picker/index.jsx +58 -0
- package/app/components/radio-card/index.jsx +75 -0
- package/app/components/recommended-products/index.jsx +227 -0
- package/app/components/register/index.jsx +114 -0
- package/app/components/reset-password/index.jsx +87 -0
- package/app/components/responsive/index.jsx +29 -0
- package/app/components/scroll-to-top/index.jsx +24 -0
- package/app/components/scroll-to-top/index.test.js +46 -0
- package/app/components/search/index.jsx +279 -0
- package/app/components/search/index.test.js +127 -0
- package/app/components/search/partials/recent-searches.jsx +76 -0
- package/app/components/search/partials/search-suggestions.jsx +45 -0
- package/app/components/search/partials/suggestions.jsx +43 -0
- package/app/components/section/index.jsx +68 -0
- package/app/components/seo/index.jsx +33 -0
- package/app/components/social-icons/index.jsx +101 -0
- package/app/components/social-icons/index.test.js +30 -0
- package/app/components/swatch-group/index.jsx +77 -0
- package/app/components/swatch-group/index.test.js +136 -0
- package/app/components/swatch-group/swatch.jsx +94 -0
- package/app/components/toggle-card/index.jsx +97 -0
- package/app/components/with-registration/index.jsx +58 -0
- package/app/components/with-registration/index.test.js +85 -0
- package/app/constants.js +109 -0
- package/app/contexts/index.js +92 -0
- package/app/hooks/einstein-mock-data.js +916 -0
- package/app/hooks/index.js +17 -0
- package/app/hooks/use-add-to-cart-modal.js +344 -0
- package/app/hooks/use-add-to-cart-modal.test.js +625 -0
- package/app/hooks/use-auth-modal.js +337 -0
- package/app/hooks/use-auth-modal.test.js +365 -0
- package/app/hooks/use-currency.js +20 -0
- package/app/hooks/use-currency.test.js +41 -0
- package/app/hooks/use-current-basket.js +39 -0
- package/app/hooks/use-current-customer.js +29 -0
- package/app/hooks/use-derived-product.js +77 -0
- package/app/hooks/use-derived-product.test.js +69 -0
- package/app/hooks/use-einstein.js +512 -0
- package/app/hooks/use-einstein.test.js +224 -0
- package/app/hooks/use-intersection-observer.js +64 -0
- package/app/hooks/use-limit-urls.js +31 -0
- package/app/hooks/use-limit-urls.test.js +40 -0
- package/app/hooks/use-multi-site.js +36 -0
- package/app/hooks/use-multi-site.test.js +53 -0
- package/app/hooks/use-navigation.js +37 -0
- package/app/hooks/use-navigation.test.js +109 -0
- package/app/hooks/use-page-urls.js +35 -0
- package/app/hooks/use-page-urls.test.js +39 -0
- package/app/hooks/use-pdp-search-params.js +16 -0
- package/app/hooks/use-pdp-search-params.test.js +52 -0
- package/app/hooks/use-previous.js +17 -0
- package/app/hooks/use-product-view-modal.js +93 -0
- package/app/hooks/use-product-view-modal.test.js +172 -0
- package/app/hooks/use-search-params.js +96 -0
- package/app/hooks/use-search-params.test.js +91 -0
- package/app/hooks/use-sort-urls.js +33 -0
- package/app/hooks/use-sort-urls.test.js +42 -0
- package/app/hooks/use-toast.js +68 -0
- package/app/hooks/use-toast.test.js +58 -0
- package/app/hooks/use-variant.js +32 -0
- package/app/hooks/use-variant.test.js +81 -0
- package/app/hooks/use-variation-attributes.js +138 -0
- package/app/hooks/use-variation-attributes.test.js +119 -0
- package/app/hooks/use-variation-params.js +31 -0
- package/app/hooks/use-variation-params.test.js +73 -0
- package/app/hooks/use-wish-list.js +42 -0
- package/app/main.jsx +14 -0
- package/app/mocks/basket-with-suit.js +146 -0
- package/app/mocks/empty-basket.js +39 -0
- package/app/mocks/mock-data.js +5632 -0
- package/app/mocks/product-set-winter-lookM.js +1224 -0
- package/app/mocks/searchResults.js +144 -0
- package/app/mocks/variant-750518699578M.js +434 -0
- package/app/page-designer/README.md +102 -0
- package/app/page-designer/assets/image-tile/index.jsx +51 -0
- package/app/page-designer/assets/image-tile/index.test.js +30 -0
- package/app/page-designer/assets/image-with-text/index.jsx +140 -0
- package/app/page-designer/assets/image-with-text/index.test.js +38 -0
- package/app/page-designer/assets/index.js +9 -0
- package/app/page-designer/index.js +10 -0
- package/app/page-designer/layouts/carousel/index.jsx +222 -0
- package/app/page-designer/layouts/carousel/index.test.js +43 -0
- package/app/page-designer/layouts/index.js +14 -0
- package/app/page-designer/layouts/mobileGrid1r1c/index.jsx +36 -0
- package/app/page-designer/layouts/mobileGrid1r1c/index.test.js +35 -0
- package/app/page-designer/layouts/mobileGrid2r1c/index.jsx +37 -0
- package/app/page-designer/layouts/mobileGrid2r1c/index.test.js +47 -0
- package/app/page-designer/layouts/mobileGrid2r2c/index.jsx +37 -0
- package/app/page-designer/layouts/mobileGrid2r2c/index.test.js +71 -0
- package/app/page-designer/layouts/mobileGrid2r3c/index.jsx +37 -0
- package/app/page-designer/layouts/mobileGrid2r3c/index.test.js +95 -0
- package/app/page-designer/layouts/mobileGrid3r1c/index.jsx +37 -0
- package/app/page-designer/layouts/mobileGrid3r1c/index.test.js +59 -0
- package/app/page-designer/layouts/mobileGrid3r2c/index.jsx +37 -0
- package/app/page-designer/layouts/mobileGrid3r2c/index.test.js +95 -0
- package/app/page-designer/utils.js +14 -0
- package/app/pages/account/addresses.jsx +382 -0
- package/app/pages/account/addresses.test.js +120 -0
- package/app/pages/account/constant.js +57 -0
- package/app/pages/account/index.jsx +237 -0
- package/app/pages/account/index.test.js +188 -0
- package/app/pages/account/order-detail.jsx +397 -0
- package/app/pages/account/order-history.jsx +264 -0
- package/app/pages/account/orders.jsx +30 -0
- package/app/pages/account/orders.test.js +95 -0
- package/app/pages/account/profile.jsx +357 -0
- package/app/pages/account/wishlist/index.jsx +195 -0
- package/app/pages/account/wishlist/index.mock.js +1481 -0
- package/app/pages/account/wishlist/index.test.js +56 -0
- package/app/pages/account/wishlist/partials/wishlist-primary-action.jsx +170 -0
- package/app/pages/account/wishlist/partials/wishlist-primary-action.mock.js +1623 -0
- package/app/pages/account/wishlist/partials/wishlist-primary-action.test.js +99 -0
- package/app/pages/account/wishlist/partials/wishlist-secondary-button-group.jsx +120 -0
- package/app/pages/account/wishlist/partials/wishlist-secondary-button-group.test.js +391 -0
- package/app/pages/cart/index.jsx +476 -0
- package/app/pages/cart/index.test.js +481 -0
- package/app/pages/cart/partials/cart-cta.jsx +46 -0
- package/app/pages/cart/partials/cart-secondary-button-group.jsx +135 -0
- package/app/pages/cart/partials/cart-secondary-button-group.test.js +103 -0
- package/app/pages/cart/partials/cart-skeleton.jsx +93 -0
- package/app/pages/cart/partials/cart-title.jsx +27 -0
- package/app/pages/cart/partials/empty-cart.jsx +86 -0
- package/app/pages/checkout/confirmation.jsx +541 -0
- package/app/pages/checkout/confirmation.mock.js +450 -0
- package/app/pages/checkout/confirmation.test.js +114 -0
- package/app/pages/checkout/index.jsx +169 -0
- package/app/pages/checkout/index.test.js +582 -0
- package/app/pages/checkout/partials/cc-radio-group.jsx +122 -0
- package/app/pages/checkout/partials/checkout-footer.jsx +140 -0
- package/app/pages/checkout/partials/checkout-footer.test.js +16 -0
- package/app/pages/checkout/partials/checkout-header.jsx +54 -0
- package/app/pages/checkout/partials/checkout-header.test.js +16 -0
- package/app/pages/checkout/partials/checkout-skeleton.jsx +52 -0
- package/app/pages/checkout/partials/contact-info.jsx +251 -0
- package/app/pages/checkout/partials/contact-info.test.js +43 -0
- package/app/pages/checkout/partials/payment-form.jsx +97 -0
- package/app/pages/checkout/partials/payment.jsx +276 -0
- package/app/pages/checkout/partials/shipping-address-selection.jsx +377 -0
- package/app/pages/checkout/partials/shipping-address.jsx +132 -0
- package/app/pages/checkout/partials/shipping-options.jsx +232 -0
- package/app/pages/checkout/util/checkout-context.js +94 -0
- package/app/pages/home/data.js +134 -0
- package/app/pages/home/index.jsx +301 -0
- package/app/pages/home/index.test.js +23 -0
- package/app/pages/login/index.jsx +123 -0
- package/app/pages/login/index.test.js +229 -0
- package/app/pages/login-redirect/index.jsx +23 -0
- package/app/pages/login-redirect/index.test.js +16 -0
- package/app/pages/page-not-found/index.jsx +90 -0
- package/app/pages/page-not-found/index.test.js +31 -0
- package/app/pages/product-detail/index.jsx +394 -0
- package/app/pages/product-detail/index.mock.js +197 -0
- package/app/pages/product-detail/index.test.js +162 -0
- package/app/pages/product-detail/partials/information-accordion.jsx +121 -0
- package/app/pages/product-list/index.jsx +735 -0
- package/app/pages/product-list/index.test.js +180 -0
- package/app/pages/product-list/partials/above-page-header.jsx +10 -0
- package/app/pages/product-list/partials/checkbox-refinements.jsx +41 -0
- package/app/pages/product-list/partials/checkbox-refinements.test.js +53 -0
- package/app/pages/product-list/partials/color-refinements.jsx +88 -0
- package/app/pages/product-list/partials/empty-results.jsx +118 -0
- package/app/pages/product-list/partials/link-refinements.jsx +38 -0
- package/app/pages/product-list/partials/page-header.jsx +42 -0
- package/app/pages/product-list/partials/radio-refinements.jsx +60 -0
- package/app/pages/product-list/partials/refinements.jsx +144 -0
- package/app/pages/product-list/partials/selected-refinements.jsx +100 -0
- package/app/pages/product-list/partials/size-refinements.jsx +55 -0
- package/app/pages/registration/index.jsx +87 -0
- package/app/pages/registration/index.test.jsx +132 -0
- package/app/pages/reset-password/index.jsx +112 -0
- package/app/pages/reset-password/index.test.jsx +141 -0
- package/app/request-processor.js +118 -0
- package/app/request-processor.test.js +23 -0
- package/app/routes.jsx +111 -0
- package/app/routes.test.js +13 -0
- package/app/ssr.js +70 -0
- package/app/static/ico/favicon.ico +0 -0
- package/app/static/img/global/app-icon-192.png +0 -0
- package/app/static/img/global/app-icon-512.png +0 -0
- package/app/static/img/global/apple-touch-icon.png +0 -0
- package/app/static/img/hero.png +0 -0
- package/app/static/manifest.json +19 -0
- package/app/static/robots.txt +2 -0
- package/app/theme/components/base/accordion.js +21 -0
- package/app/theme/components/base/alert.js +17 -0
- package/app/theme/components/base/badge.js +25 -0
- package/app/theme/components/base/button.js +77 -0
- package/app/theme/components/base/checkbox.js +30 -0
- package/app/theme/components/base/container.js +17 -0
- package/app/theme/components/base/drawer.js +26 -0
- package/app/theme/components/base/formLabel.js +13 -0
- package/app/theme/components/base/icon.js +13 -0
- package/app/theme/components/base/input.js +44 -0
- package/app/theme/components/base/modal.js +11 -0
- package/app/theme/components/base/popover.js +61 -0
- package/app/theme/components/base/radio.js +33 -0
- package/app/theme/components/base/select.js +15 -0
- package/app/theme/components/base/skeleton.js +12 -0
- package/app/theme/components/base/tooltip.js +19 -0
- package/app/theme/components/project/_app.js +25 -0
- package/app/theme/components/project/breadcrumb.js +25 -0
- package/app/theme/components/project/checkout-footer.js +35 -0
- package/app/theme/components/project/drawer-menu.js +66 -0
- package/app/theme/components/project/footer.js +84 -0
- package/app/theme/components/project/header.js +84 -0
- package/app/theme/components/project/image-gallery.js +59 -0
- package/app/theme/components/project/links-list.js +43 -0
- package/app/theme/components/project/list-menu.js +91 -0
- package/app/theme/components/project/locale-selector.js +42 -0
- package/app/theme/components/project/nested-accordion.js +26 -0
- package/app/theme/components/project/offline-banner.js +25 -0
- package/app/theme/components/project/pagination.js +22 -0
- package/app/theme/components/project/product-tile.js +32 -0
- package/app/theme/components/project/social-icons.js +52 -0
- package/app/theme/components/project/swatch-group.js +115 -0
- package/app/theme/foundations/colors.js +170 -0
- package/app/theme/foundations/gradients.js +9 -0
- package/app/theme/foundations/layerStyles.js +41 -0
- package/app/theme/foundations/shadows.js +9 -0
- package/app/theme/foundations/sizes.js +18 -0
- package/app/theme/foundations/space.js +9 -0
- package/app/theme/foundations/styles.js +21 -0
- package/app/theme/index.js +104 -0
- package/app/utils/cc-utils.js +112 -0
- package/app/utils/cc-utils.test.js +41 -0
- package/app/utils/image-groups-utils.js +62 -0
- package/app/utils/image-groups-utils.test.js +65 -0
- package/app/utils/locale.js +78 -0
- package/app/utils/locale.test.js +112 -0
- package/app/utils/password-utils.js +21 -0
- package/app/utils/phone-utils.js +22 -0
- package/app/utils/phone-utils.test.js +15 -0
- package/app/utils/product-utils.js +35 -0
- package/app/utils/product-utils.test.js +51 -0
- package/app/utils/responsive-image.js +198 -0
- package/app/utils/responsive-image.test.js +170 -0
- package/app/utils/routes-utils.js +111 -0
- package/app/utils/routes-utils.test.js +291 -0
- package/app/utils/site-utils.js +222 -0
- package/app/utils/site-utils.test.js +376 -0
- package/app/utils/test-utils.js +257 -0
- package/app/utils/url.js +291 -0
- package/app/utils/url.test.js +421 -0
- package/app/utils/utils.js +201 -0
- package/app/utils/utils.test.js +182 -0
- package/babel.config.js +7 -0
- package/cache-hash-config.json +8 -0
- package/config/default.js +64 -0
- package/config/mocks/default.js +131 -0
- package/config/sites.js +78 -0
- package/jest-setup.js +191 -0
- package/jest.config.js +50 -0
- package/jsconfig.json +13 -0
- package/package.json +105 -0
- package/scripts/extract-default-messages.js +92 -0
- package/tests/lighthouserc.js +37 -0
- package/translations/README.md +127 -0
- package/translations/compiled/de-DE.json +3212 -0
- package/translations/compiled/en-GB.json +3212 -0
- package/translations/compiled/en-US.json +3212 -0
- package/translations/compiled/en-XA.json +6948 -0
- package/translations/compiled/es-MX.json +3216 -0
- package/translations/compiled/fr-FR.json +3216 -0
- package/translations/compiled/it-IT.json +3188 -0
- package/translations/compiled/ja-JP.json +3200 -0
- package/translations/compiled/ko-KR.json +3180 -0
- package/translations/compiled/pt-BR.json +3220 -0
- package/translations/compiled/zh-CN.json +3212 -0
- package/translations/compiled/zh-TW.json +3208 -0
- package/translations/de-DE.json +1417 -0
- package/translations/en-GB.json +1417 -0
- package/translations/en-US.json +1417 -0
- package/translations/es-MX.json +1417 -0
- package/translations/fr-FR.json +1417 -0
- package/translations/it-IT.json +1417 -0
- package/translations/ja-JP.json +1417 -0
- package/translations/ko-KR.json +1417 -0
- package/translations/pt-BR.json +1417 -0
- package/translations/zh-CN.json +1417 -0
- package/translations/zh-TW.json +1417 -0
- package/worker/main.js +36 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
import {FormattedMessage} from 'react-intl'
|
|
10
|
+
import {Box, Button, Stack, Text, SimpleGrid, FormControl, FormErrorMessage} from '@chakra-ui/react'
|
|
11
|
+
import {PlusIcon} from '@salesforce/retail-react-app/app/components/icons'
|
|
12
|
+
import {RadioCard, RadioCardGroup} from '@salesforce/retail-react-app/app/components/radio-card'
|
|
13
|
+
import {getCreditCardIcon} from '@salesforce/retail-react-app/app/utils/cc-utils'
|
|
14
|
+
import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer'
|
|
15
|
+
|
|
16
|
+
const CCRadioGroup = ({
|
|
17
|
+
form,
|
|
18
|
+
value = '',
|
|
19
|
+
isEditingPayment = false,
|
|
20
|
+
togglePaymentEdit = () => null,
|
|
21
|
+
onPaymentIdChange = () => null
|
|
22
|
+
}) => {
|
|
23
|
+
const {data: customer} = useCurrentCustomer()
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<FormControl
|
|
27
|
+
id="paymentInstrumentId"
|
|
28
|
+
isInvalid={form.formState.errors.paymentInstrumentId}
|
|
29
|
+
isRequired={!isEditingPayment}
|
|
30
|
+
>
|
|
31
|
+
{form.formState.errors.paymentInstrumentId && (
|
|
32
|
+
<FormErrorMessage marginTop={0} marginBottom={4}>
|
|
33
|
+
{form.formState.errors.paymentInstrumentId.message}
|
|
34
|
+
</FormErrorMessage>
|
|
35
|
+
)}
|
|
36
|
+
|
|
37
|
+
<RadioCardGroup value={value} onChange={onPaymentIdChange}>
|
|
38
|
+
<Stack spacing={4}>
|
|
39
|
+
<SimpleGrid columns={[1, 1, 2]} spacing={4}>
|
|
40
|
+
{customer.paymentInstruments?.map((payment) => {
|
|
41
|
+
const CardIcon = getCreditCardIcon(payment.paymentCard?.cardType)
|
|
42
|
+
return (
|
|
43
|
+
<RadioCard
|
|
44
|
+
key={payment.paymentInstrumentId}
|
|
45
|
+
value={payment.paymentInstrumentId}
|
|
46
|
+
>
|
|
47
|
+
<Stack direction="row">
|
|
48
|
+
{CardIcon && <CardIcon layerStyle="ccIcon" />}
|
|
49
|
+
<Stack spacing={4}>
|
|
50
|
+
<Stack spacing={1}>
|
|
51
|
+
<Text>{payment.paymentCard?.cardType}</Text>
|
|
52
|
+
<Stack direction="row">
|
|
53
|
+
<Text>
|
|
54
|
+
••••{' '}
|
|
55
|
+
{payment.paymentCard?.numberLastDigits}
|
|
56
|
+
</Text>
|
|
57
|
+
<Text>
|
|
58
|
+
{payment.paymentCard?.expirationMonth}/
|
|
59
|
+
{payment.paymentCard?.expirationYear}
|
|
60
|
+
</Text>
|
|
61
|
+
</Stack>
|
|
62
|
+
<Text>{payment.paymentCard.holder}</Text>
|
|
63
|
+
</Stack>
|
|
64
|
+
|
|
65
|
+
<Box>
|
|
66
|
+
<Button variant="link" size="sm" colorScheme="red">
|
|
67
|
+
<FormattedMessage
|
|
68
|
+
defaultMessage="Remove"
|
|
69
|
+
id="cc_radio_group.action.remove"
|
|
70
|
+
/>
|
|
71
|
+
</Button>
|
|
72
|
+
</Box>
|
|
73
|
+
</Stack>
|
|
74
|
+
</Stack>
|
|
75
|
+
</RadioCard>
|
|
76
|
+
)
|
|
77
|
+
})}
|
|
78
|
+
|
|
79
|
+
{!isEditingPayment && (
|
|
80
|
+
<Button
|
|
81
|
+
variant="outline"
|
|
82
|
+
border="1px dashed"
|
|
83
|
+
borderColor="gray.200"
|
|
84
|
+
color="blue.600"
|
|
85
|
+
height={{lg: 'full'}}
|
|
86
|
+
minHeight={['44px', '44px', '154px']}
|
|
87
|
+
rounded="base"
|
|
88
|
+
fontWeight="medium"
|
|
89
|
+
leftIcon={<PlusIcon boxSize={'15px'} />}
|
|
90
|
+
onClick={togglePaymentEdit}
|
|
91
|
+
>
|
|
92
|
+
<FormattedMessage
|
|
93
|
+
defaultMessage="Add New Card"
|
|
94
|
+
id="cc_radio_group.button.add_new_card"
|
|
95
|
+
/>
|
|
96
|
+
</Button>
|
|
97
|
+
)}
|
|
98
|
+
</SimpleGrid>
|
|
99
|
+
</Stack>
|
|
100
|
+
</RadioCardGroup>
|
|
101
|
+
</FormControl>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
CCRadioGroup.propTypes = {
|
|
106
|
+
/** The form object returned from `useForm` */
|
|
107
|
+
form: PropTypes.object.isRequired,
|
|
108
|
+
|
|
109
|
+
/** The current payment ID value */
|
|
110
|
+
value: PropTypes.string,
|
|
111
|
+
|
|
112
|
+
/** Flag for payment add/edit form, used for setting validation rules */
|
|
113
|
+
isEditingPayment: PropTypes.bool,
|
|
114
|
+
|
|
115
|
+
/** Method for toggling the payment add/edit form */
|
|
116
|
+
togglePaymentEdit: PropTypes.func,
|
|
117
|
+
|
|
118
|
+
/** Callback for notifying on value change */
|
|
119
|
+
onPaymentIdChange: PropTypes.func
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default CCRadioGroup
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
import {useIntl} from 'react-intl'
|
|
10
|
+
import {
|
|
11
|
+
Box,
|
|
12
|
+
StylesProvider,
|
|
13
|
+
useMultiStyleConfig,
|
|
14
|
+
Divider,
|
|
15
|
+
Text,
|
|
16
|
+
HStack,
|
|
17
|
+
Flex,
|
|
18
|
+
Spacer,
|
|
19
|
+
useStyles
|
|
20
|
+
} from '@chakra-ui/react'
|
|
21
|
+
import LinksList from '@salesforce/retail-react-app/app/components/links-list'
|
|
22
|
+
import {
|
|
23
|
+
VisaIcon,
|
|
24
|
+
MastercardIcon,
|
|
25
|
+
AmexIcon,
|
|
26
|
+
DiscoverIcon
|
|
27
|
+
} from '@salesforce/retail-react-app/app/components/icons'
|
|
28
|
+
import {HideOnDesktop, HideOnMobile} from '@salesforce/retail-react-app/app/components/responsive'
|
|
29
|
+
|
|
30
|
+
const CheckoutFooter = ({...otherProps}) => {
|
|
31
|
+
const styles = useMultiStyleConfig('CheckoutFooter')
|
|
32
|
+
const intl = useIntl()
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Box as="footer" {...styles.container} {...otherProps}>
|
|
36
|
+
<Box {...styles.content}>
|
|
37
|
+
<StylesProvider value={styles}>
|
|
38
|
+
<LinksList
|
|
39
|
+
links={[
|
|
40
|
+
{
|
|
41
|
+
href: '/',
|
|
42
|
+
text: intl.formatMessage({
|
|
43
|
+
id: 'checkout_footer.link.shipping',
|
|
44
|
+
defaultMessage: 'Shipping'
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
href: '/',
|
|
49
|
+
text: intl.formatMessage({
|
|
50
|
+
id: 'checkout_footer.link.returns_exchanges',
|
|
51
|
+
defaultMessage: 'Returns & Exchanges'
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
]}
|
|
55
|
+
{...styles.customerService}
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
<HideOnDesktop>
|
|
59
|
+
<CreditCardIcons marginTop={4} marginBottom={4} />
|
|
60
|
+
</HideOnDesktop>
|
|
61
|
+
|
|
62
|
+
<Divider {...styles.horizontalRule} />
|
|
63
|
+
|
|
64
|
+
<Box {...styles.bottomHalf}>
|
|
65
|
+
<Text {...styles.copyright}>
|
|
66
|
+
© {new Date().getFullYear()}{' '}
|
|
67
|
+
{intl.formatMessage({
|
|
68
|
+
id: 'checkout_footer.message.copyright',
|
|
69
|
+
defaultMessage:
|
|
70
|
+
'Salesforce or its affiliates. All rights reserved. This is a demo store only. Orders made WILL NOT be processed.'
|
|
71
|
+
})}
|
|
72
|
+
</Text>
|
|
73
|
+
|
|
74
|
+
<HideOnDesktop>
|
|
75
|
+
<LegalLinks variant="vertical" />
|
|
76
|
+
</HideOnDesktop>
|
|
77
|
+
<HideOnMobile>
|
|
78
|
+
<Flex>
|
|
79
|
+
<LegalLinks variant="horizontal" />
|
|
80
|
+
<Spacer />
|
|
81
|
+
<CreditCardIcons />
|
|
82
|
+
</Flex>
|
|
83
|
+
</HideOnMobile>
|
|
84
|
+
</Box>
|
|
85
|
+
</StylesProvider>
|
|
86
|
+
</Box>
|
|
87
|
+
</Box>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default CheckoutFooter
|
|
92
|
+
|
|
93
|
+
const LegalLinks = ({variant}) => {
|
|
94
|
+
const intl = useIntl()
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<LinksList
|
|
98
|
+
links={[
|
|
99
|
+
{
|
|
100
|
+
href: '/',
|
|
101
|
+
text: intl.formatMessage({
|
|
102
|
+
id: 'checkout_footer.link.terms_conditions',
|
|
103
|
+
defaultMessage: 'Terms & Conditions'
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
href: '/',
|
|
108
|
+
text: intl.formatMessage({
|
|
109
|
+
id: 'checkout_footer.link.privacy_policy',
|
|
110
|
+
defaultMessage: 'Privacy Policy'
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
href: '/',
|
|
115
|
+
text: intl.formatMessage({
|
|
116
|
+
id: 'checkout_footer.link.site_map',
|
|
117
|
+
defaultMessage: 'Site Map'
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
]}
|
|
121
|
+
color="gray.200"
|
|
122
|
+
variant={variant}
|
|
123
|
+
/>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
LegalLinks.propTypes = {
|
|
127
|
+
variant: PropTypes.oneOf(['vertical', 'horizontal'])
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const CreditCardIcons = (props) => {
|
|
131
|
+
const styles = useStyles()
|
|
132
|
+
return (
|
|
133
|
+
<HStack sizing={2} {...props}>
|
|
134
|
+
<VisaIcon {...styles.creditCardIcon} />
|
|
135
|
+
<MastercardIcon {...styles.creditCardIcon} />
|
|
136
|
+
<AmexIcon {...styles.creditCardIcon} />
|
|
137
|
+
<DiscoverIcon {...styles.creditCardIcon} />
|
|
138
|
+
</HStack>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import {screen} from '@testing-library/react'
|
|
9
|
+
|
|
10
|
+
import CheckoutFooter from '@salesforce/retail-react-app/app/pages/checkout/partials/checkout-footer'
|
|
11
|
+
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
|
|
12
|
+
|
|
13
|
+
test('renders component', () => {
|
|
14
|
+
renderWithProviders(<CheckoutFooter />)
|
|
15
|
+
expect(screen.getByRole('link', {name: 'Shipping'})).toBeInTheDocument()
|
|
16
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import {FormattedMessage} from 'react-intl'
|
|
9
|
+
import {Badge, Box, Button, Flex, Center} from '@chakra-ui/react'
|
|
10
|
+
import Link from '@salesforce/retail-react-app/app/components/link'
|
|
11
|
+
import {BasketIcon, BrandLogo} from '@salesforce/retail-react-app/app/components/icons'
|
|
12
|
+
import {HOME_HREF} from '@salesforce/retail-react-app/app/constants'
|
|
13
|
+
import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket'
|
|
14
|
+
|
|
15
|
+
const CheckoutHeader = () => {
|
|
16
|
+
const {
|
|
17
|
+
derivedData: {totalItems}
|
|
18
|
+
} = useCurrentBasket()
|
|
19
|
+
return (
|
|
20
|
+
<Box px={[4, 4, 8]} bg="white" borderBottom="1px" borderColor="gray.100">
|
|
21
|
+
<Box maxWidth="container.xxxl" marginLeft="auto" marginRight="auto">
|
|
22
|
+
<Flex h={{base: '52px', md: '80px'}} align="center" justify="space-between">
|
|
23
|
+
<Link href={HOME_HREF} title="Back to homepage">
|
|
24
|
+
<BrandLogo
|
|
25
|
+
width={{base: '35px', md: '45px'}}
|
|
26
|
+
height={{base: '24px', md: '32px'}}
|
|
27
|
+
/>
|
|
28
|
+
</Link>
|
|
29
|
+
|
|
30
|
+
<Button
|
|
31
|
+
as={Link}
|
|
32
|
+
href="/cart"
|
|
33
|
+
display="inline-flex"
|
|
34
|
+
variant="unstyled"
|
|
35
|
+
color="gray.900"
|
|
36
|
+
rightIcon={
|
|
37
|
+
<Center position="relative" width={11} height={11}>
|
|
38
|
+
<BasketIcon position="absolute" left="0px" />
|
|
39
|
+
<Badge variant="notification">{totalItems}</Badge>
|
|
40
|
+
</Center>
|
|
41
|
+
}
|
|
42
|
+
>
|
|
43
|
+
<FormattedMessage
|
|
44
|
+
defaultMessage="Back to cart"
|
|
45
|
+
id="checkout_header.link.cart"
|
|
46
|
+
/>
|
|
47
|
+
</Button>
|
|
48
|
+
</Flex>
|
|
49
|
+
</Box>
|
|
50
|
+
</Box>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default CheckoutHeader
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import {screen} from '@testing-library/react'
|
|
9
|
+
|
|
10
|
+
import CheckoutHeader from '@salesforce/retail-react-app/app/pages/checkout/partials/checkout-header'
|
|
11
|
+
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
|
|
12
|
+
|
|
13
|
+
test('renders component', () => {
|
|
14
|
+
renderWithProviders(<CheckoutHeader />)
|
|
15
|
+
expect(screen.getByTitle(/back to homepage/i)).toBeInTheDocument()
|
|
16
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import {Box, Container, Grid, GridItem, Skeleton, Stack} from '@chakra-ui/react'
|
|
9
|
+
|
|
10
|
+
const CheckoutSkeleton = () => {
|
|
11
|
+
return (
|
|
12
|
+
<Box background="gray.50" flex="1">
|
|
13
|
+
<Container
|
|
14
|
+
data-testid="sf-checkout-skeleton"
|
|
15
|
+
maxWidth="container.xl"
|
|
16
|
+
py={{base: 7, lg: 16}}
|
|
17
|
+
px={{base: 0, lg: 4}}
|
|
18
|
+
>
|
|
19
|
+
<Grid templateColumns={{base: '1fr', lg: '66% 1fr'}} gap={{base: 10, lg: 20}}>
|
|
20
|
+
<GridItem>
|
|
21
|
+
<Stack spacing={4}>
|
|
22
|
+
<Skeleton height="78px" />
|
|
23
|
+
<Skeleton height="78px" />
|
|
24
|
+
<Skeleton height="78px" />
|
|
25
|
+
<Skeleton height="78px" />
|
|
26
|
+
</Stack>
|
|
27
|
+
</GridItem>
|
|
28
|
+
|
|
29
|
+
<GridItem py={6} px={[4, 4, 0]}>
|
|
30
|
+
<Stack spacing={5}>
|
|
31
|
+
<Skeleton height="30px" width="50%" />
|
|
32
|
+
|
|
33
|
+
<Stack spacing={5}>
|
|
34
|
+
<Skeleton height="30px" width="65%" />
|
|
35
|
+
|
|
36
|
+
<Stack w="full" py={4} borderY="1px" borderColor="gray.200">
|
|
37
|
+
<Skeleton height={6} />
|
|
38
|
+
<Skeleton height={6} />
|
|
39
|
+
<Skeleton height={6} />
|
|
40
|
+
</Stack>
|
|
41
|
+
|
|
42
|
+
<Skeleton height={6} />
|
|
43
|
+
</Stack>
|
|
44
|
+
</Stack>
|
|
45
|
+
</GridItem>
|
|
46
|
+
</Grid>
|
|
47
|
+
</Container>
|
|
48
|
+
</Box>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default CheckoutSkeleton
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import React, {useRef, useState} from 'react'
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
import {
|
|
10
|
+
Alert,
|
|
11
|
+
AlertDialog,
|
|
12
|
+
AlertDialogBody,
|
|
13
|
+
AlertDialogContent,
|
|
14
|
+
AlertDialogFooter,
|
|
15
|
+
AlertDialogHeader,
|
|
16
|
+
AlertDialogOverlay,
|
|
17
|
+
AlertIcon,
|
|
18
|
+
Box,
|
|
19
|
+
Button,
|
|
20
|
+
Container,
|
|
21
|
+
Stack,
|
|
22
|
+
Text
|
|
23
|
+
} from '@chakra-ui/react'
|
|
24
|
+
import {useForm} from 'react-hook-form'
|
|
25
|
+
import {FormattedMessage, useIntl} from 'react-intl'
|
|
26
|
+
import {useCheckout} from '@salesforce/retail-react-app/app/pages/checkout/util/checkout-context'
|
|
27
|
+
import useLoginFields from '@salesforce/retail-react-app/app/components/forms/useLoginFields'
|
|
28
|
+
import {
|
|
29
|
+
ToggleCard,
|
|
30
|
+
ToggleCardEdit,
|
|
31
|
+
ToggleCardSummary
|
|
32
|
+
} from '@salesforce/retail-react-app/app/components/toggle-card'
|
|
33
|
+
import Field from '@salesforce/retail-react-app/app/components/field'
|
|
34
|
+
import {AuthModal, useAuthModal} from '@salesforce/retail-react-app/app/hooks/use-auth-modal'
|
|
35
|
+
import useNavigation from '@salesforce/retail-react-app/app/hooks/use-navigation'
|
|
36
|
+
import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer'
|
|
37
|
+
import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket'
|
|
38
|
+
import {AuthHelpers, useAuthHelper, useShopperBasketsMutation} from '@salesforce/commerce-sdk-react'
|
|
39
|
+
|
|
40
|
+
const ContactInfo = () => {
|
|
41
|
+
const {formatMessage} = useIntl()
|
|
42
|
+
const authModal = useAuthModal('password')
|
|
43
|
+
const navigate = useNavigation()
|
|
44
|
+
const {data: customer} = useCurrentCustomer()
|
|
45
|
+
const {data: basket} = useCurrentBasket()
|
|
46
|
+
const login = useAuthHelper(AuthHelpers.LoginRegisteredUserB2C)
|
|
47
|
+
const logout = useAuthHelper(AuthHelpers.Logout)
|
|
48
|
+
const updateCustomerForBasket = useShopperBasketsMutation('updateCustomerForBasket')
|
|
49
|
+
|
|
50
|
+
const {step, STEPS, goToStep, goToNextStep} = useCheckout()
|
|
51
|
+
|
|
52
|
+
const form = useForm({
|
|
53
|
+
defaultValues: {email: customer?.email || basket?.customerInfo?.email || '', password: ''}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const fields = useLoginFields({form})
|
|
57
|
+
|
|
58
|
+
const [error, setError] = useState(null)
|
|
59
|
+
const [showPasswordField, setShowPasswordField] = useState(false)
|
|
60
|
+
const [signOutConfirmDialogIsOpen, setSignOutConfirmDialogIsOpen] = useState(false)
|
|
61
|
+
|
|
62
|
+
const submitForm = async (data) => {
|
|
63
|
+
setError(null)
|
|
64
|
+
try {
|
|
65
|
+
if (!data.password) {
|
|
66
|
+
await updateCustomerForBasket.mutateAsync({
|
|
67
|
+
parameters: {basketId: basket.basketId},
|
|
68
|
+
body: {email: data.email}
|
|
69
|
+
})
|
|
70
|
+
} else {
|
|
71
|
+
await login.mutateAsync({username: data.email, password: data.password})
|
|
72
|
+
}
|
|
73
|
+
goToNextStep()
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (/Unauthorized/i.test(error.message)) {
|
|
76
|
+
setError(
|
|
77
|
+
formatMessage({
|
|
78
|
+
defaultMessage: 'Incorrect username or password, please try again.',
|
|
79
|
+
id: 'contact_info.error.incorrect_username_or_password'
|
|
80
|
+
})
|
|
81
|
+
)
|
|
82
|
+
} else {
|
|
83
|
+
setError(error.message)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const togglePasswordField = () => {
|
|
89
|
+
if (error) {
|
|
90
|
+
setError(null)
|
|
91
|
+
}
|
|
92
|
+
setShowPasswordField(!showPasswordField)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const onForgotPasswordClick = () => {
|
|
96
|
+
authModal.onOpen()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<ToggleCard
|
|
101
|
+
id="step-0"
|
|
102
|
+
title={formatMessage({
|
|
103
|
+
defaultMessage: 'Contact Info',
|
|
104
|
+
id: 'contact_info.title.contact_info'
|
|
105
|
+
})}
|
|
106
|
+
editing={step === STEPS.CONTACT_INFO}
|
|
107
|
+
isLoading={form.formState.isSubmitting}
|
|
108
|
+
onEdit={() => {
|
|
109
|
+
if (customer.isRegistered) {
|
|
110
|
+
setSignOutConfirmDialogIsOpen(true)
|
|
111
|
+
} else {
|
|
112
|
+
goToStep(STEPS.CONTACT_INFO)
|
|
113
|
+
}
|
|
114
|
+
}}
|
|
115
|
+
editLabel={
|
|
116
|
+
customer.isRegistered ? (
|
|
117
|
+
<FormattedMessage defaultMessage="Sign Out" id="contact_info.action.sign_out" />
|
|
118
|
+
) : undefined
|
|
119
|
+
}
|
|
120
|
+
>
|
|
121
|
+
<ToggleCardEdit>
|
|
122
|
+
<Container variant="form">
|
|
123
|
+
<form onSubmit={form.handleSubmit(submitForm)}>
|
|
124
|
+
<Stack spacing={6}>
|
|
125
|
+
{error && (
|
|
126
|
+
<Alert status="error">
|
|
127
|
+
<AlertIcon />
|
|
128
|
+
{error}
|
|
129
|
+
</Alert>
|
|
130
|
+
)}
|
|
131
|
+
|
|
132
|
+
<Stack spacing={5} position="relative">
|
|
133
|
+
<Field {...fields.email} />
|
|
134
|
+
{showPasswordField && (
|
|
135
|
+
<Stack>
|
|
136
|
+
<Field {...fields.password} />
|
|
137
|
+
<Box>
|
|
138
|
+
<Button
|
|
139
|
+
variant="link"
|
|
140
|
+
size="sm"
|
|
141
|
+
onClick={onForgotPasswordClick}
|
|
142
|
+
>
|
|
143
|
+
<FormattedMessage
|
|
144
|
+
defaultMessage="Forgot password?"
|
|
145
|
+
id="contact_info.link.forgot_password"
|
|
146
|
+
/>
|
|
147
|
+
</Button>
|
|
148
|
+
</Box>
|
|
149
|
+
</Stack>
|
|
150
|
+
)}
|
|
151
|
+
</Stack>
|
|
152
|
+
|
|
153
|
+
<Stack spacing={3}>
|
|
154
|
+
<Button type="submit">
|
|
155
|
+
{!showPasswordField ? (
|
|
156
|
+
<FormattedMessage
|
|
157
|
+
defaultMessage="Checkout as Guest"
|
|
158
|
+
id="contact_info.button.checkout_as_guest"
|
|
159
|
+
/>
|
|
160
|
+
) : (
|
|
161
|
+
<FormattedMessage
|
|
162
|
+
defaultMessage="Log In"
|
|
163
|
+
id="contact_info.button.login"
|
|
164
|
+
/>
|
|
165
|
+
)}
|
|
166
|
+
</Button>
|
|
167
|
+
<Button variant="outline" onClick={togglePasswordField}>
|
|
168
|
+
{!showPasswordField ? (
|
|
169
|
+
<FormattedMessage
|
|
170
|
+
defaultMessage="Already have an account? Log in"
|
|
171
|
+
id="contact_info.button.already_have_account"
|
|
172
|
+
/>
|
|
173
|
+
) : (
|
|
174
|
+
<FormattedMessage
|
|
175
|
+
defaultMessage="Checkout as Guest"
|
|
176
|
+
id="contact_info.button.checkout_as_guest"
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
</Button>
|
|
180
|
+
</Stack>
|
|
181
|
+
</Stack>
|
|
182
|
+
</form>
|
|
183
|
+
</Container>
|
|
184
|
+
<AuthModal {...authModal} />
|
|
185
|
+
</ToggleCardEdit>
|
|
186
|
+
<ToggleCardSummary>
|
|
187
|
+
<Text>{basket?.customerInfo?.email || customer?.email}</Text>
|
|
188
|
+
|
|
189
|
+
<SignOutConfirmationDialog
|
|
190
|
+
isOpen={signOutConfirmDialogIsOpen}
|
|
191
|
+
onClose={() => setSignOutConfirmDialogIsOpen(false)}
|
|
192
|
+
onConfirm={async () => {
|
|
193
|
+
await logout.mutateAsync()
|
|
194
|
+
navigate('/login')
|
|
195
|
+
setSignOutConfirmDialogIsOpen(false)
|
|
196
|
+
}}
|
|
197
|
+
/>
|
|
198
|
+
</ToggleCardSummary>
|
|
199
|
+
</ToggleCard>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const SignOutConfirmationDialog = ({isOpen, onConfirm, onClose}) => {
|
|
204
|
+
const cancelRef = useRef()
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<AlertDialog isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={onClose}>
|
|
208
|
+
<AlertDialogOverlay>
|
|
209
|
+
<AlertDialogContent>
|
|
210
|
+
<AlertDialogHeader fontSize="lg" fontWeight="bold">
|
|
211
|
+
<FormattedMessage
|
|
212
|
+
defaultMessage="Sign Out"
|
|
213
|
+
id="signout_confirmation_dialog.heading.sign_out"
|
|
214
|
+
/>
|
|
215
|
+
</AlertDialogHeader>
|
|
216
|
+
|
|
217
|
+
<AlertDialogBody>
|
|
218
|
+
<FormattedMessage
|
|
219
|
+
defaultMessage="Are you sure you want to sign out? You will need to sign back in to proceed
|
|
220
|
+
with your current order."
|
|
221
|
+
id="signout_confirmation_dialog.message.sure_to_sign_out"
|
|
222
|
+
/>
|
|
223
|
+
</AlertDialogBody>
|
|
224
|
+
|
|
225
|
+
<AlertDialogFooter>
|
|
226
|
+
<Button ref={cancelRef} variant="outline" onClick={onClose}>
|
|
227
|
+
<FormattedMessage
|
|
228
|
+
defaultMessage="Cancel"
|
|
229
|
+
id="signout_confirmation_dialog.button.cancel"
|
|
230
|
+
/>
|
|
231
|
+
</Button>
|
|
232
|
+
<Button colorScheme="red" onClick={onConfirm} ml={3}>
|
|
233
|
+
<FormattedMessage
|
|
234
|
+
defaultMessage="Sign Out"
|
|
235
|
+
id="signout_confirmation_dialog.button.sign_out"
|
|
236
|
+
/>
|
|
237
|
+
</Button>
|
|
238
|
+
</AlertDialogFooter>
|
|
239
|
+
</AlertDialogContent>
|
|
240
|
+
</AlertDialogOverlay>
|
|
241
|
+
</AlertDialog>
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
SignOutConfirmationDialog.propTypes = {
|
|
246
|
+
isOpen: PropTypes.bool,
|
|
247
|
+
onClose: PropTypes.func,
|
|
248
|
+
onConfirm: PropTypes.func
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export default ContactInfo
|