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