@anker-in/ui 0.1.19 → 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/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 +61 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -189,6 +189,8 @@ interface Question {
|
|
|
189
189
|
hint?: string;
|
|
190
190
|
options?: QuestionOption[];
|
|
191
191
|
required: boolean;
|
|
192
|
+
is_default?: boolean;
|
|
193
|
+
order?: number;
|
|
192
194
|
}
|
|
193
195
|
interface Questionnaire {
|
|
194
196
|
id: number;
|
|
@@ -212,6 +214,7 @@ interface CreateBookingRequest {
|
|
|
212
214
|
customer_email: string;
|
|
213
215
|
customer_phone_code: string;
|
|
214
216
|
customer_phone_number: string;
|
|
217
|
+
has_booked_before?: number;
|
|
215
218
|
}
|
|
216
219
|
interface Booking {
|
|
217
220
|
booking_id: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -189,6 +189,8 @@ interface Question {
|
|
|
189
189
|
hint?: string;
|
|
190
190
|
options?: QuestionOption[];
|
|
191
191
|
required: boolean;
|
|
192
|
+
is_default?: boolean;
|
|
193
|
+
order?: number;
|
|
192
194
|
}
|
|
193
195
|
interface Questionnaire {
|
|
194
196
|
id: number;
|
|
@@ -212,6 +214,7 @@ interface CreateBookingRequest {
|
|
|
212
214
|
customer_email: string;
|
|
213
215
|
customer_phone_code: string;
|
|
214
216
|
customer_phone_number: string;
|
|
217
|
+
has_booked_before?: number;
|
|
215
218
|
}
|
|
216
219
|
interface Booking {
|
|
217
220
|
booking_id: number;
|
package/dist/index.js
CHANGED
|
@@ -1684,6 +1684,61 @@ var QuestionnaireForm = ({
|
|
|
1684
1684
|
const [agreementError, setAgreementError] = React9.useState("");
|
|
1685
1685
|
const [phoneCountryCodes, setPhoneCountryCodes] = React9.useState({});
|
|
1686
1686
|
const [otherInputs, setOtherInputs] = React9.useState({});
|
|
1687
|
+
const prevHasBookedBeforeRef = React9.useRef(false);
|
|
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";
|
|
1694
|
+
const hiddenQuestionIds = React9.useMemo(() => {
|
|
1695
|
+
if (!hasBookedBefore) return [];
|
|
1696
|
+
return questions.filter((q) => q.is_default === false).map((q) => q.key || q.id || "");
|
|
1697
|
+
}, [hasBookedBefore, questions]);
|
|
1698
|
+
const visibleQuestions = React9.useMemo(() => {
|
|
1699
|
+
return questions.filter((question) => {
|
|
1700
|
+
if (hasBookedBefore && question.is_default === false) {
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1703
|
+
return true;
|
|
1704
|
+
});
|
|
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]);
|
|
1721
|
+
React9.useEffect(() => {
|
|
1722
|
+
if (hasBookedBefore && !prevHasBookedBeforeRef.current) {
|
|
1723
|
+
if (hiddenQuestionIds.length > 0) {
|
|
1724
|
+
setResponses((prev) => {
|
|
1725
|
+
const newResponses = { ...prev };
|
|
1726
|
+
hiddenQuestionIds.forEach((questionId) => {
|
|
1727
|
+
delete newResponses[questionId];
|
|
1728
|
+
});
|
|
1729
|
+
return newResponses;
|
|
1730
|
+
});
|
|
1731
|
+
setErrors((prev) => {
|
|
1732
|
+
const newErrors = { ...prev };
|
|
1733
|
+
hiddenQuestionIds.forEach((questionId) => {
|
|
1734
|
+
delete newErrors[questionId];
|
|
1735
|
+
});
|
|
1736
|
+
return newErrors;
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
prevHasBookedBeforeRef.current = hasBookedBefore;
|
|
1741
|
+
}, [hasBookedBefore, hiddenQuestionIds]);
|
|
1687
1742
|
const defaultCountryCodes = [
|
|
1688
1743
|
{ code: "+1", country: "US/CA" },
|
|
1689
1744
|
{ code: "+86", country: "CN" },
|
|
@@ -1699,7 +1754,7 @@ var QuestionnaireForm = ({
|
|
|
1699
1754
|
];
|
|
1700
1755
|
const countryCodes = pageData?.countryCodes || defaultCountryCodes;
|
|
1701
1756
|
const getQuestionId = (question) => {
|
|
1702
|
-
return question.
|
|
1757
|
+
return question.key || question.id || "";
|
|
1703
1758
|
};
|
|
1704
1759
|
const handleChange = (questionId, value) => {
|
|
1705
1760
|
setResponses((prev) => ({
|
|
@@ -1753,7 +1808,7 @@ var QuestionnaireForm = ({
|
|
|
1753
1808
|
};
|
|
1754
1809
|
const validateForm = () => {
|
|
1755
1810
|
const newErrors = {};
|
|
1756
|
-
|
|
1811
|
+
visibleQuestions.forEach((question) => {
|
|
1757
1812
|
if (question.required) {
|
|
1758
1813
|
const questionId = getQuestionId(question);
|
|
1759
1814
|
const value = responses[questionId];
|
|
@@ -2066,7 +2121,7 @@ var QuestionnaireForm = ({
|
|
|
2066
2121
|
}
|
|
2067
2122
|
};
|
|
2068
2123
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pb-[80px] light", children: [
|
|
2069
|
-
|
|
2124
|
+
visibleQuestions && visibleQuestions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-white rounded-[12px] border border-[#E4E5E6] p-8 dark:bg-white dark:border-[#E4E5E6] l:p-4", children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: handleSubmit, className: cn("space-y-6", className), children: visibleQuestions.map((question) => {
|
|
2070
2125
|
const questionId = getQuestionId(question);
|
|
2071
2126
|
const hasError = !!errors[questionId];
|
|
2072
2127
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -2746,6 +2801,7 @@ var DateTimePicker = ({
|
|
|
2746
2801
|
const customerEmail = responses.email || responses.customer_email || "";
|
|
2747
2802
|
const customerPhone = responses.phone || responses.customer_phone_number || "";
|
|
2748
2803
|
const customerPhoneCode = responses.phone_code || responses.customer_phone_code || "+1";
|
|
2804
|
+
const hasBookedBefore = responses.has_booked_before === "option2" ? 1 : 0;
|
|
2749
2805
|
if (selectedTimeslotId) {
|
|
2750
2806
|
const result = await createBooking({
|
|
2751
2807
|
demoroom_code: demoRoomCode,
|
|
@@ -2755,7 +2811,8 @@ var DateTimePicker = ({
|
|
|
2755
2811
|
customer_name: customerName,
|
|
2756
2812
|
customer_email: customerEmail,
|
|
2757
2813
|
customer_phone_code: customerPhoneCode,
|
|
2758
|
-
customer_phone_number: customerPhone
|
|
2814
|
+
customer_phone_number: customerPhone,
|
|
2815
|
+
has_booked_before: hasBookedBefore
|
|
2759
2816
|
});
|
|
2760
2817
|
if (result && onBookingSuccess) {
|
|
2761
2818
|
onBookingSuccess(result?.cancel_token);
|