@qite/tide-booking-component 1.2.3 → 1.2.5

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 (137) hide show
  1. package/.vs/ProjectSettings.json +3 -3
  2. package/.vs/VSWorkspaceState.json +5 -5
  3. package/README.md +8 -8
  4. package/build/build-cjs/booking-product/components/footer.d.ts +1 -0
  5. package/build/build-cjs/booking-product/components/rooms.d.ts +2 -0
  6. package/build/build-cjs/booking-wizard/features/booking/selectors.d.ts +1 -1
  7. package/build/build-cjs/booking-wizard/features/flight-options/flight-option-flight.d.ts +1 -1
  8. package/build/build-cjs/booking-wizard/features/flight-options/flight-option.d.ts +1 -1
  9. package/build/build-cjs/booking-wizard/types.d.ts +5 -0
  10. package/build/build-cjs/index.js +1453 -735
  11. package/build/build-cjs/shared/utils/localization-util.d.ts +4 -0
  12. package/build/build-esm/booking-product/components/footer.d.ts +1 -0
  13. package/build/build-esm/booking-product/components/rooms.d.ts +2 -0
  14. package/build/build-esm/booking-wizard/features/booking/selectors.d.ts +1 -1
  15. package/build/build-esm/booking-wizard/features/flight-options/flight-option-flight.d.ts +1 -1
  16. package/build/build-esm/booking-wizard/features/flight-options/flight-option.d.ts +1 -1
  17. package/build/build-esm/booking-wizard/types.d.ts +5 -0
  18. package/build/build-esm/index.js +1455 -737
  19. package/build/build-esm/shared/utils/localization-util.d.ts +4 -0
  20. package/package.json +75 -77
  21. package/src/booking-product/components/age-select.tsx +35 -41
  22. package/src/booking-product/components/amount-input.tsx +78 -64
  23. package/src/booking-product/components/date-range-picker/calendar-day.tsx +58 -54
  24. package/src/booking-product/components/date-range-picker/calendar.tsx +178 -176
  25. package/src/booking-product/components/date-range-picker/index.tsx +196 -181
  26. package/src/booking-product/components/dates.tsx +136 -132
  27. package/src/booking-product/components/footer.tsx +69 -64
  28. package/src/booking-product/components/header.tsx +79 -68
  29. package/src/booking-product/components/icon.tsx +251 -208
  30. package/src/booking-product/components/product.tsx +314 -277
  31. package/src/booking-product/components/rooms.tsx +195 -177
  32. package/src/booking-product/index.tsx +30 -30
  33. package/src/booking-product/settings-context.ts +14 -14
  34. package/src/booking-product/types.ts +28 -28
  35. package/src/booking-product/utils/api.ts +25 -25
  36. package/src/booking-product/utils/price.ts +29 -27
  37. package/src/booking-wizard/api-settings-slice.ts +24 -24
  38. package/src/booking-wizard/components/icon.tsx +508 -60
  39. package/src/booking-wizard/components/message.tsx +34 -34
  40. package/src/booking-wizard/components/multi-range-filter.tsx +113 -113
  41. package/src/booking-wizard/components/product-card.tsx +37 -37
  42. package/src/booking-wizard/components/step-indicator.tsx +51 -51
  43. package/src/booking-wizard/components/step-route.tsx +27 -27
  44. package/src/booking-wizard/declarations.d.ts +4 -4
  45. package/src/booking-wizard/features/booking/api.ts +49 -45
  46. package/src/booking-wizard/features/booking/booking-self-contained.tsx +384 -357
  47. package/src/booking-wizard/features/booking/booking-slice.ts +662 -603
  48. package/src/booking-wizard/features/booking/booking.tsx +356 -349
  49. package/src/booking-wizard/features/booking/constants.ts +16 -16
  50. package/src/booking-wizard/features/booking/selectors.ts +441 -408
  51. package/src/booking-wizard/features/confirmation/confirmation.tsx +97 -94
  52. package/src/booking-wizard/features/error/error.tsx +78 -75
  53. package/src/booking-wizard/features/flight-options/flight-filter.tsx +432 -344
  54. package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +385 -351
  55. package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +229 -214
  56. package/src/booking-wizard/features/flight-options/flight-option.tsx +81 -66
  57. package/src/booking-wizard/features/flight-options/flight-utils.ts +516 -401
  58. package/src/booking-wizard/features/flight-options/index.tsx +196 -177
  59. package/src/booking-wizard/features/price-details/price-details-api.ts +24 -24
  60. package/src/booking-wizard/features/price-details/price-details-slice.ts +178 -171
  61. package/src/booking-wizard/features/price-details/util.ts +155 -155
  62. package/src/booking-wizard/features/product-options/no-options.tsx +21 -21
  63. package/src/booking-wizard/features/product-options/none-option.tsx +120 -120
  64. package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +64 -66
  65. package/src/booking-wizard/features/product-options/option-booking-group.tsx +216 -210
  66. package/src/booking-wizard/features/product-options/option-item.tsx +317 -318
  67. package/src/booking-wizard/features/product-options/option-pax-card.tsx +201 -117
  68. package/src/booking-wizard/features/product-options/option-pax-group.tsx +175 -169
  69. package/src/booking-wizard/features/product-options/option-room.tsx +321 -314
  70. package/src/booking-wizard/features/product-options/option-unit-group.tsx +198 -192
  71. package/src/booking-wizard/features/product-options/option-units-card.tsx +185 -102
  72. package/src/booking-wizard/features/product-options/options-form.tsx +459 -437
  73. package/src/booking-wizard/features/room-options/index.tsx +187 -172
  74. package/src/booking-wizard/features/room-options/room-utils.ts +190 -143
  75. package/src/booking-wizard/features/room-options/room.tsx +160 -124
  76. package/src/booking-wizard/features/room-options/traveler-rooms.tsx +75 -63
  77. package/src/booking-wizard/features/sidebar/index.tsx +76 -76
  78. package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +68 -68
  79. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  80. package/src/booking-wizard/features/sidebar/sidebar.tsx +364 -346
  81. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  82. package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +25 -25
  83. package/src/booking-wizard/features/summary/summary-flight.tsx +39 -39
  84. package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +69 -57
  85. package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +63 -51
  86. package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +66 -54
  87. package/src/booking-wizard/features/summary/summary-slice.ts +28 -28
  88. package/src/booking-wizard/features/summary/summary.tsx +674 -641
  89. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  90. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +754 -755
  91. package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +101 -101
  92. package/src/booking-wizard/features/travelers-form/validate-form.ts +245 -245
  93. package/src/booking-wizard/index.tsx +36 -36
  94. package/src/booking-wizard/settings-context.ts +60 -60
  95. package/src/booking-wizard/store.ts +31 -31
  96. package/src/booking-wizard/types.ts +276 -271
  97. package/src/index.ts +4 -5
  98. package/src/shared/components/loader.tsx +16 -16
  99. package/src/shared/translations/en-GB.json +232 -0
  100. package/src/shared/translations/fr-BE.json +233 -233
  101. package/src/shared/translations/nl-BE.json +232 -232
  102. package/src/shared/types.ts +4 -4
  103. package/src/shared/utils/localization-util.ts +62 -56
  104. package/src/shared/utils/query-string-util.ts +119 -116
  105. package/src/shared/utils/tide-api-utils.ts +36 -36
  106. package/styles/booking-product-variables.scss +394 -288
  107. package/styles/booking-product.scss +446 -440
  108. package/styles/booking-wizard-variables.scss +871 -0
  109. package/styles/booking-wizard.scss +59 -4
  110. package/styles/components/_animations.scss +39 -39
  111. package/styles/components/_base.scss +107 -106
  112. package/styles/components/_booking.scss +879 -0
  113. package/styles/components/_button.scss +238 -185
  114. package/styles/components/_checkbox.scss +219 -0
  115. package/styles/components/_cta.scss +208 -67
  116. package/styles/components/_date-list.scss +41 -0
  117. package/styles/components/_date-range-picker.scss +225 -224
  118. package/styles/components/_decrement-increment.scss +35 -37
  119. package/styles/components/_dropdown.scss +72 -74
  120. package/styles/components/_flight-option.scss +1429 -0
  121. package/styles/components/_form.scss +1583 -136
  122. package/styles/components/_info-message.scss +71 -0
  123. package/styles/components/_input.scss +25 -0
  124. package/styles/components/_list.scss +187 -0
  125. package/styles/components/_loader.scss +72 -71
  126. package/styles/components/_mixins.scss +550 -518
  127. package/styles/components/_placeholders.scss +166 -166
  128. package/styles/components/_pricing-summary.scss +155 -0
  129. package/styles/components/_qsm.scss +17 -20
  130. package/styles/components/_radiobutton.scss +170 -0
  131. package/styles/components/_select-wrapper.scss +80 -0
  132. package/styles/components/_spinner.scss +29 -0
  133. package/styles/components/_step-indicators.scss +168 -0
  134. package/styles/components/_table.scss +81 -0
  135. package/styles/components/_tree.scss +530 -0
  136. package/styles/components/_typeahead.scss +281 -0
  137. package/styles/components/_variables.scss +89 -89
@@ -1,357 +1,384 @@
1
- import React, { useContext } from "react";
2
- import { useSelector } from "react-redux";
3
- import {
4
- getDateFromParams,
5
- getFlightsFromParams,
6
- getNumberFromParams,
7
- getNumbersFromParams,
8
- getRoomsFromParams,
9
- getStringFromParams,
10
- } from "../../../shared/utils/query-string-util";
11
- import {
12
- fetchPackage,
13
- setAccommodationViewId,
14
- setAgentAdressId,
15
- setBookingAttributes,
16
- setBookingNumber,
17
- setBookingOptions,
18
- setBookingType,
19
- setCalculateDeposit,
20
- setCurrentStep,
21
- setGeneratePaymentUrl,
22
- setLanguageCode,
23
- setOfficeId,
24
- setProductAttributes,
25
- setSkipPayment,
26
- setTagIds,
27
- setTranslations,
28
- } from "./booking-slice";
29
-
30
- import { isNil } from "lodash";
31
- import { useEffect } from "react";
32
- import Loader from "../../../shared/components/loader";
33
- import { setApiKey, setApiUrl } from "../../api-settings-slice";
34
- import StepRoute from "../../components/step-route";
35
- import SettingsContext from "../../settings-context";
36
- import { useAppDispatch } from "../../store";
37
- import Confirmation from "../confirmation/confirmation";
38
- import Error from "../error/error";
39
- import FlightOptionsForm from "../flight-options";
40
- import OptionsForm from "../product-options/options-form";
41
- import RoomOptionsForm from "../room-options";
42
- import Sidebar from "../sidebar";
43
- import Summary from "../summary/summary";
44
- import TravelersForm from "../travelers-form/travelers-form";
45
- import {
46
- CONFIRMATION_STEP,
47
- ERROR_STEP,
48
- FLIGHT_OPTIONS_FORM_STEP,
49
- OPTIONS_FORM_STEP,
50
- ROOM_OPTIONS_FORM_STEP,
51
- SUMMARY_STEP,
52
- TRAVELERS_FORM_STEP,
53
- } from "./constants";
54
- import {
55
- selectApiSettings,
56
- selectBookingAttributes,
57
- selectBookingNumber,
58
- selectBookingRooms,
59
- selectCurrentStep,
60
- selectIsUnavailable,
61
- selectPackageDetails,
62
- selectProductAttributes,
63
- selectTranslations,
64
- } from "./selectors";
65
-
66
- interface BookingProps {
67
- productCode: string;
68
- productName: string;
69
- thumbnailUrl?: string;
70
- }
71
-
72
- const BookingSelfContained: React.FC<BookingProps> = ({
73
- productCode,
74
- productName,
75
- thumbnailUrl,
76
- }) => {
77
- const {
78
- officeId,
79
- bookingOptions,
80
- showSidebarDeposit,
81
- includeFlights,
82
- skipPaymentWithAgent,
83
- generatePaymentUrl,
84
- tagIds,
85
- agentAdressId,
86
- language,
87
- apiUrl,
88
- apiKey,
89
- translationFiles,
90
- roomOptions,
91
- flightOptions,
92
- accommodationViewId,
93
- isOffer
94
- } = useContext(SettingsContext);
95
-
96
- const dispatch = useAppDispatch();
97
-
98
- const productAttributes = useSelector(selectProductAttributes);
99
- const bookingAttributes = useSelector(selectBookingAttributes);
100
- const rooms = useSelector(selectBookingRooms);
101
- const bookingNumber = useSelector(selectBookingNumber);
102
- const packageDetails = useSelector(selectPackageDetails);
103
- const isUnvailable = useSelector(selectIsUnavailable);
104
- const currentStep = useSelector(selectCurrentStep);
105
- const apiSettings = useSelector(selectApiSettings);
106
- const translations = useSelector(selectTranslations);
107
-
108
- useEffect(() => {
109
- dispatch(setSkipPayment(skipPaymentWithAgent ?? false));
110
- dispatch(setGeneratePaymentUrl(generatePaymentUrl ?? false));
111
- }, [skipPaymentWithAgent, generatePaymentUrl]);
112
-
113
- useEffect(() => {
114
- if (!isNil(apiUrl) && !isNil(apiKey)) {
115
- dispatch(setApiUrl(apiUrl));
116
- dispatch(setApiKey(apiKey));
117
- }
118
- }, [apiUrl, apiKey]);
119
-
120
- useEffect(() => {
121
- const params = new URLSearchParams(location.search);
122
- const startDate = getDateFromParams(params, "startDate");
123
- const endDate = getDateFromParams(params, "endDate");
124
- const catalog = getNumberFromParams(params, "catalog");
125
- const rooms = getRoomsFromParams(params, "rooms");
126
- const flight = getFlightsFromParams(params, "flight");
127
- const allotmentName = getStringFromParams(params, "allotmentName");
128
- const allotmentIds = getNumbersFromParams(params, "allotmentId");
129
- const tourCode = getStringFromParams(params, "tourCode");
130
- const bookingNumber = params.get("bookingNr") ?? undefined;
131
-
132
- if (typeof window !== "undefined") {
133
- window.scrollTo(0, 0);
134
- }
135
-
136
- if (!isNil(bookingNumber)) {
137
- dispatch(setBookingNumber(bookingNumber));
138
- dispatch(setCurrentStep(CONFIRMATION_STEP));
139
- } else if (!flightOptions.isHidden) {
140
- dispatch(setCurrentStep(FLIGHT_OPTIONS_FORM_STEP));
141
- } else if (!roomOptions.isHidden) {
142
- dispatch(setCurrentStep(ROOM_OPTIONS_FORM_STEP));
143
- }
144
-
145
- if (
146
- !isNil(startDate) &&
147
- !isNil(endDate) &&
148
- !isNil(catalog) &&
149
- !isNil(rooms)
150
- ) {
151
- dispatch(
152
- setBookingAttributes({
153
- startDate,
154
- endDate,
155
- catalog,
156
- rooms,
157
- flight,
158
- includeFlights,
159
- allotmentName,
160
- allotmentIds,
161
- tourCode,
162
- })
163
- );
164
- } else {
165
- console.error(
166
- "Failure when setting booking attributes",
167
- startDate,
168
- endDate,
169
- catalog,
170
- rooms
171
- );
172
- }
173
- }, [location.search, setBookingAttributes, setBookingNumber, includeFlights]);
174
-
175
- useEffect(() => {
176
- if (!isNil(productCode) && !isNil(productName)) {
177
- dispatch(
178
- setProductAttributes({
179
- productCode,
180
- productName,
181
- })
182
- );
183
- } else {
184
- console.error(
185
- "Failure when setting product attributes",
186
- productCode,
187
- productName
188
- );
189
- }
190
- }, [productCode, productName, setProductAttributes]);
191
-
192
- const getTranslations = async () => {
193
- const translations = translationFiles?.map(x => fetch(x.path).then(y => y.json()).then(z => ({ language: x.language, value: z })));
194
- return translations && await Promise.all(translations);
195
- };
196
-
197
- useEffect(() => {
198
- const loadTranslations = async () => {
199
- const translations = await getTranslations();
200
- dispatch(setTranslations(translations)); // Now dispatch the resolved value
201
- };
202
-
203
- loadTranslations();
204
-
205
- dispatch(setOfficeId(officeId));
206
- dispatch(setLanguageCode(language));
207
- dispatch(setBookingOptions(bookingOptions));
208
- dispatch(setCalculateDeposit(showSidebarDeposit));
209
- if (tagIds && tagIds.length > 0) {
210
- dispatch(setTagIds(tagIds ?? undefined));
211
- }
212
- dispatch(setAgentAdressId(agentAdressId ?? undefined));
213
- if (agentAdressId && agentAdressId != 0) {
214
- dispatch(setBookingType("b2b"));
215
- }
216
- if (accommodationViewId && accommodationViewId != 0) {
217
- dispatch(setAccommodationViewId(accommodationViewId));
218
- }
219
-
220
- }, [
221
- officeId,
222
- language,
223
- bookingOptions,
224
- showSidebarDeposit,
225
- setOfficeId,
226
- setLanguageCode,
227
- setCalculateDeposit,
228
- tagIds,
229
- agentAdressId,
230
- accommodationViewId,
231
- ]);
232
-
233
- useEffect(() => {
234
- if (
235
- !productAttributes ||
236
- !bookingAttributes ||
237
- !rooms?.length ||
238
- !isNil(bookingNumber) ||
239
- !isNil(packageDetails)
240
- ) {
241
- return;
242
- }
243
-
244
- // Fetch data
245
- const promise = dispatch(fetchPackage());
246
- return () => {
247
- promise.abort();
248
- };
249
- }, [
250
- productAttributes,
251
- bookingAttributes,
252
- rooms,
253
- bookingNumber,
254
- packageDetails,
255
- apiSettings.apiUrl,
256
- apiSettings.apiKey,
257
- ]);
258
-
259
- const renderStep = () => {
260
- switch (currentStep) {
261
- case FLIGHT_OPTIONS_FORM_STEP:
262
- return (
263
- <StepRoute
264
- number={1}
265
- title={translations.STEPS.FLIGHT_OPTIONS}
266
- component={<FlightOptionsForm />}
267
- />
268
- );
269
- case ROOM_OPTIONS_FORM_STEP:
270
- return (
271
- <StepRoute
272
- number={1 + (flightOptions.isHidden ? 0 : 1)}
273
- title={translations.STEPS.ROOM_OPTIONS}
274
- component={<RoomOptionsForm />}
275
- />
276
- );
277
- case OPTIONS_FORM_STEP:
278
- return (
279
- <StepRoute
280
- number={1 + (roomOptions.isHidden ? 0 : 1) + (flightOptions.isHidden ? 0 : 1)}
281
- title={translations.STEPS.EXTRA_OPTIONS}
282
- component={<OptionsForm />}
283
- />
284
- );
285
- case TRAVELERS_FORM_STEP:
286
- return (
287
- <StepRoute
288
- number={2 + (roomOptions.isHidden ? 0 : 1) + (flightOptions.isHidden ? 0 : 1)}
289
- title={translations.STEPS.PERSONAL_DETAILS}
290
- component={<TravelersForm />}
291
- />
292
- );
293
- case SUMMARY_STEP:
294
- return (
295
- <StepRoute
296
- number={3 + (roomOptions.isHidden ? 0 : 1) + (flightOptions.isHidden ? 0 : 1)}
297
- title={translations.STEPS.SUMMARY}
298
- component={<Summary />}
299
- />
300
- );
301
- case CONFIRMATION_STEP:
302
- return (
303
- <StepRoute
304
- number={4 + (roomOptions.isHidden ? 0 : 1) + (flightOptions.isHidden ? 0 : 1)}
305
- title={translations.STEPS.CONFIRMATION}
306
- component={<Confirmation />}
307
- />
308
- );
309
- case ERROR_STEP:
310
- return (
311
- <StepRoute
312
- number={5 + (roomOptions.isHidden ? 0 : 1) + (flightOptions.isHidden ? 0 : 1)}
313
- title={translations.STEPS.ERROR}
314
- component={<Error />}
315
- />
316
- );
317
- }
318
- };
319
-
320
- return (
321
- <>
322
- {((productAttributes && bookingAttributes && packageDetails) ||
323
- bookingNumber) && (
324
- <div className="booking">
325
- <div className="booking__content">
326
- <div className="booking__panel">{renderStep()}</div>
327
- <div className="backdrop" id="backdrop"></div>
328
- {packageDetails && (
329
- <Sidebar productName={productName} thumbnailUrl={thumbnailUrl} />
330
- )}
331
- </div>
332
- </div>
333
- )}
334
- {!packageDetails && !bookingNumber && !isUnvailable && (
335
- <div className="booking">
336
- <div className="booking__loader">
337
- <Loader />
338
- <p className="booking__loader-text">
339
- {isOffer ? translations.MAIN.PREPARING_OFFER : translations.MAIN.PREPARING_BOOKING}
340
- </p>
341
- </div>
342
- </div>
343
- )}
344
- {isUnvailable && (
345
- <div className="booking">
346
- <div className="booking__loader">
347
- <p className="booking__loader-text">
348
- {translations.MAIN.PRODUCT_UNAVAILABLE}
349
- </p>
350
- </div>
351
- </div>
352
- )}
353
- </>
354
- );
355
- };
356
-
357
- export default BookingSelfContained;
1
+ import React, { useContext } from "react";
2
+ import { useSelector } from "react-redux";
3
+ import {
4
+ getDateFromParams,
5
+ getFlightsFromParams,
6
+ getNumberFromParams,
7
+ getNumbersFromParams,
8
+ getRoomsFromParams,
9
+ getStringFromParams,
10
+ } from "../../../shared/utils/query-string-util";
11
+ import {
12
+ fetchPackage,
13
+ setAccommodationViewId,
14
+ setAgentAdressId,
15
+ setBookingAttributes,
16
+ setBookingNumber,
17
+ setBookingOptions,
18
+ setBookingType,
19
+ setCalculateDeposit,
20
+ setCurrentStep,
21
+ setGeneratePaymentUrl,
22
+ setLanguageCode,
23
+ setOfficeId,
24
+ setProductAttributes,
25
+ setSkipPayment,
26
+ setTagIds,
27
+ setTranslations,
28
+ } from "./booking-slice";
29
+
30
+ import { isNil } from "lodash";
31
+ import { useEffect } from "react";
32
+ import Loader from "../../../shared/components/loader";
33
+ import { setApiKey, setApiUrl } from "../../api-settings-slice";
34
+ import StepRoute from "../../components/step-route";
35
+ import SettingsContext from "../../settings-context";
36
+ import { useAppDispatch } from "../../store";
37
+ import Confirmation from "../confirmation/confirmation";
38
+ import Error from "../error/error";
39
+ import FlightOptionsForm from "../flight-options";
40
+ import OptionsForm from "../product-options/options-form";
41
+ import RoomOptionsForm from "../room-options";
42
+ import Sidebar from "../sidebar";
43
+ import Summary from "../summary/summary";
44
+ import TravelersForm from "../travelers-form/travelers-form";
45
+ import {
46
+ CONFIRMATION_STEP,
47
+ ERROR_STEP,
48
+ FLIGHT_OPTIONS_FORM_STEP,
49
+ OPTIONS_FORM_STEP,
50
+ ROOM_OPTIONS_FORM_STEP,
51
+ SUMMARY_STEP,
52
+ TRAVELERS_FORM_STEP,
53
+ } from "./constants";
54
+ import {
55
+ selectApiSettings,
56
+ selectBookingAttributes,
57
+ selectBookingNumber,
58
+ selectBookingRooms,
59
+ selectCurrentStep,
60
+ selectIsUnavailable,
61
+ selectPackageDetails,
62
+ selectProductAttributes,
63
+ selectTranslations,
64
+ } from "./selectors";
65
+
66
+ interface BookingProps {
67
+ productCode: string;
68
+ productName: string;
69
+ thumbnailUrl?: string;
70
+ }
71
+
72
+ const BookingSelfContained: React.FC<BookingProps> = ({
73
+ productCode,
74
+ productName,
75
+ thumbnailUrl,
76
+ }) => {
77
+ const {
78
+ officeId,
79
+ bookingOptions,
80
+ showSidebarDeposit,
81
+ includeFlights,
82
+ skipPaymentWithAgent,
83
+ generatePaymentUrl,
84
+ tagIds,
85
+ agentAdressId,
86
+ language,
87
+ apiUrl,
88
+ apiKey,
89
+ translationFiles,
90
+ roomOptions,
91
+ flightOptions,
92
+ accommodationViewId,
93
+ isOffer,
94
+ } = useContext(SettingsContext);
95
+
96
+ const dispatch = useAppDispatch();
97
+
98
+ const productAttributes = useSelector(selectProductAttributes);
99
+ const bookingAttributes = useSelector(selectBookingAttributes);
100
+ const rooms = useSelector(selectBookingRooms);
101
+ const bookingNumber = useSelector(selectBookingNumber);
102
+ const packageDetails = useSelector(selectPackageDetails);
103
+ const isUnvailable = useSelector(selectIsUnavailable);
104
+ const currentStep = useSelector(selectCurrentStep);
105
+ const apiSettings = useSelector(selectApiSettings);
106
+ const translations = useSelector(selectTranslations);
107
+
108
+ useEffect(() => {
109
+ dispatch(setSkipPayment(skipPaymentWithAgent ?? false));
110
+ dispatch(setGeneratePaymentUrl(generatePaymentUrl ?? false));
111
+ }, [skipPaymentWithAgent, generatePaymentUrl]);
112
+
113
+ useEffect(() => {
114
+ if (!isNil(apiUrl) && !isNil(apiKey)) {
115
+ dispatch(setApiUrl(apiUrl));
116
+ dispatch(setApiKey(apiKey));
117
+ }
118
+ }, [apiUrl, apiKey]);
119
+
120
+ useEffect(() => {
121
+ const params = new URLSearchParams(location.search);
122
+ const startDate = getDateFromParams(params, "startDate");
123
+ const endDate = getDateFromParams(params, "endDate");
124
+ const catalog = getNumberFromParams(params, "catalog");
125
+ const rooms = getRoomsFromParams(params, "rooms");
126
+ const flight = getFlightsFromParams(params, "flight");
127
+ const flightRouteId = getStringFromParams(params, "flightRouteId");
128
+ const allotmentName = getStringFromParams(params, "allotmentName");
129
+ const allotmentIds = getNumbersFromParams(params, "allotmentId");
130
+ const tourCode = getStringFromParams(params, "tourCode");
131
+ const bookingNumber = params.get("bookingNr") ?? undefined;
132
+
133
+ if (typeof window !== "undefined") {
134
+ window.scrollTo(0, 0);
135
+ }
136
+
137
+ if (!isNil(bookingNumber)) {
138
+ dispatch(setBookingNumber(bookingNumber));
139
+ dispatch(setCurrentStep(CONFIRMATION_STEP));
140
+ } else if (!flightOptions.isHidden) {
141
+ dispatch(setCurrentStep(FLIGHT_OPTIONS_FORM_STEP));
142
+ } else if (!roomOptions.isHidden) {
143
+ dispatch(setCurrentStep(ROOM_OPTIONS_FORM_STEP));
144
+ }
145
+
146
+ if (
147
+ !isNil(startDate) &&
148
+ !isNil(endDate) &&
149
+ !isNil(catalog) &&
150
+ !isNil(rooms)
151
+ ) {
152
+ dispatch(
153
+ setBookingAttributes({
154
+ startDate,
155
+ endDate,
156
+ catalog,
157
+ rooms,
158
+ flight,
159
+ includeFlights,
160
+ allotmentName,
161
+ allotmentIds,
162
+ tourCode,
163
+ flightRouteId,
164
+ })
165
+ );
166
+ } else {
167
+ console.error(
168
+ "Failure when setting booking attributes",
169
+ startDate,
170
+ endDate,
171
+ catalog,
172
+ rooms
173
+ );
174
+ }
175
+ }, [location.search, setBookingAttributes, setBookingNumber, includeFlights]);
176
+
177
+ useEffect(() => {
178
+ if (!isNil(productCode) && !isNil(productName)) {
179
+ dispatch(
180
+ setProductAttributes({
181
+ productCode,
182
+ productName,
183
+ })
184
+ );
185
+ } else {
186
+ console.error(
187
+ "Failure when setting product attributes",
188
+ productCode,
189
+ productName
190
+ );
191
+ }
192
+ }, [productCode, productName, setProductAttributes]);
193
+
194
+ const getTranslations = async () => {
195
+ const translations = translationFiles?.map((x) =>
196
+ fetch(x.path)
197
+ .then((y) => y.json())
198
+ .then((z) => ({ language: x.language, value: z }))
199
+ );
200
+ return translations && (await Promise.all(translations));
201
+ };
202
+
203
+ useEffect(() => {
204
+ const loadTranslations = async () => {
205
+ const translations = await getTranslations();
206
+ dispatch(setTranslations(translations)); // Now dispatch the resolved value
207
+ };
208
+
209
+ loadTranslations();
210
+
211
+ dispatch(setOfficeId(officeId));
212
+ dispatch(setLanguageCode(language));
213
+ dispatch(setBookingOptions(bookingOptions));
214
+ dispatch(setCalculateDeposit(showSidebarDeposit));
215
+ if (tagIds && tagIds.length > 0) {
216
+ dispatch(setTagIds(tagIds ?? undefined));
217
+ }
218
+ dispatch(setAgentAdressId(agentAdressId ?? undefined));
219
+ if (agentAdressId && agentAdressId != 0) {
220
+ dispatch(setBookingType("b2b"));
221
+ }
222
+ if (accommodationViewId && accommodationViewId != 0) {
223
+ dispatch(setAccommodationViewId(accommodationViewId));
224
+ }
225
+ }, [
226
+ officeId,
227
+ language,
228
+ bookingOptions,
229
+ showSidebarDeposit,
230
+ setOfficeId,
231
+ setLanguageCode,
232
+ setCalculateDeposit,
233
+ tagIds,
234
+ agentAdressId,
235
+ accommodationViewId,
236
+ ]);
237
+
238
+ useEffect(() => {
239
+ if (
240
+ !productAttributes ||
241
+ !bookingAttributes ||
242
+ !rooms?.length ||
243
+ !isNil(bookingNumber) ||
244
+ !isNil(packageDetails)
245
+ ) {
246
+ return;
247
+ }
248
+
249
+ // Fetch data
250
+ const promise = dispatch(fetchPackage());
251
+ return () => {
252
+ promise.abort();
253
+ };
254
+ }, [
255
+ productAttributes,
256
+ bookingAttributes,
257
+ rooms,
258
+ bookingNumber,
259
+ packageDetails,
260
+ apiSettings.apiUrl,
261
+ apiSettings.apiKey,
262
+ ]);
263
+
264
+ const renderStep = () => {
265
+ switch (currentStep) {
266
+ case FLIGHT_OPTIONS_FORM_STEP:
267
+ return (
268
+ <StepRoute
269
+ number={1}
270
+ title={translations.STEPS.FLIGHT_OPTIONS}
271
+ component={<FlightOptionsForm />}
272
+ />
273
+ );
274
+ case ROOM_OPTIONS_FORM_STEP:
275
+ return (
276
+ <StepRoute
277
+ number={1 + (flightOptions.isHidden ? 0 : 1)}
278
+ title={translations.STEPS.ROOM_OPTIONS}
279
+ component={<RoomOptionsForm />}
280
+ />
281
+ );
282
+ case OPTIONS_FORM_STEP:
283
+ return (
284
+ <StepRoute
285
+ number={
286
+ 1 +
287
+ (roomOptions.isHidden ? 0 : 1) +
288
+ (flightOptions.isHidden ? 0 : 1)
289
+ }
290
+ title={translations.STEPS.EXTRA_OPTIONS}
291
+ component={<OptionsForm />}
292
+ />
293
+ );
294
+ case TRAVELERS_FORM_STEP:
295
+ return (
296
+ <StepRoute
297
+ number={
298
+ 2 +
299
+ (roomOptions.isHidden ? 0 : 1) +
300
+ (flightOptions.isHidden ? 0 : 1)
301
+ }
302
+ title={translations.STEPS.PERSONAL_DETAILS}
303
+ component={<TravelersForm />}
304
+ />
305
+ );
306
+ case SUMMARY_STEP:
307
+ return (
308
+ <StepRoute
309
+ number={
310
+ 3 +
311
+ (roomOptions.isHidden ? 0 : 1) +
312
+ (flightOptions.isHidden ? 0 : 1)
313
+ }
314
+ title={translations.STEPS.SUMMARY}
315
+ component={<Summary />}
316
+ />
317
+ );
318
+ case CONFIRMATION_STEP:
319
+ return (
320
+ <StepRoute
321
+ number={
322
+ 4 +
323
+ (roomOptions.isHidden ? 0 : 1) +
324
+ (flightOptions.isHidden ? 0 : 1)
325
+ }
326
+ title={translations.STEPS.CONFIRMATION}
327
+ component={<Confirmation />}
328
+ />
329
+ );
330
+ case ERROR_STEP:
331
+ return (
332
+ <StepRoute
333
+ number={
334
+ 5 +
335
+ (roomOptions.isHidden ? 0 : 1) +
336
+ (flightOptions.isHidden ? 0 : 1)
337
+ }
338
+ title={translations.STEPS.ERROR}
339
+ component={<Error />}
340
+ />
341
+ );
342
+ }
343
+ };
344
+
345
+ return (
346
+ <>
347
+ {((productAttributes && bookingAttributes && packageDetails) ||
348
+ bookingNumber) && (
349
+ <div className="booking">
350
+ <div className="booking__content">
351
+ <div className="booking__panel">{renderStep()}</div>
352
+ <div className="backdrop" id="backdrop"></div>
353
+ {packageDetails && (
354
+ <Sidebar productName={productName} thumbnailUrl={thumbnailUrl} />
355
+ )}
356
+ </div>
357
+ </div>
358
+ )}
359
+ {!packageDetails && !bookingNumber && !isUnvailable && (
360
+ <div className="booking">
361
+ <div className="booking__loader">
362
+ <Loader />
363
+ <p className="booking__loader-text">
364
+ {isOffer
365
+ ? translations.MAIN.PREPARING_OFFER
366
+ : translations.MAIN.PREPARING_BOOKING}
367
+ </p>
368
+ </div>
369
+ </div>
370
+ )}
371
+ {isUnvailable && (
372
+ <div className="booking">
373
+ <div className="booking__loader">
374
+ <p className="booking__loader-text">
375
+ {translations.MAIN.PRODUCT_UNAVAILABLE}
376
+ </p>
377
+ </div>
378
+ </div>
379
+ )}
380
+ </>
381
+ );
382
+ };
383
+
384
+ export default BookingSelfContained;