@duffel/components 2.7.20 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +67 -0
- package/.eslintrc.js +47 -0
- package/.github/renovate.json +16 -0
- package/.github/workflows/autoapprove.yml +18 -0
- package/.github/workflows/release.yml +89 -0
- package/.husky/post-commit +4 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/.prettierignore +2 -0
- package/.storybook/Storyshots.test.js +3 -0
- package/.storybook/__snapshots__/Storyshots.test.js.snap +48318 -0
- package/.storybook/main.ts +33 -0
- package/.storybook/preview.tsx +28 -0
- package/.tool-versions +1 -0
- package/CONTRIBUTING.md +83 -0
- package/README.md +53 -15
- package/__mocks__/styleMock.js +6 -0
- package/babel.config.js +20 -0
- package/commitlint.config.js +4 -0
- package/config/esbuild.base.config.js +18 -0
- package/config/esbuild.cdn.config.js +51 -0
- package/config/esbuild.dev.config.js +46 -0
- package/config/esbuild.react.config.js +42 -0
- package/jest.config.ts +14 -0
- package/package.json +135 -193
- package/react-dist/components/DuffelAncillaries/Card.d.ts +14 -0
- package/react-dist/components/DuffelAncillaries/Counter.d.ts +10 -0
- package/react-dist/components/DuffelAncillaries/DuffelAncillaries.d.ts +3 -0
- package/react-dist/components/DuffelAncillaries/DuffelAncillariesCustomElement.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionCard.d.ts +11 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionController.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionModal.d.ts +11 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionModalBody.d.ts +11 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionModalBodyPassenger.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionModalFooter.d.ts +14 -0
- package/react-dist/components/DuffelAncillaries/bags/BaggageSelectionModalHeader.d.ts +9 -0
- package/react-dist/components/DuffelAncillaries/bags/IncludedBaggageBanner.d.ts +7 -0
- package/react-dist/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionCard.d.ts +10 -0
- package/react-dist/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModal.d.ts +11 -0
- package/react-dist/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalBody.d.ts +7 -0
- package/react-dist/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalBodyListItem.d.ts +4 -0
- package/react-dist/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalFooter.d.ts +11 -0
- package/react-dist/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalHeader.d.ts +2 -0
- package/react-dist/components/DuffelAncillaries/seats/Amenity.d.ts +6 -0
- package/react-dist/components/DuffelAncillaries/seats/DeckSelect.d.ts +15 -0
- package/react-dist/components/DuffelAncillaries/seats/Element.d.ts +15 -0
- package/react-dist/components/DuffelAncillaries/seats/EmptyElement.d.ts +2 -0
- package/react-dist/components/DuffelAncillaries/seats/ExitElement.d.ts +6 -0
- package/react-dist/components/DuffelAncillaries/seats/Legend.d.ts +12 -0
- package/react-dist/components/DuffelAncillaries/seats/Row.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/seats/RowSection.d.ts +17 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatElement.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatInfo.d.ts +7 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatMap.d.ts +12 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatMapUnavailable.d.ts +2 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatSelectionCard.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatSelectionModal.d.ts +13 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatSelectionModalBody.d.ts +4 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatSelectionModalFooter.d.ts +16 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatSelectionModalHeader.d.ts +10 -0
- package/react-dist/components/DuffelAncillaries/seats/SeatUnavailable.d.ts +5 -0
- package/react-dist/components/DuffelPayments/DuffelPayments.d.ts +11 -0
- package/react-dist/components/DuffelPayments/DuffelPaymentsCustomElement.d.ts +14 -0
- package/react-dist/components/shared/AnimatedLoaderEllipsis.d.ts +2 -0
- package/react-dist/components/shared/Button.d.ts +23 -0
- package/react-dist/components/shared/ErrorBoundary.d.ts +13 -0
- package/react-dist/components/shared/FetchOfferErrorState.d.ts +5 -0
- package/react-dist/components/shared/Icon.d.ts +44 -0
- package/react-dist/components/shared/IconButton.d.ts +16 -0
- package/react-dist/components/shared/Modal.d.ts +11 -0
- package/react-dist/components/shared/NonIdealState.d.ts +4 -0
- package/react-dist/components/shared/Stamp.d.ts +7 -0
- package/react-dist/components/shared/Tabs.d.ts +16 -0
- package/react-dist/custom-elements.d.ts +6 -0
- package/react-dist/custom-elements.js +37 -0
- package/react-dist/custom-elements.js.map +7 -0
- package/react-dist/index.d.ts +7 -0
- package/react-dist/index.js +37 -0
- package/react-dist/index.js.map +7 -0
- package/react-dist/lib/captureErrorInSentry.d.ts +1 -0
- package/react-dist/lib/compileCreateOrderPayload.d.ts +14 -0
- package/react-dist/lib/createPriceFormatters.d.ts +12 -0
- package/react-dist/lib/fetchFromDuffelAPI.d.ts +8 -0
- package/react-dist/lib/fetchFromFixtures.d.ts +4 -0
- package/react-dist/lib/formatAvailableServices.d.ts +12 -0
- package/react-dist/lib/formatDate.d.ts +2 -0
- package/react-dist/lib/formatSeatMaps.d.ts +4 -0
- package/react-dist/lib/getBaggageServiceDescription.d.ts +2 -0
- package/react-dist/lib/getCabinsForSegmentAndDeck.d.ts +2 -0
- package/react-dist/lib/getCurrencyForSeatMaps.d.ts +10 -0
- package/react-dist/lib/getCurrencyForServices.d.ts +11 -0
- package/react-dist/lib/getFirstSeatElementMatchingCriteria.d.ts +3 -0
- package/react-dist/lib/getPassengerBySegmentList.d.ts +6 -0
- package/react-dist/lib/getPassengerInitials.d.ts +1 -0
- package/react-dist/lib/getPassengerMapById.d.ts +3 -0
- package/react-dist/lib/getPassengerName.d.ts +3 -0
- package/react-dist/lib/getRowNumber.d.ts +2 -0
- package/react-dist/lib/getSegmentList.d.ts +2 -0
- package/react-dist/lib/getServicePriceMapById.d.ts +3 -0
- package/react-dist/lib/getSymbols.d.ts +2 -0
- package/react-dist/lib/getTotalAmountForServices.d.ts +6 -0
- package/react-dist/lib/getTotalQuantity.d.ts +2 -0
- package/react-dist/lib/hasService.d.ts +2 -0
- package/react-dist/lib/hasServiceOfSameMetadataTypeAlreadyBeenSelected.d.ts +3 -0
- package/react-dist/lib/hasWings.d.ts +2 -0
- package/react-dist/lib/isBaggageService.d.ts +2 -0
- package/react-dist/lib/isCancelForAnyReasonService.d.ts +2 -0
- package/react-dist/lib/isFixtureOfferId.d.ts +2 -0
- package/react-dist/lib/isPayloadComplete.d.ts +2 -0
- package/react-dist/lib/isSeatElement.d.ts +2 -0
- package/react-dist/lib/logging.d.ts +46 -0
- package/react-dist/lib/moneyStringFormatter.d.ts +8 -0
- package/react-dist/lib/offerIsExpired.d.ts +2 -0
- package/react-dist/lib/retrieveOffer.d.ts +2 -0
- package/react-dist/lib/retrieveOfferFromDuffelAPI.d.ts +1 -0
- package/react-dist/lib/retrieveSeatMaps.d.ts +2 -0
- package/react-dist/lib/retrieveSeatMapsFromDuffelAPI.d.ts +1 -0
- package/react-dist/lib/setBodyScrollability.d.ts +1 -0
- package/react-dist/lib/validateProps.d.ts +7 -0
- package/react-dist/lib/withPlural.d.ts +1 -0
- package/react-dist/types/Aircraft.d.ts +14 -0
- package/react-dist/types/Airline.d.ts +14 -0
- package/react-dist/types/Airport.d.ts +44 -0
- package/react-dist/types/City.d.ts +18 -0
- package/react-dist/types/CreateOrderPayload.d.ts +72 -0
- package/react-dist/types/CurrencyConversion.d.ts +10 -0
- package/react-dist/types/DuffelAncillariesProps.d.ts +70 -0
- package/react-dist/types/Offer.d.ts +711 -0
- package/react-dist/types/Order.d.ts +8 -0
- package/react-dist/types/Place.d.ts +8 -0
- package/react-dist/types/SeatMap.d.ts +190 -0
- package/react-dist/types/index.d.ts +11 -0
- package/scripts/generate-fixture.ts +200 -0
- package/scripts/upload-to-cdn.sh +34 -0
- package/scripts.tsconfig.json +11 -0
- package/src/components/DuffelAncillaries/Card.tsx +126 -0
- package/src/components/DuffelAncillaries/Counter.tsx +40 -0
- package/src/components/DuffelAncillaries/DuffelAncillaries.tsx +344 -0
- package/src/components/DuffelAncillaries/DuffelAncillariesCustomElement.tsx +124 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionCard.tsx +96 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionController.tsx +88 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionModal.tsx +81 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionModalBody.tsx +60 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionModalBodyPassenger.tsx +122 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionModalFooter.tsx +81 -0
- package/src/components/DuffelAncillaries/bags/BaggageSelectionModalHeader.tsx +76 -0
- package/src/components/DuffelAncillaries/bags/IncludedBaggageBanner.tsx +51 -0
- package/src/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionCard.tsx +90 -0
- package/src/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModal.tsx +63 -0
- package/src/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalBody.tsx +56 -0
- package/src/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalBodyListItem.tsx +11 -0
- package/src/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalFooter.tsx +74 -0
- package/src/components/DuffelAncillaries/cancel_for_any_reason/CfarSelectionModalHeader.tsx +9 -0
- package/src/components/DuffelAncillaries/seats/Amenity.tsx +21 -0
- package/src/components/DuffelAncillaries/seats/DeckSelect.tsx +27 -0
- package/src/components/DuffelAncillaries/seats/Element.tsx +52 -0
- package/src/components/DuffelAncillaries/seats/EmptyElement.tsx +5 -0
- package/src/components/DuffelAncillaries/seats/ExitElement.tsx +17 -0
- package/src/components/DuffelAncillaries/seats/Legend.tsx +60 -0
- package/src/components/DuffelAncillaries/seats/Row.tsx +47 -0
- package/src/components/DuffelAncillaries/seats/RowSection.tsx +78 -0
- package/src/components/DuffelAncillaries/seats/SeatElement.tsx +120 -0
- package/src/components/DuffelAncillaries/seats/SeatInfo.tsx +32 -0
- package/src/components/DuffelAncillaries/seats/SeatMap.tsx +81 -0
- package/src/components/DuffelAncillaries/seats/SeatMapUnavailable.tsx +21 -0
- package/src/components/DuffelAncillaries/seats/SeatSelectionCard.tsx +103 -0
- package/src/components/DuffelAncillaries/seats/SeatSelectionModal.tsx +142 -0
- package/src/components/DuffelAncillaries/seats/SeatSelectionModalBody.tsx +13 -0
- package/src/components/DuffelAncillaries/seats/SeatSelectionModalFooter.tsx +82 -0
- package/src/components/DuffelAncillaries/seats/SeatSelectionModalHeader.tsx +87 -0
- package/src/components/DuffelAncillaries/seats/SeatUnavailable.tsx +14 -0
- package/src/components/DuffelPayments/DuffelPayments.tsx +218 -0
- package/src/components/DuffelPayments/DuffelPaymentsCustomElement.tsx +130 -0
- package/src/components/shared/AnimatedLoaderEllipsis.tsx +5 -0
- package/src/components/shared/Button.tsx +63 -0
- package/src/components/shared/ErrorBoundary.tsx +54 -0
- package/src/components/shared/FetchOfferErrorState.tsx +35 -0
- package/src/components/shared/Icon.tsx +152 -0
- package/src/components/shared/IconButton.tsx +42 -0
- package/src/components/shared/Modal.tsx +40 -0
- package/src/components/shared/NonIdealState.tsx +28 -0
- package/src/components/shared/Stamp.tsx +29 -0
- package/src/components/shared/Tabs.tsx +36 -0
- package/src/custom-elements.ts +13 -0
- package/src/examples/client-side/README.md +30 -0
- package/src/examples/client-side/index.html +57 -0
- package/src/examples/full-stack/README.md +34 -0
- package/src/examples/full-stack/index.html +48 -0
- package/src/examples/full-stack/server.mjs +158 -0
- package/src/examples/just-typescript/README.md +37 -0
- package/src/examples/just-typescript/package.json +16 -0
- package/src/examples/just-typescript/src/index.html +23 -0
- package/src/examples/just-typescript/src/index.ts +36 -0
- package/src/examples/just-typescript/yarn.lock +154 -0
- package/src/examples/payments-custom-element/README.md +17 -0
- package/src/examples/payments-custom-element/index.html +43 -0
- package/src/examples/payments-just-typescript/README.md +37 -0
- package/src/examples/payments-just-typescript/package.json +16 -0
- package/src/examples/payments-just-typescript/src/index.html +23 -0
- package/src/examples/payments-just-typescript/src/index.ts +18 -0
- package/src/examples/payments-just-typescript/yarn.lock +154 -0
- package/src/examples/react-app/README.md +37 -0
- package/src/examples/react-app/package.json +20 -0
- package/src/examples/react-app/src/index.html +19 -0
- package/src/examples/react-app/src/index.tsx +48 -0
- package/src/examples/react-app/yarn.lock +219 -0
- package/src/fixtures/offers/off_0000AUde3KwTztSRK1cznH.json +497 -0
- package/src/fixtures/offers/off_0000AVx4lUFFKW8PsPeQeQ.json +307 -0
- package/src/fixtures/offers/off_1.json +497 -0
- package/src/fixtures/passengers/mock_passengers.ts +26 -0
- package/src/fixtures/seat-maps/off_0000AUde3KwTztSRK1cznH.json +6852 -0
- package/src/fixtures/seat-maps/off_0000AVx4lUFFKW8PsPeQeQ.json +1 -0
- package/src/fixtures/seat-maps/off_1.json +6852 -0
- package/src/index.ts +7 -0
- package/src/lib/captureErrorInSentry.ts +42 -0
- package/src/lib/compileCreateOrderPayload.ts +63 -0
- package/src/lib/createPriceFormatters.ts +73 -0
- package/src/lib/fetchFromDuffelAPI.ts +54 -0
- package/src/lib/fetchFromFixtures.ts +18 -0
- package/src/lib/formatAvailableServices.ts +91 -0
- package/src/lib/formatDate.ts +20 -0
- package/src/lib/formatSeatMaps.ts +81 -0
- package/src/lib/getBaggageServiceDescription.ts +42 -0
- package/src/lib/getCabinsForSegmentAndDeck.ts +4 -0
- package/src/lib/getCurrencyForSeatMaps.ts +22 -0
- package/src/lib/getCurrencyForServices.ts +24 -0
- package/src/lib/getFirstSeatElementMatchingCriteria.ts +22 -0
- package/src/lib/getPassengerBySegmentList.ts +10 -0
- package/src/lib/getPassengerInitials.ts +6 -0
- package/src/lib/getPassengerMapById.ts +17 -0
- package/src/lib/getPassengerName.ts +37 -0
- package/src/lib/getRowNumber.ts +16 -0
- package/src/lib/getSegmentList.ts +7 -0
- package/src/lib/getServicePriceMapById.ts +20 -0
- package/src/lib/getSymbols.ts +22 -0
- package/src/lib/getTotalAmountForServices.ts +72 -0
- package/src/lib/getTotalQuantity.ts +5 -0
- package/src/lib/hasService.ts +24 -0
- package/src/lib/hasServiceOfSameMetadataTypeAlreadyBeenSelected.ts +35 -0
- package/src/lib/hasWings.ts +8 -0
- package/src/lib/isBaggageService.ts +8 -0
- package/src/lib/isCancelForAnyReasonService.ts +9 -0
- package/src/lib/isFixtureOfferId.ts +4 -0
- package/src/lib/isPayloadComplete.ts +11 -0
- package/src/lib/isSeatElement.ts +10 -0
- package/src/lib/logging.ts +120 -0
- package/src/lib/moneyStringFormatter.ts +34 -0
- package/src/lib/offerIsExpired.ts +5 -0
- package/src/lib/retrieveOffer.ts +54 -0
- package/src/lib/retrieveOfferFromDuffelAPI.ts +13 -0
- package/src/lib/retrieveSeatMaps.ts +55 -0
- package/src/lib/retrieveSeatMapsFromDuffelAPI.ts +13 -0
- package/src/lib/setBodyScrollability.ts +7 -0
- package/src/lib/validateProps.ts +37 -0
- package/src/lib/withPlural.ts +8 -0
- package/src/stories/BaggageSelectionModalHeader.stories.tsx +21 -0
- package/src/stories/Button.stories.tsx +69 -0
- package/src/stories/DuffelAncillaries.stories.tsx +126 -0
- package/src/stories/DuffelPayments.stories.tsx +34 -0
- package/src/stories/Icon.stories.tsx +35 -0
- package/src/stories/IconButton.stories.tsx +25 -0
- package/src/styles/colors.css +22 -0
- package/src/styles/components/Amenity.css +23 -0
- package/src/styles/components/BaggageDisplay.css +25 -0
- package/src/styles/components/Button.css +161 -0
- package/src/styles/components/Card.css +52 -0
- package/src/styles/components/CfarSelectionModal.css +34 -0
- package/src/styles/components/Counter.css +18 -0
- package/src/styles/components/DuffelPayments.css +42 -0
- package/src/styles/components/IconButton.css +63 -0
- package/src/styles/components/Legend.css +58 -0
- package/src/styles/components/Loader.css +37 -0
- package/src/styles/components/LoadingState.css +81 -0
- package/src/styles/components/Modal.css +84 -0
- package/src/styles/components/PassengerSelect.css +93 -0
- package/src/styles/components/PassengersLayout.css +90 -0
- package/src/styles/components/Row.css +70 -0
- package/src/styles/components/Seat.css +57 -0
- package/src/styles/components/SeatInfo.css +61 -0
- package/src/styles/components/SeatMap.css +24 -0
- package/src/styles/components/SeatSelect.css +92 -0
- package/src/styles/components/Segment.css +17 -0
- package/src/styles/components/SelectionSegment.css +10 -0
- package/src/styles/components/Summary.css +70 -0
- package/src/styles/components/Tabs.css +49 -0
- package/src/styles/flex.css +5 -0
- package/src/styles/font-families.css +47 -0
- package/src/styles/global.css +51 -0
- package/src/styles/margin.css +3 -0
- package/src/styles/spacing.css +18 -0
- package/src/styles/transitions.css +3 -0
- package/src/styles/typography.css +13 -0
- package/src/tests/components/DuffelAncillaries.test.tsx +342 -0
- package/src/tests/lib/createPriceFormatters.test.tsx +152 -0
- package/src/tests/lib/formatAvailableServices.test.tsx +79 -0
- package/src/tests/lib/formatSeatMaps.test.tsx +49 -0
- package/src/tests/lib/getCurrencyForServices.test.tsx +44 -0
- package/src/tests/lib/hasServiceOfSameMetadataTypeAlreadyBeenSelected.test.ts +86 -0
- package/src/tests/lib/logging.test.tsx +32 -0
- package/src/tests/lib/moneyStringFormatter.test.tsx +12 -0
- package/src/tests/lib/validateProps.test.tsx +57 -0
- package/src/types/Aircraft.ts +16 -0
- package/src/types/Airline.ts +16 -0
- package/src/types/Airport.ts +54 -0
- package/src/types/City.ts +21 -0
- package/src/types/CreateOrderPayload.ts +99 -0
- package/src/types/CurrencyConversion.ts +10 -0
- package/src/types/DuffelAncillariesProps.ts +108 -0
- package/src/types/Offer.ts +851 -0
- package/src/types/Order.ts +6 -0
- package/src/types/Place.ts +6 -0
- package/src/types/SeatMap.ts +231 -0
- package/src/types/index.ts +11 -0
- package/tsconfig.json +52 -0
- package/LICENSE +0 -21
- package/dist/AdditionalBaggage.esm.js +0 -1
- package/dist/AdditionalBaggage.js +0 -1
- package/dist/AdditionalBaggage.min.css +0 -408
- package/dist/AdditionalBaggage.umd.min.js +0 -2
- package/dist/AdditionalBaggage.umd.min.js.LICENSE.txt +0 -60
- package/dist/AdditionalBaggageSelection.esm.js +0 -1
- package/dist/AdditionalBaggageSelection.js +0 -1
- package/dist/AdditionalBaggageSelection.min.css +0 -744
- package/dist/AdditionalBaggageSelection.umd.min.js +0 -2
- package/dist/AdditionalBaggageSelection.umd.min.js.LICENSE.txt +0 -93
- package/dist/CardPayment.esm.js +0 -2
- package/dist/CardPayment.esm.js.LICENSE.txt +0 -6
- package/dist/CardPayment.js +0 -2
- package/dist/CardPayment.js.LICENSE.txt +0 -6
- package/dist/CardPayment.min.css +0 -233
- package/dist/CardPayment.umd.min.js +0 -2
- package/dist/CardPayment.umd.min.js.LICENSE.txt +0 -61
- package/dist/SeatSelection.esm.js +0 -1
- package/dist/SeatSelection.js +0 -1
- package/dist/SeatSelection.min.css +0 -1127
- package/dist/SeatSelection.umd.min.js +0 -2
- package/dist/SeatSelection.umd.min.js.LICENSE.txt +0 -60
- package/dist/duffel-components.d.ts +0 -1614
- package/dist/duffel-components.esm.js +0 -2
- package/dist/duffel-components.esm.js.LICENSE.txt +0 -6
- package/dist/duffel-components.js +0 -2
- package/dist/duffel-components.js.LICENSE.txt +0 -6
- package/dist/duffel-components.min.css +0 -1280
- package/dist/duffel-components.umd.min.js +0 -2
- package/dist/duffel-components.umd.min.js.LICENSE.txt +0 -102
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { AnimatedLoaderEllipsis } from "@components/shared/AnimatedLoaderEllipsis";
|
|
2
|
+
import { Stamp } from "@components/shared/Stamp";
|
|
3
|
+
import { getCurrencyForSeatMaps } from "@lib/getCurrencyForSeatMaps";
|
|
4
|
+
import { getTotalAmountForServices } from "@lib/getTotalAmountForServices";
|
|
5
|
+
import { getTotalQuantity } from "@lib/getTotalQuantity";
|
|
6
|
+
import { moneyStringFormatter } from "@lib/moneyStringFormatter";
|
|
7
|
+
import { withPlural } from "@lib/withPlural";
|
|
8
|
+
import React from "react";
|
|
9
|
+
import {
|
|
10
|
+
CreateOrderPayload,
|
|
11
|
+
CreateOrderPayloadSeatService,
|
|
12
|
+
CreateOrderPayloadServices,
|
|
13
|
+
} from "../../../types/CreateOrderPayload";
|
|
14
|
+
import { Offer } from "../../../types/Offer";
|
|
15
|
+
import { SeatMap } from "../../../types/SeatMap";
|
|
16
|
+
import { Card } from "../Card";
|
|
17
|
+
import { SeatSelectionModal } from "./SeatSelectionModal";
|
|
18
|
+
|
|
19
|
+
export interface SeatSelectionCardProps {
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
offer?: Offer;
|
|
22
|
+
seatMaps?: SeatMap[];
|
|
23
|
+
passengers: CreateOrderPayload["passengers"];
|
|
24
|
+
selectedServices: CreateOrderPayloadServices;
|
|
25
|
+
setSelectedServices: (selectedServices: CreateOrderPayloadServices) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const SeatSelectionCard: React.FC<SeatSelectionCardProps> = ({
|
|
29
|
+
isLoading,
|
|
30
|
+
offer,
|
|
31
|
+
seatMaps,
|
|
32
|
+
passengers,
|
|
33
|
+
selectedServices,
|
|
34
|
+
setSelectedServices,
|
|
35
|
+
}) => {
|
|
36
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
37
|
+
|
|
38
|
+
const containsSeatService = Array.isArray(seatMaps) && seatMaps.length > 0;
|
|
39
|
+
const totalQuantity = getTotalQuantity(selectedServices);
|
|
40
|
+
const areSeatsAdded = totalQuantity > 0;
|
|
41
|
+
|
|
42
|
+
const totalAmount = getTotalAmountForServices(
|
|
43
|
+
offer!,
|
|
44
|
+
selectedServices,
|
|
45
|
+
seatMaps
|
|
46
|
+
);
|
|
47
|
+
let currencyToUse = offer?.base_currency ?? "";
|
|
48
|
+
if (seatMaps) {
|
|
49
|
+
currencyToUse = getCurrencyForSeatMaps(seatMaps) ?? currencyToUse;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const totalAmountFormatted = offer
|
|
53
|
+
? moneyStringFormatter(currencyToUse)(totalAmount)
|
|
54
|
+
: "0";
|
|
55
|
+
|
|
56
|
+
const copy =
|
|
57
|
+
containsSeatService && areSeatsAdded
|
|
58
|
+
? `${withPlural(
|
|
59
|
+
totalQuantity,
|
|
60
|
+
"seat",
|
|
61
|
+
"seats"
|
|
62
|
+
)} selected for ${totalAmountFormatted}`
|
|
63
|
+
: "Specify where on the plane you’d like to sit";
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<Card
|
|
68
|
+
buttonTitle="Select seats"
|
|
69
|
+
title="Seat selection"
|
|
70
|
+
copy={copy}
|
|
71
|
+
icon="flight_class"
|
|
72
|
+
onClick={containsSeatService ? () => setIsOpen(true) : null}
|
|
73
|
+
isLoading={isLoading}
|
|
74
|
+
disabled={isLoading && !containsSeatService}
|
|
75
|
+
isSelected={areSeatsAdded}
|
|
76
|
+
>
|
|
77
|
+
{isLoading && (
|
|
78
|
+
<Stamp color="var(--GREY-900)" backgroundColor="var(--GREY-100)">
|
|
79
|
+
Loading
|
|
80
|
+
<AnimatedLoaderEllipsis />
|
|
81
|
+
</Stamp>
|
|
82
|
+
)}
|
|
83
|
+
{!isLoading && !containsSeatService && (
|
|
84
|
+
<Stamp color="var(--GREY-700)" backgroundColor="var(--GREY-200)">
|
|
85
|
+
Not available
|
|
86
|
+
</Stamp>
|
|
87
|
+
)}
|
|
88
|
+
</Card>
|
|
89
|
+
|
|
90
|
+
<SeatSelectionModal
|
|
91
|
+
isOpen={Boolean(offer && seatMaps && isOpen)}
|
|
92
|
+
seatMaps={seatMaps}
|
|
93
|
+
offer={offer}
|
|
94
|
+
passengers={passengers}
|
|
95
|
+
selectedServices={selectedServices as CreateOrderPayloadSeatService[]}
|
|
96
|
+
onClose={(services) => {
|
|
97
|
+
setSelectedServices(services);
|
|
98
|
+
setIsOpen(false);
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
</>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Modal } from "@components/shared/Modal";
|
|
2
|
+
import { getCurrencyForSeatMaps } from "@lib/getCurrencyForSeatMaps";
|
|
3
|
+
import { getPassengerBySegmentList } from "@lib/getPassengerBySegmentList";
|
|
4
|
+
import { getPassengerMapById } from "@lib/getPassengerMapById";
|
|
5
|
+
import { getPassengerName } from "@lib/getPassengerName";
|
|
6
|
+
import { getSegmentList } from "@lib/getSegmentList";
|
|
7
|
+
import { getServicePriceMapById } from "@lib/getServicePriceMapById";
|
|
8
|
+
import React from "react";
|
|
9
|
+
import {
|
|
10
|
+
CreateOrderPayload,
|
|
11
|
+
CreateOrderPayloadSeatService,
|
|
12
|
+
} from "../../../types/CreateOrderPayload";
|
|
13
|
+
import { Offer } from "../../../types/Offer";
|
|
14
|
+
import { SeatMap } from "../../../types/SeatMap";
|
|
15
|
+
import { SeatSelectionModalBody } from "./SeatSelectionModalBody";
|
|
16
|
+
import { SeatSelectionModalFooter } from "./SeatSelectionModalFooter";
|
|
17
|
+
import { SeatSelectionModalHeader } from "./SeatSelectionModalHeader";
|
|
18
|
+
|
|
19
|
+
export interface SeatSelectionModalProps {
|
|
20
|
+
isOpen: boolean;
|
|
21
|
+
offer?: Offer;
|
|
22
|
+
seatMaps?: SeatMap[];
|
|
23
|
+
selectedServices: CreateOrderPayloadSeatService[];
|
|
24
|
+
passengers: CreateOrderPayload["passengers"];
|
|
25
|
+
onClose: (selectedServices: CreateOrderPayloadSeatService[]) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const SeatSelectionModal: React.FC<SeatSelectionModalProps> = ({
|
|
29
|
+
isOpen,
|
|
30
|
+
offer,
|
|
31
|
+
passengers,
|
|
32
|
+
seatMaps,
|
|
33
|
+
selectedServices,
|
|
34
|
+
onClose,
|
|
35
|
+
}) => {
|
|
36
|
+
const [currentPermutationIndex, setCurrentPermutationIndex] =
|
|
37
|
+
React.useState(0);
|
|
38
|
+
|
|
39
|
+
const [selectedServicesState, setSelectedServicesState] =
|
|
40
|
+
React.useState<CreateOrderPayloadSeatService[]>(selectedServices);
|
|
41
|
+
const selectedServicesStateMap = selectedServicesState.reduce(
|
|
42
|
+
(all, service) => ({ ...all, [service.id]: service }),
|
|
43
|
+
{} as Record<string, CreateOrderPayloadSeatService>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!offer || !seatMaps) return null;
|
|
47
|
+
|
|
48
|
+
const segments = getSegmentList(offer);
|
|
49
|
+
const passengerMapById = getPassengerMapById(passengers);
|
|
50
|
+
const servicePricesMap = getServicePriceMapById(offer.available_services);
|
|
51
|
+
const segmentAndPassengerPermutations = getPassengerBySegmentList(segments);
|
|
52
|
+
const {
|
|
53
|
+
passenger: { passenger_id: currentPassengerId },
|
|
54
|
+
passengerIndex: currentPassengerIndex,
|
|
55
|
+
segment: { id: currentSegmentId },
|
|
56
|
+
} = segmentAndPassengerPermutations[currentPermutationIndex];
|
|
57
|
+
|
|
58
|
+
const currentSegment = segments.find(({ id }) => id === currentSegmentId)!;
|
|
59
|
+
const currentPassenger = passengerMapById[currentPassengerId];
|
|
60
|
+
const currentSeatMap = seatMaps.find(
|
|
61
|
+
(seatMap) => seatMap.segment_id === currentSegmentId
|
|
62
|
+
)!;
|
|
63
|
+
|
|
64
|
+
const currentPassengerName = getPassengerName(
|
|
65
|
+
currentPassenger,
|
|
66
|
+
offer.passengers[currentPassengerIndex],
|
|
67
|
+
currentPassengerIndex + 1
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const onSeatToggle = (seatServiceToToggle: CreateOrderPayloadSeatService) => {
|
|
71
|
+
let newSeatServices = new Array<CreateOrderPayloadSeatService>();
|
|
72
|
+
|
|
73
|
+
for (const selectedServiceFromState of selectedServicesState) {
|
|
74
|
+
const hasClickedSeatToToggleOff =
|
|
75
|
+
selectedServiceFromState.id === seatServiceToToggle.id &&
|
|
76
|
+
seatServiceToToggle.quantity === 0;
|
|
77
|
+
|
|
78
|
+
const isSelectedServiceFromStateForTheSameSegmentAndPassengerPermutation =
|
|
79
|
+
selectedServiceFromState.serviceInformation?.segmentId ===
|
|
80
|
+
currentSegmentId &&
|
|
81
|
+
selectedServiceFromState.serviceInformation?.passengerId ===
|
|
82
|
+
currentPassengerId;
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
!hasClickedSeatToToggleOff &&
|
|
86
|
+
!isSelectedServiceFromStateForTheSameSegmentAndPassengerPermutation
|
|
87
|
+
) {
|
|
88
|
+
newSeatServices = [...newSeatServices, selectedServiceFromState];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (seatServiceToToggle.quantity > 0) {
|
|
93
|
+
newSeatServices = [...newSeatServices, seatServiceToToggle];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setSelectedServicesState(newSeatServices);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const currencyToUse =
|
|
100
|
+
getCurrencyForSeatMaps(seatMaps) ?? offer.total_currency;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<Modal isOpen={isOpen} onClose={() => onClose(selectedServicesState)}>
|
|
104
|
+
<SeatSelectionModalHeader
|
|
105
|
+
segmentAndPassengerPermutationsCount={
|
|
106
|
+
segmentAndPassengerPermutations.length
|
|
107
|
+
}
|
|
108
|
+
currentSegment={currentSegment}
|
|
109
|
+
currentPassengerName={currentPassengerName}
|
|
110
|
+
currentSegmentAndPassengerPermutationsIndex={currentPermutationIndex}
|
|
111
|
+
setCurrentSegmentAndPassengerPermutationsIndex={
|
|
112
|
+
setCurrentPermutationIndex
|
|
113
|
+
}
|
|
114
|
+
/>
|
|
115
|
+
<SeatSelectionModalBody
|
|
116
|
+
selectedServicesMap={selectedServicesStateMap}
|
|
117
|
+
seatMap={currentSeatMap}
|
|
118
|
+
onSeatToggled={onSeatToggle}
|
|
119
|
+
currentPassengerId={currentPassengerId}
|
|
120
|
+
currentPassengerName={currentPassengerName}
|
|
121
|
+
currentSegmentId={currentSegmentId}
|
|
122
|
+
/>
|
|
123
|
+
<SeatSelectionModalFooter
|
|
124
|
+
seatMaps={seatMaps}
|
|
125
|
+
currency={currencyToUse}
|
|
126
|
+
selectedServices={selectedServicesState}
|
|
127
|
+
servicePrices={servicePricesMap}
|
|
128
|
+
isFirstSegment={currentPermutationIndex === 0}
|
|
129
|
+
isLastSegment={
|
|
130
|
+
currentPermutationIndex + 1 === segmentAndPassengerPermutations.length
|
|
131
|
+
}
|
|
132
|
+
onNextSegmentButtonClicked={() => {
|
|
133
|
+
setCurrentPermutationIndex(currentPermutationIndex + 1);
|
|
134
|
+
}}
|
|
135
|
+
onPreviousSegmentButtonClicked={() => {
|
|
136
|
+
setCurrentPermutationIndex(currentPermutationIndex - 1);
|
|
137
|
+
}}
|
|
138
|
+
onClose={() => onClose(selectedServicesState)}
|
|
139
|
+
/>
|
|
140
|
+
</Modal>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModalBody } from "@components/shared/Modal";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { SeatMap, SeatMapProps } from "./SeatMap";
|
|
4
|
+
|
|
5
|
+
export type SeatSelectionModalBodyProps = SeatMapProps;
|
|
6
|
+
|
|
7
|
+
export const SeatSelectionModalBody: React.FC<SeatSelectionModalBodyProps> = (
|
|
8
|
+
props
|
|
9
|
+
) => (
|
|
10
|
+
<ModalBody>
|
|
11
|
+
<SeatMap {...props} />
|
|
12
|
+
</ModalBody>
|
|
13
|
+
);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Button } from "@components/shared/Button";
|
|
2
|
+
import { ServicePriceMapById } from "@lib/getServicePriceMapById";
|
|
3
|
+
import { getTotalAmountForServicesWithPriceMap } from "@lib/getTotalAmountForServices";
|
|
4
|
+
import { getTotalQuantity } from "@lib/getTotalQuantity";
|
|
5
|
+
import { moneyStringFormatter } from "@lib/moneyStringFormatter";
|
|
6
|
+
import { withPlural } from "@lib/withPlural";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { CreateOrderPayloadServices } from "../../../types/CreateOrderPayload";
|
|
9
|
+
import { SeatMap } from "../../../types/SeatMap";
|
|
10
|
+
|
|
11
|
+
export interface SeatSelectionModalFooterProps {
|
|
12
|
+
currency: string;
|
|
13
|
+
selectedServices: CreateOrderPayloadServices;
|
|
14
|
+
servicePrices: ServicePriceMapById;
|
|
15
|
+
|
|
16
|
+
isFirstSegment: boolean;
|
|
17
|
+
isLastSegment: boolean;
|
|
18
|
+
|
|
19
|
+
onNextSegmentButtonClicked: () => void;
|
|
20
|
+
onPreviousSegmentButtonClicked: () => void;
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
seatMaps: SeatMap[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const SeatSelectionModalFooter: React.FC<
|
|
26
|
+
SeatSelectionModalFooterProps
|
|
27
|
+
> = ({
|
|
28
|
+
selectedServices,
|
|
29
|
+
servicePrices,
|
|
30
|
+
currency,
|
|
31
|
+
isFirstSegment,
|
|
32
|
+
isLastSegment,
|
|
33
|
+
onNextSegmentButtonClicked,
|
|
34
|
+
onPreviousSegmentButtonClicked,
|
|
35
|
+
onClose,
|
|
36
|
+
seatMaps,
|
|
37
|
+
}) => {
|
|
38
|
+
const totalQuantity = getTotalQuantity(selectedServices);
|
|
39
|
+
const totalAmount = getTotalAmountForServicesWithPriceMap(
|
|
40
|
+
servicePrices,
|
|
41
|
+
selectedServices,
|
|
42
|
+
seatMaps
|
|
43
|
+
);
|
|
44
|
+
const totalAmountLabel = moneyStringFormatter(currency)(totalAmount);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div style={{ padding: "16px 24px 24px" }}>
|
|
48
|
+
<div className="flex--space-between">
|
|
49
|
+
<div>Price for {withPlural(totalQuantity, "seat", "seats")}</div>
|
|
50
|
+
<div className="h3--semibold">+ {totalAmountLabel}</div>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<div
|
|
54
|
+
style={{
|
|
55
|
+
marginTop: "16px",
|
|
56
|
+
display: "grid",
|
|
57
|
+
columnGap: "12px",
|
|
58
|
+
gridTemplateColumns: "repeat(2, 1fr)",
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<Button
|
|
62
|
+
size={48}
|
|
63
|
+
disabled={isFirstSegment}
|
|
64
|
+
variant="outlined"
|
|
65
|
+
onClick={() => onPreviousSegmentButtonClicked()}
|
|
66
|
+
>
|
|
67
|
+
Back
|
|
68
|
+
</Button>
|
|
69
|
+
|
|
70
|
+
<Button
|
|
71
|
+
size={48}
|
|
72
|
+
data-testid="confirm-selection-for-seats"
|
|
73
|
+
onClick={() =>
|
|
74
|
+
isLastSegment ? onClose() : onNextSegmentButtonClicked()
|
|
75
|
+
}
|
|
76
|
+
>
|
|
77
|
+
{isLastSegment ? "Confirm" : "Next"}
|
|
78
|
+
</Button>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { formatDateString } from "@lib/formatDate";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { OfferSliceSegment } from "../../../types/Offer";
|
|
4
|
+
|
|
5
|
+
export interface SeatSelectionModalHeaderProps {
|
|
6
|
+
segmentAndPassengerPermutationsCount: number;
|
|
7
|
+
currentSegment: OfferSliceSegment;
|
|
8
|
+
currentPassengerName: string;
|
|
9
|
+
|
|
10
|
+
currentSegmentAndPassengerPermutationsIndex: number;
|
|
11
|
+
setCurrentSegmentAndPassengerPermutationsIndex: (index: number) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SeatSelectionModalHeader: React.FC<
|
|
15
|
+
SeatSelectionModalHeaderProps
|
|
16
|
+
> = ({
|
|
17
|
+
segmentAndPassengerPermutationsCount,
|
|
18
|
+
currentSegmentAndPassengerPermutationsIndex,
|
|
19
|
+
currentSegment,
|
|
20
|
+
currentPassengerName,
|
|
21
|
+
setCurrentSegmentAndPassengerPermutationsIndex,
|
|
22
|
+
}) => (
|
|
23
|
+
<div style={{ padding: "24px 24px 16px" }}>
|
|
24
|
+
<div style={{ display: "flex", columnGap: "4px" }}>
|
|
25
|
+
{Array(segmentAndPassengerPermutationsCount)
|
|
26
|
+
.fill(0)
|
|
27
|
+
.map((_, index) =>
|
|
28
|
+
index === currentSegmentAndPassengerPermutationsIndex ? (
|
|
29
|
+
<ActiveSegment key={`segment_${index}`} />
|
|
30
|
+
) : (
|
|
31
|
+
<InactiveSegment
|
|
32
|
+
key={`segment_${index}`}
|
|
33
|
+
onClick={() =>
|
|
34
|
+
setCurrentSegmentAndPassengerPermutationsIndex(index)
|
|
35
|
+
}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
)}
|
|
39
|
+
</div>
|
|
40
|
+
<h2 className="h3--semibold" style={{ marginBlock: "12px 0px" }}>
|
|
41
|
+
Flight to {currentSegment.destination.iata_code}
|
|
42
|
+
<span
|
|
43
|
+
className="p2--regular"
|
|
44
|
+
style={{
|
|
45
|
+
color: "var(--GREY-600)",
|
|
46
|
+
marginLeft: "8px",
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
{formatDateString(currentSegment.departing_at)}
|
|
50
|
+
</span>
|
|
51
|
+
</h2>
|
|
52
|
+
<p
|
|
53
|
+
className="h3--semibold"
|
|
54
|
+
style={{ color: `var(--GREY-600)`, marginBlock: "0 4px" }}
|
|
55
|
+
>
|
|
56
|
+
{currentPassengerName}
|
|
57
|
+
</p>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const InactiveSegment: React.FC<{
|
|
62
|
+
style?: React.CSSProperties;
|
|
63
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
64
|
+
}> = ({ onClick, style }) => (
|
|
65
|
+
<button
|
|
66
|
+
onClick={onClick}
|
|
67
|
+
style={{
|
|
68
|
+
border: "none",
|
|
69
|
+
width: "4px",
|
|
70
|
+
height: "4px",
|
|
71
|
+
padding: "0",
|
|
72
|
+
borderRadius: "4px",
|
|
73
|
+
backgroundColor: "rgba(var(--ACCENT), var(--ACCENT-LIGHT-200))",
|
|
74
|
+
transition: "background-color 0.3s var(--TRANSITION-CUBIC-BEZIER)",
|
|
75
|
+
...style,
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const ActiveSegment = () => (
|
|
81
|
+
<InactiveSegment
|
|
82
|
+
onClick={undefined}
|
|
83
|
+
style={{
|
|
84
|
+
backgroundColor: "rgb(var(--ACCENT))",
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Icon } from "@components/shared/Icon";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { SeatMapCabinRowSectionElementSeat } from "../../../types/SeatMap";
|
|
4
|
+
|
|
5
|
+
export const SeatUnavailable: React.FC<{
|
|
6
|
+
seat: SeatMapCabinRowSectionElementSeat;
|
|
7
|
+
}> = ({ seat }) => (
|
|
8
|
+
<span
|
|
9
|
+
className="map-element map-element__seat"
|
|
10
|
+
aria-label={`${seat.designator} ${seat.name || "Seat"} Unavailable`}
|
|
11
|
+
>
|
|
12
|
+
<Icon name="close" size={14} />
|
|
13
|
+
</span>
|
|
14
|
+
);
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { ErrorBoundary } from "@components/shared/ErrorBoundary";
|
|
2
|
+
import { initializeLogger } from "@lib/logging";
|
|
3
|
+
import {
|
|
4
|
+
CardElement,
|
|
5
|
+
Elements,
|
|
6
|
+
useElements,
|
|
7
|
+
useStripe,
|
|
8
|
+
} from "@stripe/react-stripe-js";
|
|
9
|
+
import { StripeCardElement, StripeError, loadStripe } from "@stripe/stripe-js";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { CustomStyles } from "../../types";
|
|
12
|
+
import { Button } from "../shared/Button";
|
|
13
|
+
|
|
14
|
+
const COMPONENT_CDN = process.env.COMPONENT_CDN || "";
|
|
15
|
+
const hrefToComponentStyles = `${COMPONENT_CDN}/global.css`;
|
|
16
|
+
|
|
17
|
+
const STRIPE_CARD_ELEMENT = "card";
|
|
18
|
+
const COMPONENT_VERSION = process.env.COMPONENT_VERSION;
|
|
19
|
+
|
|
20
|
+
export interface DuffelPaymentsProps {
|
|
21
|
+
paymentIntentClientToken: string;
|
|
22
|
+
onSuccessfulPayment: () => void;
|
|
23
|
+
onFailedPayment: (error: StripeError) => void;
|
|
24
|
+
|
|
25
|
+
styles?: CustomStyles;
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const CARD_ELEMENT_STYLE_BASE = {
|
|
30
|
+
color: "var(--GREY-900)",
|
|
31
|
+
fontFamily:
|
|
32
|
+
'"-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "sans-serif"',
|
|
33
|
+
fontSmoothing: "antialiased",
|
|
34
|
+
fontSize: "16px",
|
|
35
|
+
"::placeholder": {
|
|
36
|
+
color: "#ababb4",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const CARD_ELEMENT_STYLE_INVALID = {
|
|
41
|
+
color: "#ef4444",
|
|
42
|
+
iconColor: "#ef4444",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const CardPaymentComponent: React.FC<DuffelPaymentsProps> = ({
|
|
46
|
+
styles,
|
|
47
|
+
paymentIntentClientToken,
|
|
48
|
+
onSuccessfulPayment,
|
|
49
|
+
onFailedPayment,
|
|
50
|
+
}) => {
|
|
51
|
+
const [cardElement, setCardElement] =
|
|
52
|
+
React.useState<StripeCardElement | null>(null);
|
|
53
|
+
const [isComplete, setIsComplete] = React.useState<boolean>(false);
|
|
54
|
+
const [isInvalid, setIsInvalid] = React.useState<boolean>(false);
|
|
55
|
+
const [isProcessing, setIsProcessing] = React.useState<boolean>(false);
|
|
56
|
+
const [errorMessage, setErrorMessage] = React.useState<string>("");
|
|
57
|
+
const stripe = useStripe();
|
|
58
|
+
const elements = useElements();
|
|
59
|
+
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if (elements && !cardElement) {
|
|
62
|
+
const maybeCard = elements?.getElement(STRIPE_CARD_ELEMENT);
|
|
63
|
+
maybeCard && setCardElement(maybeCard as StripeCardElement);
|
|
64
|
+
}
|
|
65
|
+
}, [elements, cardElement]);
|
|
66
|
+
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
if (cardElement) {
|
|
69
|
+
cardElement.on("change", (event) => {
|
|
70
|
+
const { error, complete } = event;
|
|
71
|
+
|
|
72
|
+
if (error) {
|
|
73
|
+
setIsInvalid(true);
|
|
74
|
+
setErrorMessage(error.message);
|
|
75
|
+
} else {
|
|
76
|
+
setIsInvalid(false);
|
|
77
|
+
}
|
|
78
|
+
complete ? setIsComplete(true) : setIsComplete(false);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}, [cardElement]);
|
|
82
|
+
|
|
83
|
+
// User is responsible for handling outcome of payment.
|
|
84
|
+
const handleSubmit = async (
|
|
85
|
+
e: React.MouseEvent<HTMLFormElement, MouseEvent>
|
|
86
|
+
) => {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
if (!stripe || !elements) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (cardElement) {
|
|
93
|
+
setIsProcessing(true);
|
|
94
|
+
const decodedDuffelPaymentIntentClientToken = atob(
|
|
95
|
+
paymentIntentClientToken
|
|
96
|
+
);
|
|
97
|
+
const parsedDuffelPaymentIntentClientToken = JSON.parse(
|
|
98
|
+
decodedDuffelPaymentIntentClientToken
|
|
99
|
+
);
|
|
100
|
+
const { client_secret: clientSecret } =
|
|
101
|
+
parsedDuffelPaymentIntentClientToken;
|
|
102
|
+
|
|
103
|
+
const result = await stripe.confirmCardPayment(clientSecret, {
|
|
104
|
+
payment_method: {
|
|
105
|
+
card: cardElement,
|
|
106
|
+
metadata: {
|
|
107
|
+
duffel_components_version:
|
|
108
|
+
COMPONENT_VERSION || "failed-to-get-version",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
setIsProcessing(false);
|
|
114
|
+
if (result.error) {
|
|
115
|
+
const { error } = result;
|
|
116
|
+
onFailedPayment(error);
|
|
117
|
+
} else {
|
|
118
|
+
onSuccessfulPayment();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return paymentIntentClientToken ? (
|
|
124
|
+
<div className="card-payment__container">
|
|
125
|
+
<form onSubmit={handleSubmit}>
|
|
126
|
+
{isProcessing && (
|
|
127
|
+
<div
|
|
128
|
+
className="card-payment--in-progress"
|
|
129
|
+
aria-live="polite"
|
|
130
|
+
aria-busy="true"
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
<CardElement
|
|
134
|
+
className="card-details"
|
|
135
|
+
options={{
|
|
136
|
+
style: {
|
|
137
|
+
base: {
|
|
138
|
+
...CARD_ELEMENT_STYLE_BASE,
|
|
139
|
+
...(styles?.fontFamily && {
|
|
140
|
+
fontFamily: styles.fontFamily,
|
|
141
|
+
}),
|
|
142
|
+
},
|
|
143
|
+
invalid: { ...CARD_ELEMENT_STYLE_INVALID },
|
|
144
|
+
},
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
<div className="card-payment__container--invalid" role="alert">
|
|
148
|
+
{isInvalid && errorMessage}
|
|
149
|
+
</div>
|
|
150
|
+
<Button
|
|
151
|
+
className="card-payment__pay-button"
|
|
152
|
+
type="submit"
|
|
153
|
+
disabled={!isComplete || isProcessing}
|
|
154
|
+
aria-label="Pay"
|
|
155
|
+
>
|
|
156
|
+
{isProcessing ? "Processing..." : "Pay"}
|
|
157
|
+
</Button>
|
|
158
|
+
</form>
|
|
159
|
+
</div>
|
|
160
|
+
) : null;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const DuffelPayments: React.FC<DuffelPaymentsProps> = (props) => {
|
|
164
|
+
const [stripe, setStripe] = React.useState<Promise<any> | null>(null);
|
|
165
|
+
initializeLogger(props.debug || false);
|
|
166
|
+
|
|
167
|
+
const decodedDuffelPaymentIntentClientToken = atob(
|
|
168
|
+
props.paymentIntentClientToken
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
let parsedDuffelPaymentIntentClientToken;
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
parsedDuffelPaymentIntentClientToken = JSON.parse(
|
|
175
|
+
decodedDuffelPaymentIntentClientToken
|
|
176
|
+
);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw new Error("Invalid Duffel payment intent client token provided");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const { publishable_key: duffelPublishableKey } =
|
|
182
|
+
parsedDuffelPaymentIntentClientToken;
|
|
183
|
+
|
|
184
|
+
React.useEffect(() => {
|
|
185
|
+
if (!stripe && duffelPublishableKey) {
|
|
186
|
+
const stripe = loadStripe(duffelPublishableKey);
|
|
187
|
+
stripe && setStripe(stripe);
|
|
188
|
+
}
|
|
189
|
+
}, [stripe, duffelPublishableKey]);
|
|
190
|
+
|
|
191
|
+
const duffelComponentsStyle: React.CSSProperties = {
|
|
192
|
+
...(props.styles?.accentColor && {
|
|
193
|
+
"--ACCENT": props.styles.accentColor,
|
|
194
|
+
}),
|
|
195
|
+
...(props.styles?.fontFamily && {
|
|
196
|
+
"--FONT-FAMILY": props.styles.fontFamily,
|
|
197
|
+
}),
|
|
198
|
+
...(props.styles?.buttonCornerRadius && {
|
|
199
|
+
"--BUTTON-RADIUS": props.styles.buttonCornerRadius,
|
|
200
|
+
}),
|
|
201
|
+
// `as any` is needed here is needed because we want to set css variables
|
|
202
|
+
// that are not part of the css properties type
|
|
203
|
+
} as any;
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<>
|
|
207
|
+
<link rel="stylesheet" href={hrefToComponentStyles}></link>
|
|
208
|
+
|
|
209
|
+
<div className="duffel-components" style={duffelComponentsStyle}>
|
|
210
|
+
<ErrorBoundary>
|
|
211
|
+
<Elements stripe={stripe}>
|
|
212
|
+
<CardPaymentComponent {...props} />
|
|
213
|
+
</Elements>
|
|
214
|
+
</ErrorBoundary>
|
|
215
|
+
</div>
|
|
216
|
+
</>
|
|
217
|
+
);
|
|
218
|
+
};
|