@wix/headless-bookings 0.0.60 → 0.0.62

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 (37) hide show
  1. package/cjs/dist/react/booking/Book.d.ts +2 -0
  2. package/cjs/dist/react/booking/Book.js +11 -1
  3. package/cjs/dist/react/booking/Booking.d.ts +16 -15
  4. package/cjs/dist/react/booking/Booking.js +12 -16
  5. package/cjs/dist/react/core/payment/Payment.d.ts +2 -0
  6. package/cjs/dist/react/core/payment/Payment.js +5 -6
  7. package/cjs/dist/react/core/time-slot-list/TimeSlotList.d.ts +47 -3
  8. package/cjs/dist/react/core/time-slot-list/TimeSlotList.js +55 -5
  9. package/cjs/dist/react/payment/Payment.d.ts +5 -3
  10. package/cjs/dist/react/payment/Payment.js +5 -5
  11. package/cjs/dist/react/time-slot-list/TimeSlotList.d.ts +30 -7
  12. package/cjs/dist/react/time-slot-list/TimeSlotList.js +31 -8
  13. package/cjs/dist/services/payment/payment.def.d.ts +2 -0
  14. package/cjs/dist/services/payment/payment.js +2 -1
  15. package/cjs/dist/utils/index.d.ts +5 -0
  16. package/cjs/dist/utils/index.js +5 -0
  17. package/cjs/dist/utils/navigation.d.ts +7 -0
  18. package/cjs/dist/utils/navigation.js +75 -0
  19. package/dist/react/booking/Book.d.ts +2 -0
  20. package/dist/react/booking/Book.js +11 -1
  21. package/dist/react/booking/Booking.d.ts +16 -15
  22. package/dist/react/booking/Booking.js +12 -16
  23. package/dist/react/core/payment/Payment.d.ts +2 -0
  24. package/dist/react/core/payment/Payment.js +5 -6
  25. package/dist/react/core/time-slot-list/TimeSlotList.d.ts +47 -3
  26. package/dist/react/core/time-slot-list/TimeSlotList.js +55 -5
  27. package/dist/react/payment/Payment.d.ts +5 -3
  28. package/dist/react/payment/Payment.js +5 -5
  29. package/dist/react/time-slot-list/TimeSlotList.d.ts +30 -7
  30. package/dist/react/time-slot-list/TimeSlotList.js +31 -8
  31. package/dist/services/payment/payment.def.d.ts +2 -0
  32. package/dist/services/payment/payment.js +2 -1
  33. package/dist/utils/index.d.ts +5 -0
  34. package/dist/utils/index.js +5 -0
  35. package/dist/utils/navigation.d.ts +7 -0
  36. package/dist/utils/navigation.js +75 -0
  37. package/package.json +2 -2
@@ -16,9 +16,11 @@ export interface BookProps {
16
16
  disabled?: boolean;
17
17
  onCheckout?: (result: {
18
18
  checkoutId: string;
19
+ navigateToCheckout: (checkoutId: string) => void;
19
20
  }) => void;
20
21
  onComplete?: (result: {
21
22
  orderId: string;
23
+ navigateToThankYou: (orderId: string) => void;
22
24
  }) => void;
23
25
  onError?: (error: BookingError) => void;
24
26
  }
@@ -6,6 +6,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
6
6
  import React from 'react';
7
7
  import { AsChildSlot } from '@wix/headless-utils/react';
8
8
  import * as CoreBook from '../core/booking/Book.js';
9
+ import { navigateToCheckout } from '../../utils/navigation.js';
9
10
  var TestIds;
10
11
  (function (TestIds) {
11
12
  TestIds["bookingActionBook"] = "booking-action-book";
@@ -49,6 +50,15 @@ var TestIds;
49
50
  */
50
51
  export const Book = React.forwardRef((props, ref) => {
51
52
  const { asChild, children, className, label = 'Book Now', loadingState = 'Booking...', disabled, onCheckout, onComplete, onError, } = props;
52
- return (_jsx(CoreBook.Book, { onCheckout: onCheckout, onComplete: onComplete, onError: onError, disabled: disabled, children: (childProps) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.bookingActionBook, "data-in-progress": childProps.isLoading, customElement: children, customElementProps: childProps, children: _jsx("button", { onClick: childProps.onClick, disabled: childProps.disabled, children: childProps.isLoading ? loadingState : label }) })) }));
53
+ return (_jsx(CoreBook.Book, { onCheckout: (result) => {
54
+ onCheckout?.({ ...result, navigateToCheckout });
55
+ }, onComplete: (result) => {
56
+ onComplete?.({
57
+ ...result,
58
+ navigateToThankYou: (orderId) => {
59
+ console.log('navigateToThankYou', orderId);
60
+ },
61
+ });
62
+ }, onError: onError, disabled: disabled, children: (childProps) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.bookingActionBook, "data-in-progress": childProps.isLoading, customElement: children, customElementProps: childProps, children: _jsx("button", { onClick: childProps.onClick, disabled: childProps.disabled, children: childProps.isLoading ? loadingState : label }) })) }));
53
63
  });
54
64
  Book.displayName = 'Booking.Actions.Book';
@@ -192,31 +192,32 @@ export declare function TimeSlot(props: BookingTimeSlotProps): React.ReactNode;
192
192
  * Props for Booking.Payment component
193
193
  */
194
194
  export interface BookingPaymentProps {
195
- children: React.ReactNode;
195
+ children?: React.ReactNode | ((props: {
196
+ isLoading: boolean;
197
+ hasError: boolean;
198
+ }) => React.ReactNode);
199
+ asChild?: boolean;
200
+ className?: string;
196
201
  }
197
202
  /**
198
203
  * Wraps Payment.Root with all services from all booking items.
199
204
  * Should be used outside of ItemRepeater - it calculates payment for all items.
200
205
  * Children can use all Payment.* components (Payment.Total, Payment.Subtotal, etc.).
201
- * Always renders with data-has-payment attribute for CSS targeting.
206
+ * Supports asChild to expose { isLoading, hasError } to children.
202
207
  *
203
208
  * @component
204
209
  * @example
205
210
  * ```tsx
206
- * <Booking.Root>
207
- * <Booking.ItemsRoot>
208
- * <Booking.Items>
209
- * <Booking.ItemRepeater>
210
- * <Booking.Service><Service.Name /></Booking.Service>
211
- * </Booking.ItemRepeater>
212
- * </Booking.Items>
213
- * </Booking.ItemsRoot>
211
+ * // Standard usage
212
+ * <Booking.Payment>
213
+ * <Payment.Total className="text-xl font-bold" />
214
+ * <Payment.Subtotal />
215
+ * </Booking.Payment>
214
216
  *
215
- * <Booking.Payment>
216
- * <Payment.Total className="text-xl font-bold" />
217
- * <Payment.Subtotal />
218
- * </Booking.Payment>
219
- * </Booking.Root>
217
+ * // With asChild to access isLoading
218
+ * <Booking.Payment asChild>
219
+ * {({ isLoading }) => isLoading ? <Skeleton /> : <PaymentSection />}
220
+ * </Booking.Payment>
220
221
  * ```
221
222
  */
222
223
  export declare function Payment(props: BookingPaymentProps): React.ReactNode;
@@ -204,30 +204,26 @@ export function TimeSlot(props) {
204
204
  * Wraps Payment.Root with all services from all booking items.
205
205
  * Should be used outside of ItemRepeater - it calculates payment for all items.
206
206
  * Children can use all Payment.* components (Payment.Total, Payment.Subtotal, etc.).
207
- * Always renders with data-has-payment attribute for CSS targeting.
207
+ * Supports asChild to expose { isLoading, hasError } to children.
208
208
  *
209
209
  * @component
210
210
  * @example
211
211
  * ```tsx
212
- * <Booking.Root>
213
- * <Booking.ItemsRoot>
214
- * <Booking.Items>
215
- * <Booking.ItemRepeater>
216
- * <Booking.Service><Service.Name /></Booking.Service>
217
- * </Booking.ItemRepeater>
218
- * </Booking.Items>
219
- * </Booking.ItemsRoot>
212
+ * // Standard usage
213
+ * <Booking.Payment>
214
+ * <Payment.Total className="text-xl font-bold" />
215
+ * <Payment.Subtotal />
216
+ * </Booking.Payment>
220
217
  *
221
- * <Booking.Payment>
222
- * <Payment.Total className="text-xl font-bold" />
223
- * <Payment.Subtotal />
224
- * </Booking.Payment>
225
- * </Booking.Root>
218
+ * // With asChild to access isLoading
219
+ * <Booking.Payment asChild>
220
+ * {({ isLoading }) => isLoading ? <Skeleton /> : <PaymentSection />}
221
+ * </Booking.Payment>
226
222
  * ```
227
223
  */
228
224
  export function Payment(props) {
229
- const { children } = props;
230
- return (_jsx(CoreBooking.PaymentData, { children: ({ pricingServiceSelections }) => (_jsx(PaymentComponent.Root, { pricingServiceSelections: pricingServiceSelections, children: children })) }));
225
+ const { children, asChild, className } = props;
226
+ return (_jsx(CoreBooking.PaymentData, { children: ({ pricingServiceSelections }) => (_jsx(PaymentComponent.Root, { pricingServiceSelections: pricingServiceSelections, asChild: asChild, className: className, children: children })) }));
231
227
  }
232
228
  /**
233
229
  * Wraps Location context with the location from the booking context.
@@ -95,6 +95,8 @@ export interface LineItem {
95
95
  deposit: MoneyData | null;
96
96
  /** Custom price text (for CUSTOM rate type) */
97
97
  priceText: string | null;
98
+ /** Whether this is a free service (NO_FEE rate type) */
99
+ isFree: boolean;
98
100
  }
99
101
  /**
100
102
  * Props for LineItems render prop component
@@ -77,12 +77,13 @@ export function Data(props) {
77
77
  const discount = convertMultiCurrencyPriceToMoneyData(priceSummary?.discount, currency);
78
78
  const payNow = convertMultiCurrencyPriceToMoneyData(paymentDetails?.response?.payNow?.total, currency);
79
79
  const payLater = convertMultiCurrencyPriceToMoneyData(paymentDetails?.response?.payLater?.total, currency);
80
- // Get priceText from first line item (single service mode)
80
+ // Get priceText and isFree from first line item (single service mode)
81
81
  const additionalInfoList = paymentDetails?.additionalInfo?.lineItems || [];
82
82
  const firstLineItemInfo = additionalInfoList[0];
83
83
  const priceText = firstLineItemInfo?.priceText || null;
84
84
  const hasPriceText = !!priceText;
85
- const isFree = total !== null && total.amount === 0 && !hasPriceText;
85
+ // Use isFree from service (NO_FEE rate type) if available, otherwise fallback to amount check
86
+ const isFree = firstLineItemInfo?.isFree ?? false;
86
87
  // Computed flags
87
88
  const hasTax = tax !== null && tax.amount > 0;
88
89
  const hasDiscount = discount !== null && discount.amount > 0;
@@ -145,6 +146,7 @@ export function LineItems(props) {
145
146
  discount: convertMultiCurrencyPriceToMoneyData(pricesBreakdown?.totalDiscount, currency),
146
147
  deposit: convertMultiCurrencyPriceToMoneyData(pricesBreakdown?.depositAmount, currency),
147
148
  priceText: additionalInfo?.priceText || null,
149
+ isFree: additionalInfo?.isFree ?? false,
148
150
  };
149
151
  });
150
152
  const hasLineItems = lineItems.length > 0;
@@ -212,9 +214,6 @@ export function LineItemInfo(props) {
212
214
  const { lineItem, currency } = useLineItemContext();
213
215
  // Computed flags
214
216
  const hasPriceText = !!lineItem.priceText;
215
- const isFree = lineItem.totalPrice !== null &&
216
- lineItem.totalPrice.amount === 0 &&
217
- !hasPriceText;
218
217
  const hasDiscount = lineItem.discount !== null && lineItem.discount.amount > 0;
219
218
  const hasDeposit = lineItem.deposit !== null && lineItem.deposit.amount > 0;
220
219
  return props.children({
@@ -227,7 +226,7 @@ export function LineItemInfo(props) {
227
226
  deposit: lineItem.deposit,
228
227
  priceText: lineItem.priceText,
229
228
  hasPriceText,
230
- isFree,
229
+ isFree: lineItem.isFree,
231
230
  hasDiscount,
232
231
  hasDeposit,
233
232
  });
@@ -5,12 +5,49 @@
5
5
  import React from 'react';
6
6
  import { type TimeSlotListServiceConfig } from '../../../services/time-slot-list/index.js';
7
7
  import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
8
+ import { type ServiceSelectionTimeSlot } from '../../../services/booking/booking.js';
9
+ import type { Service } from '@wix/auto_sdk_bookings_services';
10
+ /**
11
+ * Render props data provided to TimeSlotList.Root children
12
+ */
13
+ export interface TimeSlotListRootRenderProps {
14
+ /** Function to navigate to the booking form with the selected time slot */
15
+ navigateToBookingForm: ({ timeSlot, service, }: {
16
+ timeSlot?: ServiceSelectionTimeSlot;
17
+ service?: Service;
18
+ }) => Promise<void>;
19
+ }
8
20
  /**
9
21
  * Props for Root component
10
22
  */
11
23
  export interface RootProps {
12
- children: React.ReactNode;
24
+ children: (data: TimeSlotListRootRenderProps) => React.ReactNode;
13
25
  config: TimeSlotListServiceConfig;
26
+ /**
27
+ * Function to navigate to the booking form with the selected time slot.
28
+ * The timeSlot and service parameters are optional - if not provided,
29
+ * BookingService will be used to get them from the current service selections.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * <Root
34
+ * config={config}
35
+ * navigateToBookingForm={async ({ timeSlot, service }) => {
36
+ * // Custom navigation logic
37
+ * await navigateToBookingForm({ timeSlot, service });
38
+ * }}
39
+ * >
40
+ * {({ navigateToBookingForm }) => (
41
+ * // Use navigateToBookingForm in children
42
+ * // Can call with: navigateToBookingForm() or navigateToBookingForm({ timeSlot, service })
43
+ * )}
44
+ * </Root>
45
+ * ```
46
+ */
47
+ navigateToBookingForm: ({ timeSlot, service, }: {
48
+ timeSlot?: ServiceSelectionTimeSlot;
49
+ service?: Service;
50
+ }) => Promise<void>;
14
51
  }
15
52
  /**
16
53
  * Root component that provides TimeSlotListService context to its children.
@@ -18,8 +55,15 @@ export interface RootProps {
18
55
  * @component
19
56
  * @example
20
57
  * ```tsx
21
- * <Root config={{ services, timeSlots, timezone }}>
22
- * {children}
58
+ * <Root
59
+ * config={{ services, timeSlots, timezone }}
60
+ * navigateToBookingForm={async (selection) => {
61
+ * await navigateToBookingForm(selection);
62
+ * }}
63
+ * >
64
+ * {({ navigateToBookingForm }) => (
65
+ * // Your components that can use navigateToBookingForm
66
+ * )}
23
67
  * </Root>
24
68
  * ```
25
69
  */
@@ -1,21 +1,71 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useService, WixServices } from '@wix/services-manager-react';
3
3
  import { createServicesMap } from '@wix/services-manager';
4
4
  import { TimeSlotListServiceDefinition, TimeSlotListService, } from '../../../services/time-slot-list/index.js';
5
- import { BookingServiceDefinition } from '../../../services/booking/booking.js';
5
+ import { BookingServiceDefinition, } from '../../../services/booking/booking.js';
6
6
  /**
7
7
  * Root component that provides TimeSlotListService context to its children.
8
8
  *
9
9
  * @component
10
10
  * @example
11
11
  * ```tsx
12
- * <Root config={{ services, timeSlots, timezone }}>
13
- * {children}
12
+ * <Root
13
+ * config={{ services, timeSlots, timezone }}
14
+ * navigateToBookingForm={async (selection) => {
15
+ * await navigateToBookingForm(selection);
16
+ * }}
17
+ * >
18
+ * {({ navigateToBookingForm }) => (
19
+ * // Your components that can use navigateToBookingForm
20
+ * )}
14
21
  * </Root>
15
22
  * ```
16
23
  */
17
24
  export function Root(props) {
18
- return (_jsx(WixServices, { servicesMap: createServicesMap().addService(TimeSlotListServiceDefinition, TimeSlotListService, props.config), children: props.children }));
25
+ return (_jsx(WixServices, { servicesMap: createServicesMap().addService(TimeSlotListServiceDefinition, TimeSlotListService, props.config), children: _jsx(RootContent, { navigateToBookingForm: props.navigateToBookingForm, children: props.children }) }));
26
+ }
27
+ /**
28
+ * Internal component that wraps navigateToBookingForm to handle optional parameters
29
+ */
30
+ function RootContent({ navigateToBookingForm: providedNavigateToBookingForm, children, }) {
31
+ // Get BookingService to use when timeSlot/service are not provided
32
+ let bookingService = null;
33
+ try {
34
+ bookingService = useService(BookingServiceDefinition);
35
+ }
36
+ catch {
37
+ // BookingService not available - that's ok, user must provide timeSlot/service
38
+ bookingService = null;
39
+ }
40
+ // Wrap the provided navigateToBookingForm to handle optional parameters
41
+ const navigateToBookingForm = async ({ timeSlot, service, }) => {
42
+ // If timeSlot or service are not provided, try to get them from BookingService
43
+ let resolvedTimeSlot = timeSlot;
44
+ let resolvedService = service;
45
+ if ((!resolvedTimeSlot || !resolvedService) && bookingService) {
46
+ const serviceSelections = bookingService.serviceSelections.get();
47
+ if (serviceSelections.length > 0) {
48
+ const firstSelection = serviceSelections[0];
49
+ if (firstSelection) {
50
+ resolvedService = resolvedService || firstSelection.service;
51
+ resolvedTimeSlot = resolvedTimeSlot || firstSelection.timeSlot;
52
+ }
53
+ }
54
+ }
55
+ // Validate that we have both timeSlot and service
56
+ if (!resolvedTimeSlot) {
57
+ throw new Error('timeSlot is required. Either provide it as a parameter or ensure BookingService has a service selection with a timeSlot.');
58
+ }
59
+ if (!resolvedService) {
60
+ throw new Error('service is required. Either provide it as a parameter or ensure BookingService has a service selection.');
61
+ }
62
+ // Call the provided function with resolved values
63
+ return providedNavigateToBookingForm({
64
+ timeSlot: resolvedTimeSlot,
65
+ service: resolvedService,
66
+ });
67
+ };
68
+ return _jsx(_Fragment, { children: children({ navigateToBookingForm }) });
19
69
  }
20
70
  // ============================================================================
21
71
  // Timezone Component
@@ -179,12 +179,13 @@ export interface PayNowProps {
179
179
  asChild?: boolean;
180
180
  children?: AsChildChildren<{
181
181
  payNow: MoneyData | null;
182
+ isDeposit: boolean;
182
183
  }>;
183
184
  className?: string;
184
185
  }
185
186
  /**
186
- * Displays the pay now amount (for deposit scenarios).
187
- * Uses data-has-deposit attribute for conditional visibility.
187
+ * Displays the pay now amount (amount to pay upfront in deposit scenarios).
188
+ * Only renders in deposit mode when payNow has a valid amount.
188
189
  *
189
190
  * @component
190
191
  * @example
@@ -200,12 +201,13 @@ export interface PayLaterProps {
200
201
  asChild?: boolean;
201
202
  children?: AsChildChildren<{
202
203
  payLater: MoneyData | null;
204
+ isDeposit: boolean;
203
205
  }>;
204
206
  className?: string;
205
207
  }
206
208
  /**
207
209
  * Displays the pay later amount (for deposit scenarios).
208
- * Uses data-has-deposit attribute for conditional visibility.
210
+ * Only renders when in deposit mode and payLater has a valid amount.
209
211
  *
210
212
  * @component
211
213
  * @example
@@ -150,8 +150,8 @@ export const Total = React.forwardRef((props, ref) => {
150
150
  });
151
151
  Total.displayName = 'Payment.Total';
152
152
  /**
153
- * Displays the pay now amount (for deposit scenarios).
154
- * Uses data-has-deposit attribute for conditional visibility.
153
+ * Displays the pay now amount (amount to pay upfront in deposit scenarios).
154
+ * Only renders in deposit mode when payNow has a valid amount.
155
155
  *
156
156
  * @component
157
157
  * @example
@@ -161,12 +161,12 @@ Total.displayName = 'Payment.Total';
161
161
  */
162
162
  export const PayNow = React.forwardRef((props, ref) => {
163
163
  const { asChild, children, className } = props;
164
- return (_jsx(CorePayment.Data, { children: ({ payNow, isDeposit }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentPayNow, "data-has-deposit": isDeposit, customElement: children, customElementProps: { payNow }, children: payNow && payNow.amount > 0 && _jsx(Money, { money: payNow }) })) }));
164
+ return (_jsx(CorePayment.Data, { children: ({ payNow, isDeposit }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentPayNow, "data-has-deposit": isDeposit, customElement: children, customElementProps: { payNow, isDeposit }, children: isDeposit && payNow && payNow.amount > 0 && (_jsx(Money, { money: payNow })) })) }));
165
165
  });
166
166
  PayNow.displayName = 'Payment.PayNow';
167
167
  /**
168
168
  * Displays the pay later amount (for deposit scenarios).
169
- * Uses data-has-deposit attribute for conditional visibility.
169
+ * Only renders when in deposit mode and payLater has a valid amount.
170
170
  *
171
171
  * @component
172
172
  * @example
@@ -176,7 +176,7 @@ PayNow.displayName = 'Payment.PayNow';
176
176
  */
177
177
  export const PayLater = React.forwardRef((props, ref) => {
178
178
  const { asChild, children, className } = props;
179
- return (_jsx(CorePayment.Data, { children: ({ payLater, isDeposit }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentPayLater, "data-has-deposit": isDeposit, customElement: children, customElementProps: { payLater }, children: payLater && payLater.amount > 0 && _jsx(Money, { money: payLater }) })) }));
179
+ return (_jsx(CorePayment.Data, { children: ({ payLater, isDeposit }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.paymentPayLater, "data-has-deposit": isDeposit, customElement: children, customElementProps: { payLater, isDeposit }, children: isDeposit && payLater && payLater.amount > 0 && (_jsx(Money, { money: payLater })) })) }));
180
180
  });
181
181
  PayLater.displayName = 'Payment.PayLater';
182
182
  /**
@@ -6,7 +6,9 @@ import React from 'react';
6
6
  import { ListVariant } from '@wix/headless-components/react';
7
7
  import { AsChildChildren } from '@wix/headless-utils/react';
8
8
  import type { TimeSlot as TimeSlotType } from '@wix/auto_sdk_bookings_availability-time-slots';
9
+ import type { Service } from '@wix/auto_sdk_bookings_services';
9
10
  import type { TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
11
+ import { ServiceSelectionTimeSlot } from '../../services/booking/booking.js';
10
12
  export type { StartDateProps as TimeSlotStartDateProps, EndDateProps as TimeSlotEndDateProps, DurationProps as TimeSlotDurationProps, SelectProps as TimeSlotSelectProps, LocationNameProps as TimeSlotLocationNameProps, StaffMembersProps as TimeSlotStaffMembersProps, StaffMemberRepeaterProps as TimeSlotStaffMemberRepeaterProps, StaffMemberNameProps as TimeSlotStaffMemberNameProps, SelectStaffMemberProps as TimeSlotSelectStaffMemberProps, ClearStaffSelectionProps as TimeSlotClearStaffSelectionProps, } from './TimeSlot.js';
11
13
  /**
12
14
  * Render props for TimeSlotList.Timezone component
@@ -49,8 +51,23 @@ export declare const Timezone: React.ForwardRefExoticComponent<TimezoneProps & R
49
51
  * Props for TimeSlotList.Root component
50
52
  */
51
53
  export interface RootProps {
52
- children: React.ReactNode;
54
+ children: React.ReactNode | ((data: {
55
+ navigateToBookingForm: ({ timeSlot, service, }: {
56
+ timeSlot?: ServiceSelectionTimeSlot;
57
+ service?: Service;
58
+ }) => Promise<void>;
59
+ }) => React.ReactNode);
53
60
  config: TimeSlotListServiceConfig;
61
+ /**
62
+ * Function to navigate to the booking form.
63
+ * The timeSlot and service parameters are optional - if not provided,
64
+ * BookingService will be used to get them from the current service selections.
65
+ * If not provided, will use the default navigation utility.
66
+ */
67
+ navigateToBookingForm?: ({ timeSlot, service, }: {
68
+ timeSlot?: ServiceSelectionTimeSlot;
69
+ service?: Service;
70
+ }) => Promise<void>;
54
71
  className?: string;
55
72
  variant?: ListVariant;
56
73
  }
@@ -62,15 +79,21 @@ export interface RootProps {
62
79
  * @example
63
80
  * ```tsx
64
81
  * import { TimeSlotList } from '@wix/bookings/components';
82
+ * import { navigateToBookingForm } from '@wix/headless-bookings/utils';
65
83
  *
66
84
  * function TimeSlotsPage({ config }) {
67
85
  * return (
68
- * <TimeSlotList.Root config={config}>
69
- * <TimeSlotList.TimeSlots>
70
- * <TimeSlotList.TimeSlotRepeater>
71
- * {children}
72
- * </TimeSlotList.TimeSlotRepeater>
73
- * </TimeSlotList.TimeSlots>
86
+ * <TimeSlotList.Root
87
+ * config={config}
88
+ * navigateToBookingForm={navigateToBookingForm}
89
+ * >
90
+ * {({ navigateToBookingForm }) => (
91
+ * <TimeSlotList.TimeSlots>
92
+ * <TimeSlotList.TimeSlotRepeater>
93
+ * {children}
94
+ * </TimeSlotList.TimeSlotRepeater>
95
+ * </TimeSlotList.TimeSlots>
96
+ * )}
74
97
  * </TimeSlotList.Root>
75
98
  * );
76
99
  * }
@@ -9,6 +9,7 @@ import { AsChildSlot } from '@wix/headless-utils/react';
9
9
  import * as CoreTimeSlotList from '../core/time-slot-list/TimeSlotList.js';
10
10
  import * as CoreTimeSlot from '../core/time-slot-list/TimeSlot.js';
11
11
  import { StartDate as TimeSlotStartDate, EndDate as TimeSlotEndDate, Duration, Actions as TimeSlotActions, Location, StaffMembers, StaffMemberRepeater, StaffMember, Root as TimeSlotRoot, } from './TimeSlot.js';
12
+ import { navigateToBookingForm as defaultNavigateToBookingForm } from '../../utils/navigation.js';
12
13
  // ============================================================================
13
14
  // Utilities
14
15
  // ============================================================================
@@ -28,6 +29,7 @@ var TestIds;
28
29
  TestIds["timeSlotListTimeSlot"] = "time-slot-list-time-slot";
29
30
  TestIds["timeSlotListTimezone"] = "time-slot-list-timezone";
30
31
  TestIds["timeSlotListLoadMore"] = "time-slot-list-load-more";
32
+ TestIds["timeSlotListContinue"] = "time-slot-list-continue";
31
33
  TestIds["timeSlotListDateRangeInput"] = "time-slot-list-date-range-input";
32
34
  })(TestIds || (TestIds = {}));
33
35
  /**
@@ -62,23 +64,44 @@ Timezone.displayName = 'TimeSlotList.Timezone';
62
64
  * @example
63
65
  * ```tsx
64
66
  * import { TimeSlotList } from '@wix/bookings/components';
67
+ * import { navigateToBookingForm } from '@wix/headless-bookings/utils';
65
68
  *
66
69
  * function TimeSlotsPage({ config }) {
67
70
  * return (
68
- * <TimeSlotList.Root config={config}>
69
- * <TimeSlotList.TimeSlots>
70
- * <TimeSlotList.TimeSlotRepeater>
71
- * {children}
72
- * </TimeSlotList.TimeSlotRepeater>
73
- * </TimeSlotList.TimeSlots>
71
+ * <TimeSlotList.Root
72
+ * config={config}
73
+ * navigateToBookingForm={navigateToBookingForm}
74
+ * >
75
+ * {({ navigateToBookingForm }) => (
76
+ * <TimeSlotList.TimeSlots>
77
+ * <TimeSlotList.TimeSlotRepeater>
78
+ * {children}
79
+ * </TimeSlotList.TimeSlotRepeater>
80
+ * </TimeSlotList.TimeSlots>
81
+ * )}
74
82
  * </TimeSlotList.Root>
75
83
  * );
76
84
  * }
77
85
  * ```
78
86
  */
79
87
  export const Root = React.forwardRef((props, ref) => {
80
- const { children, config, className, variant } = props;
81
- return (_jsx(CoreTimeSlotList.Root, { config: config, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, children: children }) }));
88
+ const { children, config, className, variant, navigateToBookingForm: providedNavigateToBookingForm, } = props;
89
+ // Wrap defaultNavigateToBookingForm to match optional parameter signature
90
+ // The core component will handle getting timeSlot/service from BookingService if not provided
91
+ const navigateToBookingForm = providedNavigateToBookingForm ||
92
+ (async ({ timeSlot, service, }) => {
93
+ // This will be handled by the core component's wrapper
94
+ // which will resolve timeSlot/service from BookingService if needed
95
+ if (!timeSlot || !service) {
96
+ throw new Error('timeSlot and service are required when using default navigation. Either provide them or ensure BookingService has service selections.');
97
+ }
98
+ return defaultNavigateToBookingForm({ timeSlot, service });
99
+ });
100
+ return (_jsx(CoreTimeSlotList.Root, { config: config, navigateToBookingForm: navigateToBookingForm, children: (coreData) => (_jsx(RootContent, { className: className, ref: ref, variant: variant, children: typeof children === 'function'
101
+ ? children({
102
+ navigateToBookingForm: coreData.navigateToBookingForm,
103
+ })
104
+ : children })) }));
82
105
  });
83
106
  Root.displayName = 'TimeSlotList.Root';
84
107
  /**
@@ -17,6 +17,8 @@ export interface LineItemAdditionalInfo {
17
17
  lineItemId: string;
18
18
  /** Custom price text (for CUSTOM rate type services) */
19
19
  priceText?: string;
20
+ /** Whether this is a free service (NO_FEE rate type) */
21
+ isFree?: boolean;
20
22
  }
21
23
  /**
22
24
  * Payment calculation result with SDK response and additional computed info
@@ -23,7 +23,8 @@ function getAdditionalInfo(service, lineItemId) {
23
23
  const priceText = payment?.rateType === RateType.CUSTOM && payment.custom?.description
24
24
  ? payment.custom.description
25
25
  : undefined;
26
- return { lineItemId, priceText };
26
+ const isFree = payment?.rateType === RateType.NO_FEE;
27
+ return { lineItemId, priceText, isFree };
27
28
  }
28
29
  function getPaymentOption(service, hasDeposit) {
29
30
  const options = service.payment?.options;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Bookings Utilities
3
+ * Exports utility functions for the bookings package
4
+ */
5
+ export { navigateToBookingForm, navigateToCheckout } from './navigation.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Bookings Utilities
3
+ * Exports utility functions for the bookings package
4
+ */
5
+ export { navigateToBookingForm, navigateToCheckout } from './navigation.js';
@@ -0,0 +1,7 @@
1
+ import type { ServiceSelectionTimeSlot } from '../services/booking/booking.js';
2
+ import type { Service } from '@wix/auto_sdk_bookings_services';
3
+ export declare function navigateToCheckout(checkoutId: string): Promise<void>;
4
+ export declare function navigateToBookingForm({ timeSlot, service, }: {
5
+ timeSlot: ServiceSelectionTimeSlot;
6
+ service: Service;
7
+ }): Promise<void>;
@@ -0,0 +1,75 @@
1
+ import { redirects } from '@wix/redirects';
2
+ import { LocationType as TimeSlotLocationType } from '@wix/auto_sdk_bookings_availability-time-slots';
3
+ import { LocationType as BookingsLocationType } from '@wix/auto_sdk_redirects_redirects';
4
+ export async function navigateToCheckout(checkoutId) {
5
+ const { redirectSession } = await redirects.createRedirectSession({
6
+ ecomCheckout: { checkoutId },
7
+ callbacks: {
8
+ postFlowUrl: window.location.href,
9
+ },
10
+ });
11
+ if (redirectSession?.fullUrl) {
12
+ window.location.href = redirectSession.fullUrl;
13
+ }
14
+ else {
15
+ throw new Error('Failed to create redirect session');
16
+ }
17
+ }
18
+ function mapTimeSlotLocationToBookingLocation(timeSlotLocationType) {
19
+ switch (timeSlotLocationType) {
20
+ case TimeSlotLocationType.BUSINESS:
21
+ return BookingsLocationType.OWNER_BUSINESS;
22
+ case TimeSlotLocationType.CUSTOMER:
23
+ return BookingsLocationType.CUSTOM;
24
+ case TimeSlotLocationType.CUSTOM:
25
+ return BookingsLocationType.OWNER_CUSTOM;
26
+ default:
27
+ return BookingsLocationType.UNDEFINED;
28
+ }
29
+ }
30
+ export async function navigateToBookingForm({ timeSlot, service, }) {
31
+ if (!timeSlot) {
32
+ throw new Error('No time slot provided');
33
+ }
34
+ if (!service) {
35
+ throw new Error('No service provided');
36
+ }
37
+ // Get the first resource (staff member) if available
38
+ const selectedResource = timeSlot.resources?.[0];
39
+ const { redirectSession } = await redirects.createRedirectSession({
40
+ bookingsCheckout: {
41
+ slotAvailability: {
42
+ bookable: true,
43
+ slot: {
44
+ ...timeSlot,
45
+ serviceId: service._id ?? undefined,
46
+ scheduleId: timeSlot.scheduleId,
47
+ startDate: timeSlot.startDate,
48
+ endDate: timeSlot.endDate,
49
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
50
+ resource: selectedResource
51
+ ? {
52
+ _id: selectedResource._id,
53
+ name: selectedResource.name,
54
+ }
55
+ : undefined,
56
+ location: {
57
+ _id: timeSlot.location?._id,
58
+ name: timeSlot.location?.name,
59
+ formattedAddress: timeSlot.location?.formattedAddress,
60
+ locationType: mapTimeSlotLocationToBookingLocation(timeSlot.location?.locationType),
61
+ },
62
+ },
63
+ },
64
+ },
65
+ callbacks: {
66
+ postFlowUrl: window.location.href,
67
+ },
68
+ });
69
+ if (redirectSession?.fullUrl) {
70
+ window.location.href = redirectSession.fullUrl;
71
+ }
72
+ else {
73
+ throw new Error('Failed to create redirect session');
74
+ }
75
+ }