@duffel/components 3.0.7-canary → 3.1.2--prototype

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.
Files changed (232) hide show
  1. package/.eslintrc.js +8 -0
  2. package/.github/CODEOWNERS +4 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  4. package/.github/renovate.json +1 -5
  5. package/.github/workflows/release.yml +3 -0
  6. package/.storybook/__snapshots__/Storyshots.test.js.snap +20384 -533
  7. package/.tool-versions +1 -1
  8. package/README.md +16 -2
  9. package/config/esbuild.base.config.js +6 -2
  10. package/config/esbuild.cdn.config.js +2 -1
  11. package/config/esbuild.dev.config.js +2 -1
  12. package/config/esbuild.react.config.js +1 -1
  13. package/data/airports.csv +9084 -0
  14. package/data/cities.csv +256 -0
  15. package/package.json +11 -1
  16. package/react-dist/index.js +51 -21
  17. package/scripts/generate-fixture.ts +13 -8
  18. package/scripts/setup-suggestion-data.ts +100 -0
  19. package/scripts/upload-to-cdn.sh +1 -1
  20. package/src/components/{Card.tsx → DuffelAncillaries/Card.tsx} +1 -1
  21. package/src/components/{Counter.tsx → DuffelAncillaries/Counter.tsx} +1 -1
  22. package/src/components/{DuffelAncillaries.tsx → DuffelAncillaries/DuffelAncillaries.tsx} +68 -64
  23. package/src/components/{DuffelAncillariesCustomElement.tsx → DuffelAncillaries/DuffelAncillariesCustomElement.tsx} +2 -2
  24. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionCard.tsx +10 -5
  25. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionController.tsx +2 -2
  26. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionModal.tsx +4 -4
  27. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionModalBody.tsx +3 -3
  28. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionModalBodyPassenger.tsx +4 -4
  29. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionModalFooter.tsx +23 -16
  30. package/src/components/{bags → DuffelAncillaries/bags}/BaggageSelectionModalHeader.tsx +24 -18
  31. package/src/components/{bags → DuffelAncillaries/bags}/IncludedBaggageBanner.tsx +1 -1
  32. package/src/components/{cancel_for_any_reason → DuffelAncillaries/cancel_for_any_reason}/CfarSelectionCard.tsx +4 -4
  33. package/src/components/{cancel_for_any_reason → DuffelAncillaries/cancel_for_any_reason}/CfarSelectionModal.tsx +3 -3
  34. package/src/components/{cancel_for_any_reason → DuffelAncillaries/cancel_for_any_reason}/CfarSelectionModalBody.tsx +3 -3
  35. package/src/components/{cancel_for_any_reason → DuffelAncillaries/cancel_for_any_reason}/CfarSelectionModalBodyListItem.tsx +1 -1
  36. package/src/components/{cancel_for_any_reason → DuffelAncillaries/cancel_for_any_reason}/CfarSelectionModalFooter.tsx +5 -5
  37. package/src/components/{seats → DuffelAncillaries/seats}/Amenity.tsx +2 -2
  38. package/src/components/{seats → DuffelAncillaries/seats}/DeckSelect.tsx +1 -1
  39. package/src/components/{seats → DuffelAncillaries/seats}/Element.tsx +2 -2
  40. package/src/components/{seats → DuffelAncillaries/seats}/ExitElement.tsx +1 -1
  41. package/src/components/{seats → DuffelAncillaries/seats}/Legend.tsx +2 -2
  42. package/src/components/{seats → DuffelAncillaries/seats}/Row.tsx +2 -2
  43. package/src/components/{seats → DuffelAncillaries/seats}/RowSection.tsx +5 -2
  44. package/src/components/{seats → DuffelAncillaries/seats}/SeatElement.tsx +3 -3
  45. package/src/components/{seats → DuffelAncillaries/seats}/SeatInfo.tsx +1 -1
  46. package/src/components/{seats → DuffelAncillaries/seats}/SeatMap.tsx +6 -2
  47. package/src/components/{seats → DuffelAncillaries/seats}/SeatMapUnavailable.tsx +1 -1
  48. package/src/components/{seats → DuffelAncillaries/seats}/SeatSelectionCard.tsx +5 -5
  49. package/src/components/{seats → DuffelAncillaries/seats}/SeatSelectionModal.tsx +5 -5
  50. package/src/components/{seats → DuffelAncillaries/seats}/SeatSelectionModalBody.tsx +1 -1
  51. package/src/components/{seats → DuffelAncillaries/seats}/SeatSelectionModalFooter.tsx +24 -17
  52. package/src/components/{seats → DuffelAncillaries/seats}/SeatSelectionModalHeader.tsx +30 -20
  53. package/src/components/{seats → DuffelAncillaries/seats}/SeatUnavailable.tsx +2 -2
  54. package/src/components/DuffelPayments/DuffelPayments.tsx +224 -0
  55. package/src/components/DuffelPayments/DuffelPaymentsCustomElement.tsx +130 -0
  56. package/src/components/PlacesLookup/PlacesLookup.tsx +123 -0
  57. package/src/components/ShowData/ShowData.tsx +38 -0
  58. package/src/components/ShowData/ShowDataCustomElement.tsx +85 -0
  59. package/src/components/{Button.tsx → shared/Button.tsx} +4 -3
  60. package/src/components/{ErrorBoundary.tsx → shared/ErrorBoundary.tsx} +2 -2
  61. package/src/components/{Icon.tsx → shared/Icon.tsx} +11 -11
  62. package/src/components/{IconButton.tsx → shared/IconButton.tsx} +1 -1
  63. package/src/components/{Modal.tsx → shared/Modal.tsx} +5 -1
  64. package/src/components/{NonIdealState.tsx → shared/NonIdealState.tsx} +1 -1
  65. package/src/custom-elements.ts +6 -1
  66. package/src/examples/client-side/index.html +1 -1
  67. package/src/examples/full-stack/index.html +1 -1
  68. package/src/examples/full-stack/server.mjs +1 -0
  69. package/src/examples/just-typescript/src/index.html +2 -2
  70. package/src/examples/just-typescript/src/index.ts +2 -1
  71. package/src/examples/payments-custom-element/README.md +17 -0
  72. package/src/examples/payments-custom-element/index.html +43 -0
  73. package/src/examples/payments-just-typescript/README.md +37 -0
  74. package/src/examples/payments-just-typescript/package.json +16 -0
  75. package/src/examples/payments-just-typescript/src/index.html +23 -0
  76. package/src/examples/payments-just-typescript/src/index.ts +18 -0
  77. package/src/examples/react-app/src/index.tsx +11 -6
  78. package/src/fixtures/offers/off_1.json +1 -10
  79. package/src/index.ts +3 -1
  80. package/src/lib/captureErrorInSentry.ts +2 -20
  81. package/src/lib/fetchFromDuffelAPI.ts +36 -6
  82. package/src/lib/formatDate.ts +3 -4
  83. package/src/lib/getBaggageServiceDescription.ts +1 -6
  84. package/src/lib/getPassengerName.ts +4 -0
  85. package/src/lib/getTotalAmountForServices.ts +1 -1
  86. package/src/lib/hasHighLuminance.ts +9 -0
  87. package/src/lib/logging.ts +52 -32
  88. package/src/lib/retrieveOffer.ts +13 -6
  89. package/src/lib/retrieveSeatMaps.ts +13 -8
  90. package/src/stories/BaggageSelectionModalHeader.stories.tsx +1 -1
  91. package/src/stories/Button.stories.tsx +33 -2
  92. package/src/stories/DuffelAncillaries.stories.tsx +42 -2
  93. package/src/stories/DuffelPayments.stories.tsx +34 -0
  94. package/src/stories/Icon.stories.tsx +3 -2
  95. package/src/stories/IconButton.stories.tsx +1 -1
  96. package/src/stories/PlacesLookup.stories.tsx +22 -0
  97. package/src/stories/ShowData.stories.tsx +16 -0
  98. package/src/styles/components/Button.css +11 -3
  99. package/src/styles/components/Card.css +3 -3
  100. package/src/styles/components/CfarSelectionModal.css +1 -1
  101. package/src/styles/components/DuffelPayments.css +42 -0
  102. package/src/styles/components/Legend.css +10 -6
  103. package/src/styles/components/LoadingState.css +8 -2
  104. package/src/styles/components/Modal.css +2 -1
  105. package/src/styles/components/PassengerSelect.css +8 -2
  106. package/src/styles/components/PlacesLookup.css +36 -0
  107. package/src/styles/components/Seat.css +9 -7
  108. package/src/styles/components/SeatInfo.css +1 -1
  109. package/src/styles/components/Tabs.css +5 -2
  110. package/src/styles/global.css +2 -0
  111. package/src/tests/components/DuffelAncillaries.test.tsx +1 -1
  112. package/src/tests/lib/createPriceFormatters.test.tsx +1 -1
  113. package/src/tests/lib/formatAvailableServices.test.tsx +1 -1
  114. package/src/tests/lib/formatSeatMaps.test.tsx +2 -2
  115. package/src/tests/lib/getCurrencyForServices.test.tsx +1 -1
  116. package/src/tests/lib/hasServiceOfSameMetadataTypeAlreadyBeenSelected.test.ts +1 -1
  117. package/src/tests/lib/logging.test.tsx +14 -14
  118. package/src/tests/lib/moneyStringFormatter.test.tsx +1 -1
  119. package/src/tests/lib/validateProps.test.tsx +1 -1
  120. package/src/types/DuffelAncillariesProps.ts +1 -1
  121. package/react-dist/components/AnimatedLoaderEllipsis.d.ts +0 -2
  122. package/react-dist/components/Button.d.ts +0 -23
  123. package/react-dist/components/Card.d.ts +0 -14
  124. package/react-dist/components/Counter.d.ts +0 -10
  125. package/react-dist/components/DuffelAncillaries.d.ts +0 -3
  126. package/react-dist/components/DuffelAncillariesCustomElement.d.ts +0 -13
  127. package/react-dist/components/ErrorBoundary.d.ts +0 -13
  128. package/react-dist/components/FetchOfferErrorState.d.ts +0 -5
  129. package/react-dist/components/Icon.d.ts +0 -44
  130. package/react-dist/components/IconButton.d.ts +0 -16
  131. package/react-dist/components/Modal.d.ts +0 -11
  132. package/react-dist/components/NonIdealState.d.ts +0 -4
  133. package/react-dist/components/Stamp.d.ts +0 -7
  134. package/react-dist/components/Tabs.d.ts +0 -16
  135. package/react-dist/components/bags/BaggageSelectionCard.d.ts +0 -11
  136. package/react-dist/components/bags/BaggageSelectionController.d.ts +0 -13
  137. package/react-dist/components/bags/BaggageSelectionModal.d.ts +0 -11
  138. package/react-dist/components/bags/BaggageSelectionModalBody.d.ts +0 -11
  139. package/react-dist/components/bags/BaggageSelectionModalBodyPassenger.d.ts +0 -13
  140. package/react-dist/components/bags/BaggageSelectionModalFooter.d.ts +0 -14
  141. package/react-dist/components/bags/BaggageSelectionModalHeader.d.ts +0 -9
  142. package/react-dist/components/bags/IncludedBaggageBanner.d.ts +0 -7
  143. package/react-dist/components/cancel_for_any_reason/CfarSelectionCard.d.ts +0 -10
  144. package/react-dist/components/cancel_for_any_reason/CfarSelectionModal.d.ts +0 -11
  145. package/react-dist/components/cancel_for_any_reason/CfarSelectionModalBody.d.ts +0 -7
  146. package/react-dist/components/cancel_for_any_reason/CfarSelectionModalBodyListItem.d.ts +0 -4
  147. package/react-dist/components/cancel_for_any_reason/CfarSelectionModalFooter.d.ts +0 -11
  148. package/react-dist/components/cancel_for_any_reason/CfarSelectionModalHeader.d.ts +0 -2
  149. package/react-dist/components/seats/Amenity.d.ts +0 -6
  150. package/react-dist/components/seats/DeckSelect.d.ts +0 -15
  151. package/react-dist/components/seats/Element.d.ts +0 -15
  152. package/react-dist/components/seats/EmptyElement.d.ts +0 -2
  153. package/react-dist/components/seats/ExitElement.d.ts +0 -6
  154. package/react-dist/components/seats/Legend.d.ts +0 -12
  155. package/react-dist/components/seats/Row.d.ts +0 -13
  156. package/react-dist/components/seats/RowSection.d.ts +0 -17
  157. package/react-dist/components/seats/SeatElement.d.ts +0 -13
  158. package/react-dist/components/seats/SeatInfo.d.ts +0 -7
  159. package/react-dist/components/seats/SeatMap.d.ts +0 -12
  160. package/react-dist/components/seats/SeatMapUnavailable.d.ts +0 -2
  161. package/react-dist/components/seats/SeatSelectionCard.d.ts +0 -13
  162. package/react-dist/components/seats/SeatSelectionModal.d.ts +0 -13
  163. package/react-dist/components/seats/SeatSelectionModalBody.d.ts +0 -4
  164. package/react-dist/components/seats/SeatSelectionModalFooter.d.ts +0 -16
  165. package/react-dist/components/seats/SeatSelectionModalHeader.d.ts +0 -10
  166. package/react-dist/components/seats/SeatUnavailable.d.ts +0 -5
  167. package/react-dist/custom-elements.d.ts +0 -5
  168. package/react-dist/custom-elements.js +0 -36
  169. package/react-dist/custom-elements.js.map +0 -7
  170. package/react-dist/index.d.ts +0 -6
  171. package/react-dist/index.js.map +0 -7
  172. package/react-dist/lib/captureErrorInSentry.d.ts +0 -1
  173. package/react-dist/lib/compileCreateOrderPayload.d.ts +0 -14
  174. package/react-dist/lib/createPriceFormatters.d.ts +0 -12
  175. package/react-dist/lib/fetchFromDuffelAPI.d.ts +0 -1
  176. package/react-dist/lib/fetchFromFixtures.d.ts +0 -4
  177. package/react-dist/lib/formatAvailableServices.d.ts +0 -12
  178. package/react-dist/lib/formatDate.d.ts +0 -2
  179. package/react-dist/lib/formatSeatMaps.d.ts +0 -4
  180. package/react-dist/lib/getBaggageServiceDescription.d.ts +0 -2
  181. package/react-dist/lib/getCabinsForSegmentAndDeck.d.ts +0 -2
  182. package/react-dist/lib/getCurrencyForSeatMaps.d.ts +0 -10
  183. package/react-dist/lib/getCurrencyForServices.d.ts +0 -11
  184. package/react-dist/lib/getFirstSeatElementMatchingCriteria.d.ts +0 -3
  185. package/react-dist/lib/getPassengerBySegmentList.d.ts +0 -6
  186. package/react-dist/lib/getPassengerInitials.d.ts +0 -1
  187. package/react-dist/lib/getPassengerMapById.d.ts +0 -3
  188. package/react-dist/lib/getPassengerName.d.ts +0 -3
  189. package/react-dist/lib/getRowNumber.d.ts +0 -2
  190. package/react-dist/lib/getSegmentList.d.ts +0 -2
  191. package/react-dist/lib/getServicePriceMapById.d.ts +0 -3
  192. package/react-dist/lib/getSymbols.d.ts +0 -2
  193. package/react-dist/lib/getTotalAmountForServices.d.ts +0 -6
  194. package/react-dist/lib/getTotalQuantity.d.ts +0 -2
  195. package/react-dist/lib/hasService.d.ts +0 -2
  196. package/react-dist/lib/hasServiceOfSameMetadataTypeAlreadyBeenSelected.d.ts +0 -3
  197. package/react-dist/lib/hasWings.d.ts +0 -2
  198. package/react-dist/lib/isBaggageService.d.ts +0 -2
  199. package/react-dist/lib/isCancelForAnyReasonService.d.ts +0 -2
  200. package/react-dist/lib/isFixtureOfferId.d.ts +0 -2
  201. package/react-dist/lib/isPayloadComplete.d.ts +0 -2
  202. package/react-dist/lib/isSeatElement.d.ts +0 -2
  203. package/react-dist/lib/logging.d.ts +0 -53
  204. package/react-dist/lib/moneyStringFormatter.d.ts +0 -8
  205. package/react-dist/lib/offerIsExpired.d.ts +0 -2
  206. package/react-dist/lib/retrieveOffer.d.ts +0 -2
  207. package/react-dist/lib/retrieveOfferFromDuffelAPI.d.ts +0 -1
  208. package/react-dist/lib/retrieveSeatMaps.d.ts +0 -2
  209. package/react-dist/lib/retrieveSeatMapsFromDuffelAPI.d.ts +0 -1
  210. package/react-dist/lib/setBodyScrollability.d.ts +0 -1
  211. package/react-dist/lib/validateProps.d.ts +0 -7
  212. package/react-dist/lib/withPlural.d.ts +0 -1
  213. package/react-dist/types/Aircraft.d.ts +0 -14
  214. package/react-dist/types/Airline.d.ts +0 -14
  215. package/react-dist/types/Airport.d.ts +0 -44
  216. package/react-dist/types/City.d.ts +0 -18
  217. package/react-dist/types/CreateOrderPayload.d.ts +0 -72
  218. package/react-dist/types/CurrencyConversion.d.ts +0 -10
  219. package/react-dist/types/DuffelAncillariesProps.d.ts +0 -70
  220. package/react-dist/types/Offer.d.ts +0 -711
  221. package/react-dist/types/Order.d.ts +0 -8
  222. package/react-dist/types/Place.d.ts +0 -8
  223. package/react-dist/types/SeatMap.d.ts +0 -190
  224. package/react-dist/types/index.d.ts +0 -11
  225. package/src/examples/just-typescript/yarn.lock +0 -154
  226. package/src/examples/react-app/yarn.lock +0 -219
  227. /package/src/components/{cancel_for_any_reason → DuffelAncillaries/cancel_for_any_reason}/CfarSelectionModalHeader.tsx +0 -0
  228. /package/src/components/{seats → DuffelAncillaries/seats}/EmptyElement.tsx +0 -0
  229. /package/src/components/{AnimatedLoaderEllipsis.tsx → shared/AnimatedLoaderEllipsis.tsx} +0 -0
  230. /package/src/components/{FetchOfferErrorState.tsx → shared/FetchOfferErrorState.tsx} +0 -0
  231. /package/src/components/{Stamp.tsx → shared/Stamp.tsx} +0 -0
  232. /package/src/components/{Tabs.tsx → shared/Tabs.tsx} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { withPlural } from "@lib/withPlural";
2
2
  import React from "react";
3
- import { OfferSliceSegmentPassengerBaggage } from "../../types/Offer";
3
+ import { OfferSliceSegmentPassengerBaggage } from "../../../types/Offer";
4
4
 
5
5
  interface IncludedBaggageBannerProps {
6
6
  includedBaggage: OfferSliceSegmentPassengerBaggage[];
@@ -1,5 +1,5 @@
1
- import { AnimatedLoaderEllipsis } from "@components/AnimatedLoaderEllipsis";
2
- import { Stamp } from "@components/Stamp";
1
+ import { AnimatedLoaderEllipsis } from "@components/shared/AnimatedLoaderEllipsis";
2
+ import { Stamp } from "@components/shared/Stamp";
3
3
  import { getCurrencyForServices } from "@lib/getCurrencyForServices";
4
4
  import { getTotalAmountForServices } from "@lib/getTotalAmountForServices";
5
5
  import { getTotalQuantity } from "@lib/getTotalQuantity";
@@ -7,8 +7,8 @@ import { hasService } from "@lib/hasService";
7
7
  import { isCancelForAnyReasonService } from "@lib/isCancelForAnyReasonService";
8
8
  import { moneyStringFormatter } from "@lib/moneyStringFormatter";
9
9
  import React from "react";
10
- import { CreateOrderPayloadServices } from "../../types/CreateOrderPayload";
11
- import { Offer } from "../../types/Offer";
10
+ import { CreateOrderPayloadServices } from "../../../types/CreateOrderPayload";
11
+ import { Offer } from "../../../types/Offer";
12
12
  import { Card } from "../Card";
13
13
  import { CfarSelectionModal } from "./CfarSelectionModal";
14
14
 
@@ -1,13 +1,13 @@
1
+ import { Modal } from "@components/shared/Modal";
1
2
  import React from "react";
2
3
  import {
3
4
  CreateOrderPayloadServiceInformationForCancelForAnyReason,
4
5
  CreateOrderPayloadServices,
5
- } from "../../types/CreateOrderPayload";
6
+ } from "../../../types/CreateOrderPayload";
6
7
  import {
7
8
  Offer,
8
9
  OfferAvailableServiceCancelForAnyReason,
9
- } from "../../types/Offer";
10
- import { Modal } from "../Modal";
10
+ } from "../../../types/Offer";
11
11
  import { CfarSelectionModalBody } from "./CfarSelectionModalBody";
12
12
  import { CfarSelectionModalFooter } from "./CfarSelectionModalFooter";
13
13
  import { CfarSelectionModalHeader } from "./CfarSelectionModalHeader";
@@ -1,11 +1,11 @@
1
- import { Icon } from "@components/Icon";
2
- import { ModalBody } from "@components/Modal";
1
+ import { Icon } from "@components/shared//Icon";
2
+ import { ModalBody } from "@components/shared/Modal";
3
3
  import { moneyStringFormatter } from "@lib/moneyStringFormatter";
4
4
  import React from "react";
5
5
  import {
6
6
  Offer,
7
7
  OfferAvailableServiceCancelForAnyReason,
8
- } from "../../types/Offer";
8
+ } from "../../../types/Offer";
9
9
  import { CfarSelectionModalBodyListItem } from "./CfarSelectionModalBodyListItem";
10
10
 
11
11
  export interface CfarSelectionModalBodyProps {
@@ -1,4 +1,4 @@
1
- import { Icon } from "@components/Icon";
1
+ import { Icon } from "@components/shared/Icon";
2
2
  import React, { ReactNode } from "react";
3
3
 
4
4
  export const CfarSelectionModalBodyListItem: React.FC<{
@@ -1,9 +1,9 @@
1
- import { Icon } from "@components/Icon";
1
+ import { Button } from "@components/shared/Button";
2
+ import { Icon } from "@components/shared/Icon";
2
3
  import { moneyStringFormatter } from "@lib/moneyStringFormatter";
3
4
  import React from "react";
4
- import { CreateOrderPayloadServices } from "../../types/CreateOrderPayload";
5
- import { OfferAvailableServiceCancelForAnyReason } from "../../types/Offer";
6
- import { Button } from "../Button";
5
+ import { CreateOrderPayloadServices } from "../../../types/CreateOrderPayload";
6
+ import { OfferAvailableServiceCancelForAnyReason } from "../../../types/Offer";
7
7
 
8
8
  export interface CfarSelectionModalFooterProps {
9
9
  service: OfferAvailableServiceCancelForAnyReason;
@@ -67,7 +67,7 @@ const ProtectedTripBanner: React.FC = () => (
67
67
  <Icon
68
68
  size={20}
69
69
  name="shield_with_moon"
70
- style={{ fill: "rgb(var(--ACCENT))" }}
70
+ style={{ fill: "var(--SECONDARY, rgb(var(--ACCENT)))" }}
71
71
  />
72
72
  Your trip is protected
73
73
  </div>
@@ -1,7 +1,7 @@
1
+ import { Icon, IconName } from "@components/shared/Icon";
1
2
  import classNames from "classnames";
2
3
  import * as React from "react";
3
- import { SeatMapCabinRowSectionElementAmenity } from "../../types/SeatMap";
4
- import { Icon, IconName } from "../Icon";
4
+ import { SeatMapCabinRowSectionElementAmenity } from "../../../types/SeatMap";
5
5
 
6
6
  const amenitiesWithoutWrapper = ["bassinet", "exit_row"];
7
7
 
@@ -1,4 +1,4 @@
1
- import { Tabs } from "@components/Tabs";
1
+ import { Tabs } from "@components/shared/Tabs";
2
2
  import * as React from "react";
3
3
 
4
4
  export interface DeckSelectProps {
@@ -1,7 +1,7 @@
1
1
  import { isSeatElement } from "@lib/isSeatElement";
2
2
  import * as React from "react";
3
- import { CreateOrderPayloadSeatService } from "../../types/CreateOrderPayload";
4
- import { SeatMapCabinRowSectionElement } from "../../types/SeatMap";
3
+ import { CreateOrderPayloadSeatService } from "../../../types/CreateOrderPayload";
4
+ import { SeatMapCabinRowSectionElement } from "../../../types/SeatMap";
5
5
  import { Amenity } from "./Amenity";
6
6
  import { EmptyElement } from "./EmptyElement";
7
7
  import { ExitElement } from "./ExitElement";
@@ -1,6 +1,6 @@
1
+ import { Icon } from "@components/shared/Icon";
1
2
  import classNames from "classnames";
2
3
  import * as React from "react";
3
- import { Icon } from "../Icon";
4
4
 
5
5
  interface ExitElementProps {
6
6
  isRight: boolean;
@@ -1,6 +1,6 @@
1
- import { Icon, IconName } from "@components/Icon";
1
+ import { Icon, IconName } from "@components/shared/Icon";
2
2
  import * as React from "react";
3
- import { SeatMapCabinRowSectionElementAmenity } from "../../types/SeatMap";
3
+ import { SeatMapCabinRowSectionElementAmenity } from "../../../types/SeatMap";
4
4
 
5
5
  export interface LegendProps {
6
6
  /**
@@ -1,7 +1,7 @@
1
1
  import { getRowNumber } from "@lib/getRowNumber";
2
2
  import * as React from "react";
3
- import { CreateOrderPayloadSeatService } from "../../types/CreateOrderPayload";
4
- import { SeatMapCabinRow } from "../../types/SeatMap";
3
+ import { CreateOrderPayloadSeatService } from "../../../types/CreateOrderPayload";
4
+ import { SeatMapCabinRow } from "../../../types/SeatMap";
5
5
  import { RowSection } from "./RowSection";
6
6
 
7
7
  export interface RowProps {
@@ -1,7 +1,10 @@
1
1
  import classNames from "classnames";
2
2
  import * as React from "react";
3
- import { CreateOrderPayloadSeatService } from "../../types/CreateOrderPayload";
4
- import { SeatMapCabinRow, SeatMapCabinRowSection } from "../../types/SeatMap";
3
+ import { CreateOrderPayloadSeatService } from "../../../types/CreateOrderPayload";
4
+ import {
5
+ SeatMapCabinRow,
6
+ SeatMapCabinRowSection,
7
+ } from "../../../types/SeatMap";
5
8
  import { Element } from "./Element";
6
9
  import { EmptyElement } from "./EmptyElement";
7
10
 
@@ -1,10 +1,10 @@
1
+ import { Icon } from "@components/shared/Icon";
1
2
  import { getPassengerInitials } from "@lib/getPassengerInitials";
2
3
  import { moneyStringFormatter } from "@lib/moneyStringFormatter";
3
4
  import classNames from "classnames";
4
5
  import * as React from "react";
5
- import { CreateOrderPayloadSeatService } from "../../types/CreateOrderPayload";
6
- import { SeatMapCabinRowSectionElementSeat } from "../../types/SeatMap";
7
- import { Icon } from "../Icon";
6
+ import { CreateOrderPayloadSeatService } from "../../../types/CreateOrderPayload";
7
+ import { SeatMapCabinRowSectionElementSeat } from "../../../types/SeatMap";
8
8
  import { SeatInfo } from "./SeatInfo";
9
9
  import { SeatUnavailable } from "./SeatUnavailable";
10
10
 
@@ -3,7 +3,7 @@ import * as React from "react";
3
3
  import {
4
4
  SeatMapCabinRowSectionAvailableService,
5
5
  SeatMapCabinRowSectionElementSeat,
6
- } from "../../types/SeatMap";
6
+ } from "../../../types/SeatMap";
7
7
 
8
8
  export interface SeatInfoProps {
9
9
  seat: SeatMapCabinRowSectionElementSeat | null;
@@ -3,8 +3,8 @@ import { getSymbols } from "@lib/getSymbols";
3
3
  import { hasWings } from "@lib/hasWings";
4
4
  import classNames from "classnames";
5
5
  import * as React from "react";
6
- import { CreateOrderPayloadSeatService } from "../../types/CreateOrderPayload";
7
- import { SeatMap as SeatMapType } from "../../types/SeatMap";
6
+ import { CreateOrderPayloadSeatService } from "../../../types/CreateOrderPayload";
7
+ import { SeatMap as SeatMapType } from "../../../types/SeatMap";
8
8
  import { DeckSelect } from "./DeckSelect";
9
9
  import { Legend } from "./Legend";
10
10
  import { Row } from "./Row";
@@ -29,6 +29,10 @@ export const SeatMap: React.FC<SeatMapProps> = ({
29
29
  }) => {
30
30
  const [selectedDeck, setSelectedDeck] = React.useState(0);
31
31
 
32
+ if (!seatMap || !seatMap.cabins || !seatMap.cabins.length) {
33
+ return <SeatMapUnavailable />;
34
+ }
35
+
32
36
  const cabins = getCabinsForSegmentAndDeck(selectedDeck, seatMap);
33
37
  const hasMultipleDecks = cabins.length !== seatMap.cabins.length;
34
38
  const anyHasWings = seatMap.cabins.some((cabin) => cabin.wings);
@@ -1,4 +1,4 @@
1
- import { NonIdealState } from "@components/NonIdealState";
1
+ import { NonIdealState } from "@components/shared/NonIdealState";
2
2
  import * as React from "react";
3
3
 
4
4
  export const SeatMapUnavailable: React.FC = () => (
@@ -1,3 +1,5 @@
1
+ import { AnimatedLoaderEllipsis } from "@components/shared/AnimatedLoaderEllipsis";
2
+ import { Stamp } from "@components/shared/Stamp";
1
3
  import { getCurrencyForSeatMaps } from "@lib/getCurrencyForSeatMaps";
2
4
  import { getTotalAmountForServices } from "@lib/getTotalAmountForServices";
3
5
  import { getTotalQuantity } from "@lib/getTotalQuantity";
@@ -8,12 +10,10 @@ import {
8
10
  CreateOrderPayload,
9
11
  CreateOrderPayloadSeatService,
10
12
  CreateOrderPayloadServices,
11
- } from "../../types/CreateOrderPayload";
12
- import { Offer } from "../../types/Offer";
13
- import { SeatMap } from "../../types/SeatMap";
14
- import { AnimatedLoaderEllipsis } from "../AnimatedLoaderEllipsis";
13
+ } from "../../../types/CreateOrderPayload";
14
+ import { Offer } from "../../../types/Offer";
15
+ import { SeatMap } from "../../../types/SeatMap";
15
16
  import { Card } from "../Card";
16
- import { Stamp } from "../Stamp";
17
17
  import { SeatSelectionModal } from "./SeatSelectionModal";
18
18
 
19
19
  export interface SeatSelectionCardProps {
@@ -1,3 +1,4 @@
1
+ import { Modal } from "@components/shared/Modal";
1
2
  import { getCurrencyForSeatMaps } from "@lib/getCurrencyForSeatMaps";
2
3
  import { getPassengerBySegmentList } from "@lib/getPassengerBySegmentList";
3
4
  import { getPassengerMapById } from "@lib/getPassengerMapById";
@@ -8,10 +9,9 @@ import React from "react";
8
9
  import {
9
10
  CreateOrderPayload,
10
11
  CreateOrderPayloadSeatService,
11
- } from "../../types/CreateOrderPayload";
12
- import { Offer } from "../../types/Offer";
13
- import { SeatMap } from "../../types/SeatMap";
14
- import { Modal } from "../Modal";
12
+ } from "../../../types/CreateOrderPayload";
13
+ import { Offer } from "../../../types/Offer";
14
+ import { SeatMap } from "../../../types/SeatMap";
15
15
  import { SeatSelectionModalBody } from "./SeatSelectionModalBody";
16
16
  import { SeatSelectionModalFooter } from "./SeatSelectionModalFooter";
17
17
  import { SeatSelectionModalHeader } from "./SeatSelectionModalHeader";
@@ -100,7 +100,7 @@ export const SeatSelectionModal: React.FC<SeatSelectionModalProps> = ({
100
100
  getCurrencyForSeatMaps(seatMaps) ?? offer.total_currency;
101
101
 
102
102
  return (
103
- <Modal isOpen={isOpen} onClose={() => onClose(selectedServicesState)}>
103
+ <Modal isOpen={isOpen} onClose={() => onClose(selectedServices)}>
104
104
  <SeatSelectionModalHeader
105
105
  segmentAndPassengerPermutationsCount={
106
106
  segmentAndPassengerPermutations.length
@@ -1,4 +1,4 @@
1
- import { ModalBody } from "@components/Modal";
1
+ import { ModalBody } from "@components/shared/Modal";
2
2
  import React from "react";
3
3
  import { SeatMap, SeatMapProps } from "./SeatMap";
4
4
 
@@ -1,12 +1,12 @@
1
+ import { Button } from "@components/shared/Button";
1
2
  import { ServicePriceMapById } from "@lib/getServicePriceMapById";
2
3
  import { getTotalAmountForServicesWithPriceMap } from "@lib/getTotalAmountForServices";
3
4
  import { getTotalQuantity } from "@lib/getTotalQuantity";
4
5
  import { moneyStringFormatter } from "@lib/moneyStringFormatter";
5
6
  import { withPlural } from "@lib/withPlural";
6
7
  import React from "react";
7
- import { CreateOrderPayloadServices } from "../../types/CreateOrderPayload";
8
- import { SeatMap } from "../../types/SeatMap";
9
- import { Button } from "../Button";
8
+ import { CreateOrderPayloadServices } from "../../../types/CreateOrderPayload";
9
+ import { SeatMap } from "../../../types/SeatMap";
10
10
 
11
11
  export interface SeatSelectionModalFooterProps {
12
12
  currency: string;
@@ -42,6 +42,7 @@ export const SeatSelectionModalFooter: React.FC<
42
42
  seatMaps
43
43
  );
44
44
  const totalAmountLabel = moneyStringFormatter(currency)(totalAmount);
45
+ const isOneWay = isFirstSegment && isLastSegment;
45
46
 
46
47
  return (
47
48
  <div style={{ padding: "16px 24px 24px" }}>
@@ -51,21 +52,27 @@ export const SeatSelectionModalFooter: React.FC<
51
52
  </div>
52
53
 
53
54
  <div
54
- style={{
55
- marginTop: "16px",
56
- display: "grid",
57
- columnGap: "12px",
58
- gridTemplateColumns: "repeat(2, 1fr)",
59
- }}
55
+ style={
56
+ isOneWay
57
+ ? { marginTop: "16px", display: "grid" }
58
+ : {
59
+ marginTop: "16px",
60
+ display: "grid",
61
+ columnGap: "12px",
62
+ gridTemplateColumns: "repeat(2, 1fr)",
63
+ }
64
+ }
60
65
  >
61
- <Button
62
- size={48}
63
- disabled={isFirstSegment}
64
- variant="outlined"
65
- onClick={() => onPreviousSegmentButtonClicked()}
66
- >
67
- Back
68
- </Button>
66
+ {!isOneWay && (
67
+ <Button
68
+ size={48}
69
+ disabled={isFirstSegment}
70
+ variant="outlined"
71
+ onClick={() => onPreviousSegmentButtonClicked()}
72
+ >
73
+ Back
74
+ </Button>
75
+ )}
69
76
 
70
77
  <Button
71
78
  size={48}
@@ -1,6 +1,6 @@
1
1
  import { formatDateString } from "@lib/formatDate";
2
2
  import React from "react";
3
- import { OfferSliceSegment } from "../../types/Offer";
3
+ import { OfferSliceSegment } from "../../../types/Offer";
4
4
 
5
5
  export interface SeatSelectionModalHeaderProps {
6
6
  segmentAndPassengerPermutationsCount: number;
@@ -21,23 +21,32 @@ export const SeatSelectionModalHeader: React.FC<
21
21
  setCurrentSegmentAndPassengerPermutationsIndex,
22
22
  }) => (
23
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" }}>
24
+ {segmentAndPassengerPermutationsCount > 1 && (
25
+ <div style={{ display: "flex", columnGap: "4px" }}>
26
+ {Array(segmentAndPassengerPermutationsCount)
27
+ .fill(0)
28
+ .map((_, index) =>
29
+ index === currentSegmentAndPassengerPermutationsIndex ? (
30
+ <ActiveSegment key={`segment_${index}`} />
31
+ ) : (
32
+ <InactiveSegment
33
+ key={`segment_${index}`}
34
+ onClick={() =>
35
+ setCurrentSegmentAndPassengerPermutationsIndex(index)
36
+ }
37
+ />
38
+ )
39
+ )}
40
+ </div>
41
+ )}
42
+ <h2
43
+ className="h3--semibold"
44
+ style={
45
+ segmentAndPassengerPermutationsCount > 1
46
+ ? { marginBlock: "12px 0px" }
47
+ : {}
48
+ }
49
+ >
41
50
  Flight to {currentSegment.destination.iata_code}
42
51
  <span
43
52
  className="p2--regular"
@@ -70,7 +79,8 @@ const InactiveSegment: React.FC<{
70
79
  height: "4px",
71
80
  padding: "0",
72
81
  borderRadius: "4px",
73
- backgroundColor: "rgba(var(--ACCENT), var(--ACCENT-LIGHT-200))",
82
+ backgroundColor:
83
+ "var(--TERTIARY, rgba(var(--ACCENT), var(--ACCENT-LIGHT-200)))",
74
84
  transition: "background-color 0.3s var(--TRANSITION-CUBIC-BEZIER)",
75
85
  ...style,
76
86
  }}
@@ -81,7 +91,7 @@ const ActiveSegment = () => (
81
91
  <InactiveSegment
82
92
  onClick={undefined}
83
93
  style={{
84
- backgroundColor: "rgb(var(--ACCENT))",
94
+ backgroundColor: "var(--SECONDARY, rgb(var(--ACCENT)))",
85
95
  }}
86
96
  />
87
97
  );
@@ -1,6 +1,6 @@
1
+ import { Icon } from "@components/shared/Icon";
1
2
  import * as React from "react";
2
- import { SeatMapCabinRowSectionElementSeat } from "../../types/SeatMap";
3
- import { Icon } from "../Icon";
3
+ import { SeatMapCabinRowSectionElementSeat } from "../../../types/SeatMap";
4
4
 
5
5
  export const SeatUnavailable: React.FC<{
6
6
  seat: SeatMapCabinRowSectionElementSeat;
@@ -0,0 +1,224 @@
1
+ import { ErrorBoundary } from "@components/shared/ErrorBoundary";
2
+ import { hasHighLuminance } from "@lib/hasHighLuminance";
3
+ import { initializeLogger } from "@lib/logging";
4
+ import {
5
+ CardElement,
6
+ Elements,
7
+ useElements,
8
+ useStripe,
9
+ } from "@stripe/react-stripe-js";
10
+ import { StripeCardElement, StripeError, loadStripe } from "@stripe/stripe-js";
11
+ import * as React from "react";
12
+ import { CustomStyles } from "../../types";
13
+ import { Button } from "../shared/Button";
14
+
15
+ const COMPONENT_CDN = process.env.COMPONENT_CDN || "";
16
+ const hrefToComponentStyles = `${COMPONENT_CDN}/global.css`;
17
+
18
+ const STRIPE_CARD_ELEMENT = "card";
19
+ const COMPONENT_VERSION = process.env.COMPONENT_VERSION;
20
+
21
+ export interface DuffelPaymentsProps {
22
+ paymentIntentClientToken: string;
23
+ onSuccessfulPayment: () => void;
24
+ onFailedPayment: (error: StripeError) => void;
25
+
26
+ styles?: CustomStyles;
27
+ debug?: boolean;
28
+ }
29
+
30
+ const CARD_ELEMENT_STYLE_BASE = {
31
+ color: "var(--GREY-900)",
32
+ fontFamily:
33
+ '"-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "sans-serif"',
34
+ fontSmoothing: "antialiased",
35
+ fontSize: "16px",
36
+ "::placeholder": {
37
+ color: "#ababb4",
38
+ },
39
+ };
40
+
41
+ const CARD_ELEMENT_STYLE_INVALID = {
42
+ color: "#ef4444",
43
+ iconColor: "#ef4444",
44
+ };
45
+
46
+ const CardPaymentComponent: React.FC<DuffelPaymentsProps> = ({
47
+ styles,
48
+ paymentIntentClientToken,
49
+ onSuccessfulPayment,
50
+ onFailedPayment,
51
+ }) => {
52
+ const [cardElement, setCardElement] =
53
+ React.useState<StripeCardElement | null>(null);
54
+ const [isComplete, setIsComplete] = React.useState<boolean>(false);
55
+ const [isInvalid, setIsInvalid] = React.useState<boolean>(false);
56
+ const [isProcessing, setIsProcessing] = React.useState<boolean>(false);
57
+ const [errorMessage, setErrorMessage] = React.useState<string>("");
58
+ const stripe = useStripe();
59
+ const elements = useElements();
60
+
61
+ React.useEffect(() => {
62
+ if (elements && !cardElement) {
63
+ const maybeCard = elements?.getElement(STRIPE_CARD_ELEMENT);
64
+ maybeCard && setCardElement(maybeCard as StripeCardElement);
65
+ }
66
+ }, [elements, cardElement]);
67
+
68
+ React.useEffect(() => {
69
+ if (cardElement) {
70
+ cardElement.on("change", (event) => {
71
+ const { error, complete } = event;
72
+
73
+ if (error) {
74
+ setIsInvalid(true);
75
+ setErrorMessage(error.message);
76
+ } else {
77
+ setIsInvalid(false);
78
+ }
79
+ complete ? setIsComplete(true) : setIsComplete(false);
80
+ });
81
+ }
82
+ }, [cardElement]);
83
+
84
+ // User is responsible for handling outcome of payment.
85
+ const handleSubmit = async (
86
+ e: React.MouseEvent<HTMLFormElement, MouseEvent>
87
+ ) => {
88
+ e.preventDefault();
89
+ if (!stripe || !elements) {
90
+ return;
91
+ }
92
+
93
+ if (cardElement) {
94
+ setIsProcessing(true);
95
+ const decodedDuffelPaymentIntentClientToken = atob(
96
+ paymentIntentClientToken
97
+ );
98
+ const parsedDuffelPaymentIntentClientToken = JSON.parse(
99
+ decodedDuffelPaymentIntentClientToken
100
+ );
101
+ const { client_secret: clientSecret } =
102
+ parsedDuffelPaymentIntentClientToken;
103
+
104
+ const result = await stripe.confirmCardPayment(clientSecret, {
105
+ payment_method: {
106
+ card: cardElement,
107
+ metadata: {
108
+ duffel_components_version:
109
+ COMPONENT_VERSION || "failed-to-get-version",
110
+ },
111
+ },
112
+ });
113
+
114
+ setIsProcessing(false);
115
+ if (result.error) {
116
+ const { error } = result;
117
+ onFailedPayment(error);
118
+ } else {
119
+ onSuccessfulPayment();
120
+ }
121
+ }
122
+ };
123
+
124
+ return paymentIntentClientToken ? (
125
+ <div className="card-payment__container">
126
+ <form onSubmit={handleSubmit}>
127
+ {isProcessing && (
128
+ <div
129
+ className="card-payment--in-progress"
130
+ aria-live="polite"
131
+ aria-busy="true"
132
+ />
133
+ )}
134
+ <CardElement
135
+ className="card-details"
136
+ options={{
137
+ style: {
138
+ base: {
139
+ ...CARD_ELEMENT_STYLE_BASE,
140
+ ...(styles?.fontFamily && {
141
+ fontFamily: styles.fontFamily,
142
+ }),
143
+ },
144
+ invalid: { ...CARD_ELEMENT_STYLE_INVALID },
145
+ },
146
+ }}
147
+ />
148
+ <div className="card-payment__container--invalid" role="alert">
149
+ {isInvalid && errorMessage}
150
+ </div>
151
+ <Button
152
+ className="card-payment__pay-button"
153
+ type="submit"
154
+ disabled={!isComplete || isProcessing}
155
+ aria-label="Pay"
156
+ >
157
+ {isProcessing ? "Processing..." : "Pay"}
158
+ </Button>
159
+ </form>
160
+ </div>
161
+ ) : null;
162
+ };
163
+
164
+ export const DuffelPayments: React.FC<DuffelPaymentsProps> = (props) => {
165
+ const [stripe, setStripe] = React.useState<Promise<any> | null>(null);
166
+ initializeLogger(props.debug || false);
167
+
168
+ const decodedDuffelPaymentIntentClientToken = atob(
169
+ props.paymentIntentClientToken
170
+ );
171
+
172
+ let parsedDuffelPaymentIntentClientToken;
173
+
174
+ try {
175
+ parsedDuffelPaymentIntentClientToken = JSON.parse(
176
+ decodedDuffelPaymentIntentClientToken
177
+ );
178
+ } catch (error) {
179
+ throw new Error("Invalid Duffel payment intent client token provided");
180
+ }
181
+
182
+ const { publishable_key: duffelPublishableKey } =
183
+ parsedDuffelPaymentIntentClientToken;
184
+
185
+ React.useEffect(() => {
186
+ if (!stripe && duffelPublishableKey) {
187
+ const stripe = loadStripe(duffelPublishableKey);
188
+ stripe && setStripe(stripe);
189
+ }
190
+ }, [stripe, duffelPublishableKey]);
191
+
192
+ const duffelComponentsStyle: React.CSSProperties = {
193
+ ...(props.styles?.accentColor && {
194
+ "--ACCENT": props.styles.accentColor,
195
+ }),
196
+ ...(props.styles?.accentColor &&
197
+ hasHighLuminance(props.styles.accentColor) && {
198
+ "--SECONDARY": "black",
199
+ "--TERTIARY": "grey",
200
+ }),
201
+ ...(props.styles?.fontFamily && {
202
+ "--FONT-FAMILY": props.styles.fontFamily,
203
+ }),
204
+ ...(props.styles?.buttonCornerRadius && {
205
+ "--BUTTON-RADIUS": props.styles.buttonCornerRadius,
206
+ }),
207
+ // `as any` is needed here is needed because we want to set css variables
208
+ // that are not part of the css properties type
209
+ } as any;
210
+
211
+ return (
212
+ <>
213
+ <link rel="stylesheet" href={hrefToComponentStyles}></link>
214
+
215
+ <div className="duffel-components" style={duffelComponentsStyle}>
216
+ <ErrorBoundary>
217
+ <Elements stripe={stripe}>
218
+ <CardPaymentComponent {...props} />
219
+ </Elements>
220
+ </ErrorBoundary>
221
+ </div>
222
+ </>
223
+ );
224
+ };