@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.cjs CHANGED
@@ -3074,9 +3074,26 @@ function useCheckoutForm(hookArgs) {
3074
3074
  const cpfError = touchedCpf || formSubmitAttempted ? validateCpf : null;
3075
3075
  const postalCodeError = touchedPostalCode || formSubmitAttempted ? validatePostalCode : null;
3076
3076
  const addressNumberError = touchedAddressNumber || formSubmitAttempted ? validateAddressNumber : null;
3077
+ const cardExpiryError = (0, import_react18.useMemo)(() => {
3078
+ if (method !== "card") return null;
3079
+ const mm = card.expiryMonth.replace(/\D/g, "");
3080
+ const yy = card.expiryYear.replace(/\D/g, "");
3081
+ if (mm.length < 2 || yy.length < 2) return null;
3082
+ const monthNum = parseInt(mm, 10);
3083
+ if (monthNum < 1 || monthNum > 12) return "M\xEAs inv\xE1lido (use 01-12).";
3084
+ const yearNum = 2e3 + parseInt(yy, 10);
3085
+ const now = /* @__PURE__ */ new Date();
3086
+ const currentMonth = now.getMonth() + 1;
3087
+ const currentYear = now.getFullYear();
3088
+ if (yearNum < currentYear || yearNum === currentYear && monthNum < currentMonth) {
3089
+ return "Cart\xE3o vencido.";
3090
+ }
3091
+ if (yearNum > currentYear + 20) return "Ano muito distante.";
3092
+ return null;
3093
+ }, [method, card.expiryMonth, card.expiryYear]);
3077
3094
  const phoneOk = method === "pix-auto" ? phone === "" || PHONE_RE.test(phone) : PHONE_RE.test(phone);
3078
3095
  const cepGateOk = !hookArgs.collectCep || method !== "card" || postalCode.replace(/\D/g, "").length === 8 && addressNumber.trim().length > 0;
3079
- 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);
3096
+ 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);
3080
3097
  const submit = (0, import_react18.useCallback)(async () => {
3081
3098
  setFormSubmitAttempted(true);
3082
3099
  setError(null);
@@ -3169,6 +3186,7 @@ function useCheckoutForm(hookArgs) {
3169
3186
  cpfError,
3170
3187
  postalCodeError,
3171
3188
  addressNumberError,
3189
+ cardExpiryError,
3172
3190
  markNameTouched: () => setTouchedName(true),
3173
3191
  markEmailTouched: () => setTouchedEmail(true),
3174
3192
  markEmailConfirmTouched: () => setTouchedEmailConfirm(true),
@@ -4136,11 +4154,11 @@ function CheckoutPageDefault() {
4136
4154
  value: form.email,
4137
4155
  onChange: form.setEmail,
4138
4156
  onBlur: form.markEmailTouched,
4139
- error: form.emailError,
4157
+ error: form.emailError ?? (form.emailStatus === "exists" ? "Este email j\xE1 tem conta. Faz login pra continuar." : null),
4140
4158
  valid: form.emailStatus === "available"
4141
4159
  }
4142
4160
  ),
4143
- !form.emailError && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(FieldHint, { children: form.emailStatus === "checking" ? "Verificando\u2026" : form.emailStatus === "available" ? "\u2713 Dispon\xEDvel" : "Voc\xEA vai usar este email para entrar no app" })
4161
+ !form.emailError && form.emailStatus !== "exists" && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(FieldHint, { children: form.emailStatus === "checking" ? "Verificando\u2026" : form.emailStatus === "available" ? "\u2713 Dispon\xEDvel" : "Voc\xEA vai usar este email para entrar no app" })
4144
4162
  ] }),
4145
4163
  /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("div", { children: [
4146
4164
  /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(FieldLabel, { children: "Nome completo" }),
@@ -4291,7 +4309,8 @@ function CheckoutPageDefault() {
4291
4309
  autoComplete: "cc-exp",
4292
4310
  placeholder: "MM/AA",
4293
4311
  value: expiryMmAa,
4294
- onChange: (v) => setExpiryMmAa(formatExpiryMmAa(v))
4312
+ onChange: (v) => setExpiryMmAa(formatExpiryMmAa(v)),
4313
+ error: form.cardExpiryError
4295
4314
  }
4296
4315
  )
4297
4316
  ] }),