@tfehotels/tfe-gatsby-library 1.0.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.
- package/README.md +41 -0
- package/lib/index.browser.cjs +2 -0
- package/lib/index.browser.cjs.map +1 -0
- package/lib/index.browser.d.ts +640 -0
- package/lib/index.browser.esm.js +2 -0
- package/lib/index.browser.esm.js.map +1 -0
- package/lib/index.node.cjs +2 -0
- package/lib/index.node.cjs.map +1 -0
- package/lib/index.node.d.ts +116 -0
- package/lib/index.node.esm.js +2 -0
- package/lib/index.node.esm.js.map +1 -0
- package/package.json +84 -0
- package/src/browser/api/button/index.tsx +16 -0
- package/src/browser/api/button/types.ts +7 -0
- package/src/browser/api/checkbox/index.tsx +74 -0
- package/src/browser/api/checkbox/types.tsx +21 -0
- package/src/browser/api/country-prefix/index.tsx +150 -0
- package/src/browser/api/country-prefix/types.tsx +17 -0
- package/src/browser/api/form/index.tsx +330 -0
- package/src/browser/api/form/types.ts +31 -0
- package/src/browser/api/google-places/index.tsx +90 -0
- package/src/browser/api/google-places/types.ts +24 -0
- package/src/browser/api/icon/index.tsx +26 -0
- package/src/browser/api/icon/types.tsx +24 -0
- package/src/browser/api/image/index.tsx +91 -0
- package/src/browser/api/image/types.ts +11 -0
- package/src/browser/api/input/index.tsx +44 -0
- package/src/browser/api/input/types.ts +10 -0
- package/src/browser/api/link/index.tsx +54 -0
- package/src/browser/api/link/types.ts +24 -0
- package/src/browser/api/linklist/index.tsx +17 -0
- package/src/browser/api/linklist/types.ts +6 -0
- package/src/browser/api/select/index.tsx +99 -0
- package/src/browser/api/select/types.ts +24 -0
- package/src/browser/api/svg/index.tsx +8 -0
- package/src/browser/api/svg/types.ts +8 -0
- package/src/browser/api/text/index.tsx +14 -0
- package/src/browser/api/text/types.ts +12 -0
- package/src/browser/api/textarea/index.tsx +12 -0
- package/src/browser/api/title/index.tsx +19 -0
- package/src/browser/api/title/types.ts +10 -0
- package/src/browser/api/types.ts +245 -0
- package/src/browser/carousel/buttons/index.tsx +81 -0
- package/src/browser/carousel/buttons/types.ts +15 -0
- package/src/browser/carousel/dots/index.tsx +53 -0
- package/src/browser/carousel/dots/types.ts +14 -0
- package/src/browser/carousel/index.tsx +131 -0
- package/src/browser/carousel/types.ts +21 -0
- package/src/browser/markdown/index.tsx +41 -0
- package/src/browser/markdown/types.ts +11 -0
- package/src/browser/modal/index.tsx +35 -0
- package/src/browser/modal/types.ts +9 -0
- package/src/browser/spinner/index.tsx +19 -0
- package/src/browser/spinner/types.ts +5 -0
- package/src/browser/toast/index.tsx +84 -0
- package/src/browser/use_viewport/index.tsx +34 -0
- package/src/browser/use_viewport/types.ts +5 -0
- package/src/browser/utils/animation.ts +12 -0
- package/src/browser/utils/booking_engine.ts +180 -0
- package/src/browser/utils/eclub.ts +30 -0
- package/src/browser/utils/forms.ts +76 -0
- package/src/browser/utils/hotel.ts +25 -0
- package/src/browser/utils/image.ts +63 -0
- package/src/browser/utils/location.ts +213 -0
- package/src/browser/utils/notifications.tsx +25 -0
- package/src/browser/utils/number.ts +6 -0
- package/src/browser/utils/requests.ts +2 -0
- package/src/browser/utils/search.ts +25 -0
- package/src/browser/utils/string.ts +9 -0
- package/src/browser/utils/types.ts +106 -0
- package/src/browser/utils/url.ts +116 -0
- package/src/browser/utils/viewport.ts +59 -0
- package/src/index.browser.ts +103 -0
- package/src/index.node.ts +16 -0
- package/src/node/api/index.ts +174 -0
- package/src/node/api/types.ts +19 -0
- package/src/node/build/index.ts +142 -0
- package/src/node/build/types.ts +5 -0
- package/src/node/config/index.ts +149 -0
- package/src/node/form/index.ts +23 -0
- package/src/node/form/types.ts +3 -0
- package/src/node/property/index.ts +78 -0
- package/src/node/property/types.ts +25 -0
- package/src/node/url/index.ts +8 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
export const countryPrefixes = [
|
|
2
|
+
["af", "93", "Afghanistan"],
|
|
3
|
+
["al", "355", "Albania"],
|
|
4
|
+
["dz", "213", "Algeria"],
|
|
5
|
+
["ad", "376", "Andorra"],
|
|
6
|
+
["ao", "244", "Angola"],
|
|
7
|
+
["ag", "1268", "Antigua and Barbuda"],
|
|
8
|
+
["ar", "54", "Argentina"],
|
|
9
|
+
["am", "374", "Armenia"],
|
|
10
|
+
["aw", "297", "Aruba"],
|
|
11
|
+
["au", "61", "Australia"],
|
|
12
|
+
["at", "43", "Austria"],
|
|
13
|
+
["az", "994", "Azerbaijan"],
|
|
14
|
+
["bs", "1242", "Bahamas"],
|
|
15
|
+
["bh", "973", "Bahrain"],
|
|
16
|
+
["bd", "880", "Bangladesh"],
|
|
17
|
+
["bb", "1246", "Barbados"],
|
|
18
|
+
["by", "375", "Belarus"],
|
|
19
|
+
["be", "32", "Belgium"],
|
|
20
|
+
["bz", "501", "Belize"],
|
|
21
|
+
["bj", "229", "Benin"],
|
|
22
|
+
["bt", "975", "Bhutan"],
|
|
23
|
+
["bo", "591", "Bolivia"],
|
|
24
|
+
["ba", "387", "Bosnia and Herzegovina"],
|
|
25
|
+
["bw", "267", "Botswana"],
|
|
26
|
+
["br", "55", "Brazil"],
|
|
27
|
+
["io", "246", "British Indian Ocean Territory"],
|
|
28
|
+
["bn", "673", "Brunei"],
|
|
29
|
+
["bg", "359", "Bulgaria"],
|
|
30
|
+
["bf", "226", "Burkina Faso"],
|
|
31
|
+
["bi", "257", "Burundi"],
|
|
32
|
+
["kh", "855", "Cambodia"],
|
|
33
|
+
["cm", "237", "Cameroon"],
|
|
34
|
+
["ca", "1", "Canada"],
|
|
35
|
+
["cv", "238", "Cape Verde"],
|
|
36
|
+
["bq", "599", "Caribbean Netherlands"],
|
|
37
|
+
["cf", "236", "Central African Republic"],
|
|
38
|
+
["td", "235", "Chad"],
|
|
39
|
+
["cl", "56", "Chile"],
|
|
40
|
+
["cn", "86", "China"],
|
|
41
|
+
["co", "57", "Colombia"],
|
|
42
|
+
["km", "269", "Comoros"],
|
|
43
|
+
["cd", "243", "Congo"],
|
|
44
|
+
["cg", "242", "Congo"],
|
|
45
|
+
["cr", "506", "Costa Rica"],
|
|
46
|
+
["ci", "225", "Côte d'Ivoire"],
|
|
47
|
+
["hr", "385", "Croatia"],
|
|
48
|
+
["cu", "53", "Cuba"],
|
|
49
|
+
["cw", "599", "Curaçao"],
|
|
50
|
+
["cy", "357", "Cyprus"],
|
|
51
|
+
["cz", "420", "Czech Republic"],
|
|
52
|
+
["dk", "45", "Denmark"],
|
|
53
|
+
["dj", "253", "Djibouti"],
|
|
54
|
+
["dm", "1767", "Dominica"],
|
|
55
|
+
["do", "1", "Dominican Republic"],
|
|
56
|
+
["ec", "593", "Ecuador"],
|
|
57
|
+
["eg", "20", "Egypt"],
|
|
58
|
+
["sv", "503", "El Salvador"],
|
|
59
|
+
["gq", "240", "Equatorial Guinea"],
|
|
60
|
+
["er", "291", "Eritrea"],
|
|
61
|
+
["ee", "372", "Estonia"],
|
|
62
|
+
["et", "251", "Ethiopia"],
|
|
63
|
+
["fj", "679", "Fiji"],
|
|
64
|
+
["fi", "358", "Finland"],
|
|
65
|
+
["fr", "33", "France"],
|
|
66
|
+
["gf", "594", "French Guiana"],
|
|
67
|
+
["pf", "689", "French Polynesia"],
|
|
68
|
+
["ga", "241", "Gabon"],
|
|
69
|
+
["gm", "220", "Gambia"],
|
|
70
|
+
["ge", "995", "Georgia"],
|
|
71
|
+
["de", "49", "Germany"],
|
|
72
|
+
["gh", "233", "Ghana"],
|
|
73
|
+
["gr", "30", "Greece"],
|
|
74
|
+
["gd", "1473", "Grenada"],
|
|
75
|
+
["gp", "590", "Guadeloupe"],
|
|
76
|
+
["gu", "1671", "Guam"],
|
|
77
|
+
["gt", "502", "Guatemala"],
|
|
78
|
+
["gn", "224", "Guinea"],
|
|
79
|
+
["gw", "245", "Guinea-Bissau"],
|
|
80
|
+
["gy", "592", "Guyana"],
|
|
81
|
+
["ht", "509", "Haiti"],
|
|
82
|
+
["hn", "504", "Honduras"],
|
|
83
|
+
["hk", "852", "Hong Kong"],
|
|
84
|
+
["hu", "36", "Hungary"],
|
|
85
|
+
["is", "354", "Iceland"],
|
|
86
|
+
["in", "91", "India"],
|
|
87
|
+
["id", "62", "Indonesia"],
|
|
88
|
+
["ir", "98", "Iran"],
|
|
89
|
+
["iq", "964", "Iraq"],
|
|
90
|
+
["ie", "353", "Ireland"],
|
|
91
|
+
["il", "972", "Israel"],
|
|
92
|
+
["it", "39", "Italy"],
|
|
93
|
+
["jm", "1876", "Jamaica"],
|
|
94
|
+
["jp", "81", "Japan"],
|
|
95
|
+
["jo", "962", "Jordan"],
|
|
96
|
+
["kz", "7", "Kazakhstan"],
|
|
97
|
+
["ke", "254", "Kenya"],
|
|
98
|
+
["ki", "686", "Kiribati"],
|
|
99
|
+
["xk", "383", "Kosovo"],
|
|
100
|
+
["kw", "965", "Kuwait"],
|
|
101
|
+
["kg", "996", "Kyrgyzstan"],
|
|
102
|
+
["la", "856", "Laos"],
|
|
103
|
+
["lv", "371", "Latvia"],
|
|
104
|
+
["lb", "961", "Lebanon"],
|
|
105
|
+
["ls", "266", "Lesotho"],
|
|
106
|
+
["lr", "231", "Liberia"],
|
|
107
|
+
["ly", "218", "Libya"],
|
|
108
|
+
["li", "423", "Liechtenstein"],
|
|
109
|
+
["lt", "370", "Lithuania"],
|
|
110
|
+
["lu", "352", "Luxembourg"],
|
|
111
|
+
["mo", "853", "Macau"],
|
|
112
|
+
["mk", "389", "Macedonia"],
|
|
113
|
+
["mg", "261", "Madagascar"],
|
|
114
|
+
["mw", "265", "Malawi"],
|
|
115
|
+
["my", "60", "Malaysia"],
|
|
116
|
+
["mv", "960", "Maldives"],
|
|
117
|
+
["ml", "223", "Mali"],
|
|
118
|
+
["mt", "356", "Malta"],
|
|
119
|
+
["mh", "692", "Marshall Islands"],
|
|
120
|
+
["mq", "596", "Martinique"],
|
|
121
|
+
["mr", "222", "Mauritania"],
|
|
122
|
+
["mu", "230", "Mauritius"],
|
|
123
|
+
["mx", "52", "Mexico"],
|
|
124
|
+
["fm", "691", "Micronesia"],
|
|
125
|
+
["md", "373", "Moldova"],
|
|
126
|
+
["mc", "377", "Monaco"],
|
|
127
|
+
["mn", "976", "Mongolia"],
|
|
128
|
+
["me", "382", "Montenegro"],
|
|
129
|
+
["ma", "212", "Morocco"],
|
|
130
|
+
["mz", "258", "Mozambique"],
|
|
131
|
+
["mm", "95", "Myanmar"],
|
|
132
|
+
["na", "264", "Namibia"],
|
|
133
|
+
["nr", "674", "Nauru"],
|
|
134
|
+
["np", "977", "Nepal"],
|
|
135
|
+
["nl", "31", "Netherlands"],
|
|
136
|
+
["nc", "687", "New Caledonia"],
|
|
137
|
+
["nz", "64", "New Zealand"],
|
|
138
|
+
["ni", "505", "Nicaragua"],
|
|
139
|
+
["ne", "227", "Niger"],
|
|
140
|
+
["ng", "234", "Nigeria"],
|
|
141
|
+
["kp", "850", "North Korea"],
|
|
142
|
+
["no", "47", "Norway"],
|
|
143
|
+
["om", "968", "Oman"],
|
|
144
|
+
["pk", "92", "Pakistan"],
|
|
145
|
+
["pw", "680", "Palau"],
|
|
146
|
+
["ps", "970", "Palestine"],
|
|
147
|
+
["pa", "507", "Panama"],
|
|
148
|
+
["pg", "675", "Papua New Guinea"],
|
|
149
|
+
["py", "595", "Paraguay"],
|
|
150
|
+
["pe", "51", "Peru"],
|
|
151
|
+
["ph", "63", "Philippines"],
|
|
152
|
+
["pl", "48", "Poland"],
|
|
153
|
+
["pt", "351", "Portugal"],
|
|
154
|
+
["pr", "1", "Puerto Rico"],
|
|
155
|
+
["qa", "974", "Qatar"],
|
|
156
|
+
["re", "262", "Réunion"],
|
|
157
|
+
["ro", "40", "Romania"],
|
|
158
|
+
["ru", "7", "Russia"],
|
|
159
|
+
["rw", "250", "Rwanda"],
|
|
160
|
+
["kn", "1869", "Saint Kitts and Nevis"],
|
|
161
|
+
["lc", "1758", "Saint Lucia"],
|
|
162
|
+
["vc", "1784", "Saint Vincent and the Grenadines"],
|
|
163
|
+
["ws", "685", "Samoa"],
|
|
164
|
+
["sm", "378", "San Marino"],
|
|
165
|
+
["st", "239", "São Tomé and Príncipe"],
|
|
166
|
+
["sa", "966", "Saudi Arabia"],
|
|
167
|
+
["sn", "221", "Senegal"],
|
|
168
|
+
["rs", "381", "Serbia"],
|
|
169
|
+
["sc", "248", "Seychelles"],
|
|
170
|
+
["sl", "232", "Sierra Leone"],
|
|
171
|
+
["sg", "65", "Singapore"],
|
|
172
|
+
["sk", "421", "Slovakia"],
|
|
173
|
+
["si", "386", "Slovenia"],
|
|
174
|
+
["sb", "677", "Solomon Islands"],
|
|
175
|
+
["so", "252", "Somalia"],
|
|
176
|
+
["za", "27", "South Africa"],
|
|
177
|
+
["kr", "82", "South Korea"],
|
|
178
|
+
["ss", "211", "South Sudan"],
|
|
179
|
+
["es", "34", "Spain"],
|
|
180
|
+
["lk", "94", "Sri Lanka"],
|
|
181
|
+
["sd", "249", "Sudan"],
|
|
182
|
+
["sr", "597", "Suriname"],
|
|
183
|
+
["sz", "268", "Swaziland"],
|
|
184
|
+
["se", "46", "Sweden"],
|
|
185
|
+
["ch", "41", "Switzerland"],
|
|
186
|
+
["sy", "963", "Syria"],
|
|
187
|
+
["tw", "886", "Taiwan"],
|
|
188
|
+
["tj", "992", "Tajikistan"],
|
|
189
|
+
["tz", "255", "Tanzania"],
|
|
190
|
+
["th", "66", "Thailand"],
|
|
191
|
+
["tl", "670", "Timor-Leste"],
|
|
192
|
+
["tg", "228", "Togo"],
|
|
193
|
+
["to", "676", "Tonga"],
|
|
194
|
+
["tt", "1868", "Trinidad and Tobago"],
|
|
195
|
+
["tn", "216", "Tunisia"],
|
|
196
|
+
["tr", "90", "Turkey"],
|
|
197
|
+
["tm", "993", "Turkmenistan"],
|
|
198
|
+
["tv", "688", "Tuvalu"],
|
|
199
|
+
["ug", "256", "Uganda"],
|
|
200
|
+
["ua", "380", "Ukraine"],
|
|
201
|
+
["ae", "971", "United Arab Emirates"],
|
|
202
|
+
["gb", "44", "United Kingdom"],
|
|
203
|
+
["us", "1", "United States"],
|
|
204
|
+
["uy", "598", "Uruguay"],
|
|
205
|
+
["uz", "998", "Uzbekistan"],
|
|
206
|
+
["vu", "678", "Vanuatu"],
|
|
207
|
+
["va", "39", "Vatican City"],
|
|
208
|
+
["ve", "58", "Venezuela"],
|
|
209
|
+
["vn", "84", "Vietnam"],
|
|
210
|
+
["ye", "967", "Yemen"],
|
|
211
|
+
["zm", "260", "Zambia"],
|
|
212
|
+
["zw", "263", "Zimbabwe"],
|
|
213
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import toast from "react-hot-toast"
|
|
2
|
+
import React, { ReactNode } from "react"
|
|
3
|
+
import Toast from "../toast"
|
|
4
|
+
|
|
5
|
+
export const toastMsg = (
|
|
6
|
+
msg: string | ReactNode,
|
|
7
|
+
variant: "error" | "info" | "success" = "error",
|
|
8
|
+
duration: number = 10000
|
|
9
|
+
) => {
|
|
10
|
+
toast.custom(
|
|
11
|
+
(t:any) => (
|
|
12
|
+
<Toast
|
|
13
|
+
id={t.id}
|
|
14
|
+
visible={t.visible}
|
|
15
|
+
message={msg}
|
|
16
|
+
variant={variant}
|
|
17
|
+
height={t.height}
|
|
18
|
+
position={t.position}
|
|
19
|
+
/>
|
|
20
|
+
),
|
|
21
|
+
{
|
|
22
|
+
duration: duration,
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import addDays from "date-fns/addDays";
|
|
2
|
+
import { CachedSearchParamsType } from "./types";
|
|
3
|
+
|
|
4
|
+
export const cachedSearchParams = (): CachedSearchParamsType | null => {
|
|
5
|
+
if (typeof window === "undefined") return null;
|
|
6
|
+
let cached: any = localStorage.getItem("search-params");
|
|
7
|
+
if (cached) {
|
|
8
|
+
cached = JSON.parse(cached);
|
|
9
|
+
cached.rate_codes = []; // Bypass Rate
|
|
10
|
+
cached.promo_codes = []; // Bypass Promo codes
|
|
11
|
+
cached.check_in = cached.check_in ? new Date(cached.check_in) : new Date();
|
|
12
|
+
cached.check_out = cached.check_out
|
|
13
|
+
? new Date(cached.check_out)
|
|
14
|
+
: addDays(new Date(), 1);
|
|
15
|
+
|
|
16
|
+
// Invalidate cache if dates are in the past
|
|
17
|
+
if (cached.check_in < new Date()) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return cached;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const cacheSearchParams = (searchParams: CachedSearchParamsType) =>
|
|
25
|
+
localStorage.setItem("search-params", JSON.stringify(searchParams));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function randomString(length: number = 9): string {
|
|
2
|
+
const characters =
|
|
3
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
4
|
+
let result = ""
|
|
5
|
+
for (let i = 0; i < length; i++) {
|
|
6
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length))
|
|
7
|
+
}
|
|
8
|
+
return result
|
|
9
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CheckboxType,
|
|
3
|
+
GoogleSitesType,
|
|
4
|
+
ImageType,
|
|
5
|
+
InputType,
|
|
6
|
+
LinkType,
|
|
7
|
+
RecaptchaType,
|
|
8
|
+
SelectType,
|
|
9
|
+
TextType,
|
|
10
|
+
TitleType,
|
|
11
|
+
} from "../api/types";
|
|
12
|
+
|
|
13
|
+
export interface SearchParamsType {
|
|
14
|
+
check_in: Date;
|
|
15
|
+
check_out: Date;
|
|
16
|
+
adult_count: number;
|
|
17
|
+
child_count: number;
|
|
18
|
+
promo_codes: string[];
|
|
19
|
+
rate_codes: string[];
|
|
20
|
+
hotel_codes: string[];
|
|
21
|
+
selected_hotel: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface HotelPagesType {
|
|
25
|
+
[hotel_code: string]: {
|
|
26
|
+
name: string;
|
|
27
|
+
city: string;
|
|
28
|
+
sort: number;
|
|
29
|
+
link: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CachedSearchParamsType {
|
|
34
|
+
check_in: Date;
|
|
35
|
+
check_out: Date;
|
|
36
|
+
adult_count: number;
|
|
37
|
+
child_count: number;
|
|
38
|
+
rate_codes: string[];
|
|
39
|
+
promo_codes: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface HotelOptionsByCityType {
|
|
43
|
+
label: string;
|
|
44
|
+
options: { value: string; label: string }[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface FormFieldsType {
|
|
48
|
+
[field: string]:
|
|
49
|
+
| InputType
|
|
50
|
+
| TitleType
|
|
51
|
+
| TextType
|
|
52
|
+
| LinkType
|
|
53
|
+
| ImageType
|
|
54
|
+
| SelectType
|
|
55
|
+
| RecaptchaType
|
|
56
|
+
| CheckboxType
|
|
57
|
+
| GoogleSitesType;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface FormSettingsType {
|
|
61
|
+
pk: number;
|
|
62
|
+
name: string;
|
|
63
|
+
form_method: "get" | "post";
|
|
64
|
+
form_recipient?: number;
|
|
65
|
+
form_submit: string;
|
|
66
|
+
form_redirection?: string | null;
|
|
67
|
+
form_success_msg?: string | null;
|
|
68
|
+
form_ajax_request?: boolean | null;
|
|
69
|
+
recaptcha_v3: boolean;
|
|
70
|
+
recaptcha_action: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type FormItemType = string | FormSectionFieldType;
|
|
74
|
+
|
|
75
|
+
export interface FormSectionFieldType {
|
|
76
|
+
name: string;
|
|
77
|
+
children: FormItemType[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface FormType {
|
|
81
|
+
settings: FormSettingsType;
|
|
82
|
+
fields: FormFieldsType;
|
|
83
|
+
items: FormItemType[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface BookingURLType {
|
|
87
|
+
date_format: string;
|
|
88
|
+
locale: string;
|
|
89
|
+
mobile_url: string;
|
|
90
|
+
mobile_url_no_availability: string;
|
|
91
|
+
url: string;
|
|
92
|
+
url_no_availability: string;
|
|
93
|
+
variables: string;
|
|
94
|
+
}
|
|
95
|
+
export interface BookingURLsType {
|
|
96
|
+
name: string;
|
|
97
|
+
booking_urls: BookingURLType;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface HotelsOptions {
|
|
101
|
+
[hotelId: string]: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface BookingURLsTypes {
|
|
105
|
+
[hotelCode: string]: BookingURLsType;
|
|
106
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import parseISO from "date-fns/parseISO"
|
|
2
|
+
import format from "date-fns/format"
|
|
3
|
+
import slugify from "slugify"
|
|
4
|
+
import { randomString } from "./string"
|
|
5
|
+
|
|
6
|
+
export interface QueryParamsType {
|
|
7
|
+
[key: string]: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const siteUrl = (path: string = "") =>
|
|
11
|
+
`${process.env.PROTOCOL}://${process.env.HOST}${path}`
|
|
12
|
+
|
|
13
|
+
const serializeDate = (date: string) => {
|
|
14
|
+
try {
|
|
15
|
+
return date ? parseISO(date) : undefined
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return undefined
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const serializeNumber = (n: string) => {
|
|
21
|
+
try {
|
|
22
|
+
return n ? parseInt(n) : undefined
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return undefined
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const serializeList = (str: string): string[] => (str ? [str] : [])
|
|
28
|
+
|
|
29
|
+
const serializeParam: any = {
|
|
30
|
+
check_in: serializeDate,
|
|
31
|
+
check_out: serializeDate,
|
|
32
|
+
child_count: serializeNumber,
|
|
33
|
+
adult_count: serializeNumber,
|
|
34
|
+
rate_codes: serializeList,
|
|
35
|
+
promo_codes: serializeList,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extracts query params from an URL
|
|
40
|
+
*
|
|
41
|
+
* @param queryString String with query params
|
|
42
|
+
* @param rename Object for renaming params, e.g: {"oldParam": "newParam"}
|
|
43
|
+
* @returns Object with the parsed params
|
|
44
|
+
*/
|
|
45
|
+
export function parseQueryParams(
|
|
46
|
+
queryString: string,
|
|
47
|
+
rename: { [k: string]: string } = {}
|
|
48
|
+
): QueryParamsType {
|
|
49
|
+
if (!queryString) return {}
|
|
50
|
+
// Transform rate_code and promo_code into their corresponding plurals
|
|
51
|
+
rename = { rate_code: "rate_codes", promo_code: "promo_codes", ...rename }
|
|
52
|
+
return queryString
|
|
53
|
+
.slice(1)
|
|
54
|
+
.split("&")
|
|
55
|
+
.reduce((acc: QueryParamsType, param: string) => {
|
|
56
|
+
let [key, value] = param.split("=")
|
|
57
|
+
key = decodeURIComponent(key)
|
|
58
|
+
value = decodeURIComponent(value || "")
|
|
59
|
+
if (rename[key]) {
|
|
60
|
+
key = rename[key]
|
|
61
|
+
}
|
|
62
|
+
acc[key] = serializeParam.hasOwnProperty(key)
|
|
63
|
+
? serializeParam[key](value)
|
|
64
|
+
: value
|
|
65
|
+
return acc
|
|
66
|
+
}, {})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const join_paths = (path1: string, path2: string): string =>
|
|
70
|
+
`${path1.replace(new RegExp(`/$`), "")}/${path2.replace(
|
|
71
|
+
new RegExp(`^/`),
|
|
72
|
+
""
|
|
73
|
+
)}`
|
|
74
|
+
|
|
75
|
+
export const api_link = (
|
|
76
|
+
apiPath: string = "",
|
|
77
|
+
queryParams: QueryParamsType | null = null
|
|
78
|
+
): string =>
|
|
79
|
+
`${join_paths(
|
|
80
|
+
`${process.env.API_PROTOCOL}://${process.env.API_HOST}`,
|
|
81
|
+
apiPath
|
|
82
|
+
)}${queryParams ? `?${new URLSearchParams(queryParams).toString()}` : ""}`
|
|
83
|
+
|
|
84
|
+
export const hotel_page_link = (city: string, hotelName: string) =>
|
|
85
|
+
`/book-accommodation/${slugify(city, {
|
|
86
|
+
lower: true,
|
|
87
|
+
})}/${slugify(hotelName, {
|
|
88
|
+
lower: true,
|
|
89
|
+
}).slice(5)}`
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* Transforms Search params into a query string
|
|
94
|
+
*/
|
|
95
|
+
export const sp_to_qs = (
|
|
96
|
+
check_in: Date,
|
|
97
|
+
check_out: Date,
|
|
98
|
+
adult_count: number,
|
|
99
|
+
child_count: number,
|
|
100
|
+
rate_codes: string[],
|
|
101
|
+
promo_codes: string[]
|
|
102
|
+
) =>
|
|
103
|
+
`?check_in=${format(check_in, "yyyy-MM-dd")}&check_out=${format(
|
|
104
|
+
check_out,
|
|
105
|
+
"yyyy-MM-dd"
|
|
106
|
+
)}&adult_count=${adult_count}&child_count=${child_count}&promo_code=${
|
|
107
|
+
promo_codes?.length ? promo_codes[0] : ""
|
|
108
|
+
}&rate_code=${rate_codes?.length ? rate_codes[0] : ""}`
|
|
109
|
+
|
|
110
|
+
export const opentableLink = (id: number): string =>
|
|
111
|
+
`https://www.opentable.com.au/restref/client?rid=${id}&restref=${id}&lang=en-AU&r3uid=${randomString(
|
|
112
|
+
9
|
|
113
|
+
)}&ot_source=Restaurant+website&color=1`
|
|
114
|
+
|
|
115
|
+
export const decodeQuotePlus = (text: string) =>
|
|
116
|
+
decodeURIComponent(text.replace(/\+/g, "%20"))
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ClassNames from "classnames";
|
|
2
|
+
|
|
3
|
+
export const IsMobile = () =>
|
|
4
|
+
typeof window !== "undefined" && window.innerWidth <= 1024; // Tablet and Mobile
|
|
5
|
+
|
|
6
|
+
export const scrollToElement = async (elementId: string) => {
|
|
7
|
+
document.getElementById(elementId)?.scrollIntoView({ behavior: "smooth" });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const scrollToChild = (parent: HTMLElement, child: HTMLElement) => {
|
|
11
|
+
const initialDisplayValue = parent.style.display;
|
|
12
|
+
// HACK: can't use getBoundingClientRect when display is 'none'
|
|
13
|
+
if (initialDisplayValue !== "block") {
|
|
14
|
+
parent.style.display = "block";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// can't use scrollIntoView because of scroll event bubbling
|
|
18
|
+
const parentPosition = parent.getBoundingClientRect();
|
|
19
|
+
const childPosition = child.getBoundingClientRect();
|
|
20
|
+
|
|
21
|
+
const topOffset = childPosition.top - parentPosition.top;
|
|
22
|
+
const bottomOffset = parentPosition.bottom - childPosition.bottom;
|
|
23
|
+
|
|
24
|
+
const isChildVisible = topOffset >= 0 && bottomOffset >= 0;
|
|
25
|
+
|
|
26
|
+
if (!isChildVisible) {
|
|
27
|
+
if (Math.abs(topOffset) < Math.abs(bottomOffset)) {
|
|
28
|
+
// element above the container
|
|
29
|
+
parent.scrollTop += topOffset;
|
|
30
|
+
} else {
|
|
31
|
+
// element below the container
|
|
32
|
+
parent.scrollTop -= bottomOffset;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
parent.style.display = initialDisplayValue;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
40
|
+
|
|
41
|
+
// Returns the device ID depending on the viewport width (d: Desktop, t: Tablet, m: Mobile)
|
|
42
|
+
export const deviceId = (width: number) =>
|
|
43
|
+
width > 1023 ? "d" : width > 768 ? "t" : "m";
|
|
44
|
+
|
|
45
|
+
const HideOnDevice = (devices: Array<string>, device: string): boolean =>
|
|
46
|
+
device ? !!devices.length && !devices.includes(device) : !devices.length;
|
|
47
|
+
|
|
48
|
+
export const classNames = (
|
|
49
|
+
classes: { [k: string]: boolean },
|
|
50
|
+
displayOn: Array<string> | null = null
|
|
51
|
+
): any => {
|
|
52
|
+
if (displayOn) {
|
|
53
|
+
classes.hidden = HideOnDevice(displayOn, "");
|
|
54
|
+
classes.hidden_mobile = HideOnDevice(displayOn, "m");
|
|
55
|
+
classes.hidden_tablet = HideOnDevice(displayOn, "t");
|
|
56
|
+
classes.hidden_desktop = HideOnDevice(displayOn, "d");
|
|
57
|
+
}
|
|
58
|
+
return ClassNames(classes);
|
|
59
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export { animateJSX } from "./browser/utils/animation";
|
|
2
|
+
export {
|
|
3
|
+
SearchAvailability,
|
|
4
|
+
BookingUrl,
|
|
5
|
+
hotelOptionsByCity,
|
|
6
|
+
pricePerNight,
|
|
7
|
+
} from "./browser/utils/booking_engine";
|
|
8
|
+
export {
|
|
9
|
+
saveUserSession,
|
|
10
|
+
loadUserSession,
|
|
11
|
+
deleteUserSession,
|
|
12
|
+
} from "./browser/utils/eclub";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
json_request,
|
|
16
|
+
getInputHumanValue,
|
|
17
|
+
getInputEventValue,
|
|
18
|
+
} from "./browser/utils/forms";
|
|
19
|
+
export { tagExists, joinAddress } from "./browser/utils/hotel";
|
|
20
|
+
export {
|
|
21
|
+
optimizedThumb,
|
|
22
|
+
getThumb,
|
|
23
|
+
toImageElement,
|
|
24
|
+
minimumSlides,
|
|
25
|
+
tripadvisorRatingURL,
|
|
26
|
+
preloadImages,
|
|
27
|
+
} from "./browser/utils/image";
|
|
28
|
+
export { countryPrefixes } from "./browser/utils/location";
|
|
29
|
+
export { toastMsg } from "./browser/utils/notifications";
|
|
30
|
+
export { human_number } from "./browser/utils/number";
|
|
31
|
+
export { ssoURL } from "./browser/utils/requests";
|
|
32
|
+
export { cacheSearchParams, cachedSearchParams } from "./browser/utils/search";
|
|
33
|
+
export { randomString } from "./browser/utils/string";
|
|
34
|
+
export {
|
|
35
|
+
siteUrl,
|
|
36
|
+
parseQueryParams,
|
|
37
|
+
join_paths,
|
|
38
|
+
api_link,
|
|
39
|
+
opentableLink,
|
|
40
|
+
hotel_page_link,
|
|
41
|
+
sp_to_qs,
|
|
42
|
+
} from "./browser/utils/url";
|
|
43
|
+
export {
|
|
44
|
+
classNames,
|
|
45
|
+
isIOS,
|
|
46
|
+
IsMobile,
|
|
47
|
+
deviceId,
|
|
48
|
+
scrollToChild,
|
|
49
|
+
scrollToElement,
|
|
50
|
+
} from "./browser/utils/viewport";
|
|
51
|
+
|
|
52
|
+
export { default as Checkbox } from "./browser/api/checkbox";
|
|
53
|
+
export { default as CountryPrefix } from "./browser/api/country-prefix";
|
|
54
|
+
export { default as Form } from "./browser/api/form";
|
|
55
|
+
export { default as GooglePlaces } from "./browser/api/google-places";
|
|
56
|
+
export { default as Icon } from "./browser/api/icon";
|
|
57
|
+
export { default as Image } from "./browser/api/image";
|
|
58
|
+
export { default as Input } from "./browser/api/input";
|
|
59
|
+
export { default as Link } from "./browser/api/link";
|
|
60
|
+
export { default as LinkList } from "./browser/api/linklist";
|
|
61
|
+
export { default as Select } from "./browser/api/select";
|
|
62
|
+
export { default as SVG } from "./browser/api/svg";
|
|
63
|
+
export { default as Text } from "./browser/api/text";
|
|
64
|
+
export { default as Textarea } from "./browser/api/textarea";
|
|
65
|
+
export { default as Title } from "./browser/api/title";
|
|
66
|
+
export { default as Button } from "./browser/api/button";
|
|
67
|
+
export { default as Carousel } from "./browser/carousel";
|
|
68
|
+
export { default as Markdown } from "./browser/markdown";
|
|
69
|
+
export { default as Modal } from "./browser/modal";
|
|
70
|
+
export { default as Spinner } from "./browser/spinner";
|
|
71
|
+
export { default as useViewport } from "./browser/use_viewport";
|
|
72
|
+
export { Toast } from "./browser/toast";
|
|
73
|
+
|
|
74
|
+
export type {
|
|
75
|
+
HotelOptionsByCityType,
|
|
76
|
+
CachedSearchParamsType,
|
|
77
|
+
FormType,
|
|
78
|
+
BookingURLType,
|
|
79
|
+
} from "./browser/utils/types";
|
|
80
|
+
|
|
81
|
+
export type {
|
|
82
|
+
ImageMediaType,
|
|
83
|
+
ImageType,
|
|
84
|
+
FileType,
|
|
85
|
+
SectionType,
|
|
86
|
+
TitleType,
|
|
87
|
+
TextType,
|
|
88
|
+
VideoMediaType,
|
|
89
|
+
LinkListType,
|
|
90
|
+
ButtonType,
|
|
91
|
+
InputType,
|
|
92
|
+
SelectType,
|
|
93
|
+
FileMediaType,
|
|
94
|
+
AnyElementType,
|
|
95
|
+
LinkType,
|
|
96
|
+
UserType,
|
|
97
|
+
MediaType,
|
|
98
|
+
DefaultPropsType,
|
|
99
|
+
LocationType,
|
|
100
|
+
PageParamsType,
|
|
101
|
+
ElementDataType,
|
|
102
|
+
} from "./browser/api/types";
|
|
103
|
+
export type { ErrorsType } from "./browser/api/form/types";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { join_paths, ssoURL } from "./node/url";
|
|
2
|
+
export { nOptions } from "./node/form";
|
|
3
|
+
export {
|
|
4
|
+
hotelOptionsByCity,
|
|
5
|
+
joinAddress,
|
|
6
|
+
hotel_page_link,
|
|
7
|
+
} from "./node/property";
|
|
8
|
+
export { createAPIPages, postBuild, buildElement } from "./node/build";
|
|
9
|
+
export {
|
|
10
|
+
extractForm,
|
|
11
|
+
tagExists,
|
|
12
|
+
api_link,
|
|
13
|
+
buildImage,
|
|
14
|
+
getImageData,
|
|
15
|
+
} from "./node/api";
|
|
16
|
+
export { defaultGatsbyConfig } from "./node/config";
|