@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,161 @@
|
|
|
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, {useState} from 'react'
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
import {Controller} from 'react-hook-form'
|
|
10
|
+
import {
|
|
11
|
+
FormControl,
|
|
12
|
+
FormLabel,
|
|
13
|
+
FormErrorMessage,
|
|
14
|
+
IconButton,
|
|
15
|
+
Input,
|
|
16
|
+
InputGroup,
|
|
17
|
+
InputRightElement,
|
|
18
|
+
Select,
|
|
19
|
+
Checkbox
|
|
20
|
+
} from '@chakra-ui/react'
|
|
21
|
+
import {VisibilityIcon, VisibilityOffIcon} from '@salesforce/retail-react-app/app/components/icons'
|
|
22
|
+
|
|
23
|
+
const Field = ({
|
|
24
|
+
name,
|
|
25
|
+
label,
|
|
26
|
+
formLabel,
|
|
27
|
+
type = 'text',
|
|
28
|
+
options = [],
|
|
29
|
+
rules = {},
|
|
30
|
+
error,
|
|
31
|
+
placeholder,
|
|
32
|
+
inputProps,
|
|
33
|
+
control,
|
|
34
|
+
defaultValue,
|
|
35
|
+
helpText,
|
|
36
|
+
children
|
|
37
|
+
}) => {
|
|
38
|
+
const [hidePassword, setHidePassword] = useState(true)
|
|
39
|
+
const PasswordIcon = hidePassword ? VisibilityIcon : VisibilityOffIcon
|
|
40
|
+
const inputType =
|
|
41
|
+
type === 'password' && hidePassword ? 'password' : type === 'password' ? 'text' : type
|
|
42
|
+
return (
|
|
43
|
+
<Controller
|
|
44
|
+
name={name}
|
|
45
|
+
control={control}
|
|
46
|
+
rules={rules}
|
|
47
|
+
defaultValue={defaultValue}
|
|
48
|
+
render={({field: {onChange, value, ref}}) => {
|
|
49
|
+
const _inputProps =
|
|
50
|
+
typeof inputProps === 'function' ? inputProps({value, onChange}) : inputProps
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<FormControl id={name} isInvalid={error}>
|
|
54
|
+
{!['checkbox', 'radio'].includes(type) &&
|
|
55
|
+
type !== 'hidden' &&
|
|
56
|
+
(formLabel || <FormLabel>{label}</FormLabel>)}
|
|
57
|
+
|
|
58
|
+
<InputGroup>
|
|
59
|
+
{['text', 'password', 'email', 'phone', 'tel', 'number'].includes(
|
|
60
|
+
type
|
|
61
|
+
) && (
|
|
62
|
+
<Input
|
|
63
|
+
ref={ref}
|
|
64
|
+
onChange={onChange}
|
|
65
|
+
value={value}
|
|
66
|
+
type={inputType}
|
|
67
|
+
placeholder={placeholder}
|
|
68
|
+
{..._inputProps}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
|
|
72
|
+
{type === 'hidden' && (
|
|
73
|
+
<input
|
|
74
|
+
ref={ref}
|
|
75
|
+
onChange={onChange}
|
|
76
|
+
value={value}
|
|
77
|
+
type="hidden"
|
|
78
|
+
{..._inputProps}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
|
|
82
|
+
{type === 'password' && (
|
|
83
|
+
<InputRightElement>
|
|
84
|
+
<IconButton
|
|
85
|
+
variant="ghosted"
|
|
86
|
+
aria-label="Show password"
|
|
87
|
+
icon={<PasswordIcon color="gray.500" boxSize={6} />}
|
|
88
|
+
onClick={() => setHidePassword(!hidePassword)}
|
|
89
|
+
/>
|
|
90
|
+
</InputRightElement>
|
|
91
|
+
)}
|
|
92
|
+
|
|
93
|
+
{type === 'select' && (
|
|
94
|
+
<Select
|
|
95
|
+
ref={ref}
|
|
96
|
+
onChange={onChange}
|
|
97
|
+
value={value}
|
|
98
|
+
placeholder={placeholder}
|
|
99
|
+
{..._inputProps}
|
|
100
|
+
>
|
|
101
|
+
{options.map((opt) => (
|
|
102
|
+
<option key={`${opt.label}-${opt.value}`} value={opt.value}>
|
|
103
|
+
{opt.label}
|
|
104
|
+
</option>
|
|
105
|
+
))}
|
|
106
|
+
</Select>
|
|
107
|
+
)}
|
|
108
|
+
|
|
109
|
+
{type === 'checkbox' && (
|
|
110
|
+
<Checkbox
|
|
111
|
+
ref={ref}
|
|
112
|
+
onChange={(e) => onChange(e.target.checked)}
|
|
113
|
+
isChecked={value}
|
|
114
|
+
{..._inputProps}
|
|
115
|
+
>
|
|
116
|
+
{formLabel || label}
|
|
117
|
+
</Checkbox>
|
|
118
|
+
)}
|
|
119
|
+
|
|
120
|
+
{children}
|
|
121
|
+
</InputGroup>
|
|
122
|
+
|
|
123
|
+
{error && !type !== 'hidden' && (
|
|
124
|
+
<FormErrorMessage>{error.message}</FormErrorMessage>
|
|
125
|
+
)}
|
|
126
|
+
|
|
127
|
+
{helpText}
|
|
128
|
+
</FormControl>
|
|
129
|
+
)
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
Field.propTypes = {
|
|
136
|
+
name: PropTypes.string,
|
|
137
|
+
label: PropTypes.string,
|
|
138
|
+
formLabel: PropTypes.any,
|
|
139
|
+
type: PropTypes.oneOf([
|
|
140
|
+
'text',
|
|
141
|
+
'number',
|
|
142
|
+
'password',
|
|
143
|
+
'email',
|
|
144
|
+
'phone',
|
|
145
|
+
'tel',
|
|
146
|
+
'select',
|
|
147
|
+
'checkbox',
|
|
148
|
+
'hidden'
|
|
149
|
+
]),
|
|
150
|
+
options: PropTypes.arrayOf(PropTypes.shape({label: PropTypes.string, value: PropTypes.any})),
|
|
151
|
+
rules: PropTypes.object,
|
|
152
|
+
error: PropTypes.shape({message: PropTypes.string}),
|
|
153
|
+
placeholder: PropTypes.string,
|
|
154
|
+
inputProps: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
155
|
+
control: PropTypes.object,
|
|
156
|
+
defaultValue: PropTypes.any,
|
|
157
|
+
helpText: PropTypes.any,
|
|
158
|
+
children: PropTypes.any
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default Field
|
|
@@ -0,0 +1,269 @@
|
|
|
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, {useState} from 'react'
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
import {
|
|
10
|
+
Box,
|
|
11
|
+
Text,
|
|
12
|
+
Divider,
|
|
13
|
+
SimpleGrid,
|
|
14
|
+
useMultiStyleConfig,
|
|
15
|
+
Select as ChakraSelect,
|
|
16
|
+
Heading,
|
|
17
|
+
Input,
|
|
18
|
+
InputGroup,
|
|
19
|
+
InputRightElement,
|
|
20
|
+
createStylesContext,
|
|
21
|
+
Button,
|
|
22
|
+
FormControl
|
|
23
|
+
} from '@chakra-ui/react'
|
|
24
|
+
import {useIntl} from 'react-intl'
|
|
25
|
+
|
|
26
|
+
import LinksList from '@salesforce/retail-react-app/app/components/links-list'
|
|
27
|
+
import SocialIcons from '@salesforce/retail-react-app/app/components/social-icons'
|
|
28
|
+
import {HideOnDesktop, HideOnMobile} from '@salesforce/retail-react-app/app/components/responsive'
|
|
29
|
+
import {getPathWithLocale} from '@salesforce/retail-react-app/app/utils/url'
|
|
30
|
+
import LocaleText from '@salesforce/retail-react-app/app/components/locale-text'
|
|
31
|
+
import useMultiSite from '@salesforce/retail-react-app/app/hooks/use-multi-site'
|
|
32
|
+
import styled from '@emotion/styled'
|
|
33
|
+
|
|
34
|
+
const [StylesProvider, useStyles] = createStylesContext('Footer')
|
|
35
|
+
const Footer = ({...otherProps}) => {
|
|
36
|
+
const styles = useMultiStyleConfig('Footer')
|
|
37
|
+
const intl = useIntl()
|
|
38
|
+
const [locale, setLocale] = useState(intl.locale)
|
|
39
|
+
const {site, buildUrl} = useMultiSite()
|
|
40
|
+
const {l10n} = site
|
|
41
|
+
const supportedLocaleIds = l10n?.supportedLocales.map((locale) => locale.id)
|
|
42
|
+
const showLocaleSelector = supportedLocaleIds?.length > 1
|
|
43
|
+
|
|
44
|
+
// NOTE: this is a workaround to fix hydration error, by making sure that the `option.selected` property is set.
|
|
45
|
+
// For some reason, adding some styles prop (to the option element) prevented `selected` from being set.
|
|
46
|
+
// So now we add the styling to the parent element instead.
|
|
47
|
+
const Select = styled(ChakraSelect)({
|
|
48
|
+
// Targeting the child element
|
|
49
|
+
option: styles.localeDropdownOption
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Box as="footer" {...styles.container} {...otherProps}>
|
|
54
|
+
<Box {...styles.content}>
|
|
55
|
+
<StylesProvider value={styles}>
|
|
56
|
+
<HideOnMobile>
|
|
57
|
+
<SimpleGrid columns={4} spacing={3}>
|
|
58
|
+
<LinksList
|
|
59
|
+
heading={intl.formatMessage({
|
|
60
|
+
id: 'footer.column.customer_support',
|
|
61
|
+
defaultMessage: 'Customer Support'
|
|
62
|
+
})}
|
|
63
|
+
links={[
|
|
64
|
+
{
|
|
65
|
+
href: '/',
|
|
66
|
+
text: intl.formatMessage({
|
|
67
|
+
id: 'footer.link.contact_us',
|
|
68
|
+
defaultMessage: 'Contact Us'
|
|
69
|
+
})
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
href: '/',
|
|
73
|
+
text: intl.formatMessage({
|
|
74
|
+
id: 'footer.link.shipping',
|
|
75
|
+
defaultMessage: 'Shipping'
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
]}
|
|
79
|
+
/>
|
|
80
|
+
<LinksList
|
|
81
|
+
heading={intl.formatMessage({
|
|
82
|
+
id: 'footer.column.account',
|
|
83
|
+
defaultMessage: 'Account'
|
|
84
|
+
})}
|
|
85
|
+
links={[
|
|
86
|
+
{
|
|
87
|
+
href: '/',
|
|
88
|
+
text: intl.formatMessage({
|
|
89
|
+
id: 'footer.link.order_status',
|
|
90
|
+
defaultMessage: 'Order Status'
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
href: '/',
|
|
95
|
+
text: intl.formatMessage({
|
|
96
|
+
id: 'footer.link.signin_create_account',
|
|
97
|
+
defaultMessage: 'Sign in or create account'
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
]}
|
|
101
|
+
/>
|
|
102
|
+
<LinksList
|
|
103
|
+
heading={intl.formatMessage({
|
|
104
|
+
id: 'footer.column.our_company',
|
|
105
|
+
defaultMessage: 'Our Company'
|
|
106
|
+
})}
|
|
107
|
+
links={[
|
|
108
|
+
{
|
|
109
|
+
href: '/',
|
|
110
|
+
text: intl.formatMessage({
|
|
111
|
+
id: 'footer.link.store_locator',
|
|
112
|
+
defaultMessage: 'Store Locator'
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
href: '/',
|
|
117
|
+
text: intl.formatMessage({
|
|
118
|
+
id: 'footer.link.about_us',
|
|
119
|
+
defaultMessage: 'About Us'
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
]}
|
|
123
|
+
/>
|
|
124
|
+
<Box>
|
|
125
|
+
<Subscribe />
|
|
126
|
+
</Box>
|
|
127
|
+
</SimpleGrid>
|
|
128
|
+
</HideOnMobile>
|
|
129
|
+
|
|
130
|
+
<HideOnDesktop>
|
|
131
|
+
<Subscribe />
|
|
132
|
+
</HideOnDesktop>
|
|
133
|
+
|
|
134
|
+
{showLocaleSelector && (
|
|
135
|
+
<Box {...styles.localeSelector}>
|
|
136
|
+
<FormControl
|
|
137
|
+
data-testid="sf-footer-locale-selector"
|
|
138
|
+
id="locale_selector"
|
|
139
|
+
width="auto"
|
|
140
|
+
{...otherProps}
|
|
141
|
+
>
|
|
142
|
+
<Select
|
|
143
|
+
defaultValue={locale}
|
|
144
|
+
onChange={({target}) => {
|
|
145
|
+
setLocale(target.value)
|
|
146
|
+
|
|
147
|
+
// Update the `locale` in the URL.
|
|
148
|
+
const newUrl = getPathWithLocale(target.value, buildUrl, {
|
|
149
|
+
disallowParams: ['refine']
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
window.location = newUrl
|
|
153
|
+
}}
|
|
154
|
+
variant="filled"
|
|
155
|
+
{...styles.localeDropdown}
|
|
156
|
+
>
|
|
157
|
+
{supportedLocaleIds.map((locale) => (
|
|
158
|
+
<option key={locale} value={locale}>
|
|
159
|
+
<LocaleText shortCode={locale} />
|
|
160
|
+
</option>
|
|
161
|
+
))}
|
|
162
|
+
</Select>
|
|
163
|
+
</FormControl>
|
|
164
|
+
</Box>
|
|
165
|
+
)}
|
|
166
|
+
|
|
167
|
+
<Divider {...styles.horizontalRule} />
|
|
168
|
+
|
|
169
|
+
<Box {...styles.bottomHalf}>
|
|
170
|
+
<Text {...styles.copyright}>
|
|
171
|
+
© {new Date().getFullYear()}{' '}
|
|
172
|
+
{intl.formatMessage({
|
|
173
|
+
id: 'footer.message.copyright',
|
|
174
|
+
defaultMessage:
|
|
175
|
+
'Salesforce or its affiliates. All rights reserved. This is a demo store only. Orders made WILL NOT be processed.'
|
|
176
|
+
})}
|
|
177
|
+
</Text>
|
|
178
|
+
|
|
179
|
+
<HideOnDesktop>
|
|
180
|
+
<LegalLinks variant="vertical" />
|
|
181
|
+
</HideOnDesktop>
|
|
182
|
+
<HideOnMobile>
|
|
183
|
+
<LegalLinks variant="horizontal" />
|
|
184
|
+
</HideOnMobile>
|
|
185
|
+
</Box>
|
|
186
|
+
</StylesProvider>
|
|
187
|
+
</Box>
|
|
188
|
+
</Box>
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export default Footer
|
|
193
|
+
|
|
194
|
+
const Subscribe = ({...otherProps}) => {
|
|
195
|
+
const styles = useStyles()
|
|
196
|
+
const intl = useIntl()
|
|
197
|
+
return (
|
|
198
|
+
<Box {...styles.subscribe} {...otherProps}>
|
|
199
|
+
<Heading {...styles.subscribeHeading}>
|
|
200
|
+
{intl.formatMessage({
|
|
201
|
+
id: 'footer.subscribe.heading.first_to_know',
|
|
202
|
+
defaultMessage: 'Be the first to know'
|
|
203
|
+
})}
|
|
204
|
+
</Heading>
|
|
205
|
+
<Text {...styles.subscribeMessage}>
|
|
206
|
+
{intl.formatMessage({
|
|
207
|
+
id: 'footer.subscribe.description.sign_up',
|
|
208
|
+
defaultMessage: 'Sign up to stay in the loop about the hottest deals'
|
|
209
|
+
})}
|
|
210
|
+
</Text>
|
|
211
|
+
|
|
212
|
+
<Box>
|
|
213
|
+
<InputGroup>
|
|
214
|
+
{/* Had to swap the following InputRightElement and Input
|
|
215
|
+
to avoid the hydration error due to mismatched html between server and client side.
|
|
216
|
+
This is a workaround for Lastpass plugin that automatically injects its icon for input fields.
|
|
217
|
+
*/}
|
|
218
|
+
<InputRightElement {...styles.subscribeButtonContainer}>
|
|
219
|
+
<Button variant="footer">
|
|
220
|
+
{intl.formatMessage({
|
|
221
|
+
id: 'footer.subscribe.button.sign_up',
|
|
222
|
+
defaultMessage: 'Sign Up'
|
|
223
|
+
})}
|
|
224
|
+
</Button>
|
|
225
|
+
</InputRightElement>
|
|
226
|
+
<Input type="email" placeholder="you@email.com" {...styles.subscribeField} />
|
|
227
|
+
</InputGroup>
|
|
228
|
+
</Box>
|
|
229
|
+
|
|
230
|
+
<SocialIcons variant="flex-start" pinterestInnerColor="black" {...styles.socialIcons} />
|
|
231
|
+
</Box>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const LegalLinks = ({variant}) => {
|
|
236
|
+
const intl = useIntl()
|
|
237
|
+
return (
|
|
238
|
+
<LinksList
|
|
239
|
+
links={[
|
|
240
|
+
{
|
|
241
|
+
href: '/',
|
|
242
|
+
text: intl.formatMessage({
|
|
243
|
+
id: 'footer.link.terms_conditions',
|
|
244
|
+
defaultMessage: 'Terms & Conditions'
|
|
245
|
+
})
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
href: '/',
|
|
249
|
+
text: intl.formatMessage({
|
|
250
|
+
id: 'footer.link.privacy_policy',
|
|
251
|
+
defaultMessage: 'Privacy Policy'
|
|
252
|
+
})
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
href: '/',
|
|
256
|
+
text: intl.formatMessage({
|
|
257
|
+
id: 'footer.link.site_map',
|
|
258
|
+
defaultMessage: 'Site Map'
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
]}
|
|
262
|
+
color="gray.200"
|
|
263
|
+
variant={variant}
|
|
264
|
+
/>
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
LegalLinks.propTypes = {
|
|
268
|
+
variant: PropTypes.oneOf(['vertical', 'horizontal'])
|
|
269
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 Footer from '@salesforce/retail-react-app/app/components/footer/index'
|
|
11
|
+
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
|
|
12
|
+
|
|
13
|
+
test('renders component', () => {
|
|
14
|
+
renderWithProviders(<Footer />)
|
|
15
|
+
expect(screen.getByRole('link', {name: 'Privacy Policy'})).toBeInTheDocument()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('renders mobile version by default', () => {
|
|
19
|
+
renderWithProviders(<Footer />)
|
|
20
|
+
// This link is hidden initially, but would be shown for desktop
|
|
21
|
+
expect(screen.getByRole('link', {name: 'About Us', hidden: true})).toBeInTheDocument()
|
|
22
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
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 {Grid, GridItem, SimpleGrid, Stack} from '@chakra-ui/react'
|
|
10
|
+
import useAddressFields from '@salesforce/retail-react-app/app/components/forms/useAddressFields'
|
|
11
|
+
import Field from '@salesforce/retail-react-app/app/components/field'
|
|
12
|
+
import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-current-customer'
|
|
13
|
+
|
|
14
|
+
const AddressFields = ({form, prefix = ''}) => {
|
|
15
|
+
const {data: customer} = useCurrentCustomer()
|
|
16
|
+
const fields = useAddressFields({form, prefix})
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Stack spacing={5}>
|
|
20
|
+
<SimpleGrid columns={[1, 1, 2]} gap={5}>
|
|
21
|
+
<Field {...fields.firstName} />
|
|
22
|
+
<Field {...fields.lastName} />
|
|
23
|
+
</SimpleGrid>
|
|
24
|
+
<Field {...fields.phone} />
|
|
25
|
+
<Field {...fields.countryCode} />
|
|
26
|
+
<Field {...fields.address1} />
|
|
27
|
+
<Field {...fields.city} />
|
|
28
|
+
<Grid templateColumns="repeat(8, 1fr)" gap={5}>
|
|
29
|
+
<GridItem colSpan={[4, 4, 4]}>
|
|
30
|
+
<Field {...fields.stateCode} />
|
|
31
|
+
</GridItem>
|
|
32
|
+
<GridItem colSpan={[4, 4, 4]}>
|
|
33
|
+
<Field {...fields.postalCode} />
|
|
34
|
+
</GridItem>
|
|
35
|
+
</Grid>
|
|
36
|
+
{customer.isRegistered && <Field {...fields.preferred} />}
|
|
37
|
+
</Stack>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
AddressFields.propTypes = {
|
|
42
|
+
/** Object returned from `useForm` */
|
|
43
|
+
form: PropTypes.object.isRequired,
|
|
44
|
+
|
|
45
|
+
/** Optional prefix for field names */
|
|
46
|
+
prefix: PropTypes.string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default AddressFields
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, Salesforce, 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 ccValidator from 'card-validator'
|
|
10
|
+
import {useIntl} from 'react-intl'
|
|
11
|
+
import {Box, Flex, FormLabel, InputRightElement, SimpleGrid, Stack, Tooltip} from '@chakra-ui/react'
|
|
12
|
+
import {
|
|
13
|
+
formatCreditCardNumber,
|
|
14
|
+
getCreditCardIcon
|
|
15
|
+
} from '@salesforce/retail-react-app/app/utils/cc-utils'
|
|
16
|
+
import useCreditCardFields from '@salesforce/retail-react-app/app/components/forms/useCreditCardFields'
|
|
17
|
+
import Field from '@salesforce/retail-react-app/app/components/field'
|
|
18
|
+
import {
|
|
19
|
+
AmexIcon,
|
|
20
|
+
DiscoverIcon,
|
|
21
|
+
MastercardIcon,
|
|
22
|
+
VisaIcon,
|
|
23
|
+
InfoIcon
|
|
24
|
+
} from '@salesforce/retail-react-app/app/components/icons'
|
|
25
|
+
|
|
26
|
+
const CreditCardFields = ({form, prefix = ''}) => {
|
|
27
|
+
const {formatMessage} = useIntl()
|
|
28
|
+
const fields = useCreditCardFields({form, prefix})
|
|
29
|
+
|
|
30
|
+
// Rerender the fields when we `cardType` changes so the detected
|
|
31
|
+
// card icon appears while typing the card number.
|
|
32
|
+
// https://react-hook-form.com/api#watch
|
|
33
|
+
const cardType = form.watch('cardType')
|
|
34
|
+
|
|
35
|
+
const CardIcon = getCreditCardIcon(form.getValues().cardType)
|
|
36
|
+
|
|
37
|
+
// Note: The ternary should NOT be placed inside a call to `formatMessage`. The message
|
|
38
|
+
// extraction script (`npm run extract-default-translations`) only works when `formatMessage` is
|
|
39
|
+
// used with object literals.
|
|
40
|
+
const securityCodeTooltipLabel =
|
|
41
|
+
cardType === 'american-express'
|
|
42
|
+
? formatMessage({
|
|
43
|
+
id: 'credit_card_fields.tool_tip.security_code.american_express',
|
|
44
|
+
defaultMessage: 'This 4-digit code can be found on the front of your card.',
|
|
45
|
+
description: 'American Express security code help text'
|
|
46
|
+
})
|
|
47
|
+
: formatMessage({
|
|
48
|
+
id: 'credit_card_fields.tool_tip.security_code',
|
|
49
|
+
defaultMessage: 'This 3-digit code can be found on the back of your card.',
|
|
50
|
+
description: 'Generic credit card security code help text'
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Box>
|
|
55
|
+
<Stack spacing={5}>
|
|
56
|
+
<Field
|
|
57
|
+
{...fields.number}
|
|
58
|
+
formLabel={
|
|
59
|
+
<Flex justify="space-between">
|
|
60
|
+
<FormLabel>{fields.number.label}</FormLabel>
|
|
61
|
+
<Stack direction="row" spacing={1}>
|
|
62
|
+
<VisaIcon layerStyle="ccIcon" />
|
|
63
|
+
<MastercardIcon layerStyle="ccIcon" />
|
|
64
|
+
<AmexIcon layerStyle="ccIcon" />
|
|
65
|
+
<DiscoverIcon layerStyle="ccIcon" />
|
|
66
|
+
</Stack>
|
|
67
|
+
</Flex>
|
|
68
|
+
}
|
|
69
|
+
inputProps={({onChange}) => ({
|
|
70
|
+
...fields.number.inputProps,
|
|
71
|
+
onChange(evt) {
|
|
72
|
+
const number = evt.target.value.replace(/[^0-9 ]+/, '')
|
|
73
|
+
const {card} = ccValidator.number(number)
|
|
74
|
+
const formattedNumber = card
|
|
75
|
+
? formatCreditCardNumber(number, card)
|
|
76
|
+
: number
|
|
77
|
+
form.setValue('cardType', card?.type || '')
|
|
78
|
+
return onChange(formattedNumber)
|
|
79
|
+
}
|
|
80
|
+
})}
|
|
81
|
+
>
|
|
82
|
+
{CardIcon && form.getValues().number?.length > 2 && (
|
|
83
|
+
<InputRightElement width="60px">
|
|
84
|
+
<CardIcon layerStyle="ccIcon" />
|
|
85
|
+
</InputRightElement>
|
|
86
|
+
)}
|
|
87
|
+
</Field>
|
|
88
|
+
|
|
89
|
+
<Field {...fields.holder} />
|
|
90
|
+
|
|
91
|
+
<SimpleGrid columns={[2, 2, 3]} spacing={5}>
|
|
92
|
+
<Field
|
|
93
|
+
{...fields.expiry}
|
|
94
|
+
inputProps={({onChange}) => ({
|
|
95
|
+
...fields.expiry.inputProps,
|
|
96
|
+
onChange(evt) {
|
|
97
|
+
let value = evt.target.value.replace('/', '')
|
|
98
|
+
|
|
99
|
+
// We ignore input values other than digits and `/`.
|
|
100
|
+
if (value.match(/[^\d|/]/g)) {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Ignore input when we already have MM/YY
|
|
105
|
+
if (value.length > 4) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
if (value.length >= 2) {
|
|
109
|
+
value = `${value.substr(0, 2)}/${value.substr(2)}`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return onChange(value)
|
|
113
|
+
},
|
|
114
|
+
onKeyDown(evt) {
|
|
115
|
+
if (evt.keyCode === 8 || evt.keyCode === 46) {
|
|
116
|
+
evt.preventDefault()
|
|
117
|
+
return onChange(evt.target.value.slice(0, -1))
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
})}
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
<Field
|
|
124
|
+
{...fields.securityCode}
|
|
125
|
+
formLabel={
|
|
126
|
+
<FormLabel>
|
|
127
|
+
{fields.securityCode.label}{' '}
|
|
128
|
+
<Tooltip hasArrow placement="top" label={securityCodeTooltipLabel}>
|
|
129
|
+
<InfoIcon boxSize={5} color="gray.700" ml={1} />
|
|
130
|
+
</Tooltip>
|
|
131
|
+
</FormLabel>
|
|
132
|
+
}
|
|
133
|
+
/>
|
|
134
|
+
</SimpleGrid>
|
|
135
|
+
</Stack>
|
|
136
|
+
<Field {...fields.cardType} />
|
|
137
|
+
</Box>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
CreditCardFields.propTypes = {
|
|
142
|
+
/** Object returned from `useForm` */
|
|
143
|
+
form: PropTypes.object.isRequired,
|
|
144
|
+
|
|
145
|
+
/** Optional prefix for field names */
|
|
146
|
+
prefix: PropTypes.string
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default CreditCardFields
|