@voyant-travel/inventory-react 0.13.1 → 0.13.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-departure-form.d.ts","sourceRoot":"","sources":["../../../src/components/product-detail/product-departure-form.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product-departure-form.d.ts","sourceRoot":"","sources":["../../../src/components/product-detail/product-departure-form.tsx"],"names":[],"mappings":"AAkFA,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAA;IACpD,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAyDD,wBAAgB,aAAa,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB,2CAwczF"}
|
|
@@ -8,7 +8,7 @@ import { Loader2 } from "lucide-react";
|
|
|
8
8
|
import { useEffect, useMemo, useRef } from "react";
|
|
9
9
|
import { useForm } from "react-hook-form";
|
|
10
10
|
import { z } from "zod/v4";
|
|
11
|
-
import { useProductItineraries } from "../../index.js";
|
|
11
|
+
import { useProductItineraries, useProductOptions } from "../../index.js";
|
|
12
12
|
import { useProductResourceTemplates } from "./commerce-client.js";
|
|
13
13
|
import { useProductDetailApi, useProductDetailMessages } from "./host.js";
|
|
14
14
|
import { getTimezoneLabel, TIMEZONE_IDS, TIMEZONE_OPTIONS } from "./timezone-options.js";
|
|
@@ -20,6 +20,7 @@ const buildDepartureFormSchema = (messages) => z
|
|
|
20
20
|
endDate: z.string().optional().nullable(),
|
|
21
21
|
endTime: z.string().optional().nullable(),
|
|
22
22
|
itineraryId: z.string().optional().nullable(),
|
|
23
|
+
optionId: z.string().optional().nullable(),
|
|
23
24
|
timezone: z.string().min(1, messages.validationTimezoneRequired),
|
|
24
25
|
status: z.enum(["open", "closed", "sold_out", "cancelled"]),
|
|
25
26
|
unlimited: z.boolean(),
|
|
@@ -69,6 +70,7 @@ function initialValues(slot, defaultTz) {
|
|
|
69
70
|
endDate: slot.endsAt ? isoToLocalDate(slot.endsAt) : "",
|
|
70
71
|
endTime: slot.endsAt ? isoToLocalTime(slot.endsAt) : "",
|
|
71
72
|
itineraryId: slot.itineraryId ?? "",
|
|
73
|
+
optionId: slot.optionId ?? "",
|
|
72
74
|
timezone: slot.timezone,
|
|
73
75
|
status: slot.status,
|
|
74
76
|
unlimited: slot.unlimited,
|
|
@@ -84,6 +86,7 @@ function initialValues(slot, defaultTz) {
|
|
|
84
86
|
endDate: "",
|
|
85
87
|
endTime: "",
|
|
86
88
|
itineraryId: "",
|
|
89
|
+
optionId: "",
|
|
87
90
|
timezone: defaultTz,
|
|
88
91
|
status: "open",
|
|
89
92
|
unlimited: false,
|
|
@@ -121,6 +124,11 @@ export function DepartureForm({ productId, slot, onSuccess, onCancel }) {
|
|
|
121
124
|
const { data: itineraryData } = useProductItineraries(productId);
|
|
122
125
|
const itineraries = itineraryData?.data ?? [];
|
|
123
126
|
const defaultItinerary = itineraries.find((itinerary) => itinerary.isDefault) ?? itineraries[0];
|
|
127
|
+
const { data: optionData } = useProductOptions({ productId, status: "active", limit: 100 });
|
|
128
|
+
const productOptions = optionData?.data ?? [];
|
|
129
|
+
const defaultOption = productOptions.find((option) => option.isDefault) ?? productOptions[0];
|
|
130
|
+
const selectedOptionId = form.watch("optionId");
|
|
131
|
+
const shouldShowOptionSelect = productOptions.length > 1 || (isEditing && !selectedOptionId && Boolean(defaultOption));
|
|
124
132
|
// Suggested pax = total physical capacity of the configured departure
|
|
125
133
|
// inventory (each room/seat type's count × its capacity, e.g. 20 doubles
|
|
126
134
|
// sleeping 2 = 40). Lets a new departure inherit capacity from the rooms the
|
|
@@ -151,6 +159,17 @@ export function DepartureForm({ productId, slot, onSuccess, onCancel }) {
|
|
|
151
159
|
useEffect(() => {
|
|
152
160
|
form.reset(initialValues(slot, defaultTz));
|
|
153
161
|
}, [slot, form, defaultTz]);
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!defaultOption)
|
|
164
|
+
return;
|
|
165
|
+
const current = form.getValues("optionId");
|
|
166
|
+
if (current)
|
|
167
|
+
return;
|
|
168
|
+
form.setValue("optionId", defaultOption.id, {
|
|
169
|
+
shouldDirty: false,
|
|
170
|
+
shouldValidate: true,
|
|
171
|
+
});
|
|
172
|
+
}, [defaultOption, form]);
|
|
154
173
|
const onSubmit = async (values) => {
|
|
155
174
|
const startsAt = combineLocalToIso(values.startDate, values.startTime);
|
|
156
175
|
const effectiveEndDate = values.endDate && typeof values.endDate === "string" && values.endDate.length > 0
|
|
@@ -167,6 +186,7 @@ export function DepartureForm({ productId, slot, onSuccess, onCancel }) {
|
|
|
167
186
|
// bug). The schema accepts `null` for both; sending `0` was the bug.
|
|
168
187
|
const nightsOverride = typeof values.nights === "number" && values.nights > 0 ? values.nights : null;
|
|
169
188
|
const daysOverride = typeof values.days === "number" && values.days > 0 ? values.days : null;
|
|
189
|
+
const optionId = values.optionId || defaultOption?.id || null;
|
|
170
190
|
// `remainingPax` is intentionally omitted on edit — the slot service is
|
|
171
191
|
// the source of truth for that field. Concurrent flows (holds, bookings,
|
|
172
192
|
// refunds) mutate it atomically while a form is open, so any snapshot
|
|
@@ -176,6 +196,7 @@ export function DepartureForm({ productId, slot, onSuccess, onCancel }) {
|
|
|
176
196
|
const baseFields = {
|
|
177
197
|
productId,
|
|
178
198
|
itineraryId: values.itineraryId ? values.itineraryId : null,
|
|
199
|
+
optionId,
|
|
179
200
|
dateLocal: values.startDate,
|
|
180
201
|
startsAt,
|
|
181
202
|
endsAt,
|
|
@@ -227,7 +248,17 @@ export function DepartureForm({ productId, slot, onSuccess, onCancel }) {
|
|
|
227
248
|
? formatMessage(itineraryMessages.defaultWithName, {
|
|
228
249
|
name: defaultItinerary.name,
|
|
229
250
|
})
|
|
230
|
-
: itineraryMessages.defaultBadge }), itineraries.map((itinerary) => (_jsx(SelectItem, { value: itinerary.id, children: itinerary.name }, itinerary.id)))] })] }), _jsx("p", { className: "text-xs text-muted-foreground", children: itineraryMessages.overrideHint })] })) : null, _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: departureMessages.
|
|
251
|
+
: itineraryMessages.defaultBadge }), itineraries.map((itinerary) => (_jsx(SelectItem, { value: itinerary.id, children: itinerary.name }, itinerary.id)))] })] }), _jsx("p", { className: "text-xs text-muted-foreground", children: itineraryMessages.overrideHint })] })) : null, shouldShowOptionSelect ? (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: departureMessages.optionLabel }), _jsxs(Select, { value: selectedOptionId || defaultOption?.id || "", onValueChange: (value) => form.setValue("optionId", value, {
|
|
252
|
+
shouldDirty: true,
|
|
253
|
+
shouldValidate: true,
|
|
254
|
+
}), items: productOptions.map((option) => ({
|
|
255
|
+
label: option.isDefault
|
|
256
|
+
? formatMessage(departureMessages.defaultOptionLabel, { name: option.name })
|
|
257
|
+
: option.name,
|
|
258
|
+
value: option.id,
|
|
259
|
+
})), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: productOptions.map((option) => (_jsx(SelectItem, { value: option.id, children: option.isDefault
|
|
260
|
+
? formatMessage(departureMessages.defaultOptionLabel, { name: option.name })
|
|
261
|
+
: option.name }, option.id))) })] }), _jsx("p", { className: "text-xs text-muted-foreground", children: departureMessages.optionRepairHint })] })) : null, _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: departureMessages.timezoneLabel }), _jsxs(Combobox, { items: TIMEZONE_IDS, value: timezone || null, autoHighlight: true, itemToStringValue: (id) => getTimezoneLabel(id), onValueChange: (next) => {
|
|
231
262
|
if (typeof next === "string") {
|
|
232
263
|
form.setValue("timezone", next, {
|
|
233
264
|
shouldValidate: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyant-travel/inventory-react",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -85,13 +85,13 @@
|
|
|
85
85
|
"react-dom": "^19.0.0",
|
|
86
86
|
"react-hook-form": "^7.60.0",
|
|
87
87
|
"zod": "^4.0.0",
|
|
88
|
-
"@voyant-travel/
|
|
88
|
+
"@voyant-travel/admin": "^0.114.0",
|
|
89
89
|
"@voyant-travel/catalog-react": "^0.129.0",
|
|
90
90
|
"@voyant-travel/finance": "^0.131.0",
|
|
91
|
-
"@voyant-travel/admin": "^0.114.0",
|
|
92
|
-
"@voyant-travel/inventory": "^0.4.4",
|
|
93
91
|
"@voyant-travel/ui": "^0.108.0",
|
|
94
|
-
"@voyant-travel/utils": "^0.105.2"
|
|
92
|
+
"@voyant-travel/utils": "^0.105.2",
|
|
93
|
+
"@voyant-travel/finance-react": "^0.131.0",
|
|
94
|
+
"@voyant-travel/inventory": "^0.4.4"
|
|
95
95
|
},
|
|
96
96
|
"peerDependenciesMeta": {
|
|
97
97
|
"@voyant-travel/admin": {
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"react-day-picker": "^9.8.0",
|
|
117
117
|
"sonner": "^2.0.7",
|
|
118
118
|
"@voyant-travel/react": "^0.104.1",
|
|
119
|
-
"@voyant-travel/i18n": "^0.107.
|
|
119
|
+
"@voyant-travel/i18n": "^0.107.4"
|
|
120
120
|
},
|
|
121
121
|
"devDependencies": {
|
|
122
122
|
"@tanstack/react-query": "^5.100.11",
|
|
@@ -129,16 +129,16 @@
|
|
|
129
129
|
"typescript": "^6.0.2",
|
|
130
130
|
"vitest": "^4.1.2",
|
|
131
131
|
"zod": "^4.3.6",
|
|
132
|
-
"@voyant-travel/admin": "^0.114.0",
|
|
133
|
-
"@voyant-travel/catalog-react": "^0.129.0",
|
|
134
132
|
"@voyant-travel/finance": "^0.131.0",
|
|
133
|
+
"@voyant-travel/catalog-react": "^0.129.0",
|
|
134
|
+
"@voyant-travel/admin": "^0.114.0",
|
|
135
135
|
"@voyant-travel/finance-react": "^0.131.0",
|
|
136
|
-
"@voyant-travel/inventory": "^0.4.4",
|
|
137
|
-
"@voyant-travel/i18n": "^0.107.3",
|
|
138
|
-
"@voyant-travel/ui": "^0.108.0",
|
|
139
136
|
"@voyant-travel/react": "^0.104.1",
|
|
137
|
+
"@voyant-travel/i18n": "^0.107.4",
|
|
138
|
+
"@voyant-travel/ui": "^0.108.0",
|
|
140
139
|
"@voyant-travel/utils": "^0.105.2",
|
|
141
|
-
"@voyant-travel/voyant-typescript-config": "^0.1.0"
|
|
140
|
+
"@voyant-travel/voyant-typescript-config": "^0.1.0",
|
|
141
|
+
"@voyant-travel/inventory": "^0.4.4"
|
|
142
142
|
},
|
|
143
143
|
"files": [
|
|
144
144
|
"dist",
|