@wix/headless-bookings 0.0.64 → 0.0.65

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.
@@ -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
@@ -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.65",
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": "a7381beae4b122c7bdbd9d7b7f4079f31688f2a11cd3c6d246e683c5"
76
76
  }