@travories/frontend-sdk 0.1.2 → 0.1.3

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
@@ -314,6 +314,45 @@ var AgenciesResource = class {
314
314
  }
315
315
  };
316
316
 
317
+ // src/api/bookings.ts
318
+ var BookingsResource = class {
319
+ constructor(http) {
320
+ this.http = http;
321
+ }
322
+ /**
323
+ * Open a booking. The BE returns a booking UUID — combine it with
324
+ * `https://travories.com/package/<id>/payment`
325
+ * to send the user into the existing payment flow.
326
+ *
327
+ * Throws (not silent) so the consumer can surface errors to the user. Wrap
328
+ * in try/catch in your `onReserve` handler.
329
+ */
330
+ async initiate(payload, options) {
331
+ if (!payload?.packageId) {
332
+ throw new Error("[TravoriesClient] bookings.initiate requires packageId");
333
+ }
334
+ if (!payload?.arrivalDate) {
335
+ throw new Error("[TravoriesClient] bookings.initiate requires arrivalDate");
336
+ }
337
+ if (!payload?.travelers?.length) {
338
+ throw new Error("[TravoriesClient] bookings.initiate requires at least one traveler");
339
+ }
340
+ const res = await this.http.request(
341
+ `/booking/initiate`,
342
+ {
343
+ method: "POST",
344
+ body: payload,
345
+ silent: false,
346
+ ...options
347
+ }
348
+ );
349
+ if (!res?.data) {
350
+ throw new Error("[TravoriesClient] bookings.initiate returned no booking id");
351
+ }
352
+ return res;
353
+ }
354
+ };
355
+
317
356
  // src/client/TravoriesClient.ts
318
357
  var TravoriesClient = class {
319
358
  constructor(config) {
@@ -326,6 +365,7 @@ var TravoriesClient = class {
326
365
  this.http = new HttpClient(config);
327
366
  this.packages = new PackagesResource(this.http);
328
367
  this.agencies = new AgenciesResource(this.http);
368
+ this.bookings = new BookingsResource(this.http);
329
369
  }
330
370
  };
331
371
  function createTravoriesClient(config) {
@@ -955,16 +995,21 @@ var BookingCardLite = ({
955
995
  (o) => o.id === id ? { ...o, count: Math.max(0, o.count + (inc ? 1 : -1)) } : o
956
996
  )
957
997
  );
998
+ const [isSubmitting, setIsSubmitting] = useState(false);
958
999
  const handleReserve = () => {
959
1000
  if (!onReserve) return;
960
1001
  if (allPeopleCount === 0) return;
961
- onReserve({
1002
+ const result = onReserve({
962
1003
  arrival,
963
1004
  departure,
964
1005
  travelers: options.filter((o) => o.count > 0),
965
1006
  totalCost,
966
1007
  pricePerPerson: currentPrice
967
1008
  });
1009
+ if (result && typeof result.then === "function") {
1010
+ setIsSubmitting(true);
1011
+ result.finally(() => setIsSubmitting(false));
1012
+ }
968
1013
  };
969
1014
  return /* @__PURE__ */ jsxs("div", { className: "w-full sm:w-full lg:w-[520px] h-fit border rounded-xl shadow-md px-4 sm:px-6 bg-white flex flex-col gap-6 py-8 sm:py-10", children: [
970
1015
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
@@ -1124,9 +1169,9 @@ var BookingCardLite = ({
1124
1169
  {
1125
1170
  type: "button",
1126
1171
  onClick: handleReserve,
1127
- disabled: allPeopleCount === 0 || !onReserve,
1172
+ disabled: allPeopleCount === 0 || !onReserve || isSubmitting,
1128
1173
  className: "w-full py-2 md:py-3 bg-primary-normal text-white font-semibold rounded-lg hover:bg-primary-normal-hover transition text-sm md:text-base disabled:opacity-60 disabled:cursor-not-allowed",
1129
- children: allPeopleCount === 0 ? "Reserve Now" : /* @__PURE__ */ jsxs(Fragment, { children: [
1174
+ children: isSubmitting ? "Initiating\u2026" : allPeopleCount === 0 ? "Reserve Now" : /* @__PURE__ */ jsxs(Fragment, { children: [
1130
1175
  "Book Now - ",
1131
1176
  formatCurrency(totalCost, currency)
1132
1177
  ] })
@@ -2739,6 +2784,6 @@ function DefaultLoading2() {
2739
2784
  ] });
2740
2785
  }
2741
2786
 
2742
- export { AgenciesResource, AgencyAssociations_default as AgencyAssociations, AgencyDetailView, BookingCardLite_default as BookingCardLite, DescriptionSection_default as DescriptionSection, GallerySection_default as GallerySection, HomeSections, HomeSectionsProvider, HostAbout_default as HostAbout, HostCard_default as HostCard, Itinerary_default as Itinerary, PackageCard_default as PackageCard, PackageDetailView, PackageExcludedAndToPack_default as PackageExcludedAndToPack, PackageIncluded_default as PackageIncluded, PackageMap, PackageOverview_default as PackageOverview, PackagesCarousel_default as PackagesCarousel, PackagesResource, PackagesSection_default as PackagesSection, TopSection_default as TopSection, TravoriesApiError, TravoriesClient, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
2787
+ export { AgenciesResource, AgencyAssociations_default as AgencyAssociations, AgencyDetailView, BookingCardLite_default as BookingCardLite, BookingsResource, DescriptionSection_default as DescriptionSection, GallerySection_default as GallerySection, HomeSections, HomeSectionsProvider, HostAbout_default as HostAbout, HostCard_default as HostCard, Itinerary_default as Itinerary, PackageCard_default as PackageCard, PackageDetailView, PackageExcludedAndToPack_default as PackageExcludedAndToPack, PackageIncluded_default as PackageIncluded, PackageMap, PackageOverview_default as PackageOverview, PackagesCarousel_default as PackagesCarousel, PackagesResource, PackagesSection_default as PackagesSection, TopSection_default as TopSection, TravoriesApiError, TravoriesClient, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
2743
2788
  //# sourceMappingURL=index.mjs.map
2744
2789
  //# sourceMappingURL=index.mjs.map