@qite/tide-booking-component 1.3.4 → 1.3.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 (33) hide show
  1. package/build/build-cjs/booking-wizard/features/sidebar/sidebar-util.d.ts +3 -3
  2. package/build/build-cjs/booking-wizard/features/travelers-form/travelers-form-slice.d.ts +5 -5
  3. package/build/build-cjs/booking-wizard/types.d.ts +6 -0
  4. package/build/build-cjs/index.js +223 -147
  5. package/build/build-cjs/shared/utils/localization-util.d.ts +2 -0
  6. package/build/build-esm/booking-wizard/features/sidebar/sidebar-util.d.ts +3 -3
  7. package/build/build-esm/booking-wizard/features/travelers-form/travelers-form-slice.d.ts +5 -5
  8. package/build/build-esm/booking-wizard/types.d.ts +6 -0
  9. package/build/build-esm/index.js +223 -147
  10. package/build/build-esm/shared/utils/localization-util.d.ts +2 -0
  11. package/package.json +75 -75
  12. package/src/booking-wizard/components/print-offer-button.tsx +63 -63
  13. package/src/booking-wizard/features/booking/booking-self-contained.tsx +389 -389
  14. package/src/booking-wizard/features/booking/booking-slice.ts +663 -663
  15. package/src/booking-wizard/features/booking/booking.tsx +361 -361
  16. package/src/booking-wizard/features/flight-options/flight-utils.ts +522 -522
  17. package/src/booking-wizard/features/product-options/options-form.tsx +481 -481
  18. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  19. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  20. package/src/booking-wizard/features/summary/summary.tsx +674 -674
  21. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  22. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +888 -754
  23. package/src/booking-wizard/settings-context.ts +62 -62
  24. package/src/booking-wizard/types.ts +286 -279
  25. package/src/booking-wizard/use-offer-printer.ts +117 -117
  26. package/src/shared/translations/en-GB.json +239 -237
  27. package/src/shared/translations/fr-BE.json +239 -238
  28. package/src/shared/translations/nl-BE.json +239 -237
  29. package/src/shared/utils/tide-api-utils.ts +36 -36
  30. package/styles/booking-wizard-variables.scss +873 -873
  31. package/styles/components/_booking.scss +879 -879
  32. package/styles/components/_dropdown.scss +72 -72
  33. package/styles/components/_form.scss +1583 -1583
@@ -1,674 +1,674 @@
1
- import { book, validateVoucher } from "@qite/tide-client";
2
- import {
3
- BookingPackageRequest,
4
- BookingPackageVoucherRequest,
5
- } from "@qite/tide-client/build/types";
6
- import { Link, navigate, useLocation } from "@reach/router";
7
- import { compact, findIndex, isEmpty, isNil, uniqBy } from "lodash";
8
- import React, { useContext, useEffect, useState } from "react";
9
- import { useSelector } from "react-redux";
10
- import { buildClassName } from "../../../shared/utils/class-util";
11
- import { buildTideClientConfig } from "../../../shared/utils/tide-api-utils";
12
- import Icon from "../../components/icon";
13
- import SettingsContext from "../../settings-context";
14
- import { useAppDispatch } from "../../store";
15
- import { SummaryCheckbox } from "../../types";
16
- import {
17
- setBookingNumber,
18
- setBookingRemarks,
19
- setCurrentStep,
20
- setVoucherCodes,
21
- } from "../booking/booking-slice";
22
- import {
23
- CONFIRMATION_STEP,
24
- ERROR_STEP,
25
- TRAVELERS_FORM_STEP,
26
- } from "../booking/constants";
27
- import {
28
- selectActiveOption,
29
- selectAgentAdressId,
30
- selectApiSettings,
31
- selectBookingPackageBookRequest,
32
- selectBookingQueryString,
33
- selectLanguageCode,
34
- selectOfficeId,
35
- selectPackageDetails,
36
- selectTranslations,
37
- } from "../booking/selectors";
38
- import {
39
- fetchPriceDetails,
40
- selectNotifications,
41
- setNotifications,
42
- } from "../price-details/price-details-slice";
43
- import { getDateText } from "../sidebar/sidebar-util";
44
- import {
45
- selectRooms,
46
- selectTravelersFormValues,
47
- } from "../travelers-form/travelers-form-slice";
48
- import SummaryBookingOptionPax from "./summary-booking-option-pax";
49
- import SummaryBookingOptionUnit from "./summary-booking-option-unit";
50
- import SummaryFlight from "./summary-flight";
51
- import SummaryBookingOption from "./summary-per-booking-option-group";
52
- import { selectUserValidated, setUserValidated } from "./summary-slice";
53
-
54
- interface VoucherProps {
55
- code?: string;
56
- isValidated?: boolean;
57
- isValid?: boolean;
58
- }
59
-
60
- interface SummaryProps {}
61
-
62
- const Summary: React.FC<SummaryProps> = () => {
63
- const dispatch = useAppDispatch();
64
-
65
- const settings = useContext(SettingsContext);
66
-
67
- const [isSubmitting, setIsSubmitting] = useState(false);
68
- const [checkboxes, setCheckboxes] = useState<
69
- SummaryCheckbox[] | undefined | null
70
- >(settings.summary?.checkboxes);
71
- const [remarks, setRemarks] = useState<string>("");
72
-
73
- const [voucher, setVoucher] = useState<VoucherProps>({});
74
-
75
- const bookingQueryString = useSelector(selectBookingQueryString);
76
- const travelerFormValues = useSelector(selectTravelersFormValues);
77
- const packageDetails = useSelector(selectPackageDetails);
78
- const activeOption = useSelector(selectActiveOption);
79
- const apiSettings = useSelector(selectApiSettings);
80
- const languageCode = useSelector(selectLanguageCode);
81
- const officeId = useSelector(selectOfficeId);
82
- const agentId = useSelector(selectAgentAdressId);
83
-
84
- if (!travelerFormValues) {
85
- if (settings.skipRouter) {
86
- dispatch(setCurrentStep(TRAVELERS_FORM_STEP));
87
- } else {
88
- navigate(`${settings.basePath}?${bookingQueryString}`);
89
- }
90
- }
91
-
92
- const rooms = useSelector(selectRooms);
93
-
94
- const userValidated = useSelector(selectUserValidated);
95
- const notifications = useSelector(selectNotifications);
96
-
97
- const bookRequest = useSelector(selectBookingPackageBookRequest);
98
-
99
- useEffect(() => {
100
- // Every checkbox should be checked, or no checkboxes
101
- const checkboxesValidated = !isNil(checkboxes)
102
- ? checkboxes.every((checkbox) => checkbox.isSelected)
103
- : true;
104
-
105
- const notificationsValidated = !isNil(notifications)
106
- ? notifications
107
- .filter((x) => x.hasToBeConfirmed)
108
- .every((checkbox) => checkbox.isConfirmed)
109
- : true;
110
-
111
- dispatch(setUserValidated(checkboxesValidated && notificationsValidated));
112
- }, [checkboxes, notifications]);
113
-
114
- const handleSubmit: React.FormEventHandler<HTMLFormElement> = async (e) => {
115
- e.preventDefault();
116
- setIsSubmitting(true);
117
-
118
- if (typeof window !== "undefined") {
119
- window.scrollTo(0, 0);
120
- }
121
-
122
- const tideClientConfig = buildTideClientConfig(apiSettings);
123
-
124
- if (!bookRequest || !tideClientConfig) {
125
- return;
126
- }
127
-
128
- if (bookRequest.payload.returnPaymentUrl) {
129
- const location = useLocation();
130
- bookRequest.payload.redirectUrl = `${location.protocol}//${location.host}${settings.basePath}`;
131
- }
132
-
133
- try {
134
- const bookingResponse = await book(
135
- tideClientConfig,
136
- bookRequest,
137
- undefined,
138
- languageCode
139
- );
140
-
141
- // Booking successfull
142
- dispatch(setBookingNumber(bookingResponse.number));
143
-
144
- if (bookingResponse.paymentUrl) {
145
- window.location.href = bookingResponse.paymentUrl;
146
- } else {
147
- if (settings.skipRouter) {
148
- dispatch(setCurrentStep(CONFIRMATION_STEP));
149
- } else {
150
- navigate(
151
- `${settings.basePath}${settings.confirmation.pathSuffix}?${bookingQueryString}`
152
- );
153
- }
154
- }
155
- } catch (error) {
156
- if (settings.skipRouter) {
157
- dispatch(setCurrentStep(ERROR_STEP));
158
- } else {
159
- navigate(
160
- `${settings.basePath}${settings.error.pathSuffix}?${bookingQueryString}`
161
- );
162
- }
163
- } finally {
164
- setIsSubmitting(false);
165
- }
166
- };
167
-
168
- const handleNotificationChange = (id: number, checked: boolean) => {
169
- const updatedNotifications = notifications.map((notification) =>
170
- notification.id === id
171
- ? { ...notification, isConfirmed: checked }
172
- : notification
173
- );
174
-
175
- dispatch(setNotifications(updatedNotifications));
176
- };
177
-
178
- const handleCheckboxChange = (id: string, checked: boolean) => {
179
- if (isNil(checkboxes)) {
180
- return;
181
- }
182
-
183
- const newCheckboxes = [...checkboxes];
184
-
185
- const index = findIndex(checkboxes, (checkbox) => checkbox.id === id);
186
- newCheckboxes[index].isSelected = !newCheckboxes[index].isSelected;
187
-
188
- setCheckboxes(newCheckboxes);
189
- };
190
-
191
- const handleRemarksChange = (text: string) => {
192
- dispatch(setBookingRemarks(text));
193
-
194
- setRemarks(text);
195
- };
196
-
197
- const handleValidateVoucher = async () => {
198
- if (!voucher?.code) return;
199
-
200
- const request = {
201
- officeId: officeId,
202
- agentId: agentId,
203
- payload: {
204
- code: voucher.code,
205
- otherCodes: bookRequest?.payload.voucherCodes ?? [],
206
- },
207
- } as BookingPackageRequest<BookingPackageVoucherRequest>;
208
-
209
- const tideClientConfig = buildTideClientConfig(apiSettings);
210
- if (!tideClientConfig) return;
211
-
212
- const result = await validateVoucher(tideClientConfig, request);
213
-
214
- if (result) {
215
- setVoucher({
216
- ...voucher,
217
- isValidated: true,
218
- isValid: result.isValid,
219
- });
220
- }
221
- };
222
-
223
- const handleAddVoucher: React.MouseEventHandler<HTMLButtonElement> = (
224
- event
225
- ) => {
226
- if (!voucher.isValid) return;
227
-
228
- dispatch(
229
- setVoucherCodes(
230
- [
231
- ...(bookRequest?.payload.voucherCodes ?? []),
232
- voucher.code ?? "",
233
- ].filter((x) => x !== "")
234
- )
235
- );
236
-
237
- dispatch(fetchPriceDetails());
238
-
239
- setVoucher({});
240
- };
241
-
242
- const handleRemoveVoucher = (code: string) => {
243
- dispatch(
244
- setVoucherCodes(
245
- bookRequest?.payload.voucherCodes?.filter((x) => x !== code) ?? []
246
- )
247
- );
248
-
249
- dispatch(fetchPriceDetails());
250
- };
251
-
252
- const goPrevious = () => {
253
- dispatch(setCurrentStep(TRAVELERS_FORM_STEP));
254
- };
255
-
256
- const translations = useSelector(selectTranslations);
257
-
258
- return (
259
- <>
260
- {isSubmitting && settings.loaderComponent}
261
- {!isSubmitting && (
262
- <form
263
- className="form"
264
- name="booking--summary"
265
- id="booking--summary"
266
- onSubmit={handleSubmit}
267
- >
268
- <div className="form__booking--summary">
269
- <div className="form__region">
270
- <div className="form__row">
271
- <div className="form__group">
272
- <div className="form__region-header">
273
- <h5 className="form__region-heading">
274
- {translations.SUMMARY.PERSONAL_DETAILS}
275
- </h5>
276
- </div>
277
- </div>
278
- </div>
279
- {rooms.map((r, rIndex) => (
280
- <div className="form__row">
281
- <div className="form__group">
282
- <div className="form__region-header">
283
- <h5 className="form__region-heading">
284
- {translations.SHARED.ROOM} {rIndex + 1}
285
- </h5>
286
- <p className="form__region-label">
287
- {`${r.adults.length + r.children.length} ${
288
- r.adults.length + r.children.length === 1
289
- ? translations.SUMMARY.TRAVELER
290
- : translations.SUMMARY.TRAVELERS
291
- }: ${compact([
292
- r.adults.length,
293
- r.adults.length === 1 &&
294
- ` ${translations.SUMMARY.ADULT}`,
295
- r.adults.length > 1 &&
296
- ` ${translations.SUMMARY.ADULTS}`,
297
- r.adults &&
298
- r.adults.length &&
299
- r.children &&
300
- r.children.length &&
301
- ", ",
302
- r.children.length,
303
- r.children.length === 1 &&
304
- ` ${translations.SUMMARY.CHILD}`,
305
- r.children.length > 1 &&
306
- ` ${translations.SUMMARY.CHILDREN}`,
307
- ]).join("")}`}
308
- </p>
309
- </div>
310
- </div>
311
- {[...r.adults, ...r.children].map((traveler) => {
312
- const isMainBooker =
313
- traveler.id === travelerFormValues?.mainBookerId;
314
- return (
315
- <div
316
- className="form__group form__group--sm-50"
317
- key={traveler.id}
318
- >
319
- <ul className="list list--plain">
320
- <li className="list__item">
321
- <strong>
322
- {traveler.firstName} {traveler.lastName}
323
- </strong>{" "}
324
- {isMainBooker && (
325
- <em>({translations.SUMMARY.MAIN_BOOKER})</em>
326
- )}
327
- </li>
328
- <li className="list__item">
329
- {traveler.birthDate.split("-").reverse().join("/")}
330
- </li>
331
- {isMainBooker && (
332
- <>
333
- <li className="list__item">{`${
334
- travelerFormValues?.street
335
- } ${compact([
336
- travelerFormValues?.houseNumber,
337
- travelerFormValues?.box,
338
- ]).join(" ")}, ${travelerFormValues?.zipCode} ${
339
- travelerFormValues?.place
340
- }`}</li>
341
- <li className="list__item">
342
- {travelerFormValues?.phone}
343
- </li>
344
- <li className="list__item">
345
- {travelerFormValues?.email}
346
- </li>
347
- </>
348
- )}
349
- </ul>
350
- </div>
351
- );
352
- })}
353
- </div>
354
- ))}
355
- </div>
356
-
357
- <div className="form__region">
358
- <div className="form__row">
359
- <div className="form__group">
360
- <div className="form__region-header">
361
- <h5 className="form__region-heading">
362
- {translations.SUMMARY.OPTIONS}
363
- </h5>
364
- </div>
365
- </div>
366
- </div>
367
- <div className="form__row">
368
- <div className="form__group">
369
- <ul className="list list--booking-summary">
370
- <li>
371
- <h6>{activeOption?.name}</h6>
372
- <ul>
373
- {activeOption?.rooms.map((r, ri) => {
374
- const roomOption = r.options.find(
375
- (x) => x.isSelected
376
- );
377
- return (
378
- <li key={ri} className="list__item">
379
- {roomOption?.accommodationName}
380
- {!isNil(roomOption?.regimeName) && ", "}
381
- {roomOption?.regimeName}
382
- </li>
383
- );
384
- })}
385
- </ul>
386
- <p>
387
- ({getDateText(activeOption?.fromDate)} &gt;{" "}
388
- {getDateText(activeOption?.toDate)})
389
- </p>
390
- </li>
391
- {!isEmpty(activeOption?.groups) &&
392
- activeOption?.groups.map((x, i) => {
393
- if (!x.options.some((y) => y.isSelected)) return;
394
-
395
- return <SummaryBookingOption key={i} group={x} />;
396
- })}
397
- {!isEmpty(activeOption?.optionUnits) &&
398
- activeOption?.optionUnits.map((x) => (
399
- <SummaryBookingOptionUnit unit={x} />
400
- ))}
401
- {!isEmpty(activeOption?.optionPax) &&
402
- activeOption?.optionPax.map((x) => (
403
- <SummaryBookingOptionPax pax={x} />
404
- ))}
405
- {packageDetails?.outwardFlights &&
406
- packageDetails.outwardFlights
407
- .filter((x) => x.isSelected)
408
- .map((flight, i) => (
409
- <SummaryFlight
410
- key={i}
411
- flight={flight}
412
- header={translations.SIDEBAR.DEPARTURE_FLIGHT}
413
- />
414
- ))}
415
- {packageDetails?.returnFlights &&
416
- packageDetails.returnFlights
417
- .filter((x) => x.isSelected)
418
- .map((flight, i) => (
419
- <SummaryFlight
420
- key={i}
421
- flight={flight}
422
- header={translations.SIDEBAR.ARRIVAL_FLIGHT}
423
- />
424
- ))}
425
- </ul>
426
- </div>
427
- </div>
428
- </div>
429
-
430
- {settings.enableVoucher && (
431
- <div className="form__region">
432
- <div className="form__row">
433
- <div className="form__group">
434
- <div className="form__region-header">
435
- <h5 className="form__region-heading">
436
- {translations.SUMMARY.VOUCHERS}
437
- </h5>
438
- </div>
439
- </div>
440
- </div>
441
- <div className="form__row">
442
- <div className="form__group">
443
- <input
444
- type="text"
445
- className="form__input info-message__voucher__input"
446
- defaultValue={voucher.code}
447
- onChange={(e) => setVoucher({ code: e.target.value })}
448
- />
449
- <button
450
- type="button"
451
- className={buildClassName([
452
- "cta",
453
- !voucher.code && "cta--disabled",
454
- ])}
455
- onClick={(e) => handleValidateVoucher()}
456
- >
457
- {translations.SUMMARY.VOUCHER_VALIDATE}
458
- </button>
459
- </div>
460
- </div>
461
- <div className="form__row">
462
- <div className="form__group info-message__voucher">
463
- {voucher.isValid && voucher.isValidated && (
464
- <div className="info-message info-message__voucher__valid">
465
- <span>{translations.SUMMARY.VOUCHER_VALID}</span>
466
- <button
467
- type="button"
468
- className="cta cta--secondary"
469
- onClick={handleAddVoucher}
470
- >
471
- {translations.SUMMARY.ADD_VOUCHER}
472
- </button>
473
- </div>
474
- )}
475
- {!voucher.isValid && voucher.isValidated && (
476
- <div className="info-message--error">
477
- {translations.SUMMARY.VOUCHER_INVALID}
478
- </div>
479
- )}
480
- </div>
481
- </div>
482
- <div className="form__row">
483
- <ul className="info-message__voucher">
484
- {!isEmpty(bookRequest?.payload.voucherCodes) &&
485
- bookRequest?.payload.voucherCodes?.map((y) => (
486
- <li>
487
- <div className="info-message__voucher__list">
488
- {y}{" "}
489
- <button
490
- type="button"
491
- className="cta--add-remove"
492
- onClick={(e) => handleRemoveVoucher(y)}
493
- >
494
- <Icon height={16} name="ui-trashcan" />
495
- </button>
496
- </div>
497
- </li>
498
- ))}
499
- </ul>
500
- </div>
501
- </div>
502
- )}
503
-
504
- {!isEmpty(notifications) && (
505
- <div className="form__region">
506
- <div className="form__row">
507
- <div className="form__group">
508
- <div className="info-message">
509
- <Icon
510
- name="ui-tooltip"
511
- className="icon--secondary-color"
512
- />
513
- <div className="info-message__copy">
514
- <h5>{translations.SUMMARY.NOTIFICATIONS_TITLE}</h5>
515
- <>
516
- {uniqBy(
517
- notifications.filter((x) => !x.hasToBeConfirmed),
518
- "id"
519
- ).map((notification) => (
520
- <span
521
- key={notification.id}
522
- className="checkbox__label-text"
523
- >
524
- <strong className="checkbox__label-text--title">
525
- {notification.title}
526
- </strong>
527
- <span className="checkbox__label-text--description">
528
- {notification.description}
529
- </span>
530
- </span>
531
- ))}
532
- {uniqBy(
533
- notifications.filter((x) => x.hasToBeConfirmed),
534
- "id"
535
- ).map((notification) => (
536
- <div className="checkbox" key={notification.id}>
537
- <label className="checkbox__label">
538
- <input
539
- type="checkbox"
540
- className="checkbox__input"
541
- checked={notification.isConfirmed}
542
- onChange={(e) =>
543
- handleNotificationChange(
544
- notification.id,
545
- e.target.checked
546
- )
547
- }
548
- />
549
- <span className="checkbox__label-text">
550
- <strong className="checkbox__label-text--title">
551
- {notification.title}
552
- </strong>
553
- <span className="checkbox__label-text--description">
554
- {notification.description}
555
- </span>
556
- </span>
557
- </label>
558
- </div>
559
- ))}
560
- </>
561
- </div>
562
- </div>
563
- </div>
564
- </div>
565
- </div>
566
- )}
567
-
568
- <div className="form__region">
569
- <div className="form__row">
570
- <div className="form__group">
571
- <div className="form__region-header">
572
- <h5 className="form__region-heading">
573
- {translations.SUMMARY.REMARKS}
574
- </h5>
575
- </div>
576
- </div>
577
- </div>
578
- <div className="form__row">
579
- <div className="form__group">
580
- <textarea
581
- className="form__input"
582
- defaultValue={remarks}
583
- onChange={(e) => handleRemarksChange(e.target.value)}
584
- ></textarea>
585
- </div>
586
- </div>
587
- </div>
588
-
589
- <div className="form__region">
590
- <div className="form__row">
591
- <div className="form__group">
592
- <div className="info-message">
593
- <Icon name="ui-tooltip" className="icon--secondary-color" />
594
- <div className="info-message__copy">
595
- <h5>{translations.SUMMARY.VALIDATE_TITLE}</h5>
596
- <p>
597
- {settings.isOffer
598
- ? translations.SUMMARY.VALIDATE_TEXT_OFFER
599
- : translations.SUMMARY.VALIDATE_TEXT_BOOKING}
600
- </p>
601
- {checkboxes &&
602
- checkboxes.map((checkbox) => (
603
- <div className="checkbox" key={checkbox.id}>
604
- <label className="checkbox__label">
605
- <input
606
- type="checkbox"
607
- className="checkbox__input"
608
- checked={checkbox.isSelected}
609
- onChange={(e) =>
610
- handleCheckboxChange(
611
- checkbox.id,
612
- e.target.checked
613
- )
614
- }
615
- />
616
- <span
617
- className="checkbox__label-text"
618
- dangerouslySetInnerHTML={{
619
- __html: checkbox.text,
620
- }}
621
- />
622
- </label>
623
- </div>
624
- ))}
625
- </div>
626
- </div>
627
- </div>
628
- </div>
629
- </div>
630
- </div>
631
-
632
- <div className="booking__navigator">
633
- {settings.skipRouter ? (
634
- <button
635
- type="button"
636
- title={translations.STEPS.PREVIOUS}
637
- onClick={() => goPrevious()}
638
- className="cta cta--secondary"
639
- >
640
- {translations.STEPS.PREVIOUS}
641
- </button>
642
- ) : (
643
- <Link
644
- to={`${settings.basePath}${settings.travellers.pathSuffix}?${bookingQueryString}`}
645
- title={translations.STEPS.PREVIOUS}
646
- className="cta cta--secondary"
647
- >
648
- {translations.STEPS.PREVIOUS}
649
- </Link>
650
- )}
651
- <button
652
- title={
653
- settings.isOffer
654
- ? translations.STEPS.SUBMIT_OFFER
655
- : translations.STEPS.SUBMIT_BOOKING
656
- }
657
- className={buildClassName([
658
- "cta",
659
- !userValidated && "cta--disabled",
660
- ])}
661
- disabled={!userValidated}
662
- >
663
- {settings.isOffer
664
- ? translations.STEPS.SUBMIT_OFFER
665
- : translations.STEPS.SUBMIT_BOOKING}
666
- </button>
667
- </div>
668
- </form>
669
- )}
670
- </>
671
- );
672
- };
673
-
674
- export default Summary;
1
+ import { book, validateVoucher } from "@qite/tide-client";
2
+ import {
3
+ BookingPackageRequest,
4
+ BookingPackageVoucherRequest,
5
+ } from "@qite/tide-client/build/types";
6
+ import { Link, navigate, useLocation } from "@reach/router";
7
+ import { compact, findIndex, isEmpty, isNil, uniqBy } from "lodash";
8
+ import React, { useContext, useEffect, useState } from "react";
9
+ import { useSelector } from "react-redux";
10
+ import { buildClassName } from "../../../shared/utils/class-util";
11
+ import { buildTideClientConfig } from "../../../shared/utils/tide-api-utils";
12
+ import Icon from "../../components/icon";
13
+ import SettingsContext from "../../settings-context";
14
+ import { useAppDispatch } from "../../store";
15
+ import { SummaryCheckbox } from "../../types";
16
+ import {
17
+ setBookingNumber,
18
+ setBookingRemarks,
19
+ setCurrentStep,
20
+ setVoucherCodes,
21
+ } from "../booking/booking-slice";
22
+ import {
23
+ CONFIRMATION_STEP,
24
+ ERROR_STEP,
25
+ TRAVELERS_FORM_STEP,
26
+ } from "../booking/constants";
27
+ import {
28
+ selectActiveOption,
29
+ selectAgentAdressId,
30
+ selectApiSettings,
31
+ selectBookingPackageBookRequest,
32
+ selectBookingQueryString,
33
+ selectLanguageCode,
34
+ selectOfficeId,
35
+ selectPackageDetails,
36
+ selectTranslations,
37
+ } from "../booking/selectors";
38
+ import {
39
+ fetchPriceDetails,
40
+ selectNotifications,
41
+ setNotifications,
42
+ } from "../price-details/price-details-slice";
43
+ import { getDateText } from "../sidebar/sidebar-util";
44
+ import {
45
+ selectRooms,
46
+ selectTravelersFormValues,
47
+ } from "../travelers-form/travelers-form-slice";
48
+ import SummaryBookingOptionPax from "./summary-booking-option-pax";
49
+ import SummaryBookingOptionUnit from "./summary-booking-option-unit";
50
+ import SummaryFlight from "./summary-flight";
51
+ import SummaryBookingOption from "./summary-per-booking-option-group";
52
+ import { selectUserValidated, setUserValidated } from "./summary-slice";
53
+
54
+ interface VoucherProps {
55
+ code?: string;
56
+ isValidated?: boolean;
57
+ isValid?: boolean;
58
+ }
59
+
60
+ interface SummaryProps {}
61
+
62
+ const Summary: React.FC<SummaryProps> = () => {
63
+ const dispatch = useAppDispatch();
64
+
65
+ const settings = useContext(SettingsContext);
66
+
67
+ const [isSubmitting, setIsSubmitting] = useState(false);
68
+ const [checkboxes, setCheckboxes] = useState<
69
+ SummaryCheckbox[] | undefined | null
70
+ >(settings.summary?.checkboxes);
71
+ const [remarks, setRemarks] = useState<string>("");
72
+
73
+ const [voucher, setVoucher] = useState<VoucherProps>({});
74
+
75
+ const bookingQueryString = useSelector(selectBookingQueryString);
76
+ const travelerFormValues = useSelector(selectTravelersFormValues);
77
+ const packageDetails = useSelector(selectPackageDetails);
78
+ const activeOption = useSelector(selectActiveOption);
79
+ const apiSettings = useSelector(selectApiSettings);
80
+ const languageCode = useSelector(selectLanguageCode);
81
+ const officeId = useSelector(selectOfficeId);
82
+ const agentId = useSelector(selectAgentAdressId);
83
+
84
+ if (!travelerFormValues) {
85
+ if (settings.skipRouter) {
86
+ dispatch(setCurrentStep(TRAVELERS_FORM_STEP));
87
+ } else {
88
+ navigate(`${settings.basePath}?${bookingQueryString}`);
89
+ }
90
+ }
91
+
92
+ const rooms = useSelector(selectRooms);
93
+
94
+ const userValidated = useSelector(selectUserValidated);
95
+ const notifications = useSelector(selectNotifications);
96
+
97
+ const bookRequest = useSelector(selectBookingPackageBookRequest);
98
+
99
+ useEffect(() => {
100
+ // Every checkbox should be checked, or no checkboxes
101
+ const checkboxesValidated = !isNil(checkboxes)
102
+ ? checkboxes.every((checkbox) => checkbox.isSelected)
103
+ : true;
104
+
105
+ const notificationsValidated = !isNil(notifications)
106
+ ? notifications
107
+ .filter((x) => x.hasToBeConfirmed)
108
+ .every((checkbox) => checkbox.isConfirmed)
109
+ : true;
110
+
111
+ dispatch(setUserValidated(checkboxesValidated && notificationsValidated));
112
+ }, [checkboxes, notifications]);
113
+
114
+ const handleSubmit: React.FormEventHandler<HTMLFormElement> = async (e) => {
115
+ e.preventDefault();
116
+ setIsSubmitting(true);
117
+
118
+ if (typeof window !== "undefined") {
119
+ window.scrollTo(0, 0);
120
+ }
121
+
122
+ const tideClientConfig = buildTideClientConfig(apiSettings);
123
+
124
+ if (!bookRequest || !tideClientConfig) {
125
+ return;
126
+ }
127
+
128
+ if (bookRequest.payload.returnPaymentUrl) {
129
+ const location = useLocation();
130
+ bookRequest.payload.redirectUrl = `${location.protocol}//${location.host}${settings.basePath}`;
131
+ }
132
+
133
+ try {
134
+ const bookingResponse = await book(
135
+ tideClientConfig,
136
+ bookRequest,
137
+ undefined,
138
+ languageCode
139
+ );
140
+
141
+ // Booking successfull
142
+ dispatch(setBookingNumber(bookingResponse.number));
143
+
144
+ if (bookingResponse.paymentUrl) {
145
+ window.location.href = bookingResponse.paymentUrl;
146
+ } else {
147
+ if (settings.skipRouter) {
148
+ dispatch(setCurrentStep(CONFIRMATION_STEP));
149
+ } else {
150
+ navigate(
151
+ `${settings.basePath}${settings.confirmation.pathSuffix}?${bookingQueryString}`
152
+ );
153
+ }
154
+ }
155
+ } catch (error) {
156
+ if (settings.skipRouter) {
157
+ dispatch(setCurrentStep(ERROR_STEP));
158
+ } else {
159
+ navigate(
160
+ `${settings.basePath}${settings.error.pathSuffix}?${bookingQueryString}`
161
+ );
162
+ }
163
+ } finally {
164
+ setIsSubmitting(false);
165
+ }
166
+ };
167
+
168
+ const handleNotificationChange = (id: number, checked: boolean) => {
169
+ const updatedNotifications = notifications.map((notification) =>
170
+ notification.id === id
171
+ ? { ...notification, isConfirmed: checked }
172
+ : notification
173
+ );
174
+
175
+ dispatch(setNotifications(updatedNotifications));
176
+ };
177
+
178
+ const handleCheckboxChange = (id: string, checked: boolean) => {
179
+ if (isNil(checkboxes)) {
180
+ return;
181
+ }
182
+
183
+ const newCheckboxes = [...checkboxes];
184
+
185
+ const index = findIndex(checkboxes, (checkbox) => checkbox.id === id);
186
+ newCheckboxes[index].isSelected = !newCheckboxes[index].isSelected;
187
+
188
+ setCheckboxes(newCheckboxes);
189
+ };
190
+
191
+ const handleRemarksChange = (text: string) => {
192
+ dispatch(setBookingRemarks(text));
193
+
194
+ setRemarks(text);
195
+ };
196
+
197
+ const handleValidateVoucher = async () => {
198
+ if (!voucher?.code) return;
199
+
200
+ const request = {
201
+ officeId: officeId,
202
+ agentId: agentId,
203
+ payload: {
204
+ code: voucher.code,
205
+ otherCodes: bookRequest?.payload.voucherCodes ?? [],
206
+ },
207
+ } as BookingPackageRequest<BookingPackageVoucherRequest>;
208
+
209
+ const tideClientConfig = buildTideClientConfig(apiSettings);
210
+ if (!tideClientConfig) return;
211
+
212
+ const result = await validateVoucher(tideClientConfig, request);
213
+
214
+ if (result) {
215
+ setVoucher({
216
+ ...voucher,
217
+ isValidated: true,
218
+ isValid: result.isValid,
219
+ });
220
+ }
221
+ };
222
+
223
+ const handleAddVoucher: React.MouseEventHandler<HTMLButtonElement> = (
224
+ event
225
+ ) => {
226
+ if (!voucher.isValid) return;
227
+
228
+ dispatch(
229
+ setVoucherCodes(
230
+ [
231
+ ...(bookRequest?.payload.voucherCodes ?? []),
232
+ voucher.code ?? "",
233
+ ].filter((x) => x !== "")
234
+ )
235
+ );
236
+
237
+ dispatch(fetchPriceDetails());
238
+
239
+ setVoucher({});
240
+ };
241
+
242
+ const handleRemoveVoucher = (code: string) => {
243
+ dispatch(
244
+ setVoucherCodes(
245
+ bookRequest?.payload.voucherCodes?.filter((x) => x !== code) ?? []
246
+ )
247
+ );
248
+
249
+ dispatch(fetchPriceDetails());
250
+ };
251
+
252
+ const goPrevious = () => {
253
+ dispatch(setCurrentStep(TRAVELERS_FORM_STEP));
254
+ };
255
+
256
+ const translations = useSelector(selectTranslations);
257
+
258
+ return (
259
+ <>
260
+ {isSubmitting && settings.loaderComponent}
261
+ {!isSubmitting && (
262
+ <form
263
+ className="form"
264
+ name="booking--summary"
265
+ id="booking--summary"
266
+ onSubmit={handleSubmit}
267
+ >
268
+ <div className="form__booking--summary">
269
+ <div className="form__region">
270
+ <div className="form__row">
271
+ <div className="form__group">
272
+ <div className="form__region-header">
273
+ <h5 className="form__region-heading">
274
+ {translations.SUMMARY.PERSONAL_DETAILS}
275
+ </h5>
276
+ </div>
277
+ </div>
278
+ </div>
279
+ {rooms.map((r, rIndex) => (
280
+ <div className="form__row">
281
+ <div className="form__group">
282
+ <div className="form__region-header">
283
+ <h5 className="form__region-heading">
284
+ {translations.SHARED.ROOM} {rIndex + 1}
285
+ </h5>
286
+ <p className="form__region-label">
287
+ {`${r.adults.length + r.children.length} ${
288
+ r.adults.length + r.children.length === 1
289
+ ? translations.SUMMARY.TRAVELER
290
+ : translations.SUMMARY.TRAVELERS
291
+ }: ${compact([
292
+ r.adults.length,
293
+ r.adults.length === 1 &&
294
+ ` ${translations.SUMMARY.ADULT}`,
295
+ r.adults.length > 1 &&
296
+ ` ${translations.SUMMARY.ADULTS}`,
297
+ r.adults &&
298
+ r.adults.length &&
299
+ r.children &&
300
+ r.children.length &&
301
+ ", ",
302
+ r.children.length,
303
+ r.children.length === 1 &&
304
+ ` ${translations.SUMMARY.CHILD}`,
305
+ r.children.length > 1 &&
306
+ ` ${translations.SUMMARY.CHILDREN}`,
307
+ ]).join("")}`}
308
+ </p>
309
+ </div>
310
+ </div>
311
+ {[...r.adults, ...r.children].map((traveler) => {
312
+ const isMainBooker =
313
+ traveler.id === travelerFormValues?.mainBookerId;
314
+ return (
315
+ <div
316
+ className="form__group form__group--sm-50"
317
+ key={traveler.id}
318
+ >
319
+ <ul className="list list--plain">
320
+ <li className="list__item">
321
+ <strong>
322
+ {traveler.firstName} {traveler.lastName}
323
+ </strong>{" "}
324
+ {isMainBooker && (
325
+ <em>({translations.SUMMARY.MAIN_BOOKER})</em>
326
+ )}
327
+ </li>
328
+ <li className="list__item">
329
+ {traveler.birthDate.split("-").reverse().join("/")}
330
+ </li>
331
+ {isMainBooker && travelerFormValues?.street && (
332
+ <>
333
+ <li className="list__item">{`${
334
+ travelerFormValues?.street
335
+ } ${compact([
336
+ travelerFormValues?.houseNumber,
337
+ travelerFormValues?.box,
338
+ ]).join(" ")}, ${travelerFormValues?.zipCode} ${
339
+ travelerFormValues?.place
340
+ }`}</li>
341
+ <li className="list__item">
342
+ {travelerFormValues?.phone}
343
+ </li>
344
+ <li className="list__item">
345
+ {travelerFormValues?.email}
346
+ </li>
347
+ </>
348
+ )}
349
+ </ul>
350
+ </div>
351
+ );
352
+ })}
353
+ </div>
354
+ ))}
355
+ </div>
356
+
357
+ <div className="form__region">
358
+ <div className="form__row">
359
+ <div className="form__group">
360
+ <div className="form__region-header">
361
+ <h5 className="form__region-heading">
362
+ {translations.SUMMARY.OPTIONS}
363
+ </h5>
364
+ </div>
365
+ </div>
366
+ </div>
367
+ <div className="form__row">
368
+ <div className="form__group">
369
+ <ul className="list list--booking-summary">
370
+ <li>
371
+ <h6>{activeOption?.name}</h6>
372
+ <ul>
373
+ {activeOption?.rooms.map((r, ri) => {
374
+ const roomOption = r.options.find(
375
+ (x) => x.isSelected
376
+ );
377
+ return (
378
+ <li key={ri} className="list__item">
379
+ {roomOption?.accommodationName}
380
+ {!isNil(roomOption?.regimeName) && ", "}
381
+ {roomOption?.regimeName}
382
+ </li>
383
+ );
384
+ })}
385
+ </ul>
386
+ <p>
387
+ ({getDateText(activeOption?.fromDate)} &gt;{" "}
388
+ {getDateText(activeOption?.toDate)})
389
+ </p>
390
+ </li>
391
+ {!isEmpty(activeOption?.groups) &&
392
+ activeOption?.groups.map((x, i) => {
393
+ if (!x.options.some((y) => y.isSelected)) return;
394
+
395
+ return <SummaryBookingOption key={i} group={x} />;
396
+ })}
397
+ {!isEmpty(activeOption?.optionUnits) &&
398
+ activeOption?.optionUnits.map((x, i) => (
399
+ <SummaryBookingOptionUnit key={i} unit={x} />
400
+ ))}
401
+ {!isEmpty(activeOption?.optionPax) &&
402
+ activeOption?.optionPax.map((x, i) => (
403
+ <SummaryBookingOptionPax key={i} pax={x} />
404
+ ))}
405
+ {packageDetails?.outwardFlights &&
406
+ packageDetails.outwardFlights
407
+ .filter((x) => x.isSelected)
408
+ .map((flight, i) => (
409
+ <SummaryFlight
410
+ key={i}
411
+ flight={flight}
412
+ header={translations.SIDEBAR.DEPARTURE_FLIGHT}
413
+ />
414
+ ))}
415
+ {packageDetails?.returnFlights &&
416
+ packageDetails.returnFlights
417
+ .filter((x) => x.isSelected)
418
+ .map((flight, i) => (
419
+ <SummaryFlight
420
+ key={i}
421
+ flight={flight}
422
+ header={translations.SIDEBAR.ARRIVAL_FLIGHT}
423
+ />
424
+ ))}
425
+ </ul>
426
+ </div>
427
+ </div>
428
+ </div>
429
+
430
+ {settings.enableVoucher && (
431
+ <div className="form__region">
432
+ <div className="form__row">
433
+ <div className="form__group">
434
+ <div className="form__region-header">
435
+ <h5 className="form__region-heading">
436
+ {translations.SUMMARY.VOUCHERS}
437
+ </h5>
438
+ </div>
439
+ </div>
440
+ </div>
441
+ <div className="form__row">
442
+ <div className="form__group">
443
+ <input
444
+ type="text"
445
+ className="form__input info-message__voucher__input"
446
+ defaultValue={voucher.code}
447
+ onChange={(e) => setVoucher({ code: e.target.value })}
448
+ />
449
+ <button
450
+ type="button"
451
+ className={buildClassName([
452
+ "cta",
453
+ !voucher.code && "cta--disabled",
454
+ ])}
455
+ onClick={(e) => handleValidateVoucher()}
456
+ >
457
+ {translations.SUMMARY.VOUCHER_VALIDATE}
458
+ </button>
459
+ </div>
460
+ </div>
461
+ <div className="form__row">
462
+ <div className="form__group info-message__voucher">
463
+ {voucher.isValid && voucher.isValidated && (
464
+ <div className="info-message info-message__voucher__valid">
465
+ <span>{translations.SUMMARY.VOUCHER_VALID}</span>
466
+ <button
467
+ type="button"
468
+ className="cta cta--secondary"
469
+ onClick={handleAddVoucher}
470
+ >
471
+ {translations.SUMMARY.ADD_VOUCHER}
472
+ </button>
473
+ </div>
474
+ )}
475
+ {!voucher.isValid && voucher.isValidated && (
476
+ <div className="info-message--error">
477
+ {translations.SUMMARY.VOUCHER_INVALID}
478
+ </div>
479
+ )}
480
+ </div>
481
+ </div>
482
+ <div className="form__row">
483
+ <ul className="info-message__voucher">
484
+ {!isEmpty(bookRequest?.payload.voucherCodes) &&
485
+ bookRequest?.payload.voucherCodes?.map((y, i) => (
486
+ <li key={i}>
487
+ <div className="info-message__voucher__list">
488
+ {y}{" "}
489
+ <button
490
+ type="button"
491
+ className="cta--add-remove"
492
+ onClick={(e) => handleRemoveVoucher(y)}
493
+ >
494
+ <Icon height={16} name="ui-trashcan" />
495
+ </button>
496
+ </div>
497
+ </li>
498
+ ))}
499
+ </ul>
500
+ </div>
501
+ </div>
502
+ )}
503
+
504
+ {!isEmpty(notifications) && (
505
+ <div className="form__region">
506
+ <div className="form__row">
507
+ <div className="form__group">
508
+ <div className="info-message">
509
+ <Icon
510
+ name="ui-tooltip"
511
+ className="icon--secondary-color"
512
+ />
513
+ <div className="info-message__copy">
514
+ <h5>{translations.SUMMARY.NOTIFICATIONS_TITLE}</h5>
515
+ <>
516
+ {uniqBy(
517
+ notifications.filter((x) => !x.hasToBeConfirmed),
518
+ "id"
519
+ ).map((notification) => (
520
+ <span
521
+ key={notification.id}
522
+ className="checkbox__label-text"
523
+ >
524
+ <strong className="checkbox__label-text--title">
525
+ {notification.title}
526
+ </strong>
527
+ <span className="checkbox__label-text--description">
528
+ {notification.description}
529
+ </span>
530
+ </span>
531
+ ))}
532
+ {uniqBy(
533
+ notifications.filter((x) => x.hasToBeConfirmed),
534
+ "id"
535
+ ).map((notification) => (
536
+ <div className="checkbox" key={notification.id}>
537
+ <label className="checkbox__label">
538
+ <input
539
+ type="checkbox"
540
+ className="checkbox__input"
541
+ checked={notification.isConfirmed}
542
+ onChange={(e) =>
543
+ handleNotificationChange(
544
+ notification.id,
545
+ e.target.checked
546
+ )
547
+ }
548
+ />
549
+ <span className="checkbox__label-text">
550
+ <strong className="checkbox__label-text--title">
551
+ {notification.title}
552
+ </strong>
553
+ <span className="checkbox__label-text--description">
554
+ {notification.description}
555
+ </span>
556
+ </span>
557
+ </label>
558
+ </div>
559
+ ))}
560
+ </>
561
+ </div>
562
+ </div>
563
+ </div>
564
+ </div>
565
+ </div>
566
+ )}
567
+
568
+ <div className="form__region">
569
+ <div className="form__row">
570
+ <div className="form__group">
571
+ <div className="form__region-header">
572
+ <h5 className="form__region-heading">
573
+ {translations.SUMMARY.REMARKS}
574
+ </h5>
575
+ </div>
576
+ </div>
577
+ </div>
578
+ <div className="form__row">
579
+ <div className="form__group">
580
+ <textarea
581
+ className="form__input"
582
+ defaultValue={remarks}
583
+ onChange={(e) => handleRemarksChange(e.target.value)}
584
+ ></textarea>
585
+ </div>
586
+ </div>
587
+ </div>
588
+
589
+ <div className="form__region">
590
+ <div className="form__row">
591
+ <div className="form__group">
592
+ <div className="info-message">
593
+ <Icon name="ui-tooltip" className="icon--secondary-color" />
594
+ <div className="info-message__copy">
595
+ <h5>{translations.SUMMARY.VALIDATE_TITLE}</h5>
596
+ <p>
597
+ {settings.isOffer
598
+ ? translations.SUMMARY.VALIDATE_TEXT_OFFER
599
+ : translations.SUMMARY.VALIDATE_TEXT_BOOKING}
600
+ </p>
601
+ {checkboxes &&
602
+ checkboxes.map((checkbox) => (
603
+ <div className="checkbox" key={checkbox.id}>
604
+ <label className="checkbox__label">
605
+ <input
606
+ type="checkbox"
607
+ className="checkbox__input"
608
+ checked={checkbox.isSelected}
609
+ onChange={(e) =>
610
+ handleCheckboxChange(
611
+ checkbox.id,
612
+ e.target.checked
613
+ )
614
+ }
615
+ />
616
+ <span
617
+ className="checkbox__label-text"
618
+ dangerouslySetInnerHTML={{
619
+ __html: checkbox.text,
620
+ }}
621
+ />
622
+ </label>
623
+ </div>
624
+ ))}
625
+ </div>
626
+ </div>
627
+ </div>
628
+ </div>
629
+ </div>
630
+ </div>
631
+
632
+ <div className="booking__navigator">
633
+ {settings.skipRouter ? (
634
+ <button
635
+ type="button"
636
+ title={translations.STEPS.PREVIOUS}
637
+ onClick={() => goPrevious()}
638
+ className="cta cta--secondary"
639
+ >
640
+ {translations.STEPS.PREVIOUS}
641
+ </button>
642
+ ) : (
643
+ <Link
644
+ to={`${settings.basePath}${settings.travellers.pathSuffix}?${bookingQueryString}`}
645
+ title={translations.STEPS.PREVIOUS}
646
+ className="cta cta--secondary"
647
+ >
648
+ {translations.STEPS.PREVIOUS}
649
+ </Link>
650
+ )}
651
+ <button
652
+ title={
653
+ settings.isOffer
654
+ ? translations.STEPS.SUBMIT_OFFER
655
+ : translations.STEPS.SUBMIT_BOOKING
656
+ }
657
+ className={buildClassName([
658
+ "cta",
659
+ !userValidated && "cta--disabled",
660
+ ])}
661
+ disabled={!userValidated}
662
+ >
663
+ {settings.isOffer
664
+ ? translations.STEPS.SUBMIT_OFFER
665
+ : translations.STEPS.SUBMIT_BOOKING}
666
+ </button>
667
+ </div>
668
+ </form>
669
+ )}
670
+ </>
671
+ );
672
+ };
673
+
674
+ export default Summary;