Skip to content

Commit 7cb06ec

Browse files
committed
Fix de regresion introducido en la migracion
1 parent ab21b52 commit 7cb06ec

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/components/SubscribeBox.svelte

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import { onMount } from 'svelte';
23
/** @type {{ color: string, text: string, subscribeForm?: boolean }} */
34
let { color, text, subscribeForm = false } = $props();
45
@@ -11,11 +12,20 @@
1112
// Spam prevention variables
1213
let formStartTime = Date.now();
1314
let turnstileResponse = '';
15+
/** @type {string | null} */
1416
let turnstileWidgetId = null;
1517
let isTurnstileLoaded = false;
1618
19+
/** @returns {boolean} */
20+
function isFormTooFast() {
21+
return Date.now() - formStartTime < 3000;
22+
}
23+
24+
/** @type {any} */
25+
const win = typeof window !== 'undefined' ? window : null;
26+
1727
onMount(() => {
18-
if (!window.turnstile) {
28+
if (!win.turnstile) {
1929
console.log('Cargando script de Turnstile...');
2030
const script = document.createElement('script');
2131
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
@@ -42,23 +52,23 @@
4252
// Widget para el Captcha de Cloudflare Turnstile
4353
function initTurnstile() {
4454
console.log('Intentando inicializar Turnstile...');
45-
console.log('window.turnstile:', window.turnstile);
55+
console.log('window.turnstile:', win.turnstile);
4656
console.log('isTurnstileLoaded:', isTurnstileLoaded);
4757
48-
if (window.turnstile && isTurnstileLoaded) {
58+
if (win.turnstile && isTurnstileLoaded) {
4959
try {
5060
console.log('Renderizando widget de Turnstile...');
51-
turnstileWidgetId = window.turnstile.render('#turnstile-container', {
61+
turnstileWidgetId = win.turnstile.render('#turnstile-container', {
5262
sitekey: '0x4AAAAAAB6c7nCtT4Pnd6ZP',
53-
callback: function (token) {
63+
callback: function (/** @type {string} */ token) {
5464
console.log('Callback de Turnstile recibido:', token);
5565
turnstileResponse = token;
5666
},
5767
'expired-callback': function () {
5868
console.log('Turnstile caducado');
5969
turnstileResponse = '';
6070
},
61-
'error-callback': function (error) {
71+
'error-callback': function (/** @type {string} */ error) {
6272
console.error('Error de Turnstile:', error);
6373
turnstileResponse = '';
6474
}
@@ -73,11 +83,11 @@
7383
}
7484
7585
// Validate form submission
76-
function validateForm(event) {
77-
const target = event.target;
86+
function validateForm(/** @type {SubmitEvent} */ event) {
87+
const target = /** @type {HTMLFormElement} */ (event.target);
7888
7989
// Check honeypot field
80-
const honeypot = target.querySelector('input[name="website"]');
90+
const honeypot = /** @type {HTMLInputElement | null} */ (target.querySelector('input[name="website"]'));
8191
if (honeypot && honeypot.value !== '') {
8292
event.preventDefault();
8393
console.log('Bot detectado: campo honeypot llenado');
@@ -132,7 +142,6 @@
132142
{@html text}
133143
</p>
134144
</div>
135-
{#if subscribeForm}
136145
{#if subscribeForm}
137146
<div class="flex justify-center mx-auto my-3">
138147
<form class="w-full max-w-sm validate" action={breveo_url} method="post" id="newsletter-form" target="_blank" >

0 commit comments

Comments
 (0)