@wix/headless-bookings 0.0.64 → 0.0.66

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.
@@ -34,14 +34,14 @@ export interface BookProps {
34
34
  *
35
35
  * // With callbacks
36
36
  * <Booking.Actions.Book
37
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
37
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
38
38
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
39
39
  * onError={(error) => console.error(error.message)}
40
40
  * />
41
41
  *
42
42
  * // With render function
43
43
  * <Booking.Actions.Book
44
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
44
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
45
45
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
46
46
  * >
47
47
  * {({ isLoading, error, canBook, onClick, disabled }) => (
@@ -54,7 +54,7 @@ export interface BookProps {
54
54
  * // With asChild
55
55
  * <Booking.Actions.Book
56
56
  * asChild
57
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
57
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
58
58
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
59
59
  * >
60
60
  * <CustomBookButton />
@@ -21,14 +21,14 @@ var TestIds;
21
21
  *
22
22
  * // With callbacks
23
23
  * <Booking.Actions.Book
24
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
24
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
25
25
  * onComplete={({ orderId }) => router.push(`/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={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
31
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
32
32
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
33
33
  * >
34
34
  * {({ isLoading, error, canBook, onClick, disabled }) => (
@@ -41,7 +41,7 @@ var TestIds;
41
41
  * // With asChild
42
42
  * <Booking.Actions.Book
43
43
  * asChild
44
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
44
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
45
45
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
46
46
  * >
47
47
  * <CustomBookButton />
@@ -71,6 +71,16 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
71
71
  const timezoneSignal = signalsService.signal(config.timezone ?? getClientTimezone());
72
72
  const formSubmissionSignal = signalsService.signal(config.formSubmission || null);
73
73
  // ========================================================================
74
+ // Helpers
75
+ // ========================================================================
76
+ function getTargetItem(instanceId) {
77
+ const current = serviceSelectionsSignal.get();
78
+ const targetId = instanceId ?? current[0]?.instanceId;
79
+ if (!targetId)
80
+ return undefined;
81
+ return current.find((item) => item.instanceId === targetId);
82
+ }
83
+ // ========================================================================
74
84
  // Actions Implementation
75
85
  // ========================================================================
76
86
  const actions = {
@@ -116,45 +126,23 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
116
126
  serviceSelectionsSignal.set([]);
117
127
  },
118
128
  setResource(resource, instanceId) {
119
- const current = serviceSelectionsSignal.get();
120
- // If no instanceId provided, use the first item
121
- const targetId = instanceId ?? current[0]?.instanceId;
122
- if (!targetId)
129
+ const targetItem = getTargetItem(instanceId);
130
+ if (!targetItem)
123
131
  return;
124
- const updated = current.map((item) => {
125
- if (item.instanceId !== targetId)
126
- return item;
127
- const newResources = item.resources.filter((r) => r.type !== resource.type);
128
- newResources.push(resource);
129
- return { ...item, resources: newResources };
130
- });
131
- serviceSelectionsSignal.set(updated);
132
+ const newResources = targetItem.resources
133
+ .filter((r) => r.type !== resource.type)
134
+ .concat(resource);
135
+ this.updateItem({ resources: newResources, timeSlot: undefined }, targetItem.instanceId);
132
136
  },
133
137
  getResourceByType(resourceType, instanceId) {
134
- const current = serviceSelectionsSignal.get();
135
- // If no instanceId provided, use the first item
136
- const targetId = instanceId ?? current[0]?.instanceId;
137
- if (!targetId)
138
- return undefined;
139
- const targetItem = current.find((item) => item.instanceId === targetId);
140
- if (!targetItem)
141
- return undefined;
142
- return targetItem.resources.find((r) => r.type === resourceType);
138
+ return getTargetItem(instanceId)?.resources.find((r) => r.type === resourceType);
143
139
  },
144
140
  clearResourceByType(resourceType, instanceId) {
145
- const current = serviceSelectionsSignal.get();
146
- // If no instanceId provided, use the first item
147
- const targetId = instanceId ?? current[0]?.instanceId;
148
- if (!targetId)
141
+ const targetItem = getTargetItem(instanceId);
142
+ if (!targetItem)
149
143
  return;
150
- const updated = current.map((item) => {
151
- if (item.instanceId !== targetId)
152
- return item;
153
- // Filter out the resource with matching type
154
- const newResources = item.resources.filter((r) => r.type !== resourceType);
155
- return { ...item, resources: newResources };
156
- });
157
- serviceSelectionsSignal.set(updated);
144
+ const newResources = targetItem.resources.filter((r) => r.type !== resourceType);
145
+ this.updateItem({ resources: newResources }, targetItem.instanceId);
158
146
  },
159
147
  // Location actions
160
148
  setLocation(location) {
@@ -178,9 +166,9 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
178
166
  },
179
167
  // Clear all
180
168
  clearAll() {
181
- serviceSelectionsSignal.set([]);
182
- locationSignal.set(null);
183
- formSubmissionSignal.set(null);
169
+ this.clearItems();
170
+ this.clearLocation();
171
+ this.clearFormSubmission();
184
172
  },
185
173
  // Book action - collects data from signals and delegates to executeBookAction
186
174
  // Loading/error state management is handled in Book.tsx component
@@ -34,14 +34,14 @@ export interface BookProps {
34
34
  *
35
35
  * // With callbacks
36
36
  * <Booking.Actions.Book
37
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
37
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
38
38
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
39
39
  * onError={(error) => console.error(error.message)}
40
40
  * />
41
41
  *
42
42
  * // With render function
43
43
  * <Booking.Actions.Book
44
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
44
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
45
45
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
46
46
  * >
47
47
  * {({ isLoading, error, canBook, onClick, disabled }) => (
@@ -54,7 +54,7 @@ export interface BookProps {
54
54
  * // With asChild
55
55
  * <Booking.Actions.Book
56
56
  * asChild
57
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
57
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
58
58
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
59
59
  * >
60
60
  * <CustomBookButton />
@@ -21,14 +21,14 @@ var TestIds;
21
21
  *
22
22
  * // With callbacks
23
23
  * <Booking.Actions.Book
24
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
24
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
25
25
  * onComplete={({ orderId }) => router.push(`/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={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
31
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
32
32
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
33
33
  * >
34
34
  * {({ isLoading, error, canBook, onClick, disabled }) => (
@@ -41,7 +41,7 @@ var TestIds;
41
41
  * // With asChild
42
42
  * <Booking.Actions.Book
43
43
  * asChild
44
- * onCheckout={({ checkoutId }) => router.push(`/checkout?id=${checkoutId}`)}
44
+ * onCheckout={({ checkoutId, navigateToCheckout }) => navigateToCheckout(checkoutId)}
45
45
  * onComplete={({ orderId }) => router.push(`/thank-you?orderId=${orderId}`)}
46
46
  * >
47
47
  * <CustomBookButton />
@@ -71,6 +71,16 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
71
71
  const timezoneSignal = signalsService.signal(config.timezone ?? getClientTimezone());
72
72
  const formSubmissionSignal = signalsService.signal(config.formSubmission || null);
73
73
  // ========================================================================
74
+ // Helpers
75
+ // ========================================================================
76
+ function getTargetItem(instanceId) {
77
+ const current = serviceSelectionsSignal.get();
78
+ const targetId = instanceId ?? current[0]?.instanceId;
79
+ if (!targetId)
80
+ return undefined;
81
+ return current.find((item) => item.instanceId === targetId);
82
+ }
83
+ // ========================================================================
74
84
  // Actions Implementation
75
85
  // ========================================================================
76
86
  const actions = {
@@ -116,45 +126,23 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
116
126
  serviceSelectionsSignal.set([]);
117
127
  },
118
128
  setResource(resource, instanceId) {
119
- const current = serviceSelectionsSignal.get();
120
- // If no instanceId provided, use the first item
121
- const targetId = instanceId ?? current[0]?.instanceId;
122
- if (!targetId)
129
+ const targetItem = getTargetItem(instanceId);
130
+ if (!targetItem)
123
131
  return;
124
- const updated = current.map((item) => {
125
- if (item.instanceId !== targetId)
126
- return item;
127
- const newResources = item.resources.filter((r) => r.type !== resource.type);
128
- newResources.push(resource);
129
- return { ...item, resources: newResources };
130
- });
131
- serviceSelectionsSignal.set(updated);
132
+ const newResources = targetItem.resources
133
+ .filter((r) => r.type !== resource.type)
134
+ .concat(resource);
135
+ this.updateItem({ resources: newResources, timeSlot: undefined }, targetItem.instanceId);
132
136
  },
133
137
  getResourceByType(resourceType, instanceId) {
134
- const current = serviceSelectionsSignal.get();
135
- // If no instanceId provided, use the first item
136
- const targetId = instanceId ?? current[0]?.instanceId;
137
- if (!targetId)
138
- return undefined;
139
- const targetItem = current.find((item) => item.instanceId === targetId);
140
- if (!targetItem)
141
- return undefined;
142
- return targetItem.resources.find((r) => r.type === resourceType);
138
+ return getTargetItem(instanceId)?.resources.find((r) => r.type === resourceType);
143
139
  },
144
140
  clearResourceByType(resourceType, instanceId) {
145
- const current = serviceSelectionsSignal.get();
146
- // If no instanceId provided, use the first item
147
- const targetId = instanceId ?? current[0]?.instanceId;
148
- if (!targetId)
141
+ const targetItem = getTargetItem(instanceId);
142
+ if (!targetItem)
149
143
  return;
150
- const updated = current.map((item) => {
151
- if (item.instanceId !== targetId)
152
- return item;
153
- // Filter out the resource with matching type
154
- const newResources = item.resources.filter((r) => r.type !== resourceType);
155
- return { ...item, resources: newResources };
156
- });
157
- serviceSelectionsSignal.set(updated);
144
+ const newResources = targetItem.resources.filter((r) => r.type !== resourceType);
145
+ this.updateItem({ resources: newResources }, targetItem.instanceId);
158
146
  },
159
147
  // Location actions
160
148
  setLocation(location) {
@@ -178,9 +166,9 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
178
166
  },
179
167
  // Clear all
180
168
  clearAll() {
181
- serviceSelectionsSignal.set([]);
182
- locationSignal.set(null);
183
- formSubmissionSignal.set(null);
169
+ this.clearItems();
170
+ this.clearLocation();
171
+ this.clearFormSubmission();
184
172
  },
185
173
  // Book action - collects data from signals and delegates to executeBookAction
186
174
  // Loading/error state management is handled in Book.tsx component
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
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": "8011be143d4873e29873f1d8216f8638894a024f49336de8a215b152"
75
+ "falconPackageHash": "cdf272bf09b943d1c3a3edba1a82225f2117165605b07f82878cc26c"
76
76
  }