@travelswitchhq/flight-search-react 1.1.3 → 1.1.4

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.d.cts CHANGED
@@ -45,6 +45,18 @@ type FlightSearchWidgetProps = {
45
45
  fontName?: string;
46
46
  /** "dev" | "prod" – selects API base URLs. Defaults to "dev". */
47
47
  env?: FlightSearchEnv;
48
+ /**
49
+ * ISO 3166-1 alpha-2 country code (e.g. "AE").
50
+ * When set, the search redirect becomes `{base}/{countryCode}-{languageSegment}/flight/listing?...`
51
+ * where `languageSegment` is {@link languageCode} uppercased, or "EN" if {@link languageCode} is omitted.
52
+ */
53
+ countryCode?: string;
54
+ /**
55
+ * Language code for airport/airline APIs and the `lc` query param (e.g. "en", "ar").
56
+ * Defaults to `"en"` when omitted.
57
+ * If {@link countryCode} is set and this is omitted, the locale path segment still uses "EN".
58
+ */
59
+ languageCode?: string;
48
60
  };
49
61
  ssoUser?: FlightSearchSsoUser;
50
62
  };
package/dist/index.d.ts CHANGED
@@ -45,6 +45,18 @@ type FlightSearchWidgetProps = {
45
45
  fontName?: string;
46
46
  /** "dev" | "prod" – selects API base URLs. Defaults to "dev". */
47
47
  env?: FlightSearchEnv;
48
+ /**
49
+ * ISO 3166-1 alpha-2 country code (e.g. "AE").
50
+ * When set, the search redirect becomes `{base}/{countryCode}-{languageSegment}/flight/listing?...`
51
+ * where `languageSegment` is {@link languageCode} uppercased, or "EN" if {@link languageCode} is omitted.
52
+ */
53
+ countryCode?: string;
54
+ /**
55
+ * Language code for airport/airline APIs and the `lc` query param (e.g. "en", "ar").
56
+ * Defaults to `"en"` when omitted.
57
+ * If {@link countryCode} is set and this is omitted, the locale path segment still uses "EN".
58
+ */
59
+ languageCode?: string;
48
60
  };
49
61
  ssoUser?: FlightSearchSsoUser;
50
62
  };
package/dist/index.mjs CHANGED
@@ -1469,7 +1469,9 @@ function FlightSearchWidget({
1469
1469
  const urls = API_URLS[env];
1470
1470
  const airportSearchApiBaseUrl = urls.airport;
1471
1471
  const airlineSearchApiBaseUrl = urls.airline;
1472
- const langCode = "en";
1472
+ const countryCodeConfig = (config?.countryCode ?? "").trim();
1473
+ const languageCodeConfig = (config?.languageCode ?? "").trim();
1474
+ const langCode = languageCodeConfig || "en";
1473
1475
  const [airlineQuery, setAirlineQuery] = useState("");
1474
1476
  const [airlineSuggestions, setAirlineSuggestions] = useState([]);
1475
1477
  const [selectedAirlines, setSelectedAirlines] = useState([]);
@@ -1515,6 +1517,7 @@ function FlightSearchWidget({
1515
1517
  const [isDestinationDropdownOpen, setIsDestinationDropdownOpen] = useState(false);
1516
1518
  const [isRoomsGuestsMenuOpen, setIsRoomsGuestsMenuOpen] = useState(false);
1517
1519
  const originDropdownRef = useRef(null);
1520
+ const firstOriginDesktopInputRef = useRef(null);
1518
1521
  const destinationDropdownRef = useRef(null);
1519
1522
  const roomsGuestsMenuRef = useRef(null);
1520
1523
  const dateRangeCalendarRef = useRef(null);
@@ -1745,6 +1748,21 @@ function FlightSearchWidget({
1745
1748
  ensureStylesInjected();
1746
1749
  ensurePrimeIconsLoaded();
1747
1750
  }, []);
1751
+ useEffect(() => {
1752
+ if (typeof window === "undefined") return;
1753
+ const focusFirstOrigin = () => {
1754
+ const desktop = firstOriginDesktopInputRef.current;
1755
+ desktop?.focus({ preventScroll: true });
1756
+ };
1757
+ let innerRaf = 0;
1758
+ const outerRaf = window.requestAnimationFrame(() => {
1759
+ innerRaf = window.requestAnimationFrame(focusFirstOrigin);
1760
+ });
1761
+ return () => {
1762
+ window.cancelAnimationFrame(outerRaf);
1763
+ if (innerRaf) window.cancelAnimationFrame(innerRaf);
1764
+ };
1765
+ }, []);
1748
1766
  useEffect(() => {
1749
1767
  const handleClickOutside = (event) => {
1750
1768
  const target = event.target;
@@ -2098,7 +2116,8 @@ function FlightSearchWidget({
2098
2116
  console.log("Query String:", queryString);
2099
2117
  const base = getNormalizedRedirectionBase();
2100
2118
  if (base) {
2101
- const url = `${base}/flight/listing?${queryString}`;
2119
+ const listingPath = countryCodeConfig.length > 0 ? `/${countryCodeConfig.toUpperCase()}-${languageCodeConfig ? languageCodeConfig.toUpperCase() : "EN"}/flight/listing` : "/flight/listing";
2120
+ const url = `${base}${listingPath}?${queryString}`;
2102
2121
  window.location.href = url;
2103
2122
  }
2104
2123
  };
@@ -2130,6 +2149,7 @@ function FlightSearchWidget({
2130
2149
  const label = isOrigin ? "From" : "To";
2131
2150
  const list = isOrigin ? getPredictiveState(segmentIndex).fromAirport : getPredictiveState(segmentIndex).toAirport;
2132
2151
  const selectedIndex = isOrigin ? getPredictiveState(segmentIndex).selectedFromIndex : getPredictiveState(segmentIndex).selectedToIndex;
2152
+ const isFirstOrigin = segmentIndex === 0 && isOrigin;
2133
2153
  return /* @__PURE__ */ jsxs("div", { className: `sw-form-field sw-pos-rel${isOrigin ? " br-left" : ""} ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-is-invalid" : ""}`, children: [
2134
2154
  /* @__PURE__ */ jsx("label", { htmlFor: `${dropdownType}-${segmentIndex}`, children: label }),
2135
2155
  /* @__PURE__ */ jsxs("div", { className: `sw-custom-dropdown ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-has-error" : ""}`, ref: dropdownRef, children: [
@@ -2160,6 +2180,7 @@ function FlightSearchWidget({
2160
2180
  {
2161
2181
  type: "text",
2162
2182
  id: `${dropdownType}-${segmentIndex}`,
2183
+ ref: isFirstOrigin ? firstOriginDesktopInputRef : void 0,
2163
2184
  className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2164
2185
  value: value === placeholder ? "" : value ?? "",
2165
2186
  placeholder,