@ticketboothapp/booking 1.2.122 → 1.2.124

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.
Files changed (112) hide show
  1. package/CHANGE_BOOKING_BE_HANDOFF.md +15 -4
  2. package/package.json +1 -1
  3. package/src/components/booking/AdminChangeBookingContent.tsx +276 -0
  4. package/src/components/booking/AdminChangeBookingFlow.tsx +647 -6157
  5. package/src/components/booking/AdminChangeCheckoutDialogs.tsx +105 -0
  6. package/src/components/booking/AdminChangeCheckoutPanel.tsx +307 -0
  7. package/src/components/booking/AdminChangePricingPanel.tsx +244 -0
  8. package/src/components/booking/AdminChangeProductSwitcher.tsx +50 -0
  9. package/src/components/booking/AdminChangeReceiptComparison.tsx +167 -0
  10. package/src/components/booking/ChangeBookingCalendarPanel.tsx +126 -0
  11. package/src/components/booking/ChangeBookingCheckoutPanel.tsx +204 -0
  12. package/src/components/booking/ChangeBookingFlow.tsx +576 -4648
  13. package/src/components/booking/ChangeBookingItineraryPanel.tsx +115 -0
  14. package/src/components/booking/ChangeBookingQuoteStatusPlaceholder.tsx +57 -0
  15. package/src/components/booking/ChangeBookingSelectionControlsPanel.tsx +157 -0
  16. package/src/components/booking/ChangeBookingTicketsAndAddOnsPanel.tsx +102 -0
  17. package/src/components/booking/CheckoutModal.tsx +68 -49
  18. package/src/components/booking/NewBookingFlow.tsx +485 -3505
  19. package/src/components/booking/PriceBreakdown.tsx +17 -3
  20. package/src/components/booking/PriceSummary.tsx +21 -3
  21. package/src/components/booking/PrivateShuttleAddOnsSection.tsx +102 -0
  22. package/src/components/booking/PrivateShuttleBookingFlow.tsx +407 -2788
  23. package/src/components/booking/PrivateShuttleCheckoutDialogs.tsx +106 -0
  24. package/src/components/booking/PrivateShuttleCheckoutSection.tsx +333 -0
  25. package/src/components/booking/PrivateShuttleItinerarySection.tsx +95 -0
  26. package/src/components/booking/PrivateShuttleMediaIntro.tsx +62 -0
  27. package/src/components/booking/PrivateShuttleOptionSection.tsx +81 -0
  28. package/src/components/booking/PrivateShuttlePassengerSection.tsx +148 -0
  29. package/src/components/booking/PrivateShuttlePickupSection.tsx +91 -0
  30. package/src/components/booking/PrivateShuttlePreferencesSection.tsx +75 -0
  31. package/src/components/booking/PrivateShuttleStartTimeSection.tsx +88 -0
  32. package/src/components/booking/StandardBookingCheckoutDialogs.tsx +106 -0
  33. package/src/components/booking/StandardBookingCheckoutSection.tsx +185 -0
  34. package/src/components/booking/StandardBookingItineraryPanel.tsx +125 -0
  35. package/src/components/booking/StandardBookingMediaIntro.tsx +69 -0
  36. package/src/components/booking/StandardBookingSelectionControlsPanel.tsx +236 -0
  37. package/src/components/booking/admin-change-customer-quote-runner.ts +119 -0
  38. package/src/components/booking/admin-change-flow-state-helpers.ts +124 -0
  39. package/src/components/booking/admin-change-payment-choice-runner.ts +172 -0
  40. package/src/components/booking/admin-change-provider-payload.ts +101 -0
  41. package/src/components/booking/change-booking-checkout-builders.ts +185 -0
  42. package/src/components/booking/change-booking-checkout-quote-runner.ts +207 -0
  43. package/src/components/booking/change-booking-flow-helpers.ts +706 -0
  44. package/src/components/booking/change-booking-payment-modal-builders.ts +151 -0
  45. package/src/components/booking/change-booking-quote-guards.ts +223 -0
  46. package/src/components/booking/change-booking-quote-state.ts +64 -0
  47. package/src/components/booking/pricing-v2-checkout-summary.ts +144 -0
  48. package/src/components/booking/private-shuttle-availability.ts +111 -0
  49. package/src/components/booking/private-shuttle-checkout-builders.ts +264 -0
  50. package/src/components/booking/private-shuttle-checkout-controller.ts +744 -0
  51. package/src/components/booking/private-shuttle-payment-choice-runner.ts +271 -0
  52. package/src/components/booking/private-shuttle-provider-change-runner.ts +73 -0
  53. package/src/components/booking/private-shuttle-reservation-runner.ts +260 -0
  54. package/src/components/booking/standard-booking-availability.ts +305 -0
  55. package/src/components/booking/standard-booking-checkout-builders.ts +289 -0
  56. package/src/components/booking/standard-booking-checkout-controller.ts +659 -0
  57. package/src/components/booking/standard-booking-payment-choice-runner.ts +274 -0
  58. package/src/components/booking/standard-booking-reservation-runner.ts +229 -0
  59. package/src/components/booking/use-private-shuttle-availability.ts +602 -0
  60. package/src/components/booking/use-standard-booking-availability.ts +806 -0
  61. package/src/components/booking/useActiveProductOptions.ts +26 -0
  62. package/src/components/booking/useAdminChangeCheckoutController.ts +806 -0
  63. package/src/components/booking/useAdminChangeOrderSummaryModel.ts +246 -0
  64. package/src/components/booking/useAdminChangePriceSummary.ts +416 -0
  65. package/src/components/booking/useAdminChangePricingDebugPanel.tsx +178 -0
  66. package/src/components/booking/useAdminChangeProductReset.ts +60 -0
  67. package/src/components/booking/useAdminChangeProducts.ts +102 -0
  68. package/src/components/booking/useAdminChangePromoDiscount.ts +235 -0
  69. package/src/components/booking/useAdminChangeProtectedPricing.ts +280 -0
  70. package/src/components/booking/useAdminChangeQuoteDisplayState.tsx +437 -0
  71. package/src/components/booking/useAdminChangeQuotePreview.ts +506 -0
  72. package/src/components/booking/useAdminChangeReceiptDerivation.ts +203 -0
  73. package/src/components/booking/useAdminCustomReceiptLines.ts +57 -0
  74. package/src/components/booking/useAdminProviderPricingAdjustments.ts +146 -0
  75. package/src/components/booking/useBookingAvailabilityAddOns.ts +54 -0
  76. package/src/components/booking/useBookingPromoAndQuantityController.ts +163 -0
  77. package/src/components/booking/useBookingQuantityCapTrim.ts +56 -0
  78. package/src/components/booking/useBookingViewItemAnalytics.ts +30 -0
  79. package/src/components/booking/useChangeBookingAddOnFloorController.ts +109 -0
  80. package/src/components/booking/useChangeBookingAutoSelections.ts +148 -0
  81. package/src/components/booking/useChangeBookingAvailabilities.ts +692 -0
  82. package/src/components/booking/useChangeBookingCheckoutController.ts +461 -0
  83. package/src/components/booking/useChangeBookingInitialHydration.ts +204 -0
  84. package/src/components/booking/useChangeBookingItineraryUiState.ts +133 -0
  85. package/src/components/booking/useChangeBookingPickupItinerary.ts +472 -0
  86. package/src/components/booking/useChangeBookingPriceSummary.ts +199 -0
  87. package/src/components/booking/useChangeBookingPromoDiscount.ts +218 -0
  88. package/src/components/booking/useChangeBookingProtectedPricing.ts +256 -0
  89. package/src/components/booking/useChangeBookingQuotePreview.ts +442 -0
  90. package/src/components/booking/useChangeBookingReceiptDerivation.ts +128 -0
  91. package/src/components/booking/useChangeBookingReceiptFloorController.ts +449 -0
  92. package/src/components/booking/useChangeBookingSelection.ts +362 -0
  93. package/src/components/booking/useChangeBookingSelectionDetails.ts +200 -0
  94. package/src/components/booking/useChangeBookingSummaryLines.ts +169 -0
  95. package/src/components/booking/usePrivateShuttlePriceSummary.ts +513 -0
  96. package/src/components/booking/usePrivateShuttlePromoController.ts +143 -0
  97. package/src/components/booking/usePrivateShuttlePromoDiscount.ts +124 -0
  98. package/src/components/booking/useSeedPromoCodeInput.ts +13 -0
  99. package/src/components/booking/useStandardBookingAutoSelections.ts +224 -0
  100. package/src/components/booking/useStandardBookingPickupItinerary.ts +473 -0
  101. package/src/components/booking/useStandardBookingPriceSummary.ts +438 -0
  102. package/src/components/booking/useStandardBookingPromoController.ts +258 -0
  103. package/src/components/booking/useStandardBookingPromoDiscount.ts +203 -0
  104. package/src/data/products-config.json +1 -1
  105. package/src/lib/booking/change-booking-server-preview.ts +134 -20
  106. package/src/lib/booking/change-flow-pricing.ts +31 -11
  107. package/src/lib/booking/checkout-breakdown.ts +66 -1
  108. package/src/lib/booking/pricing-config.ts +10 -0
  109. package/src/lib/booking/source-metadata.ts +58 -0
  110. package/src/lib/booking-api.ts +154 -3
  111. package/src/lib/pricing-v2-shadow.ts +272 -0
  112. package/test/change-booking-helpers.test.ts +206 -0
@@ -0,0 +1,148 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useRef, type RefObject } from 'react';
4
+ import type { Availability, PickupLocation } from '../../lib/booking-api';
5
+
6
+ export interface UseChangeBookingAutoSelectionsOptions {
7
+ autoSelectFirstAvailableDate?: boolean;
8
+ autoSelectFirstHighlightedPickup?: boolean;
9
+ isPartialLaunch: boolean;
10
+ initialDateTime?: string | null;
11
+ selectedDate: string;
12
+ dates: string[];
13
+ getRowsForDate: (date: string) => Availability[];
14
+ isAdmin: boolean;
15
+ isCustomerSelfServeChange: boolean;
16
+ changeFlowInitialTicketCount: number;
17
+ getCalendarEffectiveOutboundVacancies: (availability: Availability) => number;
18
+ setSelectedDate: (date: string) => void;
19
+ onDateSelect: (date: string) => void;
20
+ suppressCalendarDateScroll?: boolean;
21
+ contentRef?: RefObject<HTMLDivElement | null>;
22
+ useWindowScroll: boolean;
23
+ highlightedPickupLocationIds?: string[];
24
+ pickupLocationId: string | null;
25
+ pickupLocationSkipped: boolean;
26
+ initialPickupLocationId?: string | null;
27
+ pickupLocations?: PickupLocation[];
28
+ setPickupLocationId: (locationId: string | null) => void;
29
+ setPickupLocationSkipped: (skipped: boolean) => void;
30
+ }
31
+
32
+ function scrollAfterCalendarSelection(
33
+ contentRef: RefObject<HTMLDivElement | null> | undefined,
34
+ useWindowScroll: boolean,
35
+ ) {
36
+ setTimeout(() => {
37
+ const container = contentRef?.current;
38
+ if (!useWindowScroll && container && container.scrollHeight > container.clientHeight + 16) {
39
+ container.scrollBy({ top: 400, behavior: 'smooth' });
40
+ } else if (typeof window !== 'undefined') {
41
+ window.scrollBy({ top: 400, behavior: 'smooth' });
42
+ }
43
+ }, 100);
44
+ }
45
+
46
+ export function useChangeBookingAutoSelections({
47
+ autoSelectFirstAvailableDate = false,
48
+ autoSelectFirstHighlightedPickup = false,
49
+ isPartialLaunch,
50
+ initialDateTime,
51
+ selectedDate,
52
+ dates,
53
+ getRowsForDate,
54
+ isAdmin,
55
+ isCustomerSelfServeChange,
56
+ changeFlowInitialTicketCount,
57
+ getCalendarEffectiveOutboundVacancies,
58
+ setSelectedDate,
59
+ onDateSelect,
60
+ suppressCalendarDateScroll,
61
+ contentRef,
62
+ useWindowScroll,
63
+ highlightedPickupLocationIds,
64
+ pickupLocationId,
65
+ pickupLocationSkipped,
66
+ initialPickupLocationId,
67
+ pickupLocations,
68
+ setPickupLocationId,
69
+ setPickupLocationSkipped,
70
+ }: UseChangeBookingAutoSelectionsOptions) {
71
+ const hasAutoSelectedPartnerDateRef = useRef(false);
72
+ const hasAutoSelectedPartnerPickupRef = useRef(false);
73
+
74
+ useEffect(() => {
75
+ if (!autoSelectFirstAvailableDate) return;
76
+ if (isPartialLaunch) return;
77
+ if (initialDateTime?.trim()) return;
78
+ if (selectedDate !== '') return;
79
+ if (dates.length === 0) return;
80
+ if (hasAutoSelectedPartnerDateRef.current) return;
81
+
82
+ const firstWithInventory = dates.find((date) => {
83
+ const rows = getRowsForDate(date);
84
+ if (rows.length === 0) return false;
85
+ if (isAdmin) return rows.some((availability) => (availability.vacancies ?? 0) > 0);
86
+ if (isCustomerSelfServeChange && changeFlowInitialTicketCount > 0) {
87
+ return rows.some(
88
+ (availability) =>
89
+ getCalendarEffectiveOutboundVacancies(availability) >= changeFlowInitialTicketCount,
90
+ );
91
+ }
92
+ return rows.some((availability) => (availability.vacancies ?? 0) > 0);
93
+ });
94
+ const first = firstWithInventory ?? (isAdmin && dates[0] ? dates[0] : undefined);
95
+ if (!first) return;
96
+
97
+ hasAutoSelectedPartnerDateRef.current = true;
98
+ setSelectedDate(first);
99
+ onDateSelect(first);
100
+ if (!suppressCalendarDateScroll) {
101
+ scrollAfterCalendarSelection(contentRef, useWindowScroll);
102
+ }
103
+ }, [
104
+ autoSelectFirstAvailableDate,
105
+ isPartialLaunch,
106
+ initialDateTime,
107
+ selectedDate,
108
+ dates,
109
+ getRowsForDate,
110
+ isAdmin,
111
+ isCustomerSelfServeChange,
112
+ changeFlowInitialTicketCount,
113
+ getCalendarEffectiveOutboundVacancies,
114
+ setSelectedDate,
115
+ onDateSelect,
116
+ suppressCalendarDateScroll,
117
+ contentRef,
118
+ useWindowScroll,
119
+ ]);
120
+
121
+ useEffect(() => {
122
+ if (!autoSelectFirstHighlightedPickup) return;
123
+ if (hasAutoSelectedPartnerPickupRef.current) return;
124
+ if (!highlightedPickupLocationIds?.length) return;
125
+ if (pickupLocationId) return;
126
+ if (pickupLocationSkipped) return;
127
+ if (initialPickupLocationId?.trim()) return;
128
+ if (!pickupLocations?.length) return;
129
+
130
+ const match = highlightedPickupLocationIds.find((id) =>
131
+ pickupLocations.some((location) => location.id === id),
132
+ );
133
+ if (!match) return;
134
+
135
+ hasAutoSelectedPartnerPickupRef.current = true;
136
+ setPickupLocationId(match);
137
+ setPickupLocationSkipped(false);
138
+ }, [
139
+ autoSelectFirstHighlightedPickup,
140
+ highlightedPickupLocationIds,
141
+ pickupLocationId,
142
+ pickupLocationSkipped,
143
+ initialPickupLocationId,
144
+ pickupLocations,
145
+ setPickupLocationId,
146
+ setPickupLocationSkipped,
147
+ ]);
148
+ }