@wix/headless-bookings 0.0.66 → 0.0.67
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/cjs/dist/react/booking/Book.d.ts +17 -11
- package/cjs/dist/react/booking/Book.js +13 -16
- package/cjs/dist/react/booking/Booking.d.ts +4 -3
- package/cjs/dist/react/booking/Booking.js +4 -3
- package/cjs/dist/react/core/booking/Book.d.ts +12 -2
- package/cjs/dist/react/core/booking/Book.js +12 -2
- package/cjs/dist/services/booking/book-action/types.d.ts +10 -2
- package/cjs/dist/utils/navigation.js +2 -1
- package/dist/react/booking/Book.d.ts +17 -11
- package/dist/react/booking/Book.js +13 -16
- package/dist/react/booking/Booking.d.ts +4 -3
- package/dist/react/booking/Booking.js +4 -3
- package/dist/react/core/booking/Book.d.ts +12 -2
- package/dist/react/core/booking/Book.js +12 -2
- package/dist/services/booking/book-action/types.d.ts +10 -2
- package/dist/utils/navigation.js +2 -1
- package/package.json +2 -2
|
@@ -14,13 +14,19 @@ export interface BookProps {
|
|
|
14
14
|
label?: string;
|
|
15
15
|
loadingState?: string;
|
|
16
16
|
disabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Called when checkout is required for payment.
|
|
19
|
+
* The navigateToCheckout function already has the checkoutId captured - just call it to navigate.
|
|
20
|
+
*/
|
|
17
21
|
onCheckout?: (result: {
|
|
18
|
-
|
|
19
|
-
navigateToCheckout: (checkoutId: string) => void;
|
|
22
|
+
navigateToCheckout: () => void;
|
|
20
23
|
}) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Called when booking completes without requiring checkout (free/offline services).
|
|
26
|
+
* Receives the orderId which can be used to display confirmation or navigate to a thank you page.
|
|
27
|
+
*/
|
|
21
28
|
onComplete?: (result: {
|
|
22
29
|
orderId: string;
|
|
23
|
-
navigateToThankYou: (orderId: string) => void;
|
|
24
30
|
}) => void;
|
|
25
31
|
onError?: (error: BookingError) => void;
|
|
26
32
|
}
|
|
@@ -29,20 +35,20 @@ export interface BookProps {
|
|
|
29
35
|
*
|
|
30
36
|
* @example
|
|
31
37
|
* ```tsx
|
|
32
|
-
* // Simple usage
|
|
38
|
+
* // Simple usage - uses default navigation
|
|
33
39
|
* <Booking.Actions.Book />
|
|
34
40
|
*
|
|
35
|
-
* // With callbacks
|
|
41
|
+
* // With callbacks - navigateToCheckout has checkoutId captured
|
|
36
42
|
* <Booking.Actions.Book
|
|
37
|
-
* onCheckout={({
|
|
38
|
-
* onComplete={({ orderId }) =>
|
|
43
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
44
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
39
45
|
* onError={(error) => console.error(error.message)}
|
|
40
46
|
* />
|
|
41
47
|
*
|
|
42
48
|
* // With render function
|
|
43
49
|
* <Booking.Actions.Book
|
|
44
|
-
* onCheckout={({
|
|
45
|
-
* onComplete={({ orderId }) =>
|
|
50
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
51
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
46
52
|
* >
|
|
47
53
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
48
54
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -54,8 +60,8 @@ export interface BookProps {
|
|
|
54
60
|
* // With asChild
|
|
55
61
|
* <Booking.Actions.Book
|
|
56
62
|
* asChild
|
|
57
|
-
* onCheckout={({
|
|
58
|
-
* onComplete={({ orderId }) =>
|
|
63
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
64
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
59
65
|
* >
|
|
60
66
|
* <CustomBookButton />
|
|
61
67
|
* </Booking.Actions.Book>
|
|
@@ -6,7 +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
|
+
import { navigateToCheckout as navigateToCheckoutUtil } from '../../utils/navigation.js';
|
|
10
10
|
var TestIds;
|
|
11
11
|
(function (TestIds) {
|
|
12
12
|
TestIds["bookingActionBook"] = "booking-action-book";
|
|
@@ -16,20 +16,20 @@ var TestIds;
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```tsx
|
|
19
|
-
* // Simple usage
|
|
19
|
+
* // Simple usage - uses default navigation
|
|
20
20
|
* <Booking.Actions.Book />
|
|
21
21
|
*
|
|
22
|
-
* // With callbacks
|
|
22
|
+
* // With callbacks - navigateToCheckout has checkoutId captured
|
|
23
23
|
* <Booking.Actions.Book
|
|
24
|
-
* onCheckout={({
|
|
25
|
-
* onComplete={({ orderId }) =>
|
|
24
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
25
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
26
26
|
* onError={(error) => console.error(error.message)}
|
|
27
27
|
* />
|
|
28
28
|
*
|
|
29
29
|
* // With render function
|
|
30
30
|
* <Booking.Actions.Book
|
|
31
|
-
* onCheckout={({
|
|
32
|
-
* onComplete={({ orderId }) =>
|
|
31
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
32
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
33
33
|
* >
|
|
34
34
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
35
35
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -41,8 +41,8 @@ var TestIds;
|
|
|
41
41
|
* // With asChild
|
|
42
42
|
* <Booking.Actions.Book
|
|
43
43
|
* asChild
|
|
44
|
-
* onCheckout={({
|
|
45
|
-
* onComplete={({ orderId }) =>
|
|
44
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
45
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
46
46
|
* >
|
|
47
47
|
* <CustomBookButton />
|
|
48
48
|
* </Booking.Actions.Book>
|
|
@@ -51,14 +51,11 @@ var TestIds;
|
|
|
51
51
|
export const Book = React.forwardRef((props, ref) => {
|
|
52
52
|
const { asChild, children, className, label = 'Book Now', loadingState = 'Booking...', disabled, onCheckout, onComplete, onError, } = props;
|
|
53
53
|
return (_jsx(CoreBook.Book, { onCheckout: (result) => {
|
|
54
|
-
onCheckout?.({
|
|
55
|
-
|
|
56
|
-
onComplete?.({
|
|
57
|
-
...result,
|
|
58
|
-
navigateToThankYou: (orderId) => {
|
|
59
|
-
console.log('navigateToThankYou', orderId);
|
|
60
|
-
},
|
|
54
|
+
onCheckout?.({
|
|
55
|
+
navigateToCheckout: () => navigateToCheckoutUtil(result.checkoutId),
|
|
61
56
|
});
|
|
57
|
+
}, onComplete: (result) => {
|
|
58
|
+
onComplete?.({ orderId: result.orderId });
|
|
62
59
|
}, 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 }) })) }));
|
|
63
60
|
});
|
|
64
61
|
Book.displayName = 'Booking.Actions.Book';
|
|
@@ -44,10 +44,11 @@ export declare const Root: {
|
|
|
44
44
|
* // Simple usage
|
|
45
45
|
* <Booking.Actions.Book />
|
|
46
46
|
*
|
|
47
|
-
* // With callbacks
|
|
47
|
+
* // With callbacks - navigateToCheckout has checkoutId already captured
|
|
48
48
|
* <Booking.Actions.Book
|
|
49
|
-
*
|
|
50
|
-
*
|
|
49
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
50
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
51
|
+
* onError={(error) => toast.error(error.message)}
|
|
51
52
|
* />
|
|
52
53
|
* ```
|
|
53
54
|
*/
|
|
@@ -60,10 +60,11 @@ Root.displayName = 'Booking.Root';
|
|
|
60
60
|
* // Simple usage
|
|
61
61
|
* <Booking.Actions.Book />
|
|
62
62
|
*
|
|
63
|
-
* // With callbacks
|
|
63
|
+
* // With callbacks - navigateToCheckout has checkoutId already captured
|
|
64
64
|
* <Booking.Actions.Book
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
66
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
67
|
+
* onError={(error) => toast.error(error.message)}
|
|
67
68
|
* />
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
@@ -32,11 +32,21 @@ export interface BookProps {
|
|
|
32
32
|
* Core Book component - provides book action data via render props.
|
|
33
33
|
* Used internally by higher-level Booking.Actions.Book component.
|
|
34
34
|
*
|
|
35
|
+
* The onCheckout callback receives the checkoutId for internal use.
|
|
36
|
+
* The high-level component wraps this to provide a simpler API with
|
|
37
|
+
* navigateToCheckout() that has the checkoutId already captured.
|
|
38
|
+
*
|
|
35
39
|
* @example
|
|
36
40
|
* ```tsx
|
|
37
41
|
* <Book
|
|
38
|
-
* onCheckout={({ checkoutId }) =>
|
|
39
|
-
*
|
|
42
|
+
* onCheckout={({ checkoutId }) => {
|
|
43
|
+
* // Use checkoutId to navigate to checkout
|
|
44
|
+
* navigateToCheckout(checkoutId);
|
|
45
|
+
* }}
|
|
46
|
+
* onComplete={({ orderId }) => {
|
|
47
|
+
* // Use orderId to navigate to thank you page
|
|
48
|
+
* navigate(`/thank-you?orderId=${orderId}`);
|
|
49
|
+
* }}
|
|
40
50
|
* >
|
|
41
51
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
42
52
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -11,11 +11,21 @@ import { BookResultType, } from '../../../services/booking/book-action/types.js'
|
|
|
11
11
|
* Core Book component - provides book action data via render props.
|
|
12
12
|
* Used internally by higher-level Booking.Actions.Book component.
|
|
13
13
|
*
|
|
14
|
+
* The onCheckout callback receives the checkoutId for internal use.
|
|
15
|
+
* The high-level component wraps this to provide a simpler API with
|
|
16
|
+
* navigateToCheckout() that has the checkoutId already captured.
|
|
17
|
+
*
|
|
14
18
|
* @example
|
|
15
19
|
* ```tsx
|
|
16
20
|
* <Book
|
|
17
|
-
* onCheckout={({ checkoutId }) =>
|
|
18
|
-
*
|
|
21
|
+
* onCheckout={({ checkoutId }) => {
|
|
22
|
+
* // Use checkoutId to navigate to checkout
|
|
23
|
+
* navigateToCheckout(checkoutId);
|
|
24
|
+
* }}
|
|
25
|
+
* onComplete={({ orderId }) => {
|
|
26
|
+
* // Use orderId to navigate to thank you page
|
|
27
|
+
* navigate(`/thank-you?orderId=${orderId}`);
|
|
28
|
+
* }}
|
|
19
29
|
* >
|
|
20
30
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
21
31
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -44,7 +44,7 @@ export interface BookChildProps {
|
|
|
44
44
|
isLoading: boolean;
|
|
45
45
|
error: BookingError | null;
|
|
46
46
|
canBook: boolean;
|
|
47
|
-
onClick: () => void
|
|
47
|
+
onClick: () => Promise<void>;
|
|
48
48
|
disabled: boolean;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
@@ -57,9 +57,17 @@ export interface BookProps {
|
|
|
57
57
|
label?: string;
|
|
58
58
|
loadingState?: string;
|
|
59
59
|
disabled?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Called when checkout is required for payment.
|
|
62
|
+
* The navigateToCheckout function has the checkoutId captured - just call it.
|
|
63
|
+
*/
|
|
60
64
|
onCheckout?: (result: {
|
|
61
|
-
|
|
65
|
+
navigateToCheckout: () => void;
|
|
62
66
|
}) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Called when booking completes without requiring checkout (free/offline services).
|
|
69
|
+
* Receives the orderId which can be used to display confirmation or navigate to a thank you page.
|
|
70
|
+
*/
|
|
63
71
|
onComplete?: (result: {
|
|
64
72
|
orderId: string;
|
|
65
73
|
}) => void;
|
|
@@ -5,7 +5,8 @@ export async function navigateToCheckout(checkoutId) {
|
|
|
5
5
|
const { redirectSession } = await redirects.createRedirectSession({
|
|
6
6
|
ecomCheckout: { checkoutId },
|
|
7
7
|
callbacks: {
|
|
8
|
-
postFlowUrl: window.location.
|
|
8
|
+
postFlowUrl: `${window.location.host}/booking/services`,
|
|
9
|
+
bookingsServiceListUrl: `${window.location.host}/booking/services`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
12
|
if (redirectSession?.fullUrl) {
|
|
@@ -14,13 +14,19 @@ export interface BookProps {
|
|
|
14
14
|
label?: string;
|
|
15
15
|
loadingState?: string;
|
|
16
16
|
disabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Called when checkout is required for payment.
|
|
19
|
+
* The navigateToCheckout function already has the checkoutId captured - just call it to navigate.
|
|
20
|
+
*/
|
|
17
21
|
onCheckout?: (result: {
|
|
18
|
-
|
|
19
|
-
navigateToCheckout: (checkoutId: string) => void;
|
|
22
|
+
navigateToCheckout: () => void;
|
|
20
23
|
}) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Called when booking completes without requiring checkout (free/offline services).
|
|
26
|
+
* Receives the orderId which can be used to display confirmation or navigate to a thank you page.
|
|
27
|
+
*/
|
|
21
28
|
onComplete?: (result: {
|
|
22
29
|
orderId: string;
|
|
23
|
-
navigateToThankYou: (orderId: string) => void;
|
|
24
30
|
}) => void;
|
|
25
31
|
onError?: (error: BookingError) => void;
|
|
26
32
|
}
|
|
@@ -29,20 +35,20 @@ export interface BookProps {
|
|
|
29
35
|
*
|
|
30
36
|
* @example
|
|
31
37
|
* ```tsx
|
|
32
|
-
* // Simple usage
|
|
38
|
+
* // Simple usage - uses default navigation
|
|
33
39
|
* <Booking.Actions.Book />
|
|
34
40
|
*
|
|
35
|
-
* // With callbacks
|
|
41
|
+
* // With callbacks - navigateToCheckout has checkoutId captured
|
|
36
42
|
* <Booking.Actions.Book
|
|
37
|
-
* onCheckout={({
|
|
38
|
-
* onComplete={({ orderId }) =>
|
|
43
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
44
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
39
45
|
* onError={(error) => console.error(error.message)}
|
|
40
46
|
* />
|
|
41
47
|
*
|
|
42
48
|
* // With render function
|
|
43
49
|
* <Booking.Actions.Book
|
|
44
|
-
* onCheckout={({
|
|
45
|
-
* onComplete={({ orderId }) =>
|
|
50
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
51
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
46
52
|
* >
|
|
47
53
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
48
54
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -54,8 +60,8 @@ export interface BookProps {
|
|
|
54
60
|
* // With asChild
|
|
55
61
|
* <Booking.Actions.Book
|
|
56
62
|
* asChild
|
|
57
|
-
* onCheckout={({
|
|
58
|
-
* onComplete={({ orderId }) =>
|
|
63
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
64
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
59
65
|
* >
|
|
60
66
|
* <CustomBookButton />
|
|
61
67
|
* </Booking.Actions.Book>
|
|
@@ -6,7 +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
|
+
import { navigateToCheckout as navigateToCheckoutUtil } from '../../utils/navigation.js';
|
|
10
10
|
var TestIds;
|
|
11
11
|
(function (TestIds) {
|
|
12
12
|
TestIds["bookingActionBook"] = "booking-action-book";
|
|
@@ -16,20 +16,20 @@ var TestIds;
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```tsx
|
|
19
|
-
* // Simple usage
|
|
19
|
+
* // Simple usage - uses default navigation
|
|
20
20
|
* <Booking.Actions.Book />
|
|
21
21
|
*
|
|
22
|
-
* // With callbacks
|
|
22
|
+
* // With callbacks - navigateToCheckout has checkoutId captured
|
|
23
23
|
* <Booking.Actions.Book
|
|
24
|
-
* onCheckout={({
|
|
25
|
-
* onComplete={({ orderId }) =>
|
|
24
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
25
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
26
26
|
* onError={(error) => console.error(error.message)}
|
|
27
27
|
* />
|
|
28
28
|
*
|
|
29
29
|
* // With render function
|
|
30
30
|
* <Booking.Actions.Book
|
|
31
|
-
* onCheckout={({
|
|
32
|
-
* onComplete={({ orderId }) =>
|
|
31
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
32
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
33
33
|
* >
|
|
34
34
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
35
35
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -41,8 +41,8 @@ var TestIds;
|
|
|
41
41
|
* // With asChild
|
|
42
42
|
* <Booking.Actions.Book
|
|
43
43
|
* asChild
|
|
44
|
-
* onCheckout={({
|
|
45
|
-
* onComplete={({ orderId }) =>
|
|
44
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
45
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
46
46
|
* >
|
|
47
47
|
* <CustomBookButton />
|
|
48
48
|
* </Booking.Actions.Book>
|
|
@@ -51,14 +51,11 @@ var TestIds;
|
|
|
51
51
|
export const Book = React.forwardRef((props, ref) => {
|
|
52
52
|
const { asChild, children, className, label = 'Book Now', loadingState = 'Booking...', disabled, onCheckout, onComplete, onError, } = props;
|
|
53
53
|
return (_jsx(CoreBook.Book, { onCheckout: (result) => {
|
|
54
|
-
onCheckout?.({
|
|
55
|
-
|
|
56
|
-
onComplete?.({
|
|
57
|
-
...result,
|
|
58
|
-
navigateToThankYou: (orderId) => {
|
|
59
|
-
console.log('navigateToThankYou', orderId);
|
|
60
|
-
},
|
|
54
|
+
onCheckout?.({
|
|
55
|
+
navigateToCheckout: () => navigateToCheckoutUtil(result.checkoutId),
|
|
61
56
|
});
|
|
57
|
+
}, onComplete: (result) => {
|
|
58
|
+
onComplete?.({ orderId: result.orderId });
|
|
62
59
|
}, 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 }) })) }));
|
|
63
60
|
});
|
|
64
61
|
Book.displayName = 'Booking.Actions.Book';
|
|
@@ -44,10 +44,11 @@ export declare const Root: {
|
|
|
44
44
|
* // Simple usage
|
|
45
45
|
* <Booking.Actions.Book />
|
|
46
46
|
*
|
|
47
|
-
* // With callbacks
|
|
47
|
+
* // With callbacks - navigateToCheckout has checkoutId already captured
|
|
48
48
|
* <Booking.Actions.Book
|
|
49
|
-
*
|
|
50
|
-
*
|
|
49
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
50
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
51
|
+
* onError={(error) => toast.error(error.message)}
|
|
51
52
|
* />
|
|
52
53
|
* ```
|
|
53
54
|
*/
|
|
@@ -60,10 +60,11 @@ Root.displayName = 'Booking.Root';
|
|
|
60
60
|
* // Simple usage
|
|
61
61
|
* <Booking.Actions.Book />
|
|
62
62
|
*
|
|
63
|
-
* // With callbacks
|
|
63
|
+
* // With callbacks - navigateToCheckout has checkoutId already captured
|
|
64
64
|
* <Booking.Actions.Book
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* onCheckout={({ navigateToCheckout }) => navigateToCheckout()}
|
|
66
|
+
* onComplete={({ orderId }) => navigate(`/thank-you?orderId=${orderId}`)}
|
|
67
|
+
* onError={(error) => toast.error(error.message)}
|
|
67
68
|
* />
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
@@ -32,11 +32,21 @@ export interface BookProps {
|
|
|
32
32
|
* Core Book component - provides book action data via render props.
|
|
33
33
|
* Used internally by higher-level Booking.Actions.Book component.
|
|
34
34
|
*
|
|
35
|
+
* The onCheckout callback receives the checkoutId for internal use.
|
|
36
|
+
* The high-level component wraps this to provide a simpler API with
|
|
37
|
+
* navigateToCheckout() that has the checkoutId already captured.
|
|
38
|
+
*
|
|
35
39
|
* @example
|
|
36
40
|
* ```tsx
|
|
37
41
|
* <Book
|
|
38
|
-
* onCheckout={({ checkoutId }) =>
|
|
39
|
-
*
|
|
42
|
+
* onCheckout={({ checkoutId }) => {
|
|
43
|
+
* // Use checkoutId to navigate to checkout
|
|
44
|
+
* navigateToCheckout(checkoutId);
|
|
45
|
+
* }}
|
|
46
|
+
* onComplete={({ orderId }) => {
|
|
47
|
+
* // Use orderId to navigate to thank you page
|
|
48
|
+
* navigate(`/thank-you?orderId=${orderId}`);
|
|
49
|
+
* }}
|
|
40
50
|
* >
|
|
41
51
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
42
52
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -11,11 +11,21 @@ import { BookResultType, } from '../../../services/booking/book-action/types.js'
|
|
|
11
11
|
* Core Book component - provides book action data via render props.
|
|
12
12
|
* Used internally by higher-level Booking.Actions.Book component.
|
|
13
13
|
*
|
|
14
|
+
* The onCheckout callback receives the checkoutId for internal use.
|
|
15
|
+
* The high-level component wraps this to provide a simpler API with
|
|
16
|
+
* navigateToCheckout() that has the checkoutId already captured.
|
|
17
|
+
*
|
|
14
18
|
* @example
|
|
15
19
|
* ```tsx
|
|
16
20
|
* <Book
|
|
17
|
-
* onCheckout={({ checkoutId }) =>
|
|
18
|
-
*
|
|
21
|
+
* onCheckout={({ checkoutId }) => {
|
|
22
|
+
* // Use checkoutId to navigate to checkout
|
|
23
|
+
* navigateToCheckout(checkoutId);
|
|
24
|
+
* }}
|
|
25
|
+
* onComplete={({ orderId }) => {
|
|
26
|
+
* // Use orderId to navigate to thank you page
|
|
27
|
+
* navigate(`/thank-you?orderId=${orderId}`);
|
|
28
|
+
* }}
|
|
19
29
|
* >
|
|
20
30
|
* {({ isLoading, error, canBook, onClick, disabled }) => (
|
|
21
31
|
* <button onClick={onClick} disabled={disabled}>
|
|
@@ -44,7 +44,7 @@ export interface BookChildProps {
|
|
|
44
44
|
isLoading: boolean;
|
|
45
45
|
error: BookingError | null;
|
|
46
46
|
canBook: boolean;
|
|
47
|
-
onClick: () => void
|
|
47
|
+
onClick: () => Promise<void>;
|
|
48
48
|
disabled: boolean;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
@@ -57,9 +57,17 @@ export interface BookProps {
|
|
|
57
57
|
label?: string;
|
|
58
58
|
loadingState?: string;
|
|
59
59
|
disabled?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Called when checkout is required for payment.
|
|
62
|
+
* The navigateToCheckout function has the checkoutId captured - just call it.
|
|
63
|
+
*/
|
|
60
64
|
onCheckout?: (result: {
|
|
61
|
-
|
|
65
|
+
navigateToCheckout: () => void;
|
|
62
66
|
}) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Called when booking completes without requiring checkout (free/offline services).
|
|
69
|
+
* Receives the orderId which can be used to display confirmation or navigate to a thank you page.
|
|
70
|
+
*/
|
|
63
71
|
onComplete?: (result: {
|
|
64
72
|
orderId: string;
|
|
65
73
|
}) => void;
|
package/dist/utils/navigation.js
CHANGED
|
@@ -5,7 +5,8 @@ export async function navigateToCheckout(checkoutId) {
|
|
|
5
5
|
const { redirectSession } = await redirects.createRedirectSession({
|
|
6
6
|
ecomCheckout: { checkoutId },
|
|
7
7
|
callbacks: {
|
|
8
|
-
postFlowUrl: window.location.
|
|
8
|
+
postFlowUrl: `${window.location.host}/booking/services`,
|
|
9
|
+
bookingsServiceListUrl: `${window.location.host}/booking/services`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
12
|
if (redirectSession?.fullUrl) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-bookings",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.67",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"groupId": "com.wixpress.headless-components"
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"falconPackageHash": "
|
|
75
|
+
"falconPackageHash": "f753dc96a84c513f1de40c287b7dca7b153ceea1706ec4a28ee69f97"
|
|
76
76
|
}
|