@vtex/faststore 0.0.10 → 0.0.11
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/CHANGELOG.md +42 -0
- package/README.md +0 -1
- package/dist/actions.json +6 -1
- package/dist/catalog.json +789 -1701
- package/dist/cli/index.d.ts +66 -28
- package/dist/cli/index.js +7371 -512
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/server-runtime.js +41 -60
- package/dist/cli/server-runtime.js.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -2
- package/dist/components.d.ts +63 -57
- package/dist/components.js +60 -54
- package/dist/content-types.json +5785 -754
- package/dist/core/dist/define-component.d.ts +1 -1
- package/dist/core/dist/define-content-type.d.ts +50 -2
- package/dist/core/dist/define-content-type.js +107 -3
- package/dist/core/dist/define-content-type.js.map +1 -1
- package/dist/core/dist/index.d.ts +2 -2
- package/dist/docs/access-code-field.md +1 -1
- package/dist/docs/access-code-sign-in.md +126 -77
- package/dist/docs/account-address-book.md +210 -95
- package/dist/docs/account-menu.md +14 -15
- package/dist/docs/account-saved-cards.md +44 -39
- package/dist/docs/alert-dialog.md +3 -1
- package/dist/docs/avatar.md +4 -2
- package/dist/docs/billing-address.md +99 -30
- package/dist/docs/binding-switcher.md +5 -2
- package/dist/docs/buy-button.md +7 -8
- package/dist/docs/card-entry.md +39 -26
- package/dist/docs/card-summary.md +18 -8
- package/dist/docs/cardholder-document.md +5 -3
- package/dist/docs/carousel.md +5 -4
- package/dist/docs/cart-destination.md +39 -26
- package/dist/docs/cart-item.md +29 -14
- package/dist/docs/cart-totalizer.md +7 -5
- package/dist/docs/cart.md +135 -41
- package/dist/docs/challenge-return.md +135 -0
- package/dist/docs/client-preferences-fieldset.md +10 -5
- package/dist/docs/client-preferences.md +31 -8
- package/dist/docs/client-profile-fieldset.md +20 -6
- package/dist/docs/client-profile.md +12 -3
- package/dist/docs/copy-text.md +9 -7
- package/dist/docs/document-field.md +1 -1
- package/dist/docs/email-field.md +2 -1
- package/dist/docs/email-identification.md +12 -2
- package/dist/docs/footer-copyright.md +4 -2
- package/dist/docs/form.md +54 -18
- package/dist/docs/free-shipping-progress.md +6 -5
- package/dist/docs/identity-edit.md +8 -2
- package/dist/docs/identity-summary.md +18 -5
- package/dist/docs/installments.md +46 -32
- package/dist/docs/my-account-profile.md +16 -11
- package/dist/docs/navigation-link.md +5 -3
- package/dist/docs/order-cancel.md +3 -1
- package/dist/docs/order-delivery-address.md +7 -5
- package/dist/docs/order-delivery-group.md +1 -3
- package/dist/docs/order-details-back.md +1 -1
- package/dist/docs/order-details-header.md +1 -4
- package/dist/docs/order-invoice-download.md +60 -0
- package/dist/docs/order-list-row.md +1 -1
- package/dist/docs/order-list-search.md +13 -20
- package/dist/docs/order-list-views.md +11 -17
- package/dist/docs/order-list.md +12 -5
- package/dist/docs/order-payment.md +9 -7
- package/dist/docs/order-placed-date.md +1 -1
- package/dist/docs/order-placed-payment-summary.md +28 -15
- package/dist/docs/order-placed.md +49 -14
- package/dist/docs/order-progress.md +1 -1
- package/dist/docs/order-status-badge.md +20 -9
- package/dist/docs/order-summary.md +2 -2
- package/dist/docs/order-tracking-link.md +58 -0
- package/dist/docs/payment-method-badges.md +30 -4
- package/dist/docs/payment-methods.md +1 -1
- package/dist/docs/payment.md +36 -17
- package/dist/docs/phone-field.md +4 -4
- package/dist/docs/place-order.md +84 -36
- package/dist/docs/postal-code-field.md +3 -1
- package/dist/docs/pricing.md +21 -23
- package/dist/docs/product-gallery.md +19 -20
- package/dist/docs/product-information.md +13 -9
- package/dist/docs/product-list.md +7 -6
- package/dist/docs/product-shelf.md +0 -1
- package/dist/docs/promotion.md +4 -2
- package/dist/docs/region.md +23 -15
- package/dist/docs/save-card.md +7 -6
- package/dist/docs/saved-cards.md +65 -36
- package/dist/docs/shipping-address.md +57 -21
- package/dist/docs/shipping-simulator.md +53 -15
- package/dist/docs/sign-in-disclosure.md +176 -0
- package/dist/docs/sign-in-form.md +78 -47
- package/dist/docs/sign-in-redirect.md +4 -2
- package/dist/docs/sign-in.md +173 -0
- package/dist/docs/toast.md +15 -4
- package/dist/docs/variant-selector.md +15 -11
- package/dist/graphql/types.d.ts +4 -14
- package/dist/index.d.ts +2 -2
- package/dist/internal/client.d.ts +1 -3
- package/dist/internal/client.js +1 -1
- package/dist/internal/server.d.ts +7 -4
- package/dist/internal/server.js +7 -4
- package/dist/matter/access-code-sign-in/access-code-sign-in.d.ts +250 -66
- package/dist/matter/access-code-sign-in/access-code-sign-in.js +459 -188
- package/dist/matter/access-code-sign-in/access-code-sign-in.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-delete.d.ts +78 -40
- package/dist/matter/account-address-book/account-address-book-delete.js +86 -50
- package/dist/matter/account-address-book/account-address-book-delete.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-deliverability.d.ts +21 -4
- package/dist/matter/account-address-book/account-address-book-deliverability.js +45 -17
- package/dist/matter/account-address-book/account-address-book-deliverability.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-form-parts.d.ts +74 -19
- package/dist/matter/account-address-book/account-address-book-form-parts.js +77 -26
- package/dist/matter/account-address-book/account-address-book-form-parts.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-profile-notice.d.ts +27 -6
- package/dist/matter/account-address-book/account-address-book-profile-notice.js +55 -28
- package/dist/matter/account-address-book/account-address-book-profile-notice.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book.d.ts +67 -14
- package/dist/matter/account-address-book/account-address-book.js +74 -33
- package/dist/matter/account-address-book/account-address-book.js.map +1 -1
- package/dist/matter/account-address-book/account-address-country-switch.js +3 -3
- package/dist/matter/account-address-book/account-address-country-switch.js.map +1 -1
- package/dist/matter/account-address-book/account-address-country.d.ts +66 -20
- package/dist/matter/account-address-book/account-address-country.js +83 -49
- package/dist/matter/account-address-book/account-address-country.js.map +1 -1
- package/dist/matter/account-address-book/account-address-form-context.d.ts +8 -4
- package/dist/matter/account-address-book/account-address-form-context.js.map +1 -1
- package/dist/matter/account-address-book/account-address-form.d.ts +468 -45
- package/dist/matter/account-address-book/account-address-form.js +518 -155
- package/dist/matter/account-address-book/account-address-form.js.map +1 -1
- package/dist/matter/account-address-book/account-address-record.d.ts +27 -6
- package/dist/matter/account-address-book/account-address-record.js +32 -17
- package/dist/matter/account-address-book/account-address-record.js.map +1 -1
- package/dist/matter/account-menu/account-menu.d.ts +34 -17
- package/dist/matter/account-menu/account-menu.js +46 -54
- package/dist/matter/account-menu/account-menu.js.map +1 -1
- package/dist/matter/account-menu-identity/account-menu-identity.js +1 -1
- package/dist/matter/account-saved-cards/account-saved-cards.d.ts +108 -28
- package/dist/matter/account-saved-cards/account-saved-cards.js +177 -122
- package/dist/matter/account-saved-cards/account-saved-cards.js.map +1 -1
- package/dist/matter/billing-address/billing-address.d.ts +156 -74
- package/dist/matter/billing-address/billing-address.js +227 -156
- package/dist/matter/billing-address/billing-address.js.map +1 -1
- package/dist/matter/breadcrumb/breadcrumb.d.ts +21 -3
- package/dist/matter/breadcrumb/breadcrumb.js +24 -9
- package/dist/matter/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/matter/buy-button/buy-button.d.ts +8 -11
- package/dist/matter/buy-button/buy-button.js +10 -19
- package/dist/matter/buy-button/buy-button.js.map +1 -1
- package/dist/matter/card-entry/card-capture.js +12 -4
- package/dist/matter/card-entry/card-capture.js.map +1 -1
- package/dist/matter/card-entry/card-entry.d.ts +123 -32
- package/dist/matter/card-entry/card-entry.js +348 -221
- package/dist/matter/card-entry/card-entry.js.map +1 -1
- package/dist/matter/cart/cart-namespace.d.ts +7 -1
- package/dist/matter/cart/cart-namespace.js +7 -1
- package/dist/matter/cart/cart-namespace.js.map +1 -1
- package/dist/matter/cart/cart.d.ts +402 -61
- package/dist/matter/cart/cart.js +624 -153
- package/dist/matter/cart/cart.js.map +1 -1
- package/dist/matter/cart-destination/cart-destination.d.ts +30 -19
- package/dist/matter/cart-destination/cart-destination.js +160 -70
- package/dist/matter/cart-destination/cart-destination.js.map +1 -1
- package/dist/matter/cart-item/cart-item.d.ts +144 -17
- package/dist/matter/cart-item/cart-item.js +166 -49
- package/dist/matter/cart-item/cart-item.js.map +1 -1
- package/dist/matter/cart-item-compositions/cart-item-compositions.js +1 -1
- package/dist/matter/cart-item-compositions/cart-item-compositions.js.map +1 -1
- package/dist/matter/cart-item-customizations/cart-item-customizations.js +1 -1
- package/dist/matter/cart-item-customizations/cart-item-customizations.js.map +1 -1
- package/dist/matter/cart-item-discounts/cart-item-discounts.js +1 -1
- package/dist/matter/cart-item-discounts/cart-item-discounts.js.map +1 -1
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.js +1 -1
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.js.map +1 -1
- package/dist/matter/cart-item-variations/cart-item-variations.js +1 -1
- package/dist/matter/cart-item-variations/cart-item-variations.js.map +1 -1
- package/dist/matter/cart-totalizer/cart-totalizer.d.ts +43 -9
- package/dist/matter/cart-totalizer/cart-totalizer.js +46 -17
- package/dist/matter/cart-totalizer/cart-totalizer.js.map +1 -1
- package/dist/matter/challenge-return/challenge-return.d.ts +62 -0
- package/dist/matter/challenge-return/challenge-return.js +241 -0
- package/dist/matter/challenge-return/challenge-return.js.map +1 -0
- package/dist/matter/client-preferences/client-preferences-fieldset.d.ts +86 -17
- package/dist/matter/client-preferences/client-preferences-fieldset.js +126 -54
- package/dist/matter/client-preferences/client-preferences-fieldset.js.map +1 -1
- package/dist/matter/client-preferences/client-preferences.d.ts +50 -7
- package/dist/matter/client-preferences/client-preferences.js +84 -15
- package/dist/matter/client-preferences/client-preferences.js.map +1 -1
- package/dist/matter/client-profile/client-profile.d.ts +44 -9
- package/dist/matter/client-profile/client-profile.js +64 -24
- package/dist/matter/client-profile/client-profile.js.map +1 -1
- package/dist/matter/client-profile-form/client-profile-fieldset.d.ts +119 -22
- package/dist/matter/client-profile-form/client-profile-fieldset.js +161 -73
- package/dist/matter/client-profile-form/client-profile-fieldset.js.map +1 -1
- package/dist/matter/delivery-options/delivery-options-accordion.d.ts +49 -4
- package/dist/matter/delivery-options/delivery-options-accordion.js +67 -14
- package/dist/matter/delivery-options/delivery-options-accordion.js.map +1 -1
- package/dist/matter/delivery-options/delivery-options-controller.d.ts +69 -9
- package/dist/matter/delivery-options/delivery-options-controller.js +80 -14
- package/dist/matter/delivery-options/delivery-options-controller.js.map +1 -1
- package/dist/matter/delivery-options/delivery-options.d.ts +37 -2
- package/dist/matter/delivery-options/delivery-options.js +75 -12
- package/dist/matter/delivery-options/delivery-options.js.map +1 -1
- package/dist/matter/delivery-options/use-delivery-option-selection.d.ts +1 -0
- package/dist/matter/delivery-options/use-delivery-option-selection.js +1 -1
- package/dist/matter/delivery-options/use-delivery-option-selection.js.map +1 -1
- package/dist/matter/email-identification/email-identification.d.ts +25 -3
- package/dist/matter/email-identification/email-identification.js +49 -12
- package/dist/matter/email-identification/email-identification.js.map +1 -1
- package/dist/matter/free-shipping-progress/free-shipping-progress.d.ts +79 -7
- package/dist/matter/free-shipping-progress/free-shipping-progress.js +77 -20
- package/dist/matter/free-shipping-progress/free-shipping-progress.js.map +1 -1
- package/dist/matter/identity-edit/identity-edit.d.ts +52 -10
- package/dist/matter/identity-edit/identity-edit.js +47 -19
- package/dist/matter/identity-edit/identity-edit.js.map +1 -1
- package/dist/matter/identity-summary/identity-summary.d.ts +76 -22
- package/dist/matter/identity-summary/identity-summary.js +95 -45
- package/dist/matter/identity-summary/identity-summary.js.map +1 -1
- package/dist/matter/installments/installments-select.d.ts +98 -16
- package/dist/matter/installments/installments-select.js +156 -48
- package/dist/matter/installments/installments-select.js.map +1 -1
- package/dist/matter/installments/installments.d.ts +96 -16
- package/dist/matter/installments/installments.js +115 -40
- package/dist/matter/installments/installments.js.map +1 -1
- package/dist/matter/installments/use-installments-selection.d.ts +1 -0
- package/dist/matter/installments/use-installments-selection.js +8 -3
- package/dist/matter/installments/use-installments-selection.js.map +1 -1
- package/dist/matter/my-account-profile/my-account-profile.d.ts +358 -103
- package/dist/matter/my-account-profile/my-account-profile.js +370 -174
- package/dist/matter/my-account-profile/my-account-profile.js.map +1 -1
- package/dist/matter/order-cancel/order-cancel.d.ts +65 -19
- package/dist/matter/order-cancel/order-cancel.js +118 -51
- package/dist/matter/order-cancel/order-cancel.js.map +1 -1
- package/dist/matter/order-delivery-address/order-delivery-address.d.ts +8 -18
- package/dist/matter/order-delivery-address/order-delivery-address.js +14 -23
- package/dist/matter/order-delivery-address/order-delivery-address.js.map +1 -1
- package/dist/matter/order-delivery-group/order-delivery-group.d.ts +40 -24
- package/dist/matter/order-delivery-group/order-delivery-group.js +64 -74
- package/dist/matter/order-delivery-group/order-delivery-group.js.map +1 -1
- package/dist/matter/order-details-header/order-details-header.d.ts +32 -15
- package/dist/matter/order-details-header/order-details-header.js +66 -58
- package/dist/matter/order-details-header/order-details-header.js.map +1 -1
- package/dist/matter/order-invoice-download/order-invoice-download.d.ts +78 -0
- package/dist/matter/order-invoice-download/order-invoice-download.js +173 -0
- package/dist/matter/order-invoice-download/order-invoice-download.js.map +1 -0
- package/dist/matter/order-list/order-list.d.ts +164 -19
- package/dist/matter/order-list/order-list.js +229 -87
- package/dist/matter/order-list/order-list.js.map +1 -1
- package/dist/matter/order-list-row/order-list-row.d.ts +6 -1
- package/dist/matter/order-list-row/order-list-row.js +3 -2
- package/dist/matter/order-list-row/order-list-row.js.map +1 -1
- package/dist/matter/order-list-search/order-list-search.d.ts +18 -26
- package/dist/matter/order-list-search/order-list-search.js +30 -69
- package/dist/matter/order-list-search/order-list-search.js.map +1 -1
- package/dist/matter/order-list-views/order-list-views.d.ts +15 -22
- package/dist/matter/order-list-views/order-list-views.js +22 -68
- package/dist/matter/order-list-views/order-list-views.js.map +1 -1
- package/dist/matter/order-payment/order-payment.d.ts +33 -10
- package/dist/matter/order-payment/order-payment.js +44 -39
- package/dist/matter/order-payment/order-payment.js.map +1 -1
- package/dist/matter/order-placed/order-placed-deliveries.d.ts +144 -12
- package/dist/matter/order-placed/order-placed-deliveries.js +115 -40
- package/dist/matter/order-placed/order-placed-deliveries.js.map +1 -1
- package/dist/matter/order-placed/order-placed.d.ts +198 -31
- package/dist/matter/order-placed/order-placed.js +230 -139
- package/dist/matter/order-placed/order-placed.js.map +1 -1
- package/dist/matter/order-placed-date/order-placed-date.d.ts +5 -8
- package/dist/matter/order-placed-date/order-placed-date.js +7 -8
- package/dist/matter/order-placed-date/order-placed-date.js.map +1 -1
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.d.ts +90 -17
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.js +93 -117
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.js.map +1 -1
- package/dist/matter/order-progress/order-progress.d.ts +19 -8
- package/dist/matter/order-progress/order-progress.js +37 -45
- package/dist/matter/order-progress/order-progress.js.map +1 -1
- package/dist/matter/order-summary/order-summary.d.ts +19 -9
- package/dist/matter/order-summary/order-summary.js +38 -44
- package/dist/matter/order-summary/order-summary.js.map +1 -1
- package/dist/matter/order-tracking-link/order-tracking-link.d.ts +43 -0
- package/dist/matter/order-tracking-link/order-tracking-link.js +107 -0
- package/dist/matter/order-tracking-link/order-tracking-link.js.map +1 -0
- package/dist/matter/payment/payment-card-capture.js +17 -10
- package/dist/matter/payment/payment-card-capture.js.map +1 -1
- package/dist/matter/payment/payment-controller.d.ts +4 -2
- package/dist/matter/payment/payment-controller.js +30 -9
- package/dist/matter/payment/payment-controller.js.map +1 -1
- package/dist/matter/payment/payment-method-badges.js +1 -1
- package/dist/matter/payment/payment.d.ts +69 -19
- package/dist/matter/payment/payment.js +101 -35
- package/dist/matter/payment/payment.js.map +1 -1
- package/dist/matter/payment/use-payment-method-selection.d.ts +25 -4
- package/dist/matter/payment/use-payment-method-selection.js +94 -32
- package/dist/matter/payment/use-payment-method-selection.js.map +1 -1
- package/dist/matter/payment/use-payment-submit-gate.d.ts +14 -3
- package/dist/matter/payment/use-payment-submit-gate.js +47 -8
- package/dist/matter/payment/use-payment-submit-gate.js.map +1 -1
- package/dist/matter/place-order/place-order.d.ts +171 -57
- package/dist/matter/place-order/place-order.js +376 -185
- package/dist/matter/place-order/place-order.js.map +1 -1
- package/dist/matter/pricing/pricing.d.ts +152 -13
- package/dist/matter/pricing/pricing.js +153 -52
- package/dist/matter/pricing/pricing.js.map +1 -1
- package/dist/matter/product-information/product-information.d.ts +27 -4
- package/dist/matter/product-information/product-information.js +32 -15
- package/dist/matter/product-information/product-information.js.map +1 -1
- package/dist/matter/product-list/product-list.d.ts +24 -6
- package/dist/matter/product-list/product-list.js +32 -26
- package/dist/matter/product-list/product-list.js.map +1 -1
- package/dist/matter/product-shelf/product-shelf.d.ts +1 -3
- package/dist/matter/product-shelf/product-shelf.js +2 -15
- package/dist/matter/product-shelf/product-shelf.js.map +1 -1
- package/dist/matter/region/region.d.ts +33 -16
- package/dist/matter/region/region.js +59 -52
- package/dist/matter/region/region.js.map +1 -1
- package/dist/matter/save-card/save-card.d.ts +43 -8
- package/dist/matter/save-card/save-card.js +61 -23
- package/dist/matter/save-card/save-card.js.map +1 -1
- package/dist/matter/saved-cards/saved-cards.d.ts +113 -21
- package/dist/matter/saved-cards/saved-cards.js +349 -77
- package/dist/matter/saved-cards/saved-cards.js.map +1 -1
- package/dist/matter/shipping-address/address-payload.js +25 -0
- package/dist/matter/shipping-address/address-payload.js.map +1 -0
- package/dist/matter/shipping-address/country-descriptors.js +71 -71
- package/dist/matter/shipping-address/country-descriptors.js.map +1 -1
- package/dist/matter/shipping-address/library-country-descriptors.js +136 -0
- package/dist/matter/shipping-address/library-country-descriptors.js.map +1 -0
- package/dist/matter/shipping-address/shipping-address.d.ts +312 -45
- package/dist/matter/shipping-address/shipping-address.js +443 -188
- package/dist/matter/shipping-address/shipping-address.js.map +1 -1
- package/dist/matter/shipping-simulator/shipping-simulator.d.ts +250 -24
- package/dist/matter/shipping-simulator/shipping-simulator.js +257 -51
- package/dist/matter/shipping-simulator/shipping-simulator.js.map +1 -1
- package/dist/matter/sign-in/sign-in.d.ts +108 -0
- package/dist/matter/sign-in/sign-in.js +285 -0
- package/dist/matter/sign-in/sign-in.js.map +1 -0
- package/dist/matter/sign-in-disclosure/sign-in-disclosure.d.ts +81 -0
- package/dist/matter/sign-in-disclosure/sign-in-disclosure.js +232 -0
- package/dist/matter/sign-in-disclosure/sign-in-disclosure.js.map +1 -0
- package/dist/matter/sign-in-form/sign-in-form.d.ts +93 -62
- package/dist/matter/sign-in-form/sign-in-form.js +134 -144
- package/dist/matter/sign-in-form/sign-in-form.js.map +1 -1
- package/dist/particles/binding-switcher/binding-switcher.d.ts +29 -8
- package/dist/particles/binding-switcher/binding-switcher.js +37 -26
- package/dist/particles/binding-switcher/binding-switcher.js.map +1 -1
- package/dist/particles/card-summary/card-summary.d.ts +38 -8
- package/dist/particles/card-summary/card-summary.js +55 -22
- package/dist/particles/card-summary/card-summary.js.map +1 -1
- package/dist/particles/carousel/carousel.d.ts +99 -11
- package/dist/particles/carousel/carousel.js +103 -35
- package/dist/particles/carousel/carousel.js.map +1 -1
- package/dist/particles/copy-text/copy-text.js +5 -15
- package/dist/particles/copy-text/copy-text.js.map +1 -1
- package/dist/particles/dialog/dialog.d.ts +14 -6
- package/dist/particles/dialog/dialog.js +6 -3
- package/dist/particles/dialog/dialog.js.map +1 -1
- package/dist/particles/drawer/drawer.js +1 -1
- package/dist/particles/drawer/drawer.js.map +1 -1
- package/dist/particles/email-field/email-field.d.ts +2 -1
- package/dist/particles/email-field/email-field.js +2 -1
- package/dist/particles/email-field/email-field.js.map +1 -1
- package/dist/particles/footer-link-group/footer-link-group.js +1 -0
- package/dist/particles/footer-link-group/footer-link-group.js.map +1 -1
- package/dist/particles/form/form.d.ts +85 -13
- package/dist/particles/form/form.js +91 -42
- package/dist/particles/form/form.js.map +1 -1
- package/dist/particles/gallery/gallery.d.ts +129 -12
- package/dist/particles/gallery/gallery.js +121 -34
- package/dist/particles/gallery/gallery.js.map +1 -1
- package/dist/particles/order-details-back/order-details-back.d.ts +5 -3
- package/dist/particles/order-details-back/order-details-back.js +8 -10
- package/dist/particles/order-details-back/order-details-back.js.map +1 -1
- package/dist/particles/order-status-badge/order-status-badge.d.ts +3 -3
- package/dist/particles/order-status-badge/order-status-badge.js +4 -20
- package/dist/particles/order-status-badge/order-status-badge.js.map +1 -1
- package/dist/particles/password-field/password-field.d.ts +1 -1
- package/dist/particles/password-field/password-field.js +2 -4
- package/dist/particles/password-field/password-field.js.map +1 -1
- package/dist/particles/phone-field/phone-field.d.ts +4 -4
- package/dist/particles/phone-field/phone-field.js +8 -11
- package/dist/particles/phone-field/phone-field.js.map +1 -1
- package/dist/particles/spinner/spinner.d.ts +24 -4
- package/dist/particles/spinner/spinner.js +25 -9
- package/dist/particles/spinner/spinner.js.map +1 -1
- package/dist/particles/switch/switch.d.ts +4 -1
- package/dist/particles/switch/switch.js +3 -1
- package/dist/particles/switch/switch.js.map +1 -1
- package/dist/particles/toast/toast.d.ts +29 -3
- package/dist/particles/toast/toast.js +34 -10
- package/dist/particles/toast/toast.js.map +1 -1
- package/dist/schema.graphql +164 -56
- package/dist/sdk/address/address-fields.js +4 -4
- package/dist/sdk/address/address-fields.js.map +1 -1
- package/dist/sdk/address/constants.js +1 -6
- package/dist/sdk/address/constants.js.map +1 -1
- package/dist/sdk/address/messages.js +44 -44
- package/dist/sdk/address/messages.js.map +1 -1
- package/dist/sdk/address/postal-code.js +15 -2
- package/dist/sdk/address/postal-code.js.map +1 -1
- package/dist/sdk/address/types.d.ts +5 -3
- package/dist/sdk/address/validate-address.js +3 -3
- package/dist/sdk/address/validate-address.js.map +1 -1
- package/dist/sdk/analytics/use-analytics-actions.d.ts +1 -1
- package/dist/sdk/analytics/use-analytics-actions.js.map +1 -1
- package/dist/sdk/cart/use-cart-actions.js.map +1 -1
- package/dist/sdk/data/index.js +2 -2
- package/dist/sdk/data/reactive-list-item-data-provider.js +2 -2
- package/dist/sdk/generated/gql.js +1 -1
- package/dist/sdk/generated/gql.js.map +1 -1
- package/dist/sdk/generated/graphql.d.ts +20 -5
- package/dist/sdk/generated/graphql.js +6 -0
- package/dist/sdk/generated/graphql.js.map +1 -1
- package/dist/sdk/i18n/format-error-code.js +23 -0
- package/dist/sdk/i18n/format-error-code.js.map +1 -0
- package/dist/sdk/i18n/message-formatter.d.ts +22 -0
- package/dist/sdk/i18n/message-formatter.js +140 -0
- package/dist/sdk/i18n/message-formatter.js.map +1 -0
- package/dist/sdk/i18n/use-message-formatter.d.ts +8 -0
- package/dist/sdk/i18n/use-message-formatter.js +18 -0
- package/dist/sdk/i18n/use-message-formatter.js.map +1 -0
- package/dist/sdk/identity/use-identity-actions.js.map +1 -1
- package/dist/sdk/navigation/redirect.d.ts +2 -0
- package/dist/sdk/navigation/redirect.js +19 -1
- package/dist/sdk/navigation/redirect.js.map +1 -1
- package/dist/sdk/navigation/types.d.ts +13 -0
- package/dist/sdk/payment/bin-format.js +20 -0
- package/dist/sdk/payment/bin-format.js.map +1 -0
- package/dist/sdk/payment/challenge-return.js +37 -0
- package/dist/sdk/payment/challenge-return.js.map +1 -0
- package/dist/sdk/payment/confirmation-last-four.js +39 -0
- package/dist/sdk/payment/confirmation-last-four.js.map +1 -0
- package/dist/sdk/payment/gateway.d.ts +1 -1
- package/dist/sdk/payment/gateway.js +8 -2
- package/dist/sdk/payment/gateway.js.map +1 -1
- package/dist/sdk/payment/operations.d.ts +1 -0
- package/dist/sdk/payment/operations.js +28 -6
- package/dist/sdk/payment/operations.js.map +1 -1
- package/dist/sdk/payment/resumed-purchase.d.ts +1 -0
- package/dist/sdk/payment/resumed-purchase.js +119 -0
- package/dist/sdk/payment/resumed-purchase.js.map +1 -0
- package/dist/sdk/payment/security-code-mask.js +16 -23
- package/dist/sdk/payment/security-code-mask.js.map +1 -1
- package/dist/sdk/payment/submission-registry.js +6 -2
- package/dist/sdk/payment/submission-registry.js.map +1 -1
- package/dist/sdk/payment/use-payment-actions.d.ts +18 -3
- package/dist/sdk/payment/use-payment-actions.js +23 -3
- package/dist/sdk/payment/use-payment-actions.js.map +1 -1
- package/dist/sdk/payment/use-place-order.d.ts +10 -2
- package/dist/sdk/payment/use-place-order.js +138 -76
- package/dist/sdk/payment/use-place-order.js.map +1 -1
- package/dist/sdk/provider/storefront-provider.d.ts +1 -7
- package/dist/sdk/provider/storefront-provider.js +4 -11
- package/dist/sdk/provider/storefront-provider.js.map +1 -1
- package/dist/sdk/seo/entity-landing.d.ts +24 -0
- package/dist/sdk/seo/entity-landing.js +30 -0
- package/dist/sdk/seo/entity-landing.js.map +1 -0
- package/dist/sdk/seo/page-alternates.d.ts +3 -2
- package/dist/sdk/seo/page-alternates.js +4 -2
- package/dist/sdk/seo/page-alternates.js.map +1 -1
- package/dist/sdk/seo/search-landing.d.ts +42 -0
- package/dist/sdk/seo/search-landing.js +85 -0
- package/dist/sdk/seo/search-landing.js.map +1 -0
- package/dist/sdk/session/mock-session.d.ts +9 -0
- package/dist/sdk/session/mock-session.js +31 -0
- package/dist/sdk/session/mock-session.js.map +1 -0
- package/dist/sdk/session/read-server-session.d.ts +3 -0
- package/dist/sdk/session/read-server-session.js +5 -0
- package/dist/sdk/session/read-server-session.js.map +1 -1
- package/dist/sdk/session/return-path-segment.d.ts +10 -0
- package/dist/sdk/session/return-path-segment.js +15 -0
- package/dist/sdk/session/return-path-segment.js.map +1 -0
- package/dist/sdk/session/use-session-actions.js.map +1 -1
- package/dist/sdk/shipping/use-cart-shipping-simulation.js.map +1 -1
- package/dist/sdk/shipping/use-shipping-actions.js.map +1 -1
- package/dist/sdk/shipping/use-shipping-simulation.js.map +1 -1
- package/dist/utils/safe-href.d.ts +2 -0
- package/package.json +4 -3
- package/skills/storefront-asset/SKILL.md +2 -2
- package/skills/storefront-asset/references/api-side.md +27 -14
- package/skills/storefront-asset/references/findings.md +5 -2
- package/src/styles/tailwind.css +8 -0
- package/dist/matter/shipping-address/country-descriptors.d.ts +0 -1
- package/dist/message-locales.json +0 -7
- package/dist/sdk/i18n/client.d.ts +0 -4
- package/dist/sdk/i18n/client.js +0 -4
- package/dist/sdk/i18n/locales.d.ts +0 -8
- package/dist/sdk/i18n/locales.js +0 -57
- package/dist/sdk/i18n/locales.js.map +0 -1
- package/dist/sdk/i18n/messages/en-US.js +0 -183
- package/dist/sdk/i18n/messages/en-US.js.map +0 -1
- package/dist/sdk/i18n/messages/en-US.json +0 -178
- package/dist/sdk/i18n/messages/en-US.json.d.ts +0 -182
- package/dist/sdk/i18n/messages/es-ES.js +0 -183
- package/dist/sdk/i18n/messages/es-ES.js.map +0 -1
- package/dist/sdk/i18n/messages/es-ES.json +0 -178
- package/dist/sdk/i18n/messages/pt-BR.js +0 -183
- package/dist/sdk/i18n/messages/pt-BR.js.map +0 -1
- package/dist/sdk/i18n/messages/pt-BR.json +0 -178
- package/dist/sdk/i18n/provider.d.ts +0 -1
- package/dist/sdk/i18n/provider.js +0 -30
- package/dist/sdk/i18n/provider.js.map +0 -1
- package/dist/sdk/i18n/server.d.ts +0 -28
- package/dist/sdk/i18n/server.js +0 -59
- package/dist/sdk/i18n/server.js.map +0 -1
- package/dist/utils/resolve-authored-copy.js +0 -18
- package/dist/utils/resolve-authored-copy.js.map +0 -1
- package/dist/utils/substitute-template.js +0 -33
- package/dist/utils/substitute-template.js.map +0 -1
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import { defineComponent } from "../../core/dist/define-component.js";
|
|
3
3
|
import { defineContentType } from "../../core/dist/define-content-type.js";
|
|
4
4
|
import "../../core/dist/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useMessageFormatter } from "../../sdk/i18n/use-message-formatter.js";
|
|
6
6
|
import { useStorefrontNavigation } from "../../sdk/navigation/use-storefront-navigation.js";
|
|
7
7
|
import { useActionsOverride } from "../../sdk/actions/actions-override-context.js";
|
|
8
|
+
import { formatErrorCode } from "../../sdk/i18n/format-error-code.js";
|
|
8
9
|
import { Button } from "../../particles/button/button.js";
|
|
9
10
|
import { AlertDialogBackdrop, AlertDialogClose, AlertDialogDescription, AlertDialogPopup, AlertDialogPortal, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, AlertDialogViewport } from "../../particles/alert-dialog/alert-dialog.js";
|
|
10
11
|
import { Radio } from "../../particles/radio/radio.js";
|
|
@@ -36,12 +37,6 @@ const HIDDEN_STATUSES = /* @__PURE__ */ new Set([
|
|
|
36
37
|
const OTHER = "other";
|
|
37
38
|
/** Matches `CUSTOMER_ORDER_CANCEL_REASON_MAX_LENGTH` in the orders module. */
|
|
38
39
|
const REASON_MAX_LENGTH = 500;
|
|
39
|
-
const REASON_IDS = [
|
|
40
|
-
"fs/order-cancel.reason.changed-mind",
|
|
41
|
-
"fs/order-cancel.reason.bought-by-mistake",
|
|
42
|
-
"fs/order-cancel.reason.better-price",
|
|
43
|
-
"fs/order-cancel.reason.slow-delivery"
|
|
44
|
-
];
|
|
45
40
|
const OrderCancelContent = defineContentType({
|
|
46
41
|
id: "order-cancel",
|
|
47
42
|
title: "Order Cancel",
|
|
@@ -52,53 +47,105 @@ const OrderCancelContent = defineContentType({
|
|
|
52
47
|
properties: {
|
|
53
48
|
trigger: {
|
|
54
49
|
type: "string",
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
title: "Trigger",
|
|
51
|
+
format: "icu-message",
|
|
52
|
+
messageSource: "Cancel order"
|
|
57
53
|
},
|
|
58
54
|
title: {
|
|
59
55
|
type: "string",
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
title: "Title",
|
|
57
|
+
format: "icu-message",
|
|
58
|
+
messageSource: "Cancel this order?"
|
|
62
59
|
},
|
|
63
60
|
description: {
|
|
64
61
|
type: "string",
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
title: "Description",
|
|
63
|
+
format: "icu-message",
|
|
64
|
+
messageSource: "This cannot be undone."
|
|
67
65
|
},
|
|
68
66
|
confirm: {
|
|
69
67
|
type: "string",
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
title: "Confirm",
|
|
69
|
+
format: "icu-message",
|
|
70
|
+
messageSource: "Cancel order"
|
|
72
71
|
},
|
|
73
72
|
dismiss: {
|
|
74
73
|
type: "string",
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
title: "Dismiss",
|
|
75
|
+
format: "icu-message",
|
|
76
|
+
messageSource: "Keep order"
|
|
77
77
|
},
|
|
78
78
|
other: {
|
|
79
79
|
type: "string",
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
title: "Other",
|
|
81
|
+
format: "icu-message",
|
|
82
|
+
messageSource: "Other"
|
|
82
83
|
},
|
|
83
84
|
otherField: {
|
|
84
85
|
type: "string",
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
title: "Other field",
|
|
87
|
+
format: "icu-message",
|
|
88
|
+
messageSource: "Reason"
|
|
87
89
|
},
|
|
88
90
|
success: {
|
|
89
91
|
type: "string",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
title: "Success",
|
|
93
|
+
format: "icu-message",
|
|
94
|
+
messageSource: "Your order was cancelled."
|
|
92
95
|
},
|
|
93
96
|
failure: {
|
|
94
97
|
type: "string",
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
title: "Failure",
|
|
99
|
+
format: "icu-message",
|
|
100
|
+
messageSource: "Unable to cancel the order. Please try again."
|
|
101
|
+
},
|
|
102
|
+
notCancellableMessage: {
|
|
103
|
+
type: "string",
|
|
104
|
+
title: "Not cancellable message",
|
|
105
|
+
description: "Shown when the order is past the point where it can be cancelled.",
|
|
106
|
+
format: "icu-message",
|
|
107
|
+
messageSource: "This order can no longer be cancelled."
|
|
108
|
+
},
|
|
109
|
+
notFoundMessage: {
|
|
110
|
+
type: "string",
|
|
111
|
+
title: "Order not found message",
|
|
112
|
+
description: "Shown when the order is not one the signed-in shopper can see.",
|
|
113
|
+
format: "icu-message",
|
|
114
|
+
messageSource: "We could not find this order."
|
|
97
115
|
},
|
|
98
116
|
dismissMessage: {
|
|
99
117
|
type: "string",
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
title: "Dismiss message",
|
|
119
|
+
format: "icu-message",
|
|
120
|
+
messageSource: "Dismiss"
|
|
121
|
+
},
|
|
122
|
+
reasonChangedMind: {
|
|
123
|
+
type: "string",
|
|
124
|
+
title: "Reason: changed mind",
|
|
125
|
+
description: "Default reason option.",
|
|
126
|
+
format: "icu-message",
|
|
127
|
+
messageSource: "Changed my mind"
|
|
128
|
+
},
|
|
129
|
+
reasonBoughtByMistake: {
|
|
130
|
+
type: "string",
|
|
131
|
+
title: "Reason: bought by mistake",
|
|
132
|
+
description: "Default reason option.",
|
|
133
|
+
format: "icu-message",
|
|
134
|
+
messageSource: "Bought by mistake"
|
|
135
|
+
},
|
|
136
|
+
reasonBetterPrice: {
|
|
137
|
+
type: "string",
|
|
138
|
+
title: "Reason: better price",
|
|
139
|
+
description: "Default reason option.",
|
|
140
|
+
format: "icu-message",
|
|
141
|
+
messageSource: "Found a better price"
|
|
142
|
+
},
|
|
143
|
+
reasonSlowDelivery: {
|
|
144
|
+
type: "string",
|
|
145
|
+
title: "Reason: slow delivery",
|
|
146
|
+
description: "Default reason option.",
|
|
147
|
+
format: "icu-message",
|
|
148
|
+
messageSource: "Delivery is too slow"
|
|
102
149
|
},
|
|
103
150
|
reasons: {
|
|
104
151
|
type: "array",
|
|
@@ -117,6 +164,13 @@ const OrderCancelContent = defineContentType({
|
|
|
117
164
|
}
|
|
118
165
|
}
|
|
119
166
|
});
|
|
167
|
+
/** The default reasons, in display order, offered when the content authors no `reasons`. */
|
|
168
|
+
const DEFAULT_REASONS = [
|
|
169
|
+
"reasonChangedMind",
|
|
170
|
+
"reasonBoughtByMistake",
|
|
171
|
+
"reasonBetterPrice",
|
|
172
|
+
"reasonSlowDelivery"
|
|
173
|
+
];
|
|
120
174
|
const OrderCancelDefinition = defineComponent({
|
|
121
175
|
name: "OrderCancel",
|
|
122
176
|
importPath: "@vtex/faststore/components",
|
|
@@ -130,7 +184,7 @@ const OrderCancelDefinition = defineComponent({
|
|
|
130
184
|
category: "action"
|
|
131
185
|
},
|
|
132
186
|
schema: {},
|
|
133
|
-
guideline: "Cancels one eligible order after the shopper confirms in an alert dialog. Place it on the order page. It hides when the order cannot be cancelled or a cancellation is already requested. Reasons and the dialog copy are content
|
|
187
|
+
guideline: "Cancels one eligible order after the shopper confirms in an alert dialog. Place it on the order page. It hides when the order cannot be cancelled or a cancellation is already requested. Reasons and the dialog copy are content. Other is always offered. See order-cancel.md."
|
|
134
188
|
});
|
|
135
189
|
function OrderCancelSkeleton({ className }) {
|
|
136
190
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -139,28 +193,37 @@ function OrderCancelSkeleton({ className }) {
|
|
|
139
193
|
"aria-hidden": "true"
|
|
140
194
|
});
|
|
141
195
|
}
|
|
142
|
-
function
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
function copyOf(content, intl) {
|
|
146
|
-
const authored = content?.reasons?.flatMap((item) => {
|
|
196
|
+
function reasonsOf(content, format) {
|
|
197
|
+
if (content?.reasons == null) return DEFAULT_REASONS.map((field) => format(field));
|
|
198
|
+
return content.reasons.flatMap((item) => {
|
|
147
199
|
const label = item.label.trim();
|
|
148
200
|
return label ? [label] : [];
|
|
149
201
|
});
|
|
202
|
+
}
|
|
203
|
+
function copyOf(content, { format }) {
|
|
150
204
|
return {
|
|
151
|
-
trigger:
|
|
152
|
-
title:
|
|
153
|
-
description:
|
|
154
|
-
confirm:
|
|
155
|
-
dismiss:
|
|
156
|
-
other:
|
|
157
|
-
otherField:
|
|
158
|
-
success:
|
|
159
|
-
failure:
|
|
160
|
-
dismissMessage:
|
|
161
|
-
reasons: content
|
|
205
|
+
trigger: format("trigger"),
|
|
206
|
+
title: format("title"),
|
|
207
|
+
description: format("description"),
|
|
208
|
+
confirm: format("confirm"),
|
|
209
|
+
dismiss: format("dismiss"),
|
|
210
|
+
other: format("other"),
|
|
211
|
+
otherField: format("otherField"),
|
|
212
|
+
success: format("success"),
|
|
213
|
+
failure: format("failure"),
|
|
214
|
+
dismissMessage: format("dismissMessage"),
|
|
215
|
+
reasons: reasonsOf(content, format)
|
|
162
216
|
};
|
|
163
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* The message for each cancellation refusal: the server's `CustomerOrderCancelErrorCode` values plus
|
|
220
|
+
* the client-minted transport failure. A code this map does not know shows `failure`.
|
|
221
|
+
*/
|
|
222
|
+
const ORDER_CANCEL_ERROR_FIELDS = {
|
|
223
|
+
ORDER_NOT_CANCELLABLE: "notCancellableMessage",
|
|
224
|
+
NOT_FOUND: "notFoundMessage",
|
|
225
|
+
NETWORK_ERROR: "failure"
|
|
226
|
+
};
|
|
164
227
|
function chosenReason(selected, reasons, otherText) {
|
|
165
228
|
if (selected == null) return void 0;
|
|
166
229
|
if (selected === OTHER) return otherText.trim() || void 0;
|
|
@@ -168,16 +231,16 @@ function chosenReason(selected, reasons, otherText) {
|
|
|
168
231
|
}
|
|
169
232
|
function OrderCancel({ $data, $actions: $actionsProp, $content, className, ref }) {
|
|
170
233
|
const $actions = useActionsOverride($actionsProp);
|
|
171
|
-
const
|
|
234
|
+
const messages = useMessageFormatter(OrderCancelContent, $content);
|
|
172
235
|
const { refresh } = useStorefrontNavigation();
|
|
173
|
-
const copy = copyOf($content,
|
|
236
|
+
const copy = copyOf($content, messages);
|
|
174
237
|
const [open, setOpen] = useState(false);
|
|
175
238
|
const [selected, setSelected] = useState(null);
|
|
176
239
|
const [otherText, setOtherText] = useState("");
|
|
177
240
|
const [pending, setPending] = useState(false);
|
|
178
241
|
const [succeeded, setSucceeded] = useState(false);
|
|
179
242
|
const [outcome, setOutcome] = useState("idle");
|
|
180
|
-
const [
|
|
243
|
+
const [failure, setFailure] = useState(null);
|
|
181
244
|
const pendingRef = useRef(false);
|
|
182
245
|
const requestRef = useRef(0);
|
|
183
246
|
const messageRef = useRef(null);
|
|
@@ -200,7 +263,7 @@ function OrderCancel({ $data, $actions: $actionsProp, $content, className, ref }
|
|
|
200
263
|
if (pendingRef.current || !$data) return;
|
|
201
264
|
const cancel = $actions?.order?.cancel;
|
|
202
265
|
if (!cancel) {
|
|
203
|
-
|
|
266
|
+
setFailure(null);
|
|
204
267
|
setOutcome("failure");
|
|
205
268
|
return;
|
|
206
269
|
}
|
|
@@ -222,13 +285,17 @@ function OrderCancel({ $data, $actions: $actionsProp, $content, className, ref }
|
|
|
222
285
|
refresh();
|
|
223
286
|
return;
|
|
224
287
|
}
|
|
225
|
-
|
|
288
|
+
setFailure(result.userErrors[0] ?? null);
|
|
226
289
|
setOutcome("failure");
|
|
227
290
|
} finally {
|
|
228
291
|
pendingRef.current = false;
|
|
229
292
|
setPending(false);
|
|
230
293
|
}
|
|
231
294
|
}
|
|
295
|
+
function failureMessage() {
|
|
296
|
+
if (!failure) return copy.failure;
|
|
297
|
+
return formatErrorCode(OrderCancelContent, ORDER_CANCEL_ERROR_FIELDS, failure, messages.format, "failure");
|
|
298
|
+
}
|
|
232
299
|
function dismissMessage() {
|
|
233
300
|
setOutcome("idle");
|
|
234
301
|
}
|
|
@@ -303,7 +370,7 @@ function OrderCancel({ $data, $actions: $actionsProp, $content, className, ref }
|
|
|
303
370
|
}) : null,
|
|
304
371
|
outcome === "failure" ? /* @__PURE__ */ jsx(Acknowledgement, {
|
|
305
372
|
ref: messageRef,
|
|
306
|
-
message: failureMessage,
|
|
373
|
+
message: failureMessage(),
|
|
307
374
|
dismissLabel: copy.dismissMessage,
|
|
308
375
|
onDismiss: dismissMessage
|
|
309
376
|
}) : null,
|
|
@@ -339,6 +406,6 @@ function Acknowledgement({ ref, message, dismissLabel, onDismiss }) {
|
|
|
339
406
|
});
|
|
340
407
|
}
|
|
341
408
|
//#endregion
|
|
342
|
-
export { OrderCancel, OrderCancelContent, OrderCancelDefinition, OrderCancelSkeleton };
|
|
409
|
+
export { ORDER_CANCEL_ERROR_FIELDS, OrderCancel, OrderCancelContent, OrderCancelDefinition, OrderCancelSkeleton };
|
|
343
410
|
|
|
344
411
|
//# sourceMappingURL=order-cancel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-cancel.js","names":[],"sources":["../../../src/matter/order-cancel/order-cancel.tsx"],"sourcesContent":["'use client';\n\nimport { type ContentValue, defineComponent, defineContentType } from '@vtex/fs-core';\nimport type { Ref } from 'react';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n AlertDialogBackdrop,\n AlertDialogClose,\n AlertDialogDescription,\n AlertDialogPopup,\n AlertDialogPortal,\n AlertDialogRoot,\n AlertDialogTitle,\n AlertDialogTrigger,\n AlertDialogViewport,\n} from '../../particles/alert-dialog/alert-dialog.js';\nimport { Button } from '../../particles/button/button.js';\nimport { Input } from '../../particles/input/input.js';\nimport { Radio } from '../../particles/radio/radio.js';\nimport { useActionsOverride } from '../../sdk/actions/actions-override-context.js';\nimport type { ComponentActions } from '../../sdk/actions/types.js';\nimport { useIntl } from '../../sdk/i18n/client.js';\nimport type { MessageId } from '../../sdk/i18n/locales.js';\nimport { useStorefrontNavigation } from '../../sdk/navigation/use-storefront-navigation.js';\n\nconst fragment = /* GraphQL */ `\n fragment OrderCancelData on Query {\n customerOrder(id: $orderId) {\n id\n status\n allowCancellation\n }\n }\n`;\n\n/**\n * OMS statuses that already mean a cancellation was requested or finished.\n * `allowCancellation` can stay true in the intermediate ones, so the flag alone\n * would show the button again.\n */\nconst HIDDEN_STATUSES = new Set([\n 'request-cancel',\n 'cancellation-requested',\n 'cancellation-requested-with-ack',\n 'cancel',\n 'canceled',\n]);\n\nconst OTHER = 'other';\n\n/** Matches `CUSTOMER_ORDER_CANCEL_REASON_MAX_LENGTH` in the orders module. */\nconst REASON_MAX_LENGTH = 500;\n\nconst REASON_IDS = [\n 'fs/order-cancel.reason.changed-mind',\n 'fs/order-cancel.reason.bought-by-mistake',\n 'fs/order-cancel.reason.better-price',\n 'fs/order-cancel.reason.slow-delivery',\n] as const satisfies readonly MessageId[];\n\nexport const OrderCancelContent = defineContentType({\n id: 'order-cancel',\n title: 'Order Cancel',\n description: 'Confirmation copy and the optional cancellation reasons for one order.',\n schema: {\n type: 'object',\n additionalProperties: false,\n // Literals, not `COPY.*`: the catalog scanner only evaluates values it can see in the call.\n properties: {\n trigger: { type: 'string', default: 'Cancel order', title: 'Trigger' },\n title: { type: 'string', default: 'Cancel this order?', title: 'Title' },\n description: { type: 'string', default: 'This cannot be undone.', title: 'Description' },\n confirm: { type: 'string', default: 'Cancel order', title: 'Confirm' },\n dismiss: { type: 'string', default: 'Keep order', title: 'Dismiss' },\n other: { type: 'string', default: 'Other', title: 'Other' },\n otherField: { type: 'string', default: 'Reason', title: 'Other field' },\n success: { type: 'string', default: 'Your order was cancelled.', title: 'Success' },\n failure: { type: 'string', default: 'Unable to cancel the order. Please try again.', title: 'Failure' },\n dismissMessage: { type: 'string', default: 'Dismiss', title: 'Dismiss message' },\n reasons: {\n type: 'array',\n title: 'Reasons',\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['label'],\n properties: {\n label: { type: 'string', minLength: 1, title: 'Label' },\n },\n },\n },\n },\n },\n});\n\nexport type OrderCancelContentValue = ContentValue<typeof OrderCancelContent>;\n\n/** Unwrapped `customerOrder`. A single-root fragment binds `$data` to that field. */\nexport type OrderCancelData = {\n id: string;\n status: string;\n allowCancellation: boolean;\n};\n\nexport type OrderCancelProps = Readonly<{\n $data?: OrderCancelData | null;\n $actions?: ComponentActions;\n $content?: OrderCancelContentValue;\n className?: string;\n ref?: Ref<HTMLDivElement>;\n}>;\n\ntype OrderCancelCopy = {\n trigger: string;\n title: string;\n description: string;\n confirm: string;\n dismiss: string;\n other: string;\n otherField: string;\n success: string;\n failure: string;\n dismissMessage: string;\n reasons: readonly string[];\n};\n\nexport const OrderCancelDefinition = defineComponent<OrderCancelProps>({\n name: 'OrderCancel',\n importPath: '@vtex/faststore/components',\n component: OrderCancel,\n fragment,\n skeleton: OrderCancelSkeleton,\n actions: { order: ['cancel'] },\n content: OrderCancelContent,\n editor: { label: 'Order Cancel', category: 'action' },\n schema: {},\n guideline:\n 'Cancels one eligible order after the shopper confirms in an alert dialog. Place it on the order page. It hides when the order cannot be cancelled or a cancellation is already requested. Reasons and the dialog copy are content; a blank field uses the message catalog. Other is always offered. See order-cancel.md.',\n});\n\nexport function OrderCancelSkeleton({ className }: Readonly<{ className?: string }>) {\n return <div className={className} data-fs-order-cancel-skeleton=\"\" aria-hidden=\"true\" />;\n}\n\nfunction text(value: string | undefined, fallback: string): string {\n const trimmed = value?.trim();\n return trimmed || fallback;\n}\n\nfunction copyOf(content: OrderCancelContentValue | undefined, intl: ReturnType<typeof useIntl>): OrderCancelCopy {\n const authored = content?.reasons?.flatMap((item) => {\n const label = item.label.trim();\n return label ? [label] : [];\n });\n return {\n trigger: text(content?.trigger, intl.formatMessage({ id: 'fs/order-cancel.trigger' })),\n title: text(content?.title, intl.formatMessage({ id: 'fs/order-cancel.title' })),\n description: text(content?.description, intl.formatMessage({ id: 'fs/order-cancel.description' })),\n confirm: text(content?.confirm, intl.formatMessage({ id: 'fs/order-cancel.confirm' })),\n dismiss: text(content?.dismiss, intl.formatMessage({ id: 'fs/order-cancel.dismiss' })),\n other: text(content?.other, intl.formatMessage({ id: 'fs/order-cancel.other' })),\n otherField: text(content?.otherField, intl.formatMessage({ id: 'fs/order-cancel.other-field' })),\n success: text(content?.success, intl.formatMessage({ id: 'fs/order-cancel.success' })),\n failure: text(content?.failure, intl.formatMessage({ id: 'fs/order-cancel.failure' })),\n dismissMessage: text(content?.dismissMessage, intl.formatMessage({ id: 'fs/order-cancel.dismiss-message' })),\n reasons: content?.reasons == null ? REASON_IDS.map((id) => intl.formatMessage({ id })) : (authored ?? []),\n };\n}\n\nfunction chosenReason(selected: string | null, reasons: readonly string[], otherText: string): string | undefined {\n if (selected == null) return undefined;\n if (selected === OTHER) {\n const trimmed = otherText.trim();\n return trimmed || undefined;\n }\n const label = reasons[Number(selected)]?.trim();\n return label || undefined;\n}\n\nexport function OrderCancel({ $data, $actions: $actionsProp, $content, className, ref }: OrderCancelProps) {\n const $actions = useActionsOverride($actionsProp);\n const intl = useIntl();\n const { refresh } = useStorefrontNavigation();\n const copy = copyOf($content, intl);\n const [open, setOpen] = useState(false);\n const [selected, setSelected] = useState<string | null>(null);\n const [otherText, setOtherText] = useState('');\n const [pending, setPending] = useState(false);\n const [succeeded, setSucceeded] = useState(false);\n const [outcome, setOutcome] = useState<'idle' | 'success' | 'failure'>('idle');\n const [failureMessage, setFailureMessage] = useState(copy.failure);\n const pendingRef = useRef(false);\n const requestRef = useRef(0);\n const messageRef = useRef<HTMLButtonElement>(null);\n const portalRoot = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (outcome === 'success' || outcome === 'failure') {\n messageRef.current?.focus();\n }\n }, [outcome]);\n\n const ineligible = !$data?.allowCancellation || ($data != null && HIDDEN_STATUSES.has($data.status));\n\n function onOpenChange(next: boolean) {\n if (!next && pendingRef.current) return;\n setOpen(next);\n if (!next) {\n requestRef.current += 1;\n setSelected(null);\n setOtherText('');\n setOutcome((current) => (current === 'failure' ? 'idle' : current));\n }\n }\n\n async function confirm() {\n if (pendingRef.current || !$data) return;\n const cancel = $actions?.order?.cancel;\n if (!cancel) {\n setFailureMessage(copy.failure);\n setOutcome('failure');\n return;\n }\n\n const request = requestRef.current + 1;\n requestRef.current = request;\n pendingRef.current = true;\n setPending(true);\n try {\n const reason = chosenReason(selected, copy.reasons, otherText);\n const result = await cancel(reason == null ? { id: $data.id } : { id: $data.id, reason });\n if (request !== requestRef.current) return;\n if (result.userErrors.length === 0) {\n setSucceeded(true);\n setOutcome('success');\n setOpen(false);\n refresh();\n return;\n }\n\n setFailureMessage(result.userErrors[0]?.message ?? copy.failure);\n setOutcome('failure');\n } finally {\n pendingRef.current = false;\n setPending(false);\n }\n }\n\n function dismissMessage() {\n setOutcome('idle');\n }\n\n function setRoot(node: HTMLDivElement | null) {\n portalRoot.current = node;\n if (typeof ref === 'function') {\n ref(node);\n return;\n }\n if (ref) {\n ref.current = node;\n }\n }\n\n if (ineligible || (succeeded && outcome !== 'success')) return null;\n\n if (succeeded) {\n return (\n <div ref={ref} className={className} data-fs-order-cancel=\"\" data-fs-order-cancel-outcome=\"success\">\n <Acknowledgement\n ref={messageRef}\n message={copy.success}\n dismissLabel={copy.dismissMessage}\n onDismiss={dismissMessage}\n />\n </div>\n );\n }\n\n return (\n <div ref={setRoot} className={className} data-fs-order-cancel=\"\" data-fs-order-cancel-outcome={outcome}>\n <AlertDialogRoot open={open} onOpenChange={onOpenChange}>\n <AlertDialogTrigger data-fs-order-cancel-action=\"\">{copy.trigger}</AlertDialogTrigger>\n <AlertDialogPortal container={portalRoot}>\n <AlertDialogBackdrop />\n <AlertDialogViewport>\n <AlertDialogPopup>\n <AlertDialogTitle>{copy.title}</AlertDialogTitle>\n <AlertDialogDescription>{copy.description}</AlertDialogDescription>\n <Radio.Group\n value={selected ?? ''}\n onValueChange={setSelected}\n data-fs-order-cancel-reasons=\"\"\n disabled={pending}\n >\n {copy.reasons.map((label, index) => (\n <Radio.Root key={label} value={String(index)}>\n <Radio.Indicator keepMounted>\n <span data-fs-order-cancel-mark=\"\" />\n </Radio.Indicator>\n {label}\n </Radio.Root>\n ))}\n <Radio.Root value={OTHER}>\n <Radio.Indicator keepMounted>\n <span data-fs-order-cancel-mark=\"\" />\n </Radio.Indicator>\n {copy.other}\n </Radio.Root>\n </Radio.Group>\n {selected === OTHER ? (\n <label htmlFor=\"order-cancel-other\" data-fs-order-cancel-other=\"\">\n <span>{copy.otherField}</span>\n <Input\n id=\"order-cancel-other\"\n value={otherText}\n disabled={pending}\n maxLength={REASON_MAX_LENGTH}\n onChange={(event) => {\n setOtherText(event.target.value.slice(0, REASON_MAX_LENGTH));\n }}\n />\n </label>\n ) : null}\n {outcome === 'failure' ? (\n <Acknowledgement\n ref={messageRef}\n message={failureMessage}\n dismissLabel={copy.dismissMessage}\n onDismiss={dismissMessage}\n />\n ) : null}\n <div data-fs-order-cancel-actions=\"\">\n <Button type=\"button\" data-fs-order-cancel-confirm=\"\" disabled={pending} onClick={() => void confirm()}>\n {copy.confirm}\n </Button>\n <AlertDialogClose data-fs-order-cancel-dismiss=\"\" disabled={pending}>\n {copy.dismiss}\n </AlertDialogClose>\n </div>\n </AlertDialogPopup>\n </AlertDialogViewport>\n </AlertDialogPortal>\n </AlertDialogRoot>\n </div>\n );\n}\n\nfunction Acknowledgement({\n ref,\n message,\n dismissLabel,\n onDismiss,\n}: Readonly<{\n ref: Ref<HTMLButtonElement>;\n message: string;\n dismissLabel: string;\n onDismiss: () => void;\n}>) {\n return (\n <output data-fs-order-cancel-message=\"\">\n {message}\n <Button ref={ref} type=\"button\" aria-label={dismissLabel} onClick={onDismiss}>\n {dismissLabel}\n </Button>\n </output>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAM,WAAyB;;;;;;;;;;;;;;AAe/B,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,QAAQ;;AAGd,MAAM,oBAAoB;AAE1B,MAAM,aAAa;CACjB;CACA;CACA;CACA;AACF;AAEA,MAAa,qBAAqB,kBAAkB;CAClD,IAAI;CACJ,OAAO;CACP,aAAa;CACb,QAAQ;EACN,MAAM;EACN,sBAAsB;EAEtB,YAAY;GACV,SAAS;IAAE,MAAM;IAAU,SAAS;IAAgB,OAAO;GAAU;GACrE,OAAO;IAAE,MAAM;IAAU,SAAS;IAAsB,OAAO;GAAQ;GACvE,aAAa;IAAE,MAAM;IAAU,SAAS;IAA0B,OAAO;GAAc;GACvF,SAAS;IAAE,MAAM;IAAU,SAAS;IAAgB,OAAO;GAAU;GACrE,SAAS;IAAE,MAAM;IAAU,SAAS;IAAc,OAAO;GAAU;GACnE,OAAO;IAAE,MAAM;IAAU,SAAS;IAAS,OAAO;GAAQ;GAC1D,YAAY;IAAE,MAAM;IAAU,SAAS;IAAU,OAAO;GAAc;GACtE,SAAS;IAAE,MAAM;IAAU,SAAS;IAA6B,OAAO;GAAU;GAClF,SAAS;IAAE,MAAM;IAAU,SAAS;IAAiD,OAAO;GAAU;GACtG,gBAAgB;IAAE,MAAM;IAAU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AA,CAAA;;KACZ,aAAa,QACZ,qBAAC,SAAD;MAAO,SAAQ;MAAqB,8BAA2B;MAA/D,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,KAAK,WAAiB,CAAA,GAC7B,oBAAC,OAAD;OACE,IAAG;OACH,OAAO;OACP,UAAU;OACV,WAAW;OACX,WAAW,UAAU;QACnB,aAAa,MAAM,OAAO,MAAM,MAAM,GAAG,iBAAiB,CAAC;OAC7D;MACD,CAAA,CACI;KACL,CAAA,IAAA;KACH,YAAY,YACX,oBAAC,iBAAD;MACE,KAAK;MACL,SAAS;MACT,cAAc,KAAK;MACnB,WAAW;KACZ,CAAA,IACC;KACJ,qBAAC,OAAD;MAAK,gCAA6B;MAAlC,UAAA,CACE,oBAAC,QAAD;OAAQ,MAAK;OAAS,gCAA6B;OAAG,UAAU;OAAS,eAAe,KAAK,QAAQ;OAClG,UAAA,KAAK;MACA,CAAA,GACR,oBAAC,kBAAD;OAAkB,gCAA6B;OAAG,UAAU;OACzD,UAAA,KAAK;MACU,CAAA,CACf;;IACW,EAAA,CAAA,EACC,CAAA,CACJ;GACJ,CAAA,CAAA;;CACd,CAAA;AAET;AAEA,SAAS,gBAAgB,EACvB,KACA,SACA,cACA,aAME;CACF,OACE,qBAAC,UAAD;EAAQ,gCAA6B;EAArC,UAAA,CACG,SACD,oBAAC,QAAD;GAAa;GAAK,MAAK;GAAS,cAAY;GAAc,SAAS;GAChE,UAAA;EACK,CAAA,CACF;;AAEZ"}
|
|
1
|
+
{"version":3,"file":"order-cancel.js","names":[],"sources":["../../../src/matter/order-cancel/order-cancel.tsx"],"sourcesContent":["'use client';\n\nimport {\n type ContentValue,\n defineComponent,\n defineContentType,\n type MessageFieldName,\n type MessageLocaleProp,\n} from '@vtex/fs-core';\nimport type { Ref } from 'react';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n AlertDialogBackdrop,\n AlertDialogClose,\n AlertDialogDescription,\n AlertDialogPopup,\n AlertDialogPortal,\n AlertDialogRoot,\n AlertDialogTitle,\n AlertDialogTrigger,\n AlertDialogViewport,\n} from '../../particles/alert-dialog/alert-dialog.js';\nimport { Button } from '../../particles/button/button.js';\nimport { Input } from '../../particles/input/input.js';\nimport { Radio } from '../../particles/radio/radio.js';\nimport { useActionsOverride } from '../../sdk/actions/actions-override-context.js';\nimport type { ComponentActions } from '../../sdk/actions/types.js';\nimport { formatErrorCode } from '../../sdk/i18n/format-error-code.js';\nimport type { MessageFormatter } from '../../sdk/i18n/message-formatter.js';\nimport { useMessageFormatter } from '../../sdk/i18n/use-message-formatter.js';\nimport { useStorefrontNavigation } from '../../sdk/navigation/use-storefront-navigation.js';\nimport type { OrderCancelUserError } from '../../sdk/orders/order-operations.js';\n\nconst fragment = /* GraphQL */ `\n fragment OrderCancelData on Query {\n customerOrder(id: $orderId) {\n id\n status\n allowCancellation\n }\n }\n`;\n\n/**\n * OMS statuses that already mean a cancellation was requested or finished.\n * `allowCancellation` can stay true in the intermediate ones, so the flag alone\n * would show the button again.\n */\nconst HIDDEN_STATUSES = new Set([\n 'request-cancel',\n 'cancellation-requested',\n 'cancellation-requested-with-ack',\n 'cancel',\n 'canceled',\n]);\n\nconst OTHER = 'other';\n\n/** Matches `CUSTOMER_ORDER_CANCEL_REASON_MAX_LENGTH` in the orders module. */\nconst REASON_MAX_LENGTH = 500;\n\nexport const OrderCancelContent = defineContentType({\n id: 'order-cancel',\n title: 'Order Cancel',\n description: 'Confirmation copy and the optional cancellation reasons for one order.',\n schema: {\n type: 'object',\n additionalProperties: false,\n // Literals, not `COPY.*`: the catalog scanner only evaluates values it can see in the call.\n properties: {\n trigger: {\n type: 'string',\n title: 'Trigger',\n format: 'icu-message',\n messageSource: 'Cancel order',\n },\n title: {\n type: 'string',\n title: 'Title',\n format: 'icu-message',\n messageSource: 'Cancel this order?',\n },\n description: {\n type: 'string',\n title: 'Description',\n format: 'icu-message',\n messageSource: 'This cannot be undone.',\n },\n confirm: {\n type: 'string',\n title: 'Confirm',\n format: 'icu-message',\n messageSource: 'Cancel order',\n },\n dismiss: {\n type: 'string',\n title: 'Dismiss',\n format: 'icu-message',\n messageSource: 'Keep order',\n },\n other: { type: 'string', title: 'Other', format: 'icu-message', messageSource: 'Other' },\n otherField: {\n type: 'string',\n title: 'Other field',\n format: 'icu-message',\n messageSource: 'Reason',\n },\n success: {\n type: 'string',\n title: 'Success',\n format: 'icu-message',\n messageSource: 'Your order was cancelled.',\n },\n failure: {\n type: 'string',\n title: 'Failure',\n format: 'icu-message',\n messageSource: 'Unable to cancel the order. Please try again.',\n },\n notCancellableMessage: {\n type: 'string',\n title: 'Not cancellable message',\n description: 'Shown when the order is past the point where it can be cancelled.',\n format: 'icu-message',\n messageSource: 'This order can no longer be cancelled.',\n },\n notFoundMessage: {\n type: 'string',\n title: 'Order not found message',\n description: 'Shown when the order is not one the signed-in shopper can see.',\n format: 'icu-message',\n messageSource: 'We could not find this order.',\n },\n dismissMessage: {\n type: 'string',\n title: 'Dismiss message',\n format: 'icu-message',\n messageSource: 'Dismiss',\n },\n reasonChangedMind: {\n type: 'string',\n title: 'Reason: changed mind',\n description: 'Default reason option.',\n format: 'icu-message',\n messageSource: 'Changed my mind',\n },\n reasonBoughtByMistake: {\n type: 'string',\n title: 'Reason: bought by mistake',\n description: 'Default reason option.',\n format: 'icu-message',\n messageSource: 'Bought by mistake',\n },\n reasonBetterPrice: {\n type: 'string',\n title: 'Reason: better price',\n description: 'Default reason option.',\n format: 'icu-message',\n messageSource: 'Found a better price',\n },\n reasonSlowDelivery: {\n type: 'string',\n title: 'Reason: slow delivery',\n description: 'Default reason option.',\n format: 'icu-message',\n messageSource: 'Delivery is too slow',\n },\n reasons: {\n type: 'array',\n title: 'Reasons',\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['label'],\n properties: {\n label: { type: 'string', minLength: 1, title: 'Label' },\n },\n },\n },\n },\n },\n});\n\nexport type OrderCancelContentValue = ContentValue<typeof OrderCancelContent>;\n\n/** The default reasons, in display order, offered when the content authors no `reasons`. */\nconst DEFAULT_REASONS = [\n 'reasonChangedMind',\n 'reasonBoughtByMistake',\n 'reasonBetterPrice',\n 'reasonSlowDelivery',\n] as const satisfies readonly MessageFieldName<typeof OrderCancelContent>[];\n\n/** Unwrapped `customerOrder`. A single-root fragment binds `$data` to that field. */\nexport type OrderCancelData = {\n id: string;\n status: string;\n allowCancellation: boolean;\n};\n\nexport type OrderCancelProps = MessageLocaleProp &\n Readonly<{\n $data?: OrderCancelData | null;\n $actions?: ComponentActions;\n $content?: OrderCancelContentValue;\n className?: string;\n ref?: Ref<HTMLDivElement>;\n }>;\n\ntype OrderCancelCopy = {\n trigger: string;\n title: string;\n description: string;\n confirm: string;\n dismiss: string;\n other: string;\n otherField: string;\n success: string;\n failure: string;\n dismissMessage: string;\n reasons: readonly string[];\n};\n\nexport const OrderCancelDefinition = defineComponent<OrderCancelProps>({\n name: 'OrderCancel',\n importPath: '@vtex/faststore/components',\n component: OrderCancel,\n fragment,\n skeleton: OrderCancelSkeleton,\n actions: { order: ['cancel'] },\n content: OrderCancelContent,\n editor: { label: 'Order Cancel', category: 'action' },\n schema: {},\n guideline:\n 'Cancels one eligible order after the shopper confirms in an alert dialog. Place it on the order page. It hides when the order cannot be cancelled or a cancellation is already requested. Reasons and the dialog copy are content. Other is always offered. See order-cancel.md.',\n});\n\nexport function OrderCancelSkeleton({ className }: Readonly<{ className?: string }>) {\n return <div className={className} data-fs-order-cancel-skeleton=\"\" aria-hidden=\"true\" />;\n}\n\nfunction reasonsOf(\n content: OrderCancelContentValue | undefined,\n format: MessageFormatter<typeof OrderCancelContent>['format'],\n): readonly string[] {\n if (content?.reasons == null) {\n return DEFAULT_REASONS.map((field) => format(field));\n }\n return content.reasons.flatMap((item) => {\n const label = item.label.trim();\n return label ? [label] : [];\n });\n}\n\nfunction copyOf(\n content: OrderCancelContentValue | undefined,\n { format }: MessageFormatter<typeof OrderCancelContent>,\n): OrderCancelCopy {\n return {\n trigger: format('trigger'),\n title: format('title'),\n description: format('description'),\n confirm: format('confirm'),\n dismiss: format('dismiss'),\n other: format('other'),\n otherField: format('otherField'),\n success: format('success'),\n failure: format('failure'),\n dismissMessage: format('dismissMessage'),\n reasons: reasonsOf(content, format),\n };\n}\n\n/**\n * The message for each cancellation refusal: the server's `CustomerOrderCancelErrorCode` values plus\n * the client-minted transport failure. A code this map does not know shows `failure`.\n */\nexport const ORDER_CANCEL_ERROR_FIELDS = {\n ORDER_NOT_CANCELLABLE: 'notCancellableMessage',\n NOT_FOUND: 'notFoundMessage',\n NETWORK_ERROR: 'failure',\n} as const satisfies Record<\n 'ORDER_NOT_CANCELLABLE' | 'NOT_FOUND' | 'NETWORK_ERROR',\n MessageFieldName<typeof OrderCancelContent>\n>;\n\nfunction chosenReason(selected: string | null, reasons: readonly string[], otherText: string): string | undefined {\n if (selected == null) return undefined;\n if (selected === OTHER) {\n const trimmed = otherText.trim();\n return trimmed || undefined;\n }\n const label = reasons[Number(selected)]?.trim();\n return label || undefined;\n}\n\nexport function OrderCancel({ $data, $actions: $actionsProp, $content, className, ref }: OrderCancelProps) {\n const $actions = useActionsOverride($actionsProp);\n const messages = useMessageFormatter(OrderCancelContent, $content);\n const { refresh } = useStorefrontNavigation();\n const copy = copyOf($content, messages);\n const [open, setOpen] = useState(false);\n const [selected, setSelected] = useState<string | null>(null);\n const [otherText, setOtherText] = useState('');\n const [pending, setPending] = useState(false);\n const [succeeded, setSucceeded] = useState(false);\n const [outcome, setOutcome] = useState<'idle' | 'success' | 'failure'>('idle');\n const [failure, setFailure] = useState<OrderCancelUserError | null>(null);\n const pendingRef = useRef(false);\n const requestRef = useRef(0);\n const messageRef = useRef<HTMLButtonElement>(null);\n const portalRoot = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (outcome === 'success' || outcome === 'failure') {\n messageRef.current?.focus();\n }\n }, [outcome]);\n\n const ineligible = !$data?.allowCancellation || ($data != null && HIDDEN_STATUSES.has($data.status));\n\n function onOpenChange(next: boolean) {\n if (!next && pendingRef.current) return;\n setOpen(next);\n if (!next) {\n requestRef.current += 1;\n setSelected(null);\n setOtherText('');\n setOutcome((current) => (current === 'failure' ? 'idle' : current));\n }\n }\n\n async function confirm() {\n if (pendingRef.current || !$data) return;\n const cancel = $actions?.order?.cancel;\n if (!cancel) {\n setFailure(null);\n setOutcome('failure');\n return;\n }\n\n const request = requestRef.current + 1;\n requestRef.current = request;\n pendingRef.current = true;\n setPending(true);\n try {\n const reason = chosenReason(selected, copy.reasons, otherText);\n const result = await cancel(reason == null ? { id: $data.id } : { id: $data.id, reason });\n if (request !== requestRef.current) return;\n if (result.userErrors.length === 0) {\n setSucceeded(true);\n setOutcome('success');\n setOpen(false);\n refresh();\n return;\n }\n\n setFailure(result.userErrors[0] ?? null);\n setOutcome('failure');\n } finally {\n pendingRef.current = false;\n setPending(false);\n }\n }\n\n function failureMessage(): string {\n if (!failure) return copy.failure;\n return formatErrorCode(OrderCancelContent, ORDER_CANCEL_ERROR_FIELDS, failure, messages.format, 'failure');\n }\n\n function dismissMessage() {\n setOutcome('idle');\n }\n\n function setRoot(node: HTMLDivElement | null) {\n portalRoot.current = node;\n if (typeof ref === 'function') {\n ref(node);\n return;\n }\n if (ref) {\n ref.current = node;\n }\n }\n\n if (ineligible || (succeeded && outcome !== 'success')) return null;\n\n if (succeeded) {\n return (\n <div ref={ref} className={className} data-fs-order-cancel=\"\" data-fs-order-cancel-outcome=\"success\">\n <Acknowledgement\n ref={messageRef}\n message={copy.success}\n dismissLabel={copy.dismissMessage}\n onDismiss={dismissMessage}\n />\n </div>\n );\n }\n\n return (\n <div ref={setRoot} className={className} data-fs-order-cancel=\"\" data-fs-order-cancel-outcome={outcome}>\n <AlertDialogRoot open={open} onOpenChange={onOpenChange}>\n <AlertDialogTrigger data-fs-order-cancel-action=\"\">{copy.trigger}</AlertDialogTrigger>\n <AlertDialogPortal container={portalRoot}>\n <AlertDialogBackdrop />\n <AlertDialogViewport>\n <AlertDialogPopup>\n <AlertDialogTitle>{copy.title}</AlertDialogTitle>\n <AlertDialogDescription>{copy.description}</AlertDialogDescription>\n <Radio.Group\n value={selected ?? ''}\n onValueChange={setSelected}\n data-fs-order-cancel-reasons=\"\"\n disabled={pending}\n >\n {copy.reasons.map((label, index) => (\n <Radio.Root key={label} value={String(index)}>\n <Radio.Indicator keepMounted>\n <span data-fs-order-cancel-mark=\"\" />\n </Radio.Indicator>\n {label}\n </Radio.Root>\n ))}\n <Radio.Root value={OTHER}>\n <Radio.Indicator keepMounted>\n <span data-fs-order-cancel-mark=\"\" />\n </Radio.Indicator>\n {copy.other}\n </Radio.Root>\n </Radio.Group>\n {selected === OTHER ? (\n <label htmlFor=\"order-cancel-other\" data-fs-order-cancel-other=\"\">\n <span>{copy.otherField}</span>\n <Input\n id=\"order-cancel-other\"\n value={otherText}\n disabled={pending}\n maxLength={REASON_MAX_LENGTH}\n onChange={(event) => {\n setOtherText(event.target.value.slice(0, REASON_MAX_LENGTH));\n }}\n />\n </label>\n ) : null}\n {outcome === 'failure' ? (\n <Acknowledgement\n ref={messageRef}\n message={failureMessage()}\n dismissLabel={copy.dismissMessage}\n onDismiss={dismissMessage}\n />\n ) : null}\n <div data-fs-order-cancel-actions=\"\">\n <Button type=\"button\" data-fs-order-cancel-confirm=\"\" disabled={pending} onClick={() => void confirm()}>\n {copy.confirm}\n </Button>\n <AlertDialogClose data-fs-order-cancel-dismiss=\"\" disabled={pending}>\n {copy.dismiss}\n </AlertDialogClose>\n </div>\n </AlertDialogPopup>\n </AlertDialogViewport>\n </AlertDialogPortal>\n </AlertDialogRoot>\n </div>\n );\n}\n\nfunction Acknowledgement({\n ref,\n message,\n dismissLabel,\n onDismiss,\n}: Readonly<{\n ref: Ref<HTMLButtonElement>;\n message: string;\n dismissLabel: string;\n onDismiss: () => void;\n}>) {\n return (\n <output data-fs-order-cancel-message=\"\">\n {message}\n <Button ref={ref} type=\"button\" aria-label={dismissLabel} onClick={onDismiss}>\n {dismissLabel}\n </Button>\n </output>\n );\n}\n"],"mappings":";;;;;;;;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M,MAAM,GAAG,iBAAiB,CAAC;OAC7D;MACD,CAAA,CACI;KACL,CAAA,IAAA;KACH,YAAY,YACX,oBAAC,iBAAD;MACE,KAAK;MACL,SAAS,eAAe;MACxB,cAAc,KAAK;MACnB,WAAW;KACZ,CAAA,IACC;KACJ,qBAAC,OAAD;MAAK,gCAA6B;MAAlC,UAAA,CACE,oBAAC,QAAD;OAAQ,MAAK;OAAS,gCAA6B;OAAG,UAAU;OAAS,eAAe,KAAK,QAAQ;OAClG,UAAA,KAAK;MACA,CAAA,GACR,oBAAC,kBAAD;OAAkB,gCAA6B;OAAG,UAAU;OACzD,UAAA,KAAK;MACU,CAAA,CACf;;IACW,EAAA,CAAA,EACC,CAAA,CACJ;GACJ,CAAA,CAAA;;CACd,CAAA;AAET;AAEA,SAAS,gBAAgB,EACvB,KACA,SACA,cACA,aAME;CACF,OACE,qBAAC,UAAD;EAAQ,gCAA6B;EAArC,UAAA,CACG,SACD,oBAAC,QAAD;GAAa;GAAK,MAAK;GAAS,cAAY;GAAc,SAAS;GAChE,UAAA;EACK,CAAA,CACF;;AAEZ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentValue } from "../../core/dist/define-content-type.js";
|
|
1
|
+
import { ContentValue, MessageLocaleProp } from "../../core/dist/define-content-type.js";
|
|
2
2
|
import { ComponentDefinition } from "../../core/dist/define-component.js";
|
|
3
3
|
import "../../core/dist/index.js";
|
|
4
4
|
import { ComponentPropsWithRef, Ref } from "react";
|
|
@@ -14,10 +14,14 @@ export declare const OrderDeliveryAddressContent: {
|
|
|
14
14
|
readonly deliveryLabel: {
|
|
15
15
|
readonly type: "string";
|
|
16
16
|
readonly title: "Delivery address label";
|
|
17
|
+
readonly format: "icu-message";
|
|
18
|
+
readonly messageSource: "Delivery address";
|
|
17
19
|
};
|
|
18
20
|
readonly storeLabel: {
|
|
19
21
|
readonly type: "string";
|
|
20
22
|
readonly title: "Store address label";
|
|
23
|
+
readonly format: "icu-message";
|
|
24
|
+
readonly messageSource: "Store address";
|
|
21
25
|
};
|
|
22
26
|
};
|
|
23
27
|
};
|
|
@@ -45,29 +49,15 @@ export type OrderDeliveryAddressOptionData = {
|
|
|
45
49
|
export type OrderDeliveryAddressData = {
|
|
46
50
|
deliveryOptions: OrderDeliveryAddressOptionData[];
|
|
47
51
|
} | null;
|
|
48
|
-
export type OrderDeliveryAddressProps = Readonly<{
|
|
49
|
-
/** Label above a delivery address. Content wins, then this prop, then the catalogue. */
|
|
50
|
-
deliveryLabel?: string;
|
|
51
|
-
/** Label above a pickup store address. Content wins, then this prop, then the catalogue. */
|
|
52
|
-
storeLabel?: string;
|
|
52
|
+
export type OrderDeliveryAddressProps = MessageLocaleProp & Readonly<{
|
|
53
53
|
/** Injected by the compiler from the page content entry. */
|
|
54
54
|
$content?: OrderDeliveryAddressContentValue;
|
|
55
55
|
$data?: OrderDeliveryAddressData;
|
|
56
56
|
className?: string;
|
|
57
57
|
ref?: Ref<HTMLElement>;
|
|
58
58
|
}>;
|
|
59
|
-
export declare const OrderDeliveryAddressDefinition: ComponentDefinition<
|
|
60
|
-
/** Label above a delivery address. Content wins, then this prop, then the catalogue. */
|
|
61
|
-
deliveryLabel?: string;
|
|
62
|
-
/** Label above a pickup store address. Content wins, then this prop, then the catalogue. */
|
|
63
|
-
storeLabel?: string;
|
|
64
|
-
/** Injected by the compiler from the page content entry. */
|
|
65
|
-
$content?: OrderDeliveryAddressContentValue;
|
|
66
|
-
$data?: OrderDeliveryAddressData;
|
|
67
|
-
className?: string;
|
|
68
|
-
ref?: Ref<HTMLElement>;
|
|
69
|
-
}>>;
|
|
59
|
+
export declare const OrderDeliveryAddressDefinition: ComponentDefinition<OrderDeliveryAddressProps>;
|
|
70
60
|
export declare function OrderDeliveryAddressSkeleton({ className, ...props }: ComponentPropsWithRef<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
71
|
-
export declare function OrderDeliveryAddress({
|
|
61
|
+
export declare function OrderDeliveryAddress({ $content, $data, className, ref }: OrderDeliveryAddressProps): import("react/jsx-runtime").JSX.Element | null;
|
|
72
62
|
//#endregion
|
|
73
63
|
//# sourceMappingURL=order-delivery-address.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { defineComponent } from "../../core/dist/define-component.js";
|
|
3
3
|
import { defineContentType } from "../../core/dist/define-content-type.js";
|
|
4
4
|
import "../../core/dist/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useMessageFormatter } from "../../sdk/i18n/use-message-formatter.js";
|
|
6
6
|
import { useOrderDeliveryOption } from "../order-delivery-group/order-delivery-group.js";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
//#region src/matter/order-delivery-address/order-delivery-address.tsx
|
|
@@ -38,11 +38,15 @@ const OrderDeliveryAddressContent = defineContentType({
|
|
|
38
38
|
properties: {
|
|
39
39
|
deliveryLabel: {
|
|
40
40
|
type: "string",
|
|
41
|
-
title: "Delivery address label"
|
|
41
|
+
title: "Delivery address label",
|
|
42
|
+
format: "icu-message",
|
|
43
|
+
messageSource: "Delivery address"
|
|
42
44
|
},
|
|
43
45
|
storeLabel: {
|
|
44
46
|
type: "string",
|
|
45
|
-
title: "Store address label"
|
|
47
|
+
title: "Store address label",
|
|
48
|
+
format: "icu-message",
|
|
49
|
+
messageSource: "Store address"
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
}
|
|
@@ -60,16 +64,7 @@ const OrderDeliveryAddressDefinition = defineComponent({
|
|
|
60
64
|
label: "Order Delivery Address",
|
|
61
65
|
category: "content"
|
|
62
66
|
},
|
|
63
|
-
schema: {
|
|
64
|
-
deliveryLabel: {
|
|
65
|
-
type: "string",
|
|
66
|
-
label: "Delivery address label"
|
|
67
|
-
},
|
|
68
|
-
storeLabel: {
|
|
69
|
-
type: "string",
|
|
70
|
-
label: "Store address label"
|
|
71
|
-
}
|
|
72
|
-
},
|
|
67
|
+
schema: {},
|
|
73
68
|
guideline: "The address the order recorded for one delivery option: the recipient and the delivery-address label for a delivery, the store-address label for a pickup, and every non-empty address field. Place it inside OrderDeliveryGroup, after the rows; it renders the address of the option it sits in."
|
|
74
69
|
});
|
|
75
70
|
const PICKUP_CHANNEL = "pickup-in-point";
|
|
@@ -106,14 +101,10 @@ function OrderDeliveryAddressSkeleton({ className, ...props }) {
|
|
|
106
101
|
children: /* @__PURE__ */ jsx("span", { "data-fs-order-delivery-address-skeleton-line": "" })
|
|
107
102
|
});
|
|
108
103
|
}
|
|
109
|
-
function OrderDeliveryAddress({
|
|
110
|
-
const
|
|
104
|
+
function OrderDeliveryAddress({ $content, $data, className, ref }) {
|
|
105
|
+
const messages = useMessageFormatter(OrderDeliveryAddressContent, $content);
|
|
111
106
|
const inGroup = useOrderDeliveryOption();
|
|
112
107
|
const options = $data?.deliveryOptions ?? [];
|
|
113
|
-
const labels = {
|
|
114
|
-
delivery: text($content?.deliveryLabel) ?? text(deliveryLabel) ?? intl.formatMessage({ id: "fs/order-delivery-address.delivery" }),
|
|
115
|
-
store: text($content?.storeLabel) ?? text(storeLabel) ?? intl.formatMessage({ id: "fs/order-delivery-address.store" })
|
|
116
|
-
};
|
|
117
108
|
if (inGroup) {
|
|
118
109
|
const option = options[inGroup.index];
|
|
119
110
|
if (!option?.address) return null;
|
|
@@ -122,13 +113,13 @@ function OrderDeliveryAddress({ deliveryLabel, storeLabel, $content, $data, clas
|
|
|
122
113
|
className,
|
|
123
114
|
index: inGroup.index,
|
|
124
115
|
option,
|
|
125
|
-
|
|
116
|
+
messages
|
|
126
117
|
});
|
|
127
118
|
}
|
|
128
119
|
const blocks = options.flatMap((option, index) => option.address ? [/* @__PURE__ */ jsx(AddressBlock, {
|
|
129
120
|
index,
|
|
130
121
|
option,
|
|
131
|
-
|
|
122
|
+
messages
|
|
132
123
|
}, `${index}:${optionKey(option)}`)] : []);
|
|
133
124
|
if (blocks.length === 0) return null;
|
|
134
125
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -138,7 +129,7 @@ function OrderDeliveryAddress({ deliveryLabel, storeLabel, $content, $data, clas
|
|
|
138
129
|
children: blocks
|
|
139
130
|
});
|
|
140
131
|
}
|
|
141
|
-
function AddressBlock({ index, option,
|
|
132
|
+
function AddressBlock({ index, option, messages, className, ref }) {
|
|
142
133
|
const pickup = option.deliveryChannel === PICKUP_CHANNEL;
|
|
143
134
|
const recipient = pickup ? null : text(option.address?.receiverName);
|
|
144
135
|
return /* @__PURE__ */ jsxs("address", {
|
|
@@ -150,7 +141,7 @@ function AddressBlock({ index, option, labels, className, ref }) {
|
|
|
150
141
|
children: [
|
|
151
142
|
/* @__PURE__ */ jsx("span", {
|
|
152
143
|
"data-fs-order-delivery-address-label": "",
|
|
153
|
-
children: pickup ?
|
|
144
|
+
children: messages.format(pickup ? "storeLabel" : "deliveryLabel")
|
|
154
145
|
}),
|
|
155
146
|
recipient ? /* @__PURE__ */ jsx("span", {
|
|
156
147
|
"data-fs-order-delivery-address-recipient": "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-delivery-address.js","names":[],"sources":["../../../src/matter/order-delivery-address/order-delivery-address.tsx"],"sourcesContent":["'use client';\n\nimport { type ContentValue, defineComponent, defineContentType } from '@vtex/fs-core';\nimport type { ComponentPropsWithRef, Ref } from 'react';\nimport { useIntl } from '../../sdk/i18n/client.js';\nimport { useOrderDeliveryOption } from '../order-delivery-group/order-delivery-group.js';\n\nconst fragment = /* GraphQL */ `\n fragment OrderDeliveryAddressData on Query {\n customerOrder(id: $orderId) {\n deliveryOptions {\n addressId\n deliveryChannel\n address {\n receiverName\n street\n number\n complement\n neighborhood\n reference\n city\n state\n postalCode\n country\n }\n }\n }\n }\n`;\n\nexport const OrderDeliveryAddressContent = defineContentType({\n id: 'order-delivery-address',\n title: 'Order Delivery Address',\n description: 'The labels above a delivery address and above a pickup store address.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n deliveryLabel: { type: 'string', title: 'Delivery address label' },\n storeLabel: { type: 'string', title: 'Store address label' },\n },\n },\n});\n\nexport type OrderDeliveryAddressContentValue = ContentValue<typeof OrderDeliveryAddressContent>;\n\n/** The historical address OMS recorded on one delivery option. */\nexport type OrderDeliveryAddressRecord = {\n receiverName: string | null;\n street: string | null;\n number: string | null;\n complement: string | null;\n neighborhood: string | null;\n reference: string | null;\n city: string | null;\n state: string | null;\n postalCode: string | null;\n country: string | null;\n};\n\nexport type OrderDeliveryAddressOptionData = {\n addressId: string | null;\n deliveryChannel: string | null;\n address: OrderDeliveryAddressRecord | null;\n};\n\n/** Unwrapped `CustomerOrder` slice. Null when the id does not resolve to the shopper's order. */\nexport type OrderDeliveryAddressData = {\n deliveryOptions: OrderDeliveryAddressOptionData[];\n} | null;\n\nexport type OrderDeliveryAddressProps = Readonly<{\n /** Label above a delivery address. Content wins, then this prop, then the catalogue. */\n deliveryLabel?: string;\n /** Label above a pickup store address. Content wins, then this prop, then the catalogue. */\n storeLabel?: string;\n /** Injected by the compiler from the page content entry. */\n $content?: OrderDeliveryAddressContentValue;\n $data?: OrderDeliveryAddressData;\n className?: string;\n ref?: Ref<HTMLElement>;\n}>;\n\nexport const OrderDeliveryAddressDefinition = defineComponent<OrderDeliveryAddressProps>({\n name: 'OrderDeliveryAddress',\n importPath: '@vtex/faststore/components',\n component: OrderDeliveryAddress,\n content: OrderDeliveryAddressContent,\n fragment,\n fetchStrategy: 'static',\n skeleton: OrderDeliveryAddressSkeleton,\n requiresContext: 'order-delivery-option',\n editor: { label: 'Order Delivery Address', category: 'content' },\n schema: {\n deliveryLabel: { type: 'string', label: 'Delivery address label' },\n storeLabel: { type: 'string', label: 'Store address label' },\n },\n guideline:\n 'The address the order recorded for one delivery option: the recipient and the delivery-address label for a delivery, the store-address label for a pickup, and every non-empty address field. Place it inside OrderDeliveryGroup, after the rows; it renders the address of the option it sits in.',\n});\n\nconst PICKUP_CHANNEL = 'pickup-in-point';\n\nconst FIELDS = [\n ['street', { 'data-fs-order-delivery-address-street': '' }],\n ['number', { 'data-fs-order-delivery-address-number': '' }],\n ['complement', { 'data-fs-order-delivery-address-complement': '' }],\n ['neighborhood', { 'data-fs-order-delivery-address-neighborhood': '' }],\n ['reference', { 'data-fs-order-delivery-address-reference': '' }],\n ['city', { 'data-fs-order-delivery-address-city': '' }],\n ['state', { 'data-fs-order-delivery-address-state': '' }],\n ['postalCode', { 'data-fs-order-delivery-address-postal-code': '' }],\n ['country', { 'data-fs-order-delivery-address-country': '' }],\n] as const satisfies ReadonlyArray<readonly [keyof OrderDeliveryAddressRecord, object]>;\n\nfunction text(value: string | null | undefined): string | null {\n const trimmed = value?.trim();\n return trimmed || null;\n}\n\nfunction optionKey(option: OrderDeliveryAddressOptionData): string {\n const address = option.address;\n const key = [option.addressId, option.deliveryChannel, address?.postalCode, address?.street, address?.number]\n .filter(Boolean)\n .join('-');\n return key || 'address';\n}\n\nexport function OrderDeliveryAddressSkeleton({ className, ...props }: ComponentPropsWithRef<'div'>) {\n return (\n <div {...props} className={className} data-fs-order-delivery-address-skeleton=\"\" aria-hidden=\"true\">\n <span data-fs-order-delivery-address-skeleton-line=\"\" />\n </div>\n );\n}\n\nexport function OrderDeliveryAddress({\n deliveryLabel,\n storeLabel,\n $content,\n $data,\n className,\n ref,\n}: OrderDeliveryAddressProps) {\n const intl = useIntl();\n const inGroup = useOrderDeliveryOption();\n const options = $data?.deliveryOptions ?? [];\n const labels = {\n delivery:\n text($content?.deliveryLabel) ??\n text(deliveryLabel) ??\n intl.formatMessage({ id: 'fs/order-delivery-address.delivery' }),\n store:\n text($content?.storeLabel) ?? text(storeLabel) ?? intl.formatMessage({ id: 'fs/order-delivery-address.store' }),\n };\n\n if (inGroup) {\n const option = options[inGroup.index];\n if (!option?.address) {\n return null;\n }\n return <AddressBlock ref={ref} className={className} index={inGroup.index} option={option} labels={labels} />;\n }\n\n const blocks = options.flatMap((option, index) =>\n option.address\n ? [<AddressBlock key={`${index}:${optionKey(option)}`} index={index} option={option} labels={labels} />]\n : [],\n );\n if (blocks.length === 0) {\n return null;\n }\n\n return (\n <div ref={ref as Ref<HTMLDivElement>} className={className} data-fs-order-delivery-address-list=\"\">\n {blocks}\n </div>\n );\n}\n\ntype AddressBlockProps = Readonly<{\n index: number;\n option: OrderDeliveryAddressOptionData;\n labels: Readonly<{ delivery: string; store: string }>;\n className?: string;\n ref?: Ref<HTMLElement>;\n}>;\n\nfunction AddressBlock({ index, option, labels, className, ref }: AddressBlockProps) {\n const pickup = option.deliveryChannel === PICKUP_CHANNEL;\n const recipient = pickup ? null : text(option.address?.receiverName);\n\n return (\n <address\n ref={ref}\n className={className}\n data-fs-order-delivery-address=\"\"\n data-fs-order-delivery-address-channel={pickup ? PICKUP_CHANNEL : 'delivery'}\n data-fs-order-delivery-address-option={index}\n >\n <span data-fs-order-delivery-address-label=\"\">{pickup ? labels.store : labels.delivery}</span>\n {recipient ? <span data-fs-order-delivery-address-recipient=\"\">{recipient}</span> : null}\n {FIELDS.map(([name, hook]) => {\n const value = text(option.address?.[name]);\n return value ? (\n <span key={name} {...hook}>\n {value}\n </span>\n ) : null;\n })}\n </address>\n );\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,WAAyB;;;;;;;;;;;;;;;;;;;;;;AAuB/B,MAAa,8BAA8B,kBAAkB;CAC3D,IAAI;CACJ,OAAO;CACP,aAAa;CACb,QAAQ;EACN,MAAM;EACN,sBAAsB;EACtB,YAAY;GACV,eAAe;IAAE,MAAM;IAAU,OAAO;GAAyB;GACjE,YAAY;IAAE,MAAM;IAAU,OAAO;GAAsB;EAC7D;CACF;AACF,CAAC;AAyCD,MAAa,iCAAiC,gBAA2C;CACvF,MAAM;CACN,YAAY;CACZ,WAAW;CACX,SAAS;CACT;CACA,eAAe;CACf,UAAU;CACV,iBAAiB;CACjB,QAAQ;EAAE,OAAO;EAA0B,UAAU;CAAU;CAC/D,QAAQ;EACN,eAAe;GAAE,MAAM;GAAU,OAAO;EAAyB;EACjE,YAAY;GAAE,MAAM;GAAU,OAAO;EAAsB;CAC7D;CACA,WACE;AAC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AAI,kCAAkC,CAAC;CAClH;CAEA,IAAI,SAAS;EACX,MAAM,SAAS,QAAQ,QAAQ;EAC/B,IAAI,CAAC,QAAQ,SACX,OAAO;EAET,OAAO,oBAAC,cAAD;GAAmB;GAAgB;GAAW,OAAO,QAAQ;GAAe;GAAgB;EAAS,CAAA;CAC9G;CAEA,MAAM,SAAS,QAAQ,SAAS,QAAQ,UACtC,OAAO,UACH,CAAC,oBAAC,cAAD;EAA2D;EAAe;EAAgB;CAAS,GAAhF,GAAG,MAAM,GAAG,UAAU,MAAM,GAAoD,CAAC,IACrG,CAAC,CACP;CACA,IAAI,OAAO,WAAW,GACpB,OAAO;CAGT,OACE,oBAAC,OAAD;EAAU;EAAuC;EAAW,uCAAoC;EAC7F,UAAA;CACE,CAAA;AAET;AAUA,SAAS,aAAa,EAAE,OAAO,QAAQ,QAAQ,WAAW,OAA0B;CAClF,MAAM,SAAS,OAAO,oBAAoB;CAC1C,MAAM,YAAY,SAAS,OAAO,KAAK,OAAO,SAAS,YAAY;CAEnE,OACE,qBAAC,WAAD;EACO;EACM;EACX,kCAA+B;EAC/B,0CAAwC,SAAS,iBAAiB;EAClE,yCAAuC;EALzC,UAAA;GAOE,oBAAC,QAAD;IAAM,wCAAqC;IAAI,UAAA,SAAS,OAAO,QAAQ,OAAO;GAAe,CAAA;GAC5F,YAAY,oBAAC,QAAD;IAAM,4CAAyC;IAAI,UAAA;GAAgB,CAAA,IAAI;GACnF,OAAO,KAAK,CAAC,MAAM,UAAU;IAC5B,MAAM,QAAQ,KAAK,OAAO,UAAU,KAAK;IACzC,OAAO,QACL,oBAAC,QAAD;KAAiB,GAAI;KAClB,UAAA;IACG,GAFK,IAEL,IACJ;GACN,CAAC;EACM;;AAEb"}
|
|
1
|
+
{"version":3,"file":"order-delivery-address.js","names":[],"sources":["../../../src/matter/order-delivery-address/order-delivery-address.tsx"],"sourcesContent":["'use client';\n\nimport { type ContentValue, defineComponent, defineContentType, type MessageLocaleProp } from '@vtex/fs-core';\nimport type { ComponentPropsWithRef, Ref } from 'react';\nimport type { MessageFormatter } from '../../sdk/i18n/message-formatter.js';\nimport { useMessageFormatter } from '../../sdk/i18n/use-message-formatter.js';\nimport { useOrderDeliveryOption } from '../order-delivery-group/order-delivery-group.js';\n\nconst fragment = /* GraphQL */ `\n fragment OrderDeliveryAddressData on Query {\n customerOrder(id: $orderId) {\n deliveryOptions {\n addressId\n deliveryChannel\n address {\n receiverName\n street\n number\n complement\n neighborhood\n reference\n city\n state\n postalCode\n country\n }\n }\n }\n }\n`;\n\nexport const OrderDeliveryAddressContent = defineContentType({\n id: 'order-delivery-address',\n title: 'Order Delivery Address',\n description: 'The labels above a delivery address and above a pickup store address.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n deliveryLabel: {\n type: 'string',\n title: 'Delivery address label',\n format: 'icu-message',\n messageSource: 'Delivery address',\n },\n storeLabel: {\n type: 'string',\n title: 'Store address label',\n format: 'icu-message',\n messageSource: 'Store address',\n },\n },\n },\n});\n\nexport type OrderDeliveryAddressContentValue = ContentValue<typeof OrderDeliveryAddressContent>;\n\n/** The historical address OMS recorded on one delivery option. */\nexport type OrderDeliveryAddressRecord = {\n receiverName: string | null;\n street: string | null;\n number: string | null;\n complement: string | null;\n neighborhood: string | null;\n reference: string | null;\n city: string | null;\n state: string | null;\n postalCode: string | null;\n country: string | null;\n};\n\nexport type OrderDeliveryAddressOptionData = {\n addressId: string | null;\n deliveryChannel: string | null;\n address: OrderDeliveryAddressRecord | null;\n};\n\n/** Unwrapped `CustomerOrder` slice. Null when the id does not resolve to the shopper's order. */\nexport type OrderDeliveryAddressData = {\n deliveryOptions: OrderDeliveryAddressOptionData[];\n} | null;\n\nexport type OrderDeliveryAddressProps = MessageLocaleProp &\n Readonly<{\n /** Injected by the compiler from the page content entry. */\n $content?: OrderDeliveryAddressContentValue;\n $data?: OrderDeliveryAddressData;\n className?: string;\n ref?: Ref<HTMLElement>;\n }>;\n\nexport const OrderDeliveryAddressDefinition = defineComponent<OrderDeliveryAddressProps>({\n name: 'OrderDeliveryAddress',\n importPath: '@vtex/faststore/components',\n component: OrderDeliveryAddress,\n content: OrderDeliveryAddressContent,\n fragment,\n fetchStrategy: 'static',\n skeleton: OrderDeliveryAddressSkeleton,\n requiresContext: 'order-delivery-option',\n editor: { label: 'Order Delivery Address', category: 'content' },\n schema: {},\n guideline:\n 'The address the order recorded for one delivery option: the recipient and the delivery-address label for a delivery, the store-address label for a pickup, and every non-empty address field. Place it inside OrderDeliveryGroup, after the rows; it renders the address of the option it sits in.',\n});\n\nconst PICKUP_CHANNEL = 'pickup-in-point';\n\nconst FIELDS = [\n ['street', { 'data-fs-order-delivery-address-street': '' }],\n ['number', { 'data-fs-order-delivery-address-number': '' }],\n ['complement', { 'data-fs-order-delivery-address-complement': '' }],\n ['neighborhood', { 'data-fs-order-delivery-address-neighborhood': '' }],\n ['reference', { 'data-fs-order-delivery-address-reference': '' }],\n ['city', { 'data-fs-order-delivery-address-city': '' }],\n ['state', { 'data-fs-order-delivery-address-state': '' }],\n ['postalCode', { 'data-fs-order-delivery-address-postal-code': '' }],\n ['country', { 'data-fs-order-delivery-address-country': '' }],\n] as const satisfies ReadonlyArray<readonly [keyof OrderDeliveryAddressRecord, object]>;\n\nfunction text(value: string | null | undefined): string | null {\n const trimmed = value?.trim();\n return trimmed || null;\n}\n\nfunction optionKey(option: OrderDeliveryAddressOptionData): string {\n const address = option.address;\n const key = [option.addressId, option.deliveryChannel, address?.postalCode, address?.street, address?.number]\n .filter(Boolean)\n .join('-');\n return key || 'address';\n}\n\nexport function OrderDeliveryAddressSkeleton({ className, ...props }: ComponentPropsWithRef<'div'>) {\n return (\n <div {...props} className={className} data-fs-order-delivery-address-skeleton=\"\" aria-hidden=\"true\">\n <span data-fs-order-delivery-address-skeleton-line=\"\" />\n </div>\n );\n}\n\nexport function OrderDeliveryAddress({ $content, $data, className, ref }: OrderDeliveryAddressProps) {\n const messages = useMessageFormatter(OrderDeliveryAddressContent, $content);\n const inGroup = useOrderDeliveryOption();\n const options = $data?.deliveryOptions ?? [];\n\n if (inGroup) {\n const option = options[inGroup.index];\n if (!option?.address) {\n return null;\n }\n return <AddressBlock ref={ref} className={className} index={inGroup.index} option={option} messages={messages} />;\n }\n\n const blocks = options.flatMap((option, index) =>\n option.address\n ? [<AddressBlock key={`${index}:${optionKey(option)}`} index={index} option={option} messages={messages} />]\n : [],\n );\n if (blocks.length === 0) {\n return null;\n }\n\n return (\n <div ref={ref as Ref<HTMLDivElement>} className={className} data-fs-order-delivery-address-list=\"\">\n {blocks}\n </div>\n );\n}\n\ntype AddressBlockProps = Readonly<{\n index: number;\n option: OrderDeliveryAddressOptionData;\n messages: MessageFormatter<typeof OrderDeliveryAddressContent>;\n className?: string;\n ref?: Ref<HTMLElement>;\n}>;\n\nfunction AddressBlock({ index, option, messages, className, ref }: AddressBlockProps) {\n const pickup = option.deliveryChannel === PICKUP_CHANNEL;\n const recipient = pickup ? null : text(option.address?.receiverName);\n\n return (\n <address\n ref={ref}\n className={className}\n data-fs-order-delivery-address=\"\"\n data-fs-order-delivery-address-channel={pickup ? PICKUP_CHANNEL : 'delivery'}\n data-fs-order-delivery-address-option={index}\n >\n <span data-fs-order-delivery-address-label=\"\">{messages.format(pickup ? 'storeLabel' : 'deliveryLabel')}</span>\n {recipient ? <span data-fs-order-delivery-address-recipient=\"\">{recipient}</span> : null}\n {FIELDS.map(([name, hook]) => {\n const value = text(option.address?.[name]);\n return value ? (\n <span key={name} {...hook}>\n {value}\n </span>\n ) : null;\n })}\n </address>\n );\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,WAAyB;;;;;;;;;;;;;;;;;;;;;;AAuB/B,MAAa,8BAA8B,kBAAkB;CAC3D,IAAI;CACJ,OAAO;CACP,aAAa;CACb,QAAQ;EACN,MAAM;EACN,sBAAsB;EACtB,YAAY;GACV,eAAe;IACb,MAAM;IACN,OAAO;IACP,QAAQ;IACR,eAAe;GACjB;GACA,YAAY;IACV,MAAM;IACN,OA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