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