@odynn/awayz-hotels 0.2.8 → 0.2.9

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.
@@ -1,31 +1,31 @@
1
1
  import { jsxs as a, jsx as n } from "react/jsx-runtime";
2
- import { a as m, b as d } from "../../../index-D8bHwbxH.js";
3
- import '../../../assets/Ratings.css';var p = /* @__PURE__ */ ((r) => (r.INHERIT = "inherit", r.PRIMARY = "primary", r.LIGHT = "light", r.DARK = "dark", r))(p || {});
4
- const u = ({
2
+ import { a as p, b as o } from "../../../index-D8bHwbxH.js";
3
+ import '../../../assets/Ratings.css';var h = /* @__PURE__ */ ((r) => (r.INHERIT = "inherit", r.PRIMARY = "primary", r.LIGHT = "light", r.DARK = "dark", r))(h || {});
4
+ const f = ({
5
5
  starRating: r,
6
6
  userRating: e,
7
- color: t = "dark",
8
- fill: c = !1,
9
- starColor: s = "primary"
7
+ color: m = "dark",
8
+ fill: t = !1,
9
+ starColor: l = "primary"
10
10
  /* PRIMARY */
11
11
  }) => {
12
- const l = !e || e === 0 || e.toString().toLowerCase() === "none";
13
- if (!r && l) return null;
14
- const i = r ? c ? /* @__PURE__ */ n(m, { className: s }) : /* @__PURE__ */ n(d, { className: s }) : null;
15
- return /* @__PURE__ */ a("div", { className: `rating ${t}`, children: [
16
- i,
12
+ const s = !e || e === 0 || e.toString().toLowerCase() === "none";
13
+ if (!r && s) return null;
14
+ const d = typeof e == "number" ? Math.round(e) : typeof e == "string" && !isNaN(Number(e)) ? Math.round(Number(e)) : e, c = r ? t ? /* @__PURE__ */ n(p, { className: l }) : /* @__PURE__ */ n(o, { className: l }) : null;
15
+ return /* @__PURE__ */ a("div", { className: `rating ${m}`, children: [
16
+ c,
17
17
  r ? /* @__PURE__ */ a("p", { children: [
18
18
  r,
19
19
  "-star"
20
20
  ] }) : null,
21
- l ? null : /* @__PURE__ */ a("p", { children: [
21
+ s ? null : /* @__PURE__ */ a("p", { children: [
22
22
  "(",
23
- e,
23
+ d,
24
24
  " rating)"
25
25
  ] })
26
26
  ] });
27
27
  };
28
28
  export {
29
- p as ERatingColor,
30
- u as default
29
+ h as ERatingColor,
30
+ f as default
31
31
  };
@@ -1,5 +1,5 @@
1
1
  import { jsxs as o, jsx as t } from "react/jsx-runtime";
2
- import { useState as N, useRef as H, useEffect as m } from "react";
2
+ import { useState as N, useRef as x, useEffect as m } from "react";
3
3
  import '../../assets/_styles.css';/* empty css */
4
4
  import { o as S } from "../../stringUtils-CvWpky85.js";
5
5
  import "../../moment-BGjjqtLQ.js";
@@ -7,8 +7,8 @@ import "../../arrayExtensions-cyilNkdJ.js";
7
7
  import { UnavailableDate as B } from "../Banners/UnavailableDate/UnavailableDate.js";
8
8
  import { c as j, d as w, e as T, f as G, g as E } from "../../index-D8bHwbxH.js";
9
9
  import { HotelChains as v } from "../../definitions/HotelChains.js";
10
- import z, { ERatingColor as D } from "../Banners/Ratings/Ratings.js";
11
- import { getBookingOptions as L } from "../../utilities/hotelUtils/hotelUtils.js";
10
+ import U, { ERatingColor as z } from "../Banners/Ratings/Ratings.js";
11
+ import { getBookingOptions as D, getHotelImageUrls as L } from "../../utilities/hotelUtils/hotelUtils.js";
12
12
  import { CashValue as M } from "@odynn/awayz-core";
13
13
  const O = (...e) => e.join(" ");
14
14
  function P(e) {
@@ -16,7 +16,7 @@ function P(e) {
16
16
  let n = e == null ? void 0 : e.toString().split(".")[0];
17
17
  return n == null ? void 0 : n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
18
18
  }
19
- const te = ({
19
+ const oe = ({
20
20
  details: e,
21
21
  onHotelSelect: n,
22
22
  onViewDetails: C,
@@ -25,37 +25,37 @@ const te = ({
25
25
  showBookableTag: R = !1,
26
26
  customBookableTag: F = "Bookable"
27
27
  }) => {
28
- var g;
29
- const [i, u] = N(c), d = H(null), {
28
+ var f;
29
+ const [r, u] = N(c), d = x(null), {
30
30
  transferPartners: a,
31
31
  bestBookingOption: l,
32
32
  alternateBookingOption: s,
33
- hasPoints: V
34
- } = L(e), [r, I] = N(0), h = a == null ? void 0 : a[r], p = typeof e.cashValue.amount == "number" ? e.cashValue.amount : parseFloat(e.cashValue.amount), { currency: b } = e.cashValue, f = (h == null ? void 0 : h.value) > 0 || (l == null ? void 0 : l.value) > 0 || (s == null ? void 0 : s.value) > 0 || p > 0;
33
+ hasPoints: I
34
+ } = D(e), [i, V] = N(0), h = a == null ? void 0 : a[i], p = typeof e.cashValue.amount == "number" ? e.cashValue.amount : parseFloat(e.cashValue.amount), { currency: b } = e.cashValue, g = (h == null ? void 0 : h.value) > 0 || (l == null ? void 0 : l.value) > 0 || (s == null ? void 0 : s.value) > 0 || p > 0;
35
35
  m(() => {
36
36
  c !== void 0 && u(c);
37
37
  }, [c]), m(() => {
38
- const k = setTimeout(() => {
39
- const x = r >= (a == null ? void 0 : a.length) - 1 ? 0 : r + 1;
40
- return I(x), () => {
41
- clearTimeout(k);
38
+ const H = setTimeout(() => {
39
+ const k = i >= (a == null ? void 0 : a.length) - 1 ? 0 : i + 1;
40
+ return V(k), () => {
41
+ clearTimeout(H);
42
42
  };
43
43
  }, 2e3);
44
- }, [r, a == null ? void 0 : a.length]);
44
+ }, [i, a == null ? void 0 : a.length]);
45
45
  const A = v.isHotelChain(e.hotelGroup);
46
46
  return m(() => {
47
- i && d.current.scrollIntoView({
47
+ r && d.current.scrollIntoView({
48
48
  behavior: "smooth",
49
49
  block: "center"
50
50
  });
51
- }, [i]), /* @__PURE__ */ o(
51
+ }, [r]), /* @__PURE__ */ o(
52
52
  "div",
53
53
  {
54
54
  ref: d,
55
55
  className: O(
56
56
  y ? "hotel-result" : "awayz-hotel-result",
57
57
  // insufficient_points ? 'insufficient-points' : '',
58
- i ? "go-to-journey-button" : ""
58
+ r ? "go-to-journey-button" : ""
59
59
  ),
60
60
  "data-testid": "search-result",
61
61
  children: [
@@ -64,7 +64,7 @@ const te = ({
64
64
  {
65
65
  className: "content",
66
66
  onClick: () => {
67
- u(!i), n(e);
67
+ u(!r), n(e);
68
68
  },
69
69
  children: [
70
70
  /* @__PURE__ */ o("div", { className: "details", children: [
@@ -73,7 +73,7 @@ const te = ({
73
73
  {
74
74
  className: "hotel-image",
75
75
  style: {
76
- backgroundImage: `url(${e.images[0]})`
76
+ backgroundImage: `url(${L(e.images)[0]})`
77
77
  },
78
78
  children: /* @__PURE__ */ o("div", { className: "hotel-chain", children: [
79
79
  /* @__PURE__ */ t(j, {}),
@@ -84,15 +84,15 @@ const te = ({
84
84
  /* @__PURE__ */ o("div", { className: "info", children: [
85
85
  /* @__PURE__ */ o("div", { className: "hotel-data", children: [
86
86
  /* @__PURE__ */ o("div", { className: "hotel-information", children: [
87
- !!((g = e.cashBookingOffers) != null && g.accommodationId) && R && /* @__PURE__ */ o("div", { children: [
87
+ !!((f = e.cashBookingOffers) != null && f.accommodationId) && R && /* @__PURE__ */ o("div", { children: [
88
88
  /* @__PURE__ */ t(w, {}),
89
89
  /* @__PURE__ */ t("p", { children: F })
90
90
  ] }),
91
91
  /* @__PURE__ */ t(
92
- z,
92
+ U,
93
93
  {
94
94
  starRating: e.chainRating ?? 0,
95
- starColor: D.PRIMARY,
95
+ starColor: z.PRIMARY,
96
96
  userRating: e.reviewRating ?? "",
97
97
  fill: !0
98
98
  }
@@ -115,8 +115,8 @@ const te = ({
115
115
  /* @__PURE__ */ t(
116
116
  B,
117
117
  {
118
- hasPoints: V,
119
- isAvailable: f,
118
+ hasPoints: I,
119
+ isAvailable: g,
120
120
  selectedHotel: () => {
121
121
  },
122
122
  chainName: e.hotelGroup
@@ -124,7 +124,7 @@ const te = ({
124
124
  )
125
125
  ] })
126
126
  ] }),
127
- f && /* @__PURE__ */ o("div", { className: "payments", children: [
127
+ g && /* @__PURE__ */ o("div", { className: "payments", children: [
128
128
  A && /* @__PURE__ */ o("div", { className: "payment-details", children: [
129
129
  /* @__PURE__ */ t("p", { children: "POINTS" }),
130
130
  /* @__PURE__ */ t("p", { children: P(e.awardPoints) }),
@@ -154,5 +154,5 @@ const te = ({
154
154
  );
155
155
  };
156
156
  export {
157
- te as HotelResult
157
+ oe as HotelResult
158
158
  };
@@ -2,35 +2,35 @@ import { useState as L, useMemo as Q } from "react";
2
2
  import { h as i } from "../../moment-BGjjqtLQ.js";
3
3
  import "../../arrayExtensions-cyilNkdJ.js";
4
4
  import U from "../../stores/useHotelsStore.js";
5
- import { fetchTransferPartners as j, fetchPointsCheck as z, fetchAvailableRooms as J, fetchBestCheckout as V, combineUpdatedHotelData as O, fallbackBestCheckout as W } from "./useHotelDetails.api.js";
6
- import { calculatePointsAsCash as X } from "../../utilities/pointsAsCashUtils.js";
7
- import { useQuery as c } from "@tanstack/react-query";
8
- const Y = (t, a) => Math.abs(
9
- i(t.startOf("day")).diff(i(a.endOf("day")), "days")
10
- ), ae = (t) => {
5
+ import { fetchTransferPartners as W, fetchPointsCheck as _, fetchAvailableRooms as j, fetchBestCheckout as z, combineUpdatedHotelData as O, fallbackBestCheckout as J } from "./useHotelDetails.api.js";
6
+ import { calculatePointsAsCash as V } from "../../utilities/pointsAsCashUtils.js";
7
+ import { useQuery as a } from "@tanstack/react-query";
8
+ const X = (t, c) => Math.abs(
9
+ i(t.startOf("day")).diff(i(c.endOf("day")), "days")
10
+ ), ce = (t) => {
11
11
  var k, f, d, p, m, y, b, C, g, v, F;
12
12
  if (!t)
13
13
  throw new Error(
14
14
  "Hotel is required in order to initiate the hotel details flow"
15
15
  );
16
- const { updateHotel: a, searchParams: o } = U(), [e, q] = L({
16
+ const { updateHotel: c, searchParams: o } = U(), [e, q] = L({
17
17
  checkinDate: o == null ? void 0 : o.checkinDate,
18
18
  checkoutDate: o == null ? void 0 : o.checkoutDate
19
- }), s = Q(() => Y(e.checkinDate, e.checkoutDate), [e]), H = (x, E) => {
19
+ }), s = Q(() => X(e.checkinDate, e.checkoutDate), [e]), H = (x, E) => {
20
20
  q({
21
21
  checkinDate: i(x),
22
22
  checkoutDate: i(E)
23
23
  });
24
- }, { data: R, isFetching: A } = c({
24
+ }, { data: R, isFetching: A } = a({
25
25
  queryKey: ["transferPartners", t.hotelGroup],
26
- queryFn: () => j(t.hotelGroup),
26
+ queryFn: () => W(t.hotelGroup),
27
27
  enabled: !!t.hotelGroup,
28
28
  placeholderData: []
29
29
  }), {
30
30
  data: B,
31
31
  isFetching: n,
32
- isFetched: G
33
- } = c({
32
+ isFetched: I
33
+ } = a({
34
34
  queryKey: [
35
35
  "hotelPointsCheck",
36
36
  t.hotelId,
@@ -38,11 +38,11 @@ const Y = (t, a) => Math.abs(
38
38
  (k = e == null ? void 0 : e.checkinDate) == null ? void 0 : k.valueOf(),
39
39
  (f = e == null ? void 0 : e.checkoutDate) == null ? void 0 : f.valueOf()
40
40
  ],
41
- queryFn: () => z({
41
+ queryFn: () => _({
42
42
  hotel: t,
43
43
  checkinDate: e.checkinDate,
44
44
  checkoutDate: e.checkoutDate,
45
- updateHotel: a
45
+ updateHotel: c
46
46
  }),
47
47
  enabled: !!e.checkinDate && !!e.checkoutDate && !!t.liveScrapingCheckNeeded,
48
48
  // We don't throw an error on fail so we can gracefully handle fallback
@@ -51,14 +51,14 @@ const Y = (t, a) => Math.abs(
51
51
  pointsHotelDetails: t,
52
52
  pointsRooms: t.rooms ?? []
53
53
  }
54
- }), { pointsRooms: I, pointsHotelDetails: r } = B || {
54
+ }), { pointsRooms: G, pointsHotelDetails: r } = B || {
55
55
  pointsHotelDetails: t,
56
56
  pointsRooms: []
57
57
  }, {
58
58
  data: K,
59
59
  isFetching: u,
60
60
  isFetched: S
61
- } = c({
61
+ } = a({
62
62
  queryKey: [
63
63
  "fetchAvailableRooms",
64
64
  (d = t.cashBookingOffers) == null ? void 0 : d.accommodationId,
@@ -67,13 +67,13 @@ const Y = (t, a) => Math.abs(
67
67
  o == null ? void 0 : o.guests,
68
68
  o == null ? void 0 : o.rooms
69
69
  ],
70
- queryFn: () => J({
70
+ queryFn: () => j({
71
71
  hotel: t,
72
72
  checkinDate: e.checkinDate,
73
73
  checkoutDate: e.checkoutDate,
74
74
  guests: o.guests,
75
75
  rooms: o.rooms,
76
- updateHotel: a,
76
+ updateHotel: c,
77
77
  numberOfNights: s
78
78
  }),
79
79
  enabled: !!e.checkinDate && !!e.checkoutDate && !!((y = t.cashBookingOffers) != null && y.accommodationId),
@@ -89,7 +89,7 @@ const Y = (t, a) => Math.abs(
89
89
  data: N,
90
90
  isFetching: M,
91
91
  isFetched: P
92
- } = c({
92
+ } = a({
93
93
  queryKey: [
94
94
  "bestCheckout",
95
95
  t.hotelId,
@@ -97,19 +97,19 @@ const Y = (t, a) => Math.abs(
97
97
  (b = e == null ? void 0 : e.checkinDate) == null ? void 0 : b.valueOf(),
98
98
  (C = e == null ? void 0 : e.checkoutDate) == null ? void 0 : C.valueOf()
99
99
  ],
100
- queryFn: () => V(
100
+ queryFn: () => z(
101
101
  O(t, r, h),
102
102
  s
103
103
  ),
104
- enabled: !n && (t.liveScrapingCheckNeeded ? G : !0) && !u && ((g = t.cashBookingOffers) != null && g.accommodationId ? S : !0) && s > 0,
104
+ enabled: !t.hotelId.startsWith("duff_") && !n && (t.liveScrapingCheckNeeded ? I : !0) && !u && ((g = t.cashBookingOffers) != null && g.accommodationId ? S : !0) && s > 0,
105
105
  retry: !1,
106
106
  placeholderData: {
107
- bestCheckout: W(t, s),
107
+ bestCheckout: J(t, s),
108
108
  isAvailable: !1
109
109
  }
110
110
  }), { bestCheckout: l, isAvailable: D } = N || {
111
111
  isAvailable: !1
112
- }, { data: T } = c({
112
+ }, { data: T } = a({
113
113
  queryKey: [
114
114
  "pointsAsCash",
115
115
  t.hotelId,
@@ -117,7 +117,7 @@ const Y = (t, a) => Math.abs(
117
117
  (v = e == null ? void 0 : e.checkinDate) == null ? void 0 : v.valueOf(),
118
118
  (F = e == null ? void 0 : e.checkoutDate) == null ? void 0 : F.valueOf()
119
119
  ],
120
- queryFn: () => X(l.totalCashCost),
120
+ queryFn: () => V(l.totalCashCost),
121
121
  enabled: P && D,
122
122
  retry: !1
123
123
  });
@@ -125,7 +125,7 @@ const Y = (t, a) => Math.abs(
125
125
  transferPartners: R,
126
126
  loadingTransferPartners: A,
127
127
  // Points Check
128
- pointsRooms: I,
128
+ pointsRooms: G,
129
129
  loadingLivePointsCheck: n,
130
130
  // Cash Rooms
131
131
  cashRooms: w,
@@ -146,5 +146,5 @@ const Y = (t, a) => Math.abs(
146
146
  };
147
147
  };
148
148
  export {
149
- ae as useHotelDetails
149
+ ce as useHotelDetails
150
150
  };
@@ -32,3 +32,10 @@ export declare const getBookingOptions: (searchResult: IHotelDetails) => {
32
32
  * @returns The points value for the hotel search result.
33
33
  */
34
34
  export declare const getPointsValue: (result: IHotelDetails) => number;
35
+ type ImageUrl = string;
36
+ type ImageObject = {
37
+ url: string;
38
+ };
39
+ type ImageData = ImageUrl | ImageObject;
40
+ export declare function getHotelImageUrls(images?: ImageData[] | null): string[];
41
+ export {};
@@ -1,22 +1,26 @@
1
- import { HotelChains as s } from "../../definitions/HotelChains.js";
2
- const g = (o) => {
3
- var e;
4
- const t = o.freeNight || o.nthNightFree !== 0 ? o.awardPoints : o.points, n = {
1
+ import { HotelChains as a } from "../../definitions/HotelChains.js";
2
+ const s = (t) => {
3
+ var r;
4
+ const n = t.freeNight || t.nthNightFree !== 0 ? t.awardPoints : t.points, o = {
5
5
  type: "",
6
6
  value: -1
7
- }, a = typeof o.cashValue.amount == "number" ? o.cashValue.amount : parseFloat(o.cashValue.amount), i = { ...n };
8
- return o.bestValue === "cash" ? (n.type = "cash", n.value = a, i.type = "points", i.value = t || -1) : o.bestValue === "points" && (n.type = "points", n.value = t || -1, i.type = "cash", i.value = a), {
9
- transferPartners: ((e = o.partners) == null ? void 0 : e.map((p) => ({
7
+ }, i = typeof t.cashValue.amount == "number" ? t.cashValue.amount : parseFloat(t.cashValue.amount), e = { ...o };
8
+ return t.bestValue === "cash" ? (o.type = "cash", o.value = i, e.type = "points", e.value = n || -1) : t.bestValue === "points" && (o.type = "points", o.value = n || -1, e.type = "cash", e.value = i), {
9
+ transferPartners: ((r = t.partners) == null ? void 0 : r.map((p) => ({
10
10
  ...p,
11
- value: t ? Math.ceil(t * p.ratio) : -1
11
+ value: n ? Math.ceil(n * p.ratio) : -1
12
12
  }))) || [],
13
- bestBookingOption: n,
14
- alternateBookingOption: i,
15
- points: t || -1,
16
- hasPoints: typeof t == "number" && t > 0
13
+ bestBookingOption: o,
14
+ alternateBookingOption: e,
15
+ points: n || -1,
16
+ hasPoints: typeof n == "number" && n > 0
17
17
  };
18
- }, h = (o) => (o == null ? void 0 : o.hotelGroup) === s.IHG ? o.freeNight || o.nthNightFree ? o.awardPoints : o.points : o.awardPoints;
18
+ }, u = (t) => (t == null ? void 0 : t.hotelGroup) === a.IHG ? t.freeNight || t.nthNightFree ? t.awardPoints : t.points : t.awardPoints;
19
+ function y(t) {
20
+ return !t || !Array.isArray(t) || t.length === 0 ? [] : t.map((n) => typeof n == "string" ? n : n && typeof n == "object" && "url" in n ? n.url : "").filter((n) => n !== "");
21
+ }
19
22
  export {
20
- g as getBookingOptions,
21
- h as getPointsValue
23
+ s as getBookingOptions,
24
+ y as getHotelImageUrls,
25
+ u as getPointsValue
22
26
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.2.8",
4
+ "version": "0.2.9",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"