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