@hook-sdk/template 0.28.10 → 0.28.11

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.d.cts CHANGED
@@ -524,6 +524,7 @@ interface UseCheckoutFormResult {
524
524
  cpfError: string | null;
525
525
  postalCodeError: string | null;
526
526
  addressNumberError: string | null;
527
+ cardExpiryError: string | null;
527
528
  markNameTouched: () => void;
528
529
  markEmailTouched: () => void;
529
530
  markEmailConfirmTouched: () => void;
package/dist/index.d.ts CHANGED
@@ -524,6 +524,7 @@ interface UseCheckoutFormResult {
524
524
  cpfError: string | null;
525
525
  postalCodeError: string | null;
526
526
  addressNumberError: string | null;
527
+ cardExpiryError: string | null;
527
528
  markNameTouched: () => void;
528
529
  markEmailTouched: () => void;
529
530
  markEmailConfirmTouched: () => void;
package/dist/index.js CHANGED
@@ -2966,9 +2966,26 @@ function useCheckoutForm(hookArgs) {
2966
2966
  const cpfError = touchedCpf || formSubmitAttempted ? validateCpf : null;
2967
2967
  const postalCodeError = touchedPostalCode || formSubmitAttempted ? validatePostalCode : null;
2968
2968
  const addressNumberError = touchedAddressNumber || formSubmitAttempted ? validateAddressNumber : null;
2969
+ const cardExpiryError = useMemo4(() => {
2970
+ if (method !== "card") return null;
2971
+ const mm = card.expiryMonth.replace(/\D/g, "");
2972
+ const yy = card.expiryYear.replace(/\D/g, "");
2973
+ if (mm.length < 2 || yy.length < 2) return null;
2974
+ const monthNum = parseInt(mm, 10);
2975
+ if (monthNum < 1 || monthNum > 12) return "M\xEAs inv\xE1lido (use 01-12).";
2976
+ const yearNum = 2e3 + parseInt(yy, 10);
2977
+ const now = /* @__PURE__ */ new Date();
2978
+ const currentMonth = now.getMonth() + 1;
2979
+ const currentYear = now.getFullYear();
2980
+ if (yearNum < currentYear || yearNum === currentYear && monthNum < currentMonth) {
2981
+ return "Cart\xE3o vencido.";
2982
+ }
2983
+ if (yearNum > currentYear + 20) return "Ano muito distante.";
2984
+ return null;
2985
+ }, [method, card.expiryMonth, card.expiryYear]);
2969
2986
  const phoneOk = method === "pix-auto" ? phone === "" || PHONE_RE.test(phone) : PHONE_RE.test(phone);
2970
2987
  const cepGateOk = !hookArgs.collectCep || method !== "card" || postalCode.replace(/\D/g, "").length === 8 && addressNumber.trim().length > 0;
2971
- const canSubmit = name.trim().length >= 2 && EMAIL_RE.test(email) && (emailConfirm === "" || emailConfirm === email) && phoneOk && validateCpf === null && cpf.replace(/\D/g, "").length === 11 && emailStatus !== "exists" && !submitting && cepGateOk && (method !== "card" || card.number.length >= 12 && card.ccv.length >= 3 && card.expiryMonth.length >= 1 && card.expiryYear.length >= 2 && card.holderName.length >= 1);
2988
+ const canSubmit = name.trim().length >= 2 && EMAIL_RE.test(email) && (emailConfirm === "" || emailConfirm === email) && phoneOk && validateCpf === null && cpf.replace(/\D/g, "").length === 11 && emailStatus !== "exists" && !submitting && cepGateOk && (method !== "card" || card.number.length >= 12 && card.ccv.length >= 3 && card.expiryMonth.length >= 1 && card.expiryYear.length >= 2 && card.holderName.length >= 1 && cardExpiryError === null);
2972
2989
  const submit = useCallback6(async () => {
2973
2990
  setFormSubmitAttempted(true);
2974
2991
  setError(null);
@@ -3061,6 +3078,7 @@ function useCheckoutForm(hookArgs) {
3061
3078
  cpfError,
3062
3079
  postalCodeError,
3063
3080
  addressNumberError,
3081
+ cardExpiryError,
3064
3082
  markNameTouched: () => setTouchedName(true),
3065
3083
  markEmailTouched: () => setTouchedEmail(true),
3066
3084
  markEmailConfirmTouched: () => setTouchedEmailConfirm(true),
@@ -4028,11 +4046,11 @@ function CheckoutPageDefault() {
4028
4046
  value: form.email,
4029
4047
  onChange: form.setEmail,
4030
4048
  onBlur: form.markEmailTouched,
4031
- error: form.emailError,
4049
+ error: form.emailError ?? (form.emailStatus === "exists" ? "Este email j\xE1 tem conta. Faz login pra continuar." : null),
4032
4050
  valid: form.emailStatus === "available"
4033
4051
  }
4034
4052
  ),
4035
- !form.emailError && /* @__PURE__ */ jsx48(FieldHint, { children: form.emailStatus === "checking" ? "Verificando\u2026" : form.emailStatus === "available" ? "\u2713 Dispon\xEDvel" : "Voc\xEA vai usar este email para entrar no app" })
4053
+ !form.emailError && form.emailStatus !== "exists" && /* @__PURE__ */ jsx48(FieldHint, { children: form.emailStatus === "checking" ? "Verificando\u2026" : form.emailStatus === "available" ? "\u2713 Dispon\xEDvel" : "Voc\xEA vai usar este email para entrar no app" })
4036
4054
  ] }),
4037
4055
  /* @__PURE__ */ jsxs29("div", { children: [
4038
4056
  /* @__PURE__ */ jsx48(FieldLabel, { children: "Nome completo" }),
@@ -4183,7 +4201,8 @@ function CheckoutPageDefault() {
4183
4201
  autoComplete: "cc-exp",
4184
4202
  placeholder: "MM/AA",
4185
4203
  value: expiryMmAa,
4186
- onChange: (v) => setExpiryMmAa(formatExpiryMmAa(v))
4204
+ onChange: (v) => setExpiryMmAa(formatExpiryMmAa(v)),
4205
+ error: form.cardExpiryError
4187
4206
  }
4188
4207
  )
4189
4208
  ] }),