@bookinglab/booking-ui-react 1.11.0 → 1.11.1
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/dist/index.js +42 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -233,40 +233,70 @@ function BookingForm({
|
|
|
233
233
|
if (!settings?.conditional_answers) {
|
|
234
234
|
return true;
|
|
235
235
|
}
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
return conditionEntries.some(([questionIdStr, expectedAnswer]) => {
|
|
241
|
-
const questionId = Number(questionIdStr);
|
|
236
|
+
const conditionalAnswers = settings.conditional_answers;
|
|
237
|
+
const conditionalQuestion = settings.conditional_question;
|
|
238
|
+
const buildCandidates = (questionId) => {
|
|
242
239
|
const currentValue = values[String(questionId)];
|
|
240
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
243
241
|
if (currentValue === void 0 || currentValue === "" || currentValue === null) {
|
|
244
|
-
return
|
|
242
|
+
return candidates;
|
|
245
243
|
}
|
|
246
|
-
const normalizedCurrent = typeof currentValue === "object" && currentValue !== null && "id" in currentValue ? currentValue : currentValue;
|
|
247
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
248
244
|
const addCandidate = (v) => {
|
|
249
245
|
if (v === void 0 || v === null) return;
|
|
250
246
|
const s = String(v).trim();
|
|
251
247
|
if (s) candidates.add(s);
|
|
252
248
|
};
|
|
253
|
-
const
|
|
249
|
+
const normalizedCurrent = typeof currentValue === "object" && currentValue !== null && "id" in currentValue ? currentValue : currentValue;
|
|
254
250
|
if (typeof normalizedCurrent === "object" && normalizedCurrent !== null) {
|
|
255
251
|
addCandidate(normalizedCurrent.id);
|
|
256
252
|
addCandidate(normalizedCurrent.name);
|
|
257
253
|
} else {
|
|
258
254
|
addCandidate(normalizedCurrent);
|
|
259
255
|
}
|
|
260
|
-
|
|
256
|
+
const sourceQuestion = questions.find((q) => q.id === questionId);
|
|
257
|
+
if ((sourceQuestion?.detail_type === "select" || sourceQuestion?.detail_type === "radio") && sourceQuestion.options?.length) {
|
|
261
258
|
const currentStr = [...candidates][0] ?? "";
|
|
262
259
|
const optionById = sourceQuestion.options.find((o) => String(o.id) === currentStr);
|
|
263
|
-
const optionByName = sourceQuestion.options.find(
|
|
260
|
+
const optionByName = sourceQuestion.options.find(
|
|
261
|
+
(o) => String(o.name).trim() === currentStr
|
|
262
|
+
);
|
|
264
263
|
const opt = optionById ?? optionByName;
|
|
265
264
|
if (opt) {
|
|
266
265
|
addCandidate(opt.id);
|
|
267
266
|
addCandidate(opt.name);
|
|
268
267
|
}
|
|
269
268
|
}
|
|
269
|
+
return candidates;
|
|
270
|
+
};
|
|
271
|
+
const isTruthyFlag = (v) => {
|
|
272
|
+
if (v === void 0 || v === null) return true;
|
|
273
|
+
if (typeof v === "boolean") return v;
|
|
274
|
+
if (typeof v === "number") return v !== 0;
|
|
275
|
+
if (typeof v === "string") {
|
|
276
|
+
const s = v.trim().toLowerCase();
|
|
277
|
+
return s !== "" && s !== "0" && s !== "false";
|
|
278
|
+
}
|
|
279
|
+
return !!v;
|
|
280
|
+
};
|
|
281
|
+
if (conditionalQuestion !== void 0 && conditionalQuestion !== null && conditionalQuestion !== "") {
|
|
282
|
+
const sourceId = Number(conditionalQuestion);
|
|
283
|
+
if (!Number.isFinite(sourceId)) return true;
|
|
284
|
+
const candidates = buildCandidates(sourceId);
|
|
285
|
+
if (candidates.size === 0) return false;
|
|
286
|
+
const entries = Object.entries(conditionalAnswers);
|
|
287
|
+
if (entries.length === 0) return true;
|
|
288
|
+
return entries.some(
|
|
289
|
+
([optionKey, flag]) => isTruthyFlag(flag) && candidates.has(String(optionKey).trim())
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
const conditionEntries = Object.entries(conditionalAnswers);
|
|
293
|
+
if (conditionEntries.length === 0) {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
return conditionEntries.some(([questionIdStr, expectedAnswer]) => {
|
|
297
|
+
const questionId = Number(questionIdStr);
|
|
298
|
+
const candidates = buildCandidates(questionId);
|
|
299
|
+
if (candidates.size === 0) return false;
|
|
270
300
|
const matchesScalar = (expected) => {
|
|
271
301
|
const expectedStr = String(expected).trim();
|
|
272
302
|
return candidates.has(expectedStr);
|