@anker-in/ui 0.2.0 → 0.2.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 CHANGED
@@ -1685,7 +1685,12 @@ var QuestionnaireForm = ({
1685
1685
  const [phoneCountryCodes, setPhoneCountryCodes] = React9.useState({});
1686
1686
  const [otherInputs, setOtherInputs] = React9.useState({});
1687
1687
  const prevHasBookedBeforeRef = React9.useRef(false);
1688
- const hasBookedBefore = responses["has_booked_before"] === "option2";
1688
+ const hasBookedBeforeInitialized = React9.useRef(false);
1689
+ const hasBookedBeforeQuestion = questions.find(
1690
+ (q) => (q.key || q.id) === "has_booked_before"
1691
+ );
1692
+ const hasBookedBeforeQuestionId = hasBookedBeforeQuestion ? hasBookedBeforeQuestion.key || hasBookedBeforeQuestion.id || "" : "has_booked_before";
1693
+ const hasBookedBefore = responses[hasBookedBeforeQuestionId] === "option2";
1689
1694
  const hiddenQuestionIds = React9.useMemo(() => {
1690
1695
  if (!hasBookedBefore) return [];
1691
1696
  return questions.filter((q) => q.is_default === false).map((q) => q.key || q.id || "");
@@ -1698,6 +1703,21 @@ var QuestionnaireForm = ({
1698
1703
  return true;
1699
1704
  });
1700
1705
  }, [questions, hasBookedBefore]);
1706
+ React9.useEffect(() => {
1707
+ if (hasBookedBeforeInitialized.current) return;
1708
+ if (hasBookedBeforeQuestion && hasBookedBeforeQuestionId) {
1709
+ setResponses((prev) => {
1710
+ if (!prev[hasBookedBeforeQuestionId]) {
1711
+ return {
1712
+ ...prev,
1713
+ [hasBookedBeforeQuestionId]: "option1"
1714
+ };
1715
+ }
1716
+ return prev;
1717
+ });
1718
+ hasBookedBeforeInitialized.current = true;
1719
+ }
1720
+ }, [hasBookedBeforeQuestion, hasBookedBeforeQuestionId]);
1701
1721
  React9.useEffect(() => {
1702
1722
  if (hasBookedBefore && !prevHasBookedBeforeRef.current) {
1703
1723
  if (hiddenQuestionIds.length > 0) {