@anker-in/ui 0.1.19 → 0.2.0
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/demo-room.js.map +1 -1
- package/dist/demo-room.mjs.map +1 -1
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +41 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1670,6 +1670,41 @@ var QuestionnaireForm = ({
|
|
|
1670
1670
|
const [agreementError, setAgreementError] = useState("");
|
|
1671
1671
|
const [phoneCountryCodes, setPhoneCountryCodes] = useState({});
|
|
1672
1672
|
const [otherInputs, setOtherInputs] = useState({});
|
|
1673
|
+
const prevHasBookedBeforeRef = useRef(false);
|
|
1674
|
+
const hasBookedBefore = responses["has_booked_before"] === "option2";
|
|
1675
|
+
const hiddenQuestionIds = useMemo(() => {
|
|
1676
|
+
if (!hasBookedBefore) return [];
|
|
1677
|
+
return questions.filter((q) => q.is_default === false).map((q) => q.key || q.id || "");
|
|
1678
|
+
}, [hasBookedBefore, questions]);
|
|
1679
|
+
const visibleQuestions = useMemo(() => {
|
|
1680
|
+
return questions.filter((question) => {
|
|
1681
|
+
if (hasBookedBefore && question.is_default === false) {
|
|
1682
|
+
return false;
|
|
1683
|
+
}
|
|
1684
|
+
return true;
|
|
1685
|
+
});
|
|
1686
|
+
}, [questions, hasBookedBefore]);
|
|
1687
|
+
useEffect(() => {
|
|
1688
|
+
if (hasBookedBefore && !prevHasBookedBeforeRef.current) {
|
|
1689
|
+
if (hiddenQuestionIds.length > 0) {
|
|
1690
|
+
setResponses((prev) => {
|
|
1691
|
+
const newResponses = { ...prev };
|
|
1692
|
+
hiddenQuestionIds.forEach((questionId) => {
|
|
1693
|
+
delete newResponses[questionId];
|
|
1694
|
+
});
|
|
1695
|
+
return newResponses;
|
|
1696
|
+
});
|
|
1697
|
+
setErrors((prev) => {
|
|
1698
|
+
const newErrors = { ...prev };
|
|
1699
|
+
hiddenQuestionIds.forEach((questionId) => {
|
|
1700
|
+
delete newErrors[questionId];
|
|
1701
|
+
});
|
|
1702
|
+
return newErrors;
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
prevHasBookedBeforeRef.current = hasBookedBefore;
|
|
1707
|
+
}, [hasBookedBefore, hiddenQuestionIds]);
|
|
1673
1708
|
const defaultCountryCodes = [
|
|
1674
1709
|
{ code: "+1", country: "US/CA" },
|
|
1675
1710
|
{ code: "+86", country: "CN" },
|
|
@@ -1685,7 +1720,7 @@ var QuestionnaireForm = ({
|
|
|
1685
1720
|
];
|
|
1686
1721
|
const countryCodes = pageData?.countryCodes || defaultCountryCodes;
|
|
1687
1722
|
const getQuestionId = (question) => {
|
|
1688
|
-
return question.
|
|
1723
|
+
return question.key || question.id || "";
|
|
1689
1724
|
};
|
|
1690
1725
|
const handleChange = (questionId, value) => {
|
|
1691
1726
|
setResponses((prev) => ({
|
|
@@ -1739,7 +1774,7 @@ var QuestionnaireForm = ({
|
|
|
1739
1774
|
};
|
|
1740
1775
|
const validateForm = () => {
|
|
1741
1776
|
const newErrors = {};
|
|
1742
|
-
|
|
1777
|
+
visibleQuestions.forEach((question) => {
|
|
1743
1778
|
if (question.required) {
|
|
1744
1779
|
const questionId = getQuestionId(question);
|
|
1745
1780
|
const value = responses[questionId];
|
|
@@ -2052,7 +2087,7 @@ var QuestionnaireForm = ({
|
|
|
2052
2087
|
}
|
|
2053
2088
|
};
|
|
2054
2089
|
return /* @__PURE__ */ jsxs("div", { className: "pb-[80px] light", children: [
|
|
2055
|
-
|
|
2090
|
+
visibleQuestions && visibleQuestions.length > 0 && /* @__PURE__ */ jsx("div", { className: "bg-white rounded-[12px] border border-[#E4E5E6] p-8 dark:bg-white dark:border-[#E4E5E6] l:p-4", children: /* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, className: cn("space-y-6", className), children: visibleQuestions.map((question) => {
|
|
2056
2091
|
const questionId = getQuestionId(question);
|
|
2057
2092
|
const hasError = !!errors[questionId];
|
|
2058
2093
|
return /* @__PURE__ */ jsxs(
|
|
@@ -2732,6 +2767,7 @@ var DateTimePicker = ({
|
|
|
2732
2767
|
const customerEmail = responses.email || responses.customer_email || "";
|
|
2733
2768
|
const customerPhone = responses.phone || responses.customer_phone_number || "";
|
|
2734
2769
|
const customerPhoneCode = responses.phone_code || responses.customer_phone_code || "+1";
|
|
2770
|
+
const hasBookedBefore = responses.has_booked_before === "option2" ? 1 : 0;
|
|
2735
2771
|
if (selectedTimeslotId) {
|
|
2736
2772
|
const result = await createBooking({
|
|
2737
2773
|
demoroom_code: demoRoomCode,
|
|
@@ -2741,7 +2777,8 @@ var DateTimePicker = ({
|
|
|
2741
2777
|
customer_name: customerName,
|
|
2742
2778
|
customer_email: customerEmail,
|
|
2743
2779
|
customer_phone_code: customerPhoneCode,
|
|
2744
|
-
customer_phone_number: customerPhone
|
|
2780
|
+
customer_phone_number: customerPhone,
|
|
2781
|
+
has_booked_before: hasBookedBefore
|
|
2745
2782
|
});
|
|
2746
2783
|
if (result && onBookingSuccess) {
|
|
2747
2784
|
onBookingSuccess(result?.cancel_token);
|