@resira/ui 0.4.14 → 0.4.15

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.cjs CHANGED
@@ -3097,6 +3097,14 @@ function formatPrice5(cents, currency) {
3097
3097
  currency
3098
3098
  }).format(cents / 100);
3099
3099
  }
3100
+ function normalizeDurationMinutes(value) {
3101
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
3102
+ if (typeof value === "string" && value.trim()) {
3103
+ const parsed = Number(value);
3104
+ if (Number.isFinite(parsed) && parsed > 0) return parsed;
3105
+ }
3106
+ return void 0;
3107
+ }
3100
3108
  function buildSteps(domain, hasPayment, catalogMode) {
3101
3109
  const steps = [];
3102
3110
  if (domain === "watersport" || domain === "service" || catalogMode && domain !== "restaurant") {
@@ -3214,6 +3222,7 @@ function ResiraBookingWidget() {
3214
3222
  setPromoValidation(result);
3215
3223
  }, []);
3216
3224
  const [slotDate, setSlotDate] = react.useState(todayStr());
3225
+ const activeDurationMinutes = normalizeDurationMinutes(selection.duration);
3217
3226
  const availabilityParams = react.useMemo(() => {
3218
3227
  if (isDateBased) {
3219
3228
  if (selection.startDate && selection.endDate) {
@@ -3224,9 +3233,9 @@ function ResiraBookingWidget() {
3224
3233
  return {
3225
3234
  date: slotDate,
3226
3235
  partySize: selection.partySize,
3227
- durationMinutes: selection.duration
3236
+ durationMinutes: activeDurationMinutes
3228
3237
  };
3229
- }, [isDateBased, selection.startDate, selection.endDate, slotDate, selection.partySize, selection.duration]);
3238
+ }, [isDateBased, selection.startDate, selection.endDate, slotDate, selection.partySize, activeDurationMinutes]);
3230
3239
  const availabilityProductId = isServiceBased ? selectedProduct?.id : void 0;
3231
3240
  const { data: availability, loading, error, refetch } = useAvailability(
3232
3241
  availabilityParams,
@@ -3270,7 +3279,7 @@ function ResiraBookingWidget() {
3270
3279
  productId: selectedProduct?.id ?? "",
3271
3280
  resourceId,
3272
3281
  partySize: selection.partySize,
3273
- durationMinutes: selection.duration,
3282
+ durationMinutes: activeDurationMinutes,
3274
3283
  startDate: selection.startDate,
3275
3284
  startTime: selection.startTime,
3276
3285
  endTime: selection.endTime,
@@ -3282,7 +3291,7 @@ function ResiraBookingWidget() {
3282
3291
  termsAccepted: termsAccepted || void 0,
3283
3292
  waiverAccepted: waiverAccepted || void 0
3284
3293
  };
3285
- }, [activeResourceId, selectedProduct, selection, guest, discountCode, termsAccepted, waiverAccepted, isCheckoutMode, checkoutSession, checkoutSessionToken]);
3294
+ }, [activeResourceId, selectedProduct, selection, guest, discountCode, termsAccepted, waiverAccepted, isCheckoutMode, checkoutSession, checkoutSessionToken, activeDurationMinutes]);
3286
3295
  const blockedDates = react.useMemo(() => {
3287
3296
  const dates = calendarData?.dates?.blockedDates ?? availability?.dates?.blockedDates ?? [];
3288
3297
  return new Set(dates);
@@ -3302,11 +3311,11 @@ function ResiraBookingWidget() {
3302
3311
  if (selectedProduct) {
3303
3312
  let base = selectedProduct.priceCents;
3304
3313
  if (selectedProduct.pricingModel === "per_rider" && activeRiderDurationPricing?.length) {
3305
- const match = selection.duration ? activeRiderDurationPricing.find((dp) => dp.durationMinutes === selection.duration) : activeRiderDurationPricing[0];
3314
+ const match = activeDurationMinutes ? activeRiderDurationPricing.find((dp) => dp.durationMinutes === activeDurationMinutes) : activeRiderDurationPricing[0];
3306
3315
  if (match) base = match.priceCents;
3307
- } else if (selectedProduct.durationPricing?.length && selection.duration) {
3316
+ } else if (selectedProduct.durationPricing?.length && activeDurationMinutes) {
3308
3317
  const match = selectedProduct.durationPricing.find(
3309
- (dp) => dp.durationMinutes === selection.duration
3318
+ (dp) => dp.durationMinutes === activeDurationMinutes
3310
3319
  );
3311
3320
  if (match) base = match.priceCents;
3312
3321
  }
@@ -3324,7 +3333,7 @@ function ResiraBookingWidget() {
3324
3333
  return { total, amountNow, amountAtVenue };
3325
3334
  }
3326
3335
  return null;
3327
- }, [selectedProduct, availability, selection.partySize, selection.duration, depositPercent, activeRiderDurationPricing]);
3336
+ }, [selectedProduct, availability, selection.partySize, activeDurationMinutes, depositPercent, activeRiderDurationPricing]);
3328
3337
  const stepTitle = react.useMemo(() => {
3329
3338
  switch (step) {
3330
3339
  case "resource":
@@ -3768,7 +3777,7 @@ function ResiraBookingWidget() {
3768
3777
  onPartySizeChange: handlePartySizeChange,
3769
3778
  showPartySize: true,
3770
3779
  showDuration: domain === "watersport" || domain === "service",
3771
- selectedDuration: selection.duration,
3780
+ selectedDuration: activeDurationMinutes,
3772
3781
  onDurationChange: handleDurationChange,
3773
3782
  maxPartySizeOverride: selectedProduct?.maxPartySize,
3774
3783
  durationPricing: activeRiderDurationPricing ?? selectedProduct?.durationPricing,
@@ -3780,19 +3789,19 @@ function ResiraBookingWidget() {
3780
3789
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "resira-price-preview-row", children: [
3781
3790
  /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3782
3791
  selectedProduct.name,
3783
- selection.duration && selectedProduct.durationPricing && selectedProduct.durationPricing.length > 1 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "resira-price-preview-label", children: [
3792
+ activeDurationMinutes && selectedProduct.durationPricing && selectedProduct.durationPricing.length > 1 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "resira-price-preview-label", children: [
3784
3793
  " ",
3785
3794
  "(",
3786
- selection.duration < 60 ? `${selection.duration} min` : `${Math.floor(selection.duration / 60)}h${selection.duration % 60 ? selection.duration % 60 : ""}`,
3795
+ activeDurationMinutes < 60 ? `${activeDurationMinutes} min` : `${Math.floor(activeDurationMinutes / 60)}h${activeDurationMinutes % 60 ? activeDurationMinutes % 60 : ""}`,
3787
3796
  ")"
3788
3797
  ] })
3789
3798
  ] }),
3790
3799
  /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3791
3800
  (() => {
3792
3801
  let unitPrice = selectedProduct.priceCents;
3793
- if (selectedProduct.durationPricing?.length && selection.duration) {
3802
+ if (selectedProduct.durationPricing?.length && activeDurationMinutes) {
3794
3803
  const match = selectedProduct.durationPricing.find(
3795
- (dp) => dp.durationMinutes === selection.duration
3804
+ (dp) => dp.durationMinutes === activeDurationMinutes
3796
3805
  );
3797
3806
  if (match) unitPrice = match.priceCents;
3798
3807
  }