@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/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.id || question.key || "";
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
- questions.forEach((question) => {
1777
+ visibleQuestions.forEach((question) => {
1743
1778
  if (question.required) {
1744
1779
  const questionId = getQuestionId(question);
1745
1780
  const value = responses[questionId];
@@ -1784,6 +1819,16 @@ var QuestionnaireForm = ({
1784
1819
  }
1785
1820
  });
1786
1821
  onSubmit?.(finalResponses);
1822
+ } else {
1823
+ setTimeout(() => {
1824
+ const firstErrorElement = document.querySelector('[data-has-error="true"]');
1825
+ if (firstErrorElement) {
1826
+ firstErrorElement.scrollIntoView({
1827
+ behavior: "smooth",
1828
+ block: "center"
1829
+ });
1830
+ }
1831
+ }, 100);
1787
1832
  }
1788
1833
  };
1789
1834
  const renderQuestion = (question) => {
@@ -2042,64 +2087,80 @@ var QuestionnaireForm = ({
2042
2087
  }
2043
2088
  };
2044
2089
  return /* @__PURE__ */ jsxs("div", { className: "pb-[80px] light", children: [
2045
- questions && questions.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: questions.map((question) => {
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) => {
2046
2091
  const questionId = getQuestionId(question);
2047
- return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2048
- /* @__PURE__ */ jsxs("label", { className: "block", children: [
2049
- /* @__PURE__ */ jsxs("span", { className: "text-base font-bold text-gray-900 dark:text-gray-900", children: [
2050
- question.label,
2051
- question.required && /* @__PURE__ */ jsx("span", { className: "text-red-500 ml-1", children: "*" })
2052
- ] }),
2053
- question.description && /* @__PURE__ */ jsx("span", { className: "block text-sm text-gray-600 dark:text-gray-600 font-bold mt-1", children: question.description }),
2054
- question.type === "email" && questionId === "email" && pageData?.emailDescription && /* @__PURE__ */ jsx("span", { className: "block text-sm text-gray-600 dark:text-gray-600 font-bold mt-1", children: pageData.emailDescription })
2055
- ] }),
2056
- renderQuestion(question),
2057
- question.hint && !errors[questionId] && /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-500 dark:text-gray-500 font-bold", children: question.hint }),
2058
- errors[questionId] && /* @__PURE__ */ jsx(
2059
- "p",
2060
- {
2061
- className: "text-sm font-bold",
2062
- style: { color: "#FF4D4D" },
2063
- children: errors[questionId]
2064
- }
2065
- )
2066
- ] }, questionId);
2092
+ const hasError = !!errors[questionId];
2093
+ return /* @__PURE__ */ jsxs(
2094
+ "div",
2095
+ {
2096
+ className: "space-y-2",
2097
+ "data-has-error": hasError ? "true" : "false",
2098
+ children: [
2099
+ /* @__PURE__ */ jsxs("label", { className: "block", children: [
2100
+ /* @__PURE__ */ jsxs("span", { className: "text-base font-bold text-gray-900 dark:text-gray-900", children: [
2101
+ question.label,
2102
+ question.required && /* @__PURE__ */ jsx("span", { className: "text-red-500 ml-1", children: "*" })
2103
+ ] }),
2104
+ question.description && /* @__PURE__ */ jsx("span", { className: "block text-sm text-gray-600 dark:text-gray-600 font-bold mt-1", children: question.description }),
2105
+ question.type === "email" && questionId === "email" && pageData?.emailDescription && /* @__PURE__ */ jsx("span", { className: "block text-sm text-gray-600 dark:text-gray-600 font-bold mt-1", children: pageData.emailDescription })
2106
+ ] }),
2107
+ renderQuestion(question),
2108
+ question.hint && !errors[questionId] && /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-500 dark:text-gray-500 font-bold", children: question.hint }),
2109
+ errors[questionId] && /* @__PURE__ */ jsx(
2110
+ "p",
2111
+ {
2112
+ className: "text-sm font-bold",
2113
+ style: { color: "#FF4D4D" },
2114
+ children: errors[questionId]
2115
+ }
2116
+ )
2117
+ ]
2118
+ },
2119
+ questionId
2120
+ );
2067
2121
  }) }) }),
2068
2122
  !!selectedTimeslotId && /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center", children: [
2069
- pageData?.agrees && pageData.agrees.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-4 mt-8", children: [
2070
- pageData.agrees.map((agreeContent, index) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2071
- /* @__PURE__ */ jsx(
2072
- "input",
2073
- {
2074
- type: "checkbox",
2075
- id: `agreement-${index}`,
2076
- checked: agreements[index] || false,
2077
- onChange: (e) => handleAgreementChange(index, e.target.checked),
2078
- className: "w-5 h-5 rounded text-[#3ADB67] focus:ring-[#3ADB67] cursor-pointer flex-shrink-0",
2079
- style: {
2080
- accentColor: "#3ADB67"
2123
+ pageData?.agrees && pageData.agrees.length > 0 && /* @__PURE__ */ jsxs(
2124
+ "div",
2125
+ {
2126
+ className: "space-y-4 mt-8",
2127
+ "data-has-error": agreementError ? "true" : "false",
2128
+ children: [
2129
+ pageData.agrees.map((agreeContent, index) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2130
+ /* @__PURE__ */ jsx(
2131
+ "input",
2132
+ {
2133
+ type: "checkbox",
2134
+ id: `agreement-${index}`,
2135
+ checked: agreements[index] || false,
2136
+ onChange: (e) => handleAgreementChange(index, e.target.checked),
2137
+ className: "w-5 h-5 rounded text-[#3ADB67] focus:ring-[#3ADB67] cursor-pointer flex-shrink-0",
2138
+ style: {
2139
+ accentColor: "#3ADB67"
2140
+ }
2141
+ }
2142
+ ),
2143
+ /* @__PURE__ */ jsx(
2144
+ "label",
2145
+ {
2146
+ htmlFor: `agreement-${index}`,
2147
+ 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",
2148
+ dangerouslySetInnerHTML: { __html: agreeContent },
2149
+ "aria-label": `Agreement ${index + 1}`
2150
+ }
2151
+ )
2152
+ ] }, index)),
2153
+ agreementError && /* @__PURE__ */ jsx(
2154
+ "p",
2155
+ {
2156
+ className: "text-sm font-bold mt-2",
2157
+ style: { color: "#FF4D4D" },
2158
+ children: agreementError
2081
2159
  }
2082
- }
2083
- ),
2084
- /* @__PURE__ */ jsx(
2085
- "label",
2086
- {
2087
- htmlFor: `agreement-${index}`,
2088
- 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",
2089
- dangerouslySetInnerHTML: { __html: agreeContent },
2090
- "aria-label": `Agreement ${index + 1}`
2091
- }
2092
- )
2093
- ] }, index)),
2094
- agreementError && /* @__PURE__ */ jsx(
2095
- "p",
2096
- {
2097
- className: "text-sm font-bold mt-2",
2098
- style: { color: "#FF4D4D" },
2099
- children: agreementError
2100
- }
2101
- )
2102
- ] }),
2160
+ )
2161
+ ]
2162
+ }
2163
+ ),
2103
2164
  /* @__PURE__ */ jsx(
2104
2165
  "button",
2105
2166
  {
@@ -2706,6 +2767,7 @@ var DateTimePicker = ({
2706
2767
  const customerEmail = responses.email || responses.customer_email || "";
2707
2768
  const customerPhone = responses.phone || responses.customer_phone_number || "";
2708
2769
  const customerPhoneCode = responses.phone_code || responses.customer_phone_code || "+1";
2770
+ const hasBookedBefore = responses.has_booked_before === "option2" ? 1 : 0;
2709
2771
  if (selectedTimeslotId) {
2710
2772
  const result = await createBooking({
2711
2773
  demoroom_code: demoRoomCode,
@@ -2715,7 +2777,8 @@ var DateTimePicker = ({
2715
2777
  customer_name: customerName,
2716
2778
  customer_email: customerEmail,
2717
2779
  customer_phone_code: customerPhoneCode,
2718
- customer_phone_number: customerPhone
2780
+ customer_phone_number: customerPhone,
2781
+ has_booked_before: hasBookedBefore
2719
2782
  });
2720
2783
  if (result && onBookingSuccess) {
2721
2784
  onBookingSuccess(result?.cancel_token);
@@ -8929,23 +8992,23 @@ var BookingSuccess = ({
8929
8992
  return null;
8930
8993
  }
8931
8994
  return /* @__PURE__ */ jsx("div", { className: `min-h-screen l:py-0 l:px-0 py-12 px-6 ${className || ""}`, children: /* @__PURE__ */ jsxs("div", { className: "mx-auto", children: [
8932
- /* @__PURE__ */ jsx("h1", { className: "text-[40px] font-bold text-gray-900 mb-8", children: pageData.yourAppointment }),
8995
+ /* @__PURE__ */ jsx("h1", { className: "text-[48px] xxl:text-[32px] font-bold text-[#080A0F] mb-8", children: pageData.yourAppointment }),
8933
8996
  isCancelled && /* @__PURE__ */ 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: [
8934
- /* @__PURE__ */ jsx("p", { className: "text-base text-gray-700", children: pageData.appointmentCanceled }),
8997
+ /* @__PURE__ */ jsx("p", { className: "text-base text-[#080A0F]", children: pageData.appointmentCanceled }),
8935
8998
  onScheduleAgain && bookingData && /* @__PURE__ */ jsx(
8936
8999
  "button",
8937
9000
  {
8938
9001
  onClick: () => onScheduleAgain(bookingData.demoroom_code),
8939
- className: "px-6 py-3 bg-black text-white rounded-full hover:bg-gray-800 transition-colors whitespace-nowrap",
9002
+ className: "px-6 py-3 text-[16px] bg-black text-white rounded-full hover:bg-gray-800 transition-colors whitespace-nowrap",
8940
9003
  children: pageData.scheduleAgain
8941
9004
  }
8942
9005
  )
8943
9006
  ] }),
8944
9007
  /* @__PURE__ */ jsxs("div", { className: "space-y-8 bg-white px-[48px] l:px-[16px] l:py-[16px] py-[32px] rounded-[16px]", children: [
8945
9008
  /* @__PURE__ */ jsxs("div", { children: [
8946
- /* @__PURE__ */ jsx("h2", { className: "text-lg text-gray-900 mb-3", children: pageData.location }),
9009
+ /* @__PURE__ */ jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.location }),
8947
9010
  /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
8948
- bookingData.demoroom_name && /* @__PURE__ */ jsx("p", { className: "text-base text-gray-900", children: bookingData.demoroom_name }),
9011
+ bookingData.demoroom_name && /* @__PURE__ */ jsx("p", { className: "text-base text-[#4A4C56]", children: bookingData.demoroom_name }),
8949
9012
  bookingData.address && /* @__PURE__ */ jsx("p", { className: "text-base text-gray-600", children: bookingData.address }),
8950
9013
  bookingData.latitude && bookingData.longitude && /* @__PURE__ */ jsx(
8951
9014
  "a",
@@ -8960,25 +9023,25 @@ var BookingSuccess = ({
8960
9023
  ] })
8961
9024
  ] }),
8962
9025
  /* @__PURE__ */ jsxs("div", { children: [
8963
- /* @__PURE__ */ jsx("h2", { className: "text-lg text-gray-900 mb-3", children: pageData.dateAndTime }),
8964
- /* @__PURE__ */ jsxs("p", { className: "text-base text-gray-900", children: [
9026
+ /* @__PURE__ */ jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.dateAndTime }),
9027
+ /* @__PURE__ */ jsxs("p", { className: "text-base text-[#4A4C56]", children: [
8965
9028
  bookingData.booking_date,
8966
9029
  bookingData.time_slot && `, ${bookingData.time_slot}`,
8967
9030
  !bookingData.time_slot && bookingData.booking_time && `, ${bookingData.booking_time}`
8968
9031
  ] })
8969
9032
  ] }),
8970
9033
  bookingData.equipment && /* @__PURE__ */ jsxs("div", { children: [
8971
- /* @__PURE__ */ jsx("h2", { className: "text-lg text-gray-900 mb-3", children: pageData.event }),
8972
- /* @__PURE__ */ jsx("p", { className: "text-base text-gray-900", children: Array.isArray(bookingData.equipment) ? bookingData.equipment.join(", ") : bookingData.equipment })
9034
+ /* @__PURE__ */ jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.event }),
9035
+ /* @__PURE__ */ jsx("p", { className: "text-base text-[#4A4C56]", children: Array.isArray(bookingData.equipment) ? bookingData.equipment.join(", ") : bookingData.equipment })
8973
9036
  ] }),
8974
9037
  /* @__PURE__ */ jsxs("div", { children: [
8975
- /* @__PURE__ */ jsx("h2", { className: "text-lg text-gray-900 mb-3", children: pageData.demoRoom }),
8976
- /* @__PURE__ */ jsx("p", { className: "text-base text-gray-900", children: bookingData.demoroom_code })
9038
+ /* @__PURE__ */ jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.demoRoom }),
9039
+ /* @__PURE__ */ jsx("p", { className: "text-base text-[#4A4C56]", children: bookingData.demoroom_code })
8977
9040
  ] }),
8978
9041
  /* @__PURE__ */ jsxs("div", { children: [
8979
- /* @__PURE__ */ jsx("h2", { className: "text-lg text-gray-900 mb-3", children: pageData.visitorInfo }),
9042
+ /* @__PURE__ */ jsx("h2", { className: "text-[24px] l:text-[20px] text-[#4A4C56] mb-3", children: pageData.visitorInfo }),
8980
9043
  /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
8981
- /* @__PURE__ */ jsx("p", { className: "text-base text-gray-900", children: bookingData.customer_name }),
9044
+ /* @__PURE__ */ jsx("p", { className: "text-base text-[#4A4C56]", children: bookingData.customer_name }),
8982
9045
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-base text-gray-600", children: [
8983
9046
  /* @__PURE__ */ jsx(
8984
9047
  "svg",
@@ -9091,7 +9154,7 @@ var BookingSuccess = ({
9091
9154
  }
9092
9155
  ) }) }),
9093
9156
  /* @__PURE__ */ jsxs("div", { className: "text-center mb-8", children: [
9094
- /* @__PURE__ */ jsx("h3", { className: "text-[18px] text-gray-900 mb-2", children: pageData.cancelDialog?.title }),
9157
+ /* @__PURE__ */ jsx("h3", { className: "text-[18px] text-[#4A4C56] mb-2", children: pageData.cancelDialog?.title }),
9095
9158
  /* @__PURE__ */ jsx("p", { className: "text-[14px] text-gray-600", children: pageData.cancelDialog?.description })
9096
9159
  ] }),
9097
9160
  /* @__PURE__ */ jsxs("div", { className: "flex gap-3 justify-center", children: [