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