@anker-in/ui 0.1.18 → 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 +134 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -71
- 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];
|
|
@@ -1798,6 +1833,16 @@ var QuestionnaireForm = ({
|
|
|
1798
1833
|
}
|
|
1799
1834
|
});
|
|
1800
1835
|
onSubmit?.(finalResponses);
|
|
1836
|
+
} else {
|
|
1837
|
+
setTimeout(() => {
|
|
1838
|
+
const firstErrorElement = document.querySelector('[data-has-error="true"]');
|
|
1839
|
+
if (firstErrorElement) {
|
|
1840
|
+
firstErrorElement.scrollIntoView({
|
|
1841
|
+
behavior: "smooth",
|
|
1842
|
+
block: "center"
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
}, 100);
|
|
1801
1846
|
}
|
|
1802
1847
|
};
|
|
1803
1848
|
const renderQuestion = (question) => {
|
|
@@ -2056,64 +2101,80 @@ var QuestionnaireForm = ({
|
|
|
2056
2101
|
}
|
|
2057
2102
|
};
|
|
2058
2103
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pb-[80px] light", children: [
|
|
2059
|
-
|
|
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) => {
|
|
2060
2105
|
const questionId = getQuestionId(question);
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2106
|
+
const hasError = !!errors[questionId];
|
|
2107
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2108
|
+
"div",
|
|
2109
|
+
{
|
|
2110
|
+
className: "space-y-2",
|
|
2111
|
+
"data-has-error": hasError ? "true" : "false",
|
|
2112
|
+
children: [
|
|
2113
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { className: "block", children: [
|
|
2114
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-base font-bold text-gray-900 dark:text-gray-900", children: [
|
|
2115
|
+
question.label,
|
|
2116
|
+
question.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500 ml-1", children: "*" })
|
|
2117
|
+
] }),
|
|
2118
|
+
question.description && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-sm text-gray-600 dark:text-gray-600 font-bold mt-1", children: question.description }),
|
|
2119
|
+
question.type === "email" && questionId === "email" && pageData?.emailDescription && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-sm text-gray-600 dark:text-gray-600 font-bold mt-1", children: pageData.emailDescription })
|
|
2120
|
+
] }),
|
|
2121
|
+
renderQuestion(question),
|
|
2122
|
+
question.hint && !errors[questionId] && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-500 font-bold", children: question.hint }),
|
|
2123
|
+
errors[questionId] && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2124
|
+
"p",
|
|
2125
|
+
{
|
|
2126
|
+
className: "text-sm font-bold",
|
|
2127
|
+
style: { color: "#FF4D4D" },
|
|
2128
|
+
children: errors[questionId]
|
|
2129
|
+
}
|
|
2130
|
+
)
|
|
2131
|
+
]
|
|
2132
|
+
},
|
|
2133
|
+
questionId
|
|
2134
|
+
);
|
|
2081
2135
|
}) }) }),
|
|
2082
2136
|
!!selectedTimeslotId && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center", children: [
|
|
2083
|
-
pageData?.agrees && pageData.agrees.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2137
|
+
pageData?.agrees && pageData.agrees.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2138
|
+
"div",
|
|
2139
|
+
{
|
|
2140
|
+
className: "space-y-4 mt-8",
|
|
2141
|
+
"data-has-error": agreementError ? "true" : "false",
|
|
2142
|
+
children: [
|
|
2143
|
+
pageData.agrees.map((agreeContent, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
2144
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2145
|
+
"input",
|
|
2146
|
+
{
|
|
2147
|
+
type: "checkbox",
|
|
2148
|
+
id: `agreement-${index}`,
|
|
2149
|
+
checked: agreements[index] || false,
|
|
2150
|
+
onChange: (e) => handleAgreementChange(index, e.target.checked),
|
|
2151
|
+
className: "w-5 h-5 rounded text-[#3ADB67] focus:ring-[#3ADB67] cursor-pointer flex-shrink-0",
|
|
2152
|
+
style: {
|
|
2153
|
+
accentColor: "#3ADB67"
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
),
|
|
2157
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2158
|
+
"label",
|
|
2159
|
+
{
|
|
2160
|
+
htmlFor: `agreement-${index}`,
|
|
2161
|
+
className: "text-sm text-gray-700 dark:text-gray-700 font-bold cursor-pointer select-none flex-1 [&_a]:underline [&_a]:text-blue-600 [&_a:hover]:text-blue-700",
|
|
2162
|
+
dangerouslySetInnerHTML: { __html: agreeContent },
|
|
2163
|
+
"aria-label": `Agreement ${index + 1}`
|
|
2164
|
+
}
|
|
2165
|
+
)
|
|
2166
|
+
] }, index)),
|
|
2167
|
+
agreementError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2168
|
+
"p",
|
|
2169
|
+
{
|
|
2170
|
+
className: "text-sm font-bold mt-2",
|
|
2171
|
+
style: { color: "#FF4D4D" },
|
|
2172
|
+
children: agreementError
|
|
2095
2173
|
}
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
{
|
|
2101
|
-
htmlFor: `agreement-${index}`,
|
|
2102
|
-
className: "text-sm text-gray-700 dark:text-gray-700 font-bold cursor-pointer select-none flex-1 [&_a]:underline [&_a]:text-blue-600 [&_a:hover]:text-blue-700",
|
|
2103
|
-
dangerouslySetInnerHTML: { __html: agreeContent },
|
|
2104
|
-
"aria-label": `Agreement ${index + 1}`
|
|
2105
|
-
}
|
|
2106
|
-
)
|
|
2107
|
-
] }, index)),
|
|
2108
|
-
agreementError && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2109
|
-
"p",
|
|
2110
|
-
{
|
|
2111
|
-
className: "text-sm font-bold mt-2",
|
|
2112
|
-
style: { color: "#FF4D4D" },
|
|
2113
|
-
children: agreementError
|
|
2114
|
-
}
|
|
2115
|
-
)
|
|
2116
|
-
] }),
|
|
2174
|
+
)
|
|
2175
|
+
]
|
|
2176
|
+
}
|
|
2177
|
+
),
|
|
2117
2178
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2118
2179
|
"button",
|
|
2119
2180
|
{
|
|
@@ -2720,6 +2781,7 @@ var DateTimePicker = ({
|
|
|
2720
2781
|
const customerEmail = responses.email || responses.customer_email || "";
|
|
2721
2782
|
const customerPhone = responses.phone || responses.customer_phone_number || "";
|
|
2722
2783
|
const customerPhoneCode = responses.phone_code || responses.customer_phone_code || "+1";
|
|
2784
|
+
const hasBookedBefore = responses.has_booked_before === "option2" ? 1 : 0;
|
|
2723
2785
|
if (selectedTimeslotId) {
|
|
2724
2786
|
const result = await createBooking({
|
|
2725
2787
|
demoroom_code: demoRoomCode,
|
|
@@ -2729,7 +2791,8 @@ var DateTimePicker = ({
|
|
|
2729
2791
|
customer_name: customerName,
|
|
2730
2792
|
customer_email: customerEmail,
|
|
2731
2793
|
customer_phone_code: customerPhoneCode,
|
|
2732
|
-
customer_phone_number: customerPhone
|
|
2794
|
+
customer_phone_number: customerPhone,
|
|
2795
|
+
has_booked_before: hasBookedBefore
|
|
2733
2796
|
});
|
|
2734
2797
|
if (result && onBookingSuccess) {
|
|
2735
2798
|
onBookingSuccess(result?.cancel_token);
|
|
@@ -8943,23 +9006,23 @@ var BookingSuccess = ({
|
|
|
8943
9006
|
return null;
|
|
8944
9007
|
}
|
|
8945
9008
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `min-h-screen l:py-0 l:px-0 py-12 px-6 ${className || ""}`, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mx-auto", children: [
|
|
8946
|
-
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-[
|
|
9009
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-[48px] xxl:text-[32px] font-bold text-[#080A0F] mb-8", children: pageData.yourAppointment }),
|
|
8947
9010
|
isCancelled && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white rounded-[16px] l:items-start p-6 mb-4 l:gap-2 flex l:flex-col items-center justify-between", children: [
|
|
8948
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-
|
|
9011
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-[#080A0F]", children: pageData.appointmentCanceled }),
|
|
8949
9012
|
onScheduleAgain && bookingData && /* @__PURE__ */ jsxRuntime.jsx(
|
|
8950
9013
|
"button",
|
|
8951
9014
|
{
|
|
8952
9015
|
onClick: () => onScheduleAgain(bookingData.demoroom_code),
|
|
8953
|
-
className: "px-6 py-3 bg-black text-white rounded-full hover:bg-gray-800 transition-colors whitespace-nowrap",
|
|
9016
|
+
className: "px-6 py-3 text-[16px] bg-black text-white rounded-full hover:bg-gray-800 transition-colors whitespace-nowrap",
|
|
8954
9017
|
children: pageData.scheduleAgain
|
|
8955
9018
|
}
|
|
8956
9019
|
)
|
|
8957
9020
|
] }),
|
|
8958
9021
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-8 bg-white px-[48px] l:px-[16px] l:py-[16px] py-[32px] rounded-[16px]", children: [
|
|
8959
9022
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8960
|
-
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-
|
|
9023
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.location }),
|
|
8961
9024
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
8962
|
-
bookingData.demoroom_name && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-
|
|
9025
|
+
bookingData.demoroom_name && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-[#4A4C56]", children: bookingData.demoroom_name }),
|
|
8963
9026
|
bookingData.address && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-gray-600", children: bookingData.address }),
|
|
8964
9027
|
bookingData.latitude && bookingData.longitude && /* @__PURE__ */ jsxRuntime.jsx(
|
|
8965
9028
|
"a",
|
|
@@ -8974,25 +9037,25 @@ var BookingSuccess = ({
|
|
|
8974
9037
|
] })
|
|
8975
9038
|
] }),
|
|
8976
9039
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8977
|
-
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-
|
|
8978
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-base text-
|
|
9040
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.dateAndTime }),
|
|
9041
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-base text-[#4A4C56]", children: [
|
|
8979
9042
|
bookingData.booking_date,
|
|
8980
9043
|
bookingData.time_slot && `, ${bookingData.time_slot}`,
|
|
8981
9044
|
!bookingData.time_slot && bookingData.booking_time && `, ${bookingData.booking_time}`
|
|
8982
9045
|
] })
|
|
8983
9046
|
] }),
|
|
8984
9047
|
bookingData.equipment && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8985
|
-
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-
|
|
8986
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-
|
|
9048
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.event }),
|
|
9049
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-[#4A4C56]", children: Array.isArray(bookingData.equipment) ? bookingData.equipment.join(", ") : bookingData.equipment })
|
|
8987
9050
|
] }),
|
|
8988
9051
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8989
|
-
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-
|
|
8990
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-
|
|
9052
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.demoRoom }),
|
|
9053
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-[#4A4C56]", children: bookingData.demoroom_code })
|
|
8991
9054
|
] }),
|
|
8992
9055
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
8993
|
-
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-
|
|
9056
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.visitorInfo }),
|
|
8994
9057
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
8995
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-
|
|
9058
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base text-[#4A4C56]", children: bookingData.customer_name }),
|
|
8996
9059
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-base text-gray-600", children: [
|
|
8997
9060
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8998
9061
|
"svg",
|
|
@@ -9105,7 +9168,7 @@ var BookingSuccess = ({
|
|
|
9105
9168
|
}
|
|
9106
9169
|
) }) }),
|
|
9107
9170
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center mb-8", children: [
|
|
9108
|
-
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-[18px] text-
|
|
9171
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-[18px] text-[#4A4C56] mb-2", children: pageData.cancelDialog?.title }),
|
|
9109
9172
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[14px] text-gray-600", children: pageData.cancelDialog?.description })
|
|
9110
9173
|
] }),
|
|
9111
9174
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3 justify-center", children: [
|