@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.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,41 @@ 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 hasBookedBefore = responses["has_booked_before"] === "option2";
|
|
1689
|
+
const hiddenQuestionIds = React9.useMemo(() => {
|
|
1690
|
+
if (!hasBookedBefore) return [];
|
|
1691
|
+
return questions.filter((q) => q.is_default === false).map((q) => q.key || q.id || "");
|
|
1692
|
+
}, [hasBookedBefore, questions]);
|
|
1693
|
+
const visibleQuestions = React9.useMemo(() => {
|
|
1694
|
+
return questions.filter((question) => {
|
|
1695
|
+
if (hasBookedBefore && question.is_default === false) {
|
|
1696
|
+
return false;
|
|
1697
|
+
}
|
|
1698
|
+
return true;
|
|
1699
|
+
});
|
|
1700
|
+
}, [questions, hasBookedBefore]);
|
|
1701
|
+
React9.useEffect(() => {
|
|
1702
|
+
if (hasBookedBefore && !prevHasBookedBeforeRef.current) {
|
|
1703
|
+
if (hiddenQuestionIds.length > 0) {
|
|
1704
|
+
setResponses((prev) => {
|
|
1705
|
+
const newResponses = { ...prev };
|
|
1706
|
+
hiddenQuestionIds.forEach((questionId) => {
|
|
1707
|
+
delete newResponses[questionId];
|
|
1708
|
+
});
|
|
1709
|
+
return newResponses;
|
|
1710
|
+
});
|
|
1711
|
+
setErrors((prev) => {
|
|
1712
|
+
const newErrors = { ...prev };
|
|
1713
|
+
hiddenQuestionIds.forEach((questionId) => {
|
|
1714
|
+
delete newErrors[questionId];
|
|
1715
|
+
});
|
|
1716
|
+
return newErrors;
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
prevHasBookedBeforeRef.current = hasBookedBefore;
|
|
1721
|
+
}, [hasBookedBefore, hiddenQuestionIds]);
|
|
1687
1722
|
const defaultCountryCodes = [
|
|
1688
1723
|
{ code: "+1", country: "US/CA" },
|
|
1689
1724
|
{ code: "+86", country: "CN" },
|
|
@@ -1699,7 +1734,7 @@ var QuestionnaireForm = ({
|
|
|
1699
1734
|
];
|
|
1700
1735
|
const countryCodes = pageData?.countryCodes || defaultCountryCodes;
|
|
1701
1736
|
const getQuestionId = (question) => {
|
|
1702
|
-
return question.
|
|
1737
|
+
return question.key || question.id || "";
|
|
1703
1738
|
};
|
|
1704
1739
|
const handleChange = (questionId, value) => {
|
|
1705
1740
|
setResponses((prev) => ({
|
|
@@ -1753,7 +1788,7 @@ var QuestionnaireForm = ({
|
|
|
1753
1788
|
};
|
|
1754
1789
|
const validateForm = () => {
|
|
1755
1790
|
const newErrors = {};
|
|
1756
|
-
|
|
1791
|
+
visibleQuestions.forEach((question) => {
|
|
1757
1792
|
if (question.required) {
|
|
1758
1793
|
const questionId = getQuestionId(question);
|
|
1759
1794
|
const value = responses[questionId];
|
|
@@ -2066,7 +2101,7 @@ var QuestionnaireForm = ({
|
|
|
2066
2101
|
}
|
|
2067
2102
|
};
|
|
2068
2103
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pb-[80px] light", children: [
|
|
2069
|
-
|
|
2104
|
+
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
2105
|
const questionId = getQuestionId(question);
|
|
2071
2106
|
const hasError = !!errors[questionId];
|
|
2072
2107
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -2746,6 +2781,7 @@ var DateTimePicker = ({
|
|
|
2746
2781
|
const customerEmail = responses.email || responses.customer_email || "";
|
|
2747
2782
|
const customerPhone = responses.phone || responses.customer_phone_number || "";
|
|
2748
2783
|
const customerPhoneCode = responses.phone_code || responses.customer_phone_code || "+1";
|
|
2784
|
+
const hasBookedBefore = responses.has_booked_before === "option2" ? 1 : 0;
|
|
2749
2785
|
if (selectedTimeslotId) {
|
|
2750
2786
|
const result = await createBooking({
|
|
2751
2787
|
demoroom_code: demoRoomCode,
|
|
@@ -2755,7 +2791,8 @@ var DateTimePicker = ({
|
|
|
2755
2791
|
customer_name: customerName,
|
|
2756
2792
|
customer_email: customerEmail,
|
|
2757
2793
|
customer_phone_code: customerPhoneCode,
|
|
2758
|
-
customer_phone_number: customerPhone
|
|
2794
|
+
customer_phone_number: customerPhone,
|
|
2795
|
+
has_booked_before: hasBookedBefore
|
|
2759
2796
|
});
|
|
2760
2797
|
if (result && onBookingSuccess) {
|
|
2761
2798
|
onBookingSuccess(result?.cancel_token);
|