@odynn/awayz-hotels 0.10.2 → 0.11.0
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,74 +1,74 @@
|
|
|
1
|
-
import { useAwayzContext as
|
|
2
|
-
import { useMutation as
|
|
3
|
-
import { g as
|
|
4
|
-
import { D as
|
|
5
|
-
import { E as
|
|
1
|
+
import { useAwayzContext as F, useWallet as P, awayzClient as p } from "@odynn/awayz-core";
|
|
2
|
+
import { useMutation as f } from "@tanstack/react-query";
|
|
3
|
+
import { g as k } from "../../dateUtils-C1hKW8MF.js";
|
|
4
|
+
import { D as R, a as D } from "../../index-CJj9N0Xq.js";
|
|
5
|
+
import { E as y } from "../../enums-tLvxh02p.js";
|
|
6
6
|
import "../../arrayExtensions-CFEBYUok.js";
|
|
7
|
-
import "react";
|
|
8
|
-
import { h as
|
|
9
|
-
import { HotelChains as
|
|
10
|
-
import { HotelService as
|
|
11
|
-
import { ESearchType as
|
|
12
|
-
import
|
|
13
|
-
import { checkNthNightFree as
|
|
14
|
-
import { getHaversineDistanceKm as
|
|
15
|
-
const
|
|
7
|
+
import { useEffect as x } from "react";
|
|
8
|
+
import { h as d } from "../../moment-BGjjqtLQ.js";
|
|
9
|
+
import { HotelChains as a } from "../../definitions/HotelChains.js";
|
|
10
|
+
import { HotelService as _ } from "../../services/hotel/HotelService.js";
|
|
11
|
+
import { ESearchType as E } from "../../services/hotel/HotelService.types.js";
|
|
12
|
+
import w from "../../stores/useHotelsStore.js";
|
|
13
|
+
import { checkNthNightFree as S } from "../../utilities/hotelUtils/freeNightUtils.js";
|
|
14
|
+
import { getHaversineDistanceKm as C } from "../../utilities/hotelUtils/hotelUtils.js";
|
|
15
|
+
const K = (t) => {
|
|
16
16
|
if (!t.checkinDate || !t.checkoutDate)
|
|
17
17
|
throw new Error("Check-in and checkout dates are required.");
|
|
18
18
|
if (!t.coordinates)
|
|
19
19
|
throw new Error("Coordinates are required.");
|
|
20
|
-
t.hotelGroups && t.hotelGroups.forEach((
|
|
21
|
-
if (!
|
|
20
|
+
t.hotelGroups && t.hotelGroups.forEach((s) => {
|
|
21
|
+
if (!a.toList().includes(s))
|
|
22
22
|
throw new Error(
|
|
23
|
-
`Invalid hotel group: ${
|
|
23
|
+
`Invalid hotel group: ${s}. Please use one of the following: ${a.toList().join(
|
|
24
24
|
", "
|
|
25
25
|
)}`
|
|
26
26
|
);
|
|
27
27
|
});
|
|
28
|
-
},
|
|
28
|
+
}, O = (t) => {
|
|
29
29
|
if (!t.checkinDate || !t.checkoutDate)
|
|
30
30
|
throw new Error("Check-in and checkout dates are required.");
|
|
31
31
|
if (!t.hotelName)
|
|
32
32
|
throw new Error("Hotel name is required");
|
|
33
33
|
if (!t.hotelGroup)
|
|
34
34
|
throw new Error("Hotel group is required");
|
|
35
|
-
if (!
|
|
35
|
+
if (!a.toList().includes(t.hotelGroup))
|
|
36
36
|
throw new Error(
|
|
37
|
-
`Invalid hotel group: ${t.hotelGroup}. Please use one of the following: ${
|
|
37
|
+
`Invalid hotel group: ${t.hotelGroup}. Please use one of the following: ${a.toList().join(", ")}`
|
|
38
38
|
);
|
|
39
|
-
},
|
|
40
|
-
const { setHotels: t, hotels:
|
|
41
|
-
mutate:
|
|
42
|
-
isPending:
|
|
43
|
-
status:
|
|
44
|
-
isError:
|
|
45
|
-
error:
|
|
46
|
-
} =
|
|
39
|
+
}, te = () => {
|
|
40
|
+
const { setHotels: t, hotels: s, setSearchParams: m } = w(), { config: c } = F(), { userCards: h } = P(), {
|
|
41
|
+
mutate: I,
|
|
42
|
+
isPending: H,
|
|
43
|
+
status: L,
|
|
44
|
+
isError: T,
|
|
45
|
+
error: v
|
|
46
|
+
} = f({
|
|
47
47
|
mutationFn: async (e) => {
|
|
48
|
-
|
|
49
|
-
checkinDate:
|
|
50
|
-
checkoutDate:
|
|
48
|
+
K(e), t([]), m({
|
|
49
|
+
checkinDate: d(e.checkinDate),
|
|
50
|
+
checkoutDate: d(e.checkoutDate),
|
|
51
51
|
guests: e.guests || 2,
|
|
52
52
|
rooms: e.rooms || 1
|
|
53
53
|
});
|
|
54
|
-
const
|
|
54
|
+
const o = {
|
|
55
55
|
check_in_date: e.checkinDate,
|
|
56
56
|
check_out_date: e.checkoutDate,
|
|
57
57
|
guests: e.guests || 2,
|
|
58
58
|
rooms: e.rooms || 1,
|
|
59
59
|
cash_or_points: e.cashOrPoints || ["cash", "points"],
|
|
60
|
-
region_code: e.userRegion ||
|
|
60
|
+
region_code: e.userRegion || D,
|
|
61
61
|
lat: e.coordinates.latitude,
|
|
62
62
|
lon: e.coordinates.longitude,
|
|
63
63
|
search_range: e.searchRange || 10,
|
|
64
|
-
range_type: e.rangeType ||
|
|
65
|
-
hotel_groups: e.hotelGroups ||
|
|
66
|
-
type: e.searchType ||
|
|
67
|
-
external_inventory: (
|
|
68
|
-
use_duffel:
|
|
64
|
+
range_type: e.rangeType || R,
|
|
65
|
+
hotel_groups: e.hotelGroups || a.toList(),
|
|
66
|
+
type: e.searchType || E.CITY,
|
|
67
|
+
external_inventory: (c == null ? void 0 : c.externalInventory) || !1,
|
|
68
|
+
use_duffel: c == null ? void 0 : c.supportsDuffel
|
|
69
69
|
};
|
|
70
70
|
return {
|
|
71
|
-
...await
|
|
71
|
+
...await _.searchByCoords(o),
|
|
72
72
|
checkinDate: e.checkinDate,
|
|
73
73
|
checkoutDate: e.checkoutDate,
|
|
74
74
|
searchCoordinates: e.coordinates
|
|
@@ -76,76 +76,76 @@ const g = (t) => {
|
|
|
76
76
|
},
|
|
77
77
|
onSuccess: (e) => {
|
|
78
78
|
if (e.success) {
|
|
79
|
-
const { checkinDate:
|
|
80
|
-
...
|
|
81
|
-
distance:
|
|
79
|
+
const { checkinDate: o, checkoutDate: n, searchCoordinates: i } = e, u = k(o, n), r = e.data.map((l) => ({
|
|
80
|
+
...l,
|
|
81
|
+
distance: C(
|
|
82
82
|
i.latitude,
|
|
83
83
|
i.longitude,
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
l.coordinates.latitude,
|
|
85
|
+
l.coordinates.longitude
|
|
86
86
|
),
|
|
87
|
-
nthNightFree:
|
|
88
|
-
hotel:
|
|
89
|
-
cards:
|
|
90
|
-
nights:
|
|
87
|
+
nthNightFree: S({
|
|
88
|
+
hotel: l,
|
|
89
|
+
cards: h ?? [],
|
|
90
|
+
nights: u
|
|
91
91
|
})
|
|
92
92
|
}));
|
|
93
|
-
t(
|
|
93
|
+
t(r);
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
onSettled: () => {
|
|
97
|
-
|
|
97
|
+
p.invalidateQueries({ queryKey: [y.SEARCH_LIMIT] });
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
|
-
function
|
|
100
|
+
function g(e, o) {
|
|
101
101
|
let n = 0;
|
|
102
|
-
const i = e.length <
|
|
103
|
-
for (let
|
|
104
|
-
e[
|
|
105
|
-
return n /
|
|
102
|
+
const i = e.length < o.length ? e : o, u = e.length >= o.length ? e : o;
|
|
103
|
+
for (let r = 0; r < i.length; r++)
|
|
104
|
+
e[r] === o[r] && n++;
|
|
105
|
+
return n / u.length;
|
|
106
106
|
}
|
|
107
107
|
const {
|
|
108
|
-
mutate:
|
|
109
|
-
isPending:
|
|
110
|
-
status:
|
|
111
|
-
isError:
|
|
112
|
-
error:
|
|
113
|
-
} =
|
|
108
|
+
mutate: q,
|
|
109
|
+
isPending: N,
|
|
110
|
+
status: A,
|
|
111
|
+
isError: G,
|
|
112
|
+
error: B
|
|
113
|
+
} = f({
|
|
114
114
|
mutationFn: async (e) => {
|
|
115
|
-
|
|
116
|
-
checkinDate:
|
|
117
|
-
checkoutDate:
|
|
115
|
+
O(e), t([]), m({
|
|
116
|
+
checkinDate: d(e.checkinDate),
|
|
117
|
+
checkoutDate: d(e.checkoutDate),
|
|
118
118
|
guests: e.guests || 2,
|
|
119
119
|
rooms: e.rooms || 1
|
|
120
120
|
});
|
|
121
|
-
const
|
|
121
|
+
const o = {
|
|
122
122
|
check_in_date: e.checkinDate,
|
|
123
123
|
check_out_date: e.checkoutDate,
|
|
124
124
|
guests: e.guests || 2,
|
|
125
125
|
rooms: e.rooms || 1,
|
|
126
126
|
cash_or_points: e.cashOrPoints || ["cash", "points"],
|
|
127
|
-
region_code: e.userRegion ||
|
|
127
|
+
region_code: e.userRegion || D,
|
|
128
128
|
lat: e.coordinates.latitude,
|
|
129
129
|
lon: e.coordinates.longitude,
|
|
130
130
|
search_range: 0.5,
|
|
131
131
|
range_type: "km",
|
|
132
132
|
hotel_groups: [e.hotelGroup],
|
|
133
|
-
type:
|
|
133
|
+
type: E.HOTEL,
|
|
134
134
|
external_inventory: !1,
|
|
135
|
-
use_duffel:
|
|
136
|
-
}, n = await
|
|
135
|
+
use_duffel: c == null ? void 0 : c.supportsDuffel
|
|
136
|
+
}, n = await _.searchByCoords(o);
|
|
137
137
|
if (!n.success)
|
|
138
138
|
throw new Error(n.message || "Hotel search failed");
|
|
139
139
|
const i = 0.8;
|
|
140
140
|
return n.data.filter(
|
|
141
|
-
(
|
|
142
|
-
).map((
|
|
143
|
-
...
|
|
144
|
-
distance:
|
|
141
|
+
(r) => g(r.name.toLowerCase(), e.hotelName.toLowerCase()) >= i
|
|
142
|
+
).map((r) => ({
|
|
143
|
+
...r,
|
|
144
|
+
distance: C(
|
|
145
145
|
e.coordinates.latitude,
|
|
146
146
|
e.coordinates.longitude,
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
r.coordinates.latitude,
|
|
148
|
+
r.coordinates.longitude
|
|
149
149
|
)
|
|
150
150
|
}));
|
|
151
151
|
},
|
|
@@ -153,22 +153,38 @@ const g = (t) => {
|
|
|
153
153
|
t(e);
|
|
154
154
|
},
|
|
155
155
|
onSettled: () => {
|
|
156
|
-
|
|
156
|
+
p.invalidateQueries({ queryKey: [y.SEARCH_LIMIT] });
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
|
-
return {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
return x(() => {
|
|
160
|
+
if (!s.length || !h) return;
|
|
161
|
+
const { searchParams: e } = w.getState();
|
|
162
|
+
if (!(e != null && e.checkinDate) || !(e != null && e.checkoutDate)) return;
|
|
163
|
+
const o = k(
|
|
164
|
+
e.checkinDate,
|
|
165
|
+
e.checkoutDate
|
|
166
|
+
), n = s.map((i) => ({
|
|
167
|
+
...i,
|
|
168
|
+
nthNightFree: S({
|
|
169
|
+
hotel: i,
|
|
170
|
+
cards: h,
|
|
171
|
+
nights: o
|
|
172
|
+
})
|
|
173
|
+
}));
|
|
174
|
+
t(n);
|
|
175
|
+
}, [h, s.length]), {
|
|
176
|
+
results: s,
|
|
177
|
+
loading: L === "pending" || A === "pending" || H || N,
|
|
178
|
+
isCoordsSearchError: T,
|
|
179
|
+
coordsSearchError: v,
|
|
180
|
+
isHotelIdSearchError: G,
|
|
181
|
+
hotelIdSearchError: B,
|
|
182
|
+
searchByCoords: I,
|
|
183
|
+
searchByHotelId: q
|
|
168
184
|
};
|
|
169
185
|
};
|
|
170
186
|
export {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
187
|
+
te as useHotelSearch,
|
|
188
|
+
K as validateSearchByCoordsArgs,
|
|
189
|
+
O as validateSearchByHotelIdArgs
|
|
174
190
|
};
|