@travelswitchhq/flight-search-react 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.
package/dist/index.mjs CHANGED
@@ -38,6 +38,41 @@ var buildEncryptedToken = (domainName) => {
38
38
  const encrypted = encryptor.encrypt(payload);
39
39
  return typeof encrypted === "string" ? encrypted : null;
40
40
  };
41
+ var MACHINE_ID_STORAGE_KEY = "MacId";
42
+ var generateUuid = () => {
43
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
44
+ return crypto.randomUUID();
45
+ }
46
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
47
+ const r = Math.random() * 16 | 0;
48
+ return (c === "x" ? r : r & 3 | 8).toString(16);
49
+ });
50
+ };
51
+ var getMachineId = () => {
52
+ try {
53
+ let machineId = localStorage.getItem(MACHINE_ID_STORAGE_KEY);
54
+ if (!machineId) {
55
+ machineId = generateUuid();
56
+ localStorage.setItem(MACHINE_ID_STORAGE_KEY, machineId);
57
+ }
58
+ return machineId;
59
+ } catch {
60
+ return generateUuid();
61
+ }
62
+ };
63
+ var generateTokenKey = (domainName) => {
64
+ const domain = normalizeDomainName(domainName);
65
+ const affiliateId = "";
66
+ const loggedInUserId = "";
67
+ const orgId = "";
68
+ return [domain, (/* @__PURE__ */ new Date()).getTime(), affiliateId, loggedInUserId, orgId, "", "", getMachineId()].join("~");
69
+ };
70
+ var buildEncryptedTokenKey = (domainName) => {
71
+ const encryptor = new JSEncrypt();
72
+ encryptor.setPublicKey(RSA_PUBLIC_KEY);
73
+ const encrypted = encryptor.encrypt(generateTokenKey(domainName));
74
+ return typeof encrypted === "string" ? encrypted : "";
75
+ };
41
76
  var PRIMEICONS_LINK_ID = "tfsw-primeicons";
42
77
  var RSA_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
43
78
  MIICITANBgkqhkiG9w0BAQEFAAOCAg4AMIICCQKCAgB0rRSHGZK/FtK15IRfQxtl
@@ -207,7 +242,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
207
242
  if (!searchKeyword.trim()) return [];
208
243
  const url = `${airportSearchApiBaseUrl.replace(/\/$/, "")}/Airport/GetList/${encodeURIComponent(langCode)}/${encodeURIComponent(searchKeyword.trim())}`;
209
244
  try {
210
- const res = await fetch(url);
245
+ const res = await fetch(url, { headers: { Token: buildEncryptedTokenKey(redirectionDomain ?? "") } });
211
246
  if (!res.ok) return [];
212
247
  const data = await res.json();
213
248
  if (Array.isArray(data)) return data;
@@ -217,7 +252,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
217
252
  } catch {
218
253
  return [];
219
254
  }
220
- }, [airportSearchApiBaseUrl, langCode]);
255
+ }, [airportSearchApiBaseUrl, langCode, redirectionDomain]);
221
256
  const getAirlineListBySearch = useCallback(async (searchKeyword) => {
222
257
  if (!searchKeyword.trim()) return [];
223
258
  const lang = (langCode ?? "en").toUpperCase();
@@ -420,6 +455,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
420
455
  useEffect(() => {
421
456
  const handleClickOutside = (event) => {
422
457
  const target = event.target;
458
+ if (target.closest("[data-tfsw-sheet]")) return;
423
459
  const isInsidePrimeDropdown = Boolean(
424
460
  target.closest(".p-dropdown-panel") || target.closest(".p-dropdown-items-wrapper") || target.closest(".p-dropdown-item") || target.closest('[data-pc-section="panel"]') || target.closest('[data-pc-name="dropdown"]')
425
461
  );
@@ -2977,7 +3013,8 @@ function FlightSearchFormStandard({
2977
3013
  }
2978
3014
 
2979
3015
  // src/modern/Modern.tsx
2980
- import { useId, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
3016
+ import { useEffect as useEffect3, useId, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
3017
+ import { createPortal } from "react-dom";
2981
3018
  import { Calendar as Calendar2 } from "primereact/calendar";
2982
3019
  import { PrimeReactProvider as PrimeReactProvider2 } from "primereact/api";
2983
3020
 
@@ -3804,6 +3841,13 @@ var modernStyles = `
3804
3841
  font-size: 15px;
3805
3842
  }
3806
3843
 
3844
+ /* Sheets are portalled to <body> (see renderSheet in Modern.tsx); the wrapper only carries the theme
3845
+ variables and must sit above any fixed host chrome such as an app's bottom tab bar. */
3846
+ .mdrn_root.mdrn_portal {
3847
+ --mdrn-z: 2147483000;
3848
+ display: contents;
3849
+ }
3850
+
3807
3851
  /* Dropdowns become full-screen sheets */
3808
3852
  .mdrn_dropdown,
3809
3853
  .mdrn_panel {
@@ -4036,6 +4080,33 @@ function FlightSearchFormModern({ config, ssoUser }) {
4036
4080
  if (fontName) style["--mdrn-font"] = fontName;
4037
4081
  return style;
4038
4082
  }, [theme?.primary, theme?.primaryLight, fontName]);
4083
+ const [isMobile, setIsMobile] = useState2(false);
4084
+ useEffect3(() => {
4085
+ const query = window.matchMedia("(max-width: 1024px)");
4086
+ const sync = () => setIsMobile(query.matches);
4087
+ sync();
4088
+ query.addEventListener("change", sync);
4089
+ return () => query.removeEventListener("change", sync);
4090
+ }, []);
4091
+ const renderSheet = (sheet) => isMobile ? createPortal(/* @__PURE__ */ jsx2("div", { className: "mdrn_root mdrn_portal", style: themeStyle, "data-tfsw-sheet": "", children: sheet }), document.body) : sheet;
4092
+ const [calendarHost, setCalendarHost] = useState2(null);
4093
+ const [openMobileCalendar, setOpenMobileCalendar] = useState2(null);
4094
+ const mobileCalendarProps = (key) => ({
4095
+ appendTo: calendarHost ?? "self",
4096
+ onShow: () => setOpenMobileCalendar(key),
4097
+ onHide: () => setOpenMobileCalendar((current) => current === key ? null : current)
4098
+ });
4099
+ useEffect3(() => setOpenMobileCalendar(null), [tripType, segments.length]);
4100
+ const isSheetOpen = isMobile && (isOriginDropdownOpen || isDestinationDropdownOpen || isRoomsGuestsMenuOpen || openMobileCalendar !== null || Object.values(segmentDropdowns).some((entry) => Boolean(entry?.origin || entry?.destination)));
4101
+ useEffect3(() => {
4102
+ if (!isSheetOpen) return;
4103
+ const { body } = document;
4104
+ const previousOverflow = body.style.overflow;
4105
+ body.style.overflow = "hidden";
4106
+ return () => {
4107
+ body.style.overflow = previousOverflow;
4108
+ };
4109
+ }, [isSheetOpen]);
4039
4110
  const isMultiCity = tripType === "multi-city" || tripType === "custom-search";
4040
4111
  const first = segments[0];
4041
4112
  const travellerCount = (first?.adultCount ?? 0) + (first?.childCount ?? 0) + (first?.infantCount ?? 0);
@@ -4096,44 +4167,46 @@ function FlightSearchFormModern({ config, ssoUser }) {
4096
4167
  /* @__PURE__ */ jsxs2("div", { className: "mdrn_custom-dropdown", ref: dropdownRef, children: [
4097
4168
  /* @__PURE__ */ jsx2("input", { ...inputProps, id: inputId, className: "mdrn_input mdrn_desktop-only" }),
4098
4169
  /* @__PURE__ */ jsx2("input", { ...inputProps, id: `${inputId}-mobile`, readOnly: true, className: "mdrn_input mdrn_mobile-only" }),
4099
- isOpen && /* @__PURE__ */ jsxs2("div", { className: "mdrn_dropdown", children: [
4100
- renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4101
- /* @__PURE__ */ jsx2("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ jsx2(
4102
- "input",
4103
- {
4104
- type: "search",
4105
- autoFocus: true,
4106
- placeholder: `Search ${placeholder.toLowerCase()}`,
4107
- value: value === placeholder ? "" : value,
4108
- onChange: (e) => onSearch(e.target.value),
4109
- onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4110
- }
4111
- ) }),
4112
- /* @__PURE__ */ jsx2("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4113
- /* @__PURE__ */ jsx2("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4114
- const isActive = results.length > 0 && selectedIndex === i;
4115
- return /* @__PURE__ */ jsxs2(
4116
- "li",
4170
+ isOpen && renderSheet(
4171
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_dropdown", children: [
4172
+ renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4173
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ jsx2(
4174
+ "input",
4117
4175
  {
4118
- role: "option",
4119
- "aria-selected": isActive,
4120
- className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4121
- onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4122
- children: [
4123
- /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4124
- /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-text", children: [
4125
- /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4126
- /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-place", children: [
4127
- airport.ct,
4128
- airport.cn ? `, ${airport.cn}` : ""
4176
+ type: "search",
4177
+ autoFocus: true,
4178
+ placeholder: `Search ${placeholder.toLowerCase()}`,
4179
+ value: value === placeholder ? "" : value,
4180
+ onChange: (e) => onSearch(e.target.value),
4181
+ onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4182
+ }
4183
+ ) }),
4184
+ /* @__PURE__ */ jsx2("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4185
+ /* @__PURE__ */ jsx2("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4186
+ const isActive = results.length > 0 && selectedIndex === i;
4187
+ return /* @__PURE__ */ jsxs2(
4188
+ "li",
4189
+ {
4190
+ role: "option",
4191
+ "aria-selected": isActive,
4192
+ className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4193
+ onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4194
+ children: [
4195
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4196
+ /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-text", children: [
4197
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4198
+ /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-place", children: [
4199
+ airport.ct,
4200
+ airport.cn ? `, ${airport.cn}` : ""
4201
+ ] })
4129
4202
  ] })
4130
- ] })
4131
- ]
4132
- },
4133
- airport.id ?? airport.ac ?? i
4134
- );
4135
- }) })
4136
- ] })
4203
+ ]
4204
+ },
4205
+ airport.id ?? airport.ac ?? i
4206
+ );
4207
+ }) })
4208
+ ] })
4209
+ )
4137
4210
  ] })
4138
4211
  ] });
4139
4212
  };
@@ -4177,7 +4250,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4177
4250
  {
4178
4251
  ref: mobileDateRangeCalendarRef,
4179
4252
  numberOfMonths: 10,
4180
- appendTo: "self",
4253
+ ...mobileCalendarProps("round-trip"),
4181
4254
  selectionMode: "range",
4182
4255
  readOnlyInput: true,
4183
4256
  value: first?.dateRange ?? null,
@@ -4223,7 +4296,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4223
4296
  {
4224
4297
  ref: oneWayMobileCalendarRef,
4225
4298
  numberOfMonths: 10,
4226
- appendTo: "self",
4299
+ ...mobileCalendarProps("one-way"),
4227
4300
  readOnlyInput: true,
4228
4301
  value: first?.departureDate ?? null,
4229
4302
  minDate: /* @__PURE__ */ new Date(),
@@ -4267,7 +4340,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4267
4340
  segmentMobileCalendarRefs.current[index] = el;
4268
4341
  },
4269
4342
  numberOfMonths: 10,
4270
- appendTo: "self",
4343
+ ...mobileCalendarProps(`segment-${index}`),
4271
4344
  readOnlyInput: true,
4272
4345
  value: segment.departureDate ?? null,
4273
4346
  minDate: getMinDateForSegment(index),
@@ -4294,49 +4367,51 @@ function FlightSearchFormModern({ config, ssoUser }) {
4294
4367
  ]
4295
4368
  }
4296
4369
  ),
4297
- isRoomsGuestsMenuOpen && /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4298
- renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4299
- /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-body", children: [
4300
- /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4301
- PASSENGER_ROWS.map((row) => /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-row", children: [
4302
- /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-info", children: [
4303
- /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-label", children: row.label }),
4304
- /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-hint", children: row.hint })
4305
- ] }),
4306
- /* @__PURE__ */ jsx2("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4307
- const isActive = (first?.[row.field] ?? 0) === count;
4308
- return /* @__PURE__ */ jsx2(
4309
- "button",
4370
+ isRoomsGuestsMenuOpen && renderSheet(
4371
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4372
+ renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4373
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-body", children: [
4374
+ /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4375
+ PASSENGER_ROWS.map((row) => /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-row", children: [
4376
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-info", children: [
4377
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-label", children: row.label }),
4378
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-hint", children: row.hint })
4379
+ ] }),
4380
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4381
+ const isActive = (first?.[row.field] ?? 0) === count;
4382
+ return /* @__PURE__ */ jsx2(
4383
+ "button",
4384
+ {
4385
+ type: "button",
4386
+ className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4387
+ disabled: isPassengerOptionDisabled(row.field, count),
4388
+ onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4389
+ children: count
4390
+ },
4391
+ count
4392
+ );
4393
+ }) })
4394
+ ] }, row.field)),
4395
+ /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4396
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ jsxs2("label", { className: "mdrn_chip", children: [
4397
+ /* @__PURE__ */ jsx2(
4398
+ "input",
4310
4399
  {
4311
- type: "button",
4312
- className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4313
- disabled: isPassengerOptionDisabled(row.field, count),
4314
- onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4315
- children: count
4316
- },
4317
- count
4318
- );
4319
- }) })
4320
- ] }, row.field)),
4321
- /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4322
- /* @__PURE__ */ jsx2("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ jsxs2("label", { className: "mdrn_chip", children: [
4323
- /* @__PURE__ */ jsx2(
4324
- "input",
4325
- {
4326
- type: "radio",
4327
- name: `${uid}-travel-class`,
4328
- checked: (first?.travelerClass ?? "Economy") === travelClass,
4329
- onChange: () => handleTravellerChange("travelerClass", travelClass)
4330
- }
4331
- ),
4332
- /* @__PURE__ */ jsx2("span", { children: travelClass })
4333
- ] }, travelClass)) })
4334
- ] }),
4335
- /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-foot", children: [
4336
- /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4337
- /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4400
+ type: "radio",
4401
+ name: `${uid}-travel-class`,
4402
+ checked: (first?.travelerClass ?? "Economy") === travelClass,
4403
+ onChange: () => handleTravellerChange("travelerClass", travelClass)
4404
+ }
4405
+ ),
4406
+ /* @__PURE__ */ jsx2("span", { children: travelClass })
4407
+ ] }, travelClass)) })
4408
+ ] }),
4409
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-foot", children: [
4410
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4411
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4412
+ ] })
4338
4413
  ] })
4339
- ] })
4414
+ )
4340
4415
  ] });
4341
4416
  const searchButton = /* @__PURE__ */ jsx2("button", { type: "submit", className: "mdrn_search", children: "Search" });
4342
4417
  const renderMultiCity = () => /* @__PURE__ */ jsxs2("div", { className: "mdrn_mc", children: [
@@ -4417,7 +4492,11 @@ function FlightSearchFormModern({ config, ssoUser }) {
4417
4492
  /* @__PURE__ */ jsx2("span", { className: "mdrn_checkbox-box", "aria-hidden": "true" }),
4418
4493
  label
4419
4494
  ] }, key)) })
4420
- ] })
4495
+ ] }),
4496
+ isMobile && createPortal(
4497
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_root mdrn_portal", style: themeStyle, children: /* @__PURE__ */ jsx2("div", { className: "mdrn_calendar", ref: setCalendarHost }) }),
4498
+ document.body
4499
+ )
4421
4500
  ] }) });
4422
4501
  }
4423
4502