|
164 | 164 | updates from OpenObserve.
|
165 | 165 | </p>
|
166 | 166 | </form>
|
167 |
| - <div |
168 |
| - id="newsletter-toast" |
169 |
| - class="tw-fixed tw-bottom-5 tw-right-2 tw-transform tw-bg-[#7782FF] tw-text-white tw-p-6 tw-rounded-lg tw-shadow-lg tw-z-50 tw-hidden tw-transition-opacity tw-duration-300" |
170 |
| - ></div> |
171 | 167 | </div>
|
172 | 168 |
|
173 | 169 | <script>
|
|
306 | 302 | const recaptchaContainer = document.getElementById(
|
307 | 303 | "newsletter-recaptcha"
|
308 | 304 | );
|
309 |
| - if (!recaptchaContainer || recaptchaWidgetId !== null) return; |
| 305 | + if (!recaptchaContainer) return; |
| 306 | + |
| 307 | + // If widget already exists, don't create another one |
| 308 | + if (recaptchaWidgetId !== null) return; |
310 | 309 |
|
311 | 310 | try {
|
312 | 311 | recaptchaWidgetId = window.grecaptcha.render(recaptchaContainer, {
|
|
315 | 314 | "expired-callback": window.onRecaptchaExpired,
|
316 | 315 | theme: "dark",
|
317 | 316 | });
|
318 |
| - } catch (error) { |
319 |
| - // Silent error handling |
| 317 | + } catch (error) { |
320 | 318 | }
|
321 | 319 | }
|
322 | 320 |
|
|
327 | 325 | "newsletter-recaptcha-container"
|
328 | 326 | );
|
329 | 327 | const recaptchaDiv = document.getElementById("newsletter-recaptcha");
|
| 328 | + const loader = document.getElementById("newsletter-captcha-loader"); |
330 | 329 |
|
331 | 330 | if (container) {
|
332 | 331 | container.classList.remove("tw-hidden");
|
333 | 332 | container.classList.add("tw-flex");
|
334 | 333 | }
|
335 | 334 |
|
| 335 | + // Hide loader when showing reCAPTCHA |
| 336 | + if (loader) { |
| 337 | + loader.style.display = "none"; |
| 338 | + } |
| 339 | + |
336 | 340 | // Wait for DOM update, then render reCAPTCHA
|
337 | 341 | setTimeout(() => {
|
338 |
| - if (recaptchaDiv && window.grecaptcha && !recaptchaWidgetId) { |
| 342 | + if ( |
| 343 | + recaptchaDiv && |
| 344 | + window.grecaptcha && |
| 345 | + recaptchaWidgetId === null |
| 346 | + ) { |
339 | 347 | initializeRecaptcha();
|
340 | 348 | }
|
341 | 349 | }, 100);
|
|
352 | 360 | "Please complete the reCAPTCHA to proceed.",
|
353 | 361 | "error"
|
354 | 362 | );
|
355 |
| - // Re-enable submit button |
| 363 | + // Show submit button again |
| 364 | + const buttonContainer = subscribeBtn.parentElement; |
| 365 | + buttonContainer.style.display = "block"; |
356 | 366 | subscribeBtn.disabled = false;
|
357 | 367 | subscribeBtn.textContent = "Subscribe";
|
358 | 368 | return;
|
|
373 | 383 | "Captcha validation failed. Please try again.",
|
374 | 384 | "error"
|
375 | 385 | );
|
376 |
| - // Re-enable submit button |
| 386 | + // Show submit button again |
| 387 | + const buttonContainer = subscribeBtn.parentElement; |
| 388 | + buttonContainer.style.display = "block"; |
377 | 389 | subscribeBtn.disabled = false;
|
378 | 390 | subscribeBtn.textContent = "Subscribe";
|
379 | 391 | return;
|
|
384 | 396 |
|
385 | 397 | // Success flow
|
386 | 398 | showToastMessage(
|
387 |
| - `Successfully subscribed! Welcome to OpenObserve updates.`, |
| 399 | + `Subscribed successfully with: ${email}`, |
388 | 400 | "success"
|
389 | 401 | );
|
390 | 402 |
|
|
402 | 414 | container.classList.remove("tw-flex");
|
403 | 415 | }
|
404 | 416 |
|
405 |
| - if (window.grecaptcha && recaptchaWidgetId) { |
406 |
| - window.grecaptcha.reset(recaptchaWidgetId); |
| 417 | + // Completely destroy and recreate reCAPTCHA widget |
| 418 | + if (window.grecaptcha && recaptchaWidgetId !== null) { |
| 419 | + try { |
| 420 | + window.grecaptcha.reset(recaptchaWidgetId); |
| 421 | + // Clear the container completely |
| 422 | + const recaptchaDiv = document.getElementById( |
| 423 | + "newsletter-recaptcha" |
| 424 | + ); |
| 425 | + if (recaptchaDiv) { |
| 426 | + recaptchaDiv.innerHTML = ""; |
| 427 | + } |
| 428 | + recaptchaWidgetId = null; |
| 429 | + } catch (error) { |
| 430 | + } |
407 | 431 | }
|
408 | 432 | recaptchaToken = "";
|
409 | 433 |
|
|
443 | 467 | container.classList.remove("tw-flex");
|
444 | 468 | }
|
445 | 469 |
|
446 |
| - if (window.grecaptcha && recaptchaWidgetId) { |
447 |
| - window.grecaptcha.reset(recaptchaWidgetId); |
| 470 | + // Completely destroy and recreate reCAPTCHA widget on error |
| 471 | + if (window.grecaptcha && recaptchaWidgetId !== null) { |
| 472 | + try { |
| 473 | + window.grecaptcha.reset(recaptchaWidgetId); |
| 474 | + // Clear the container completely |
| 475 | + const recaptchaDiv = document.getElementById( |
| 476 | + "newsletter-recaptcha" |
| 477 | + ); |
| 478 | + if (recaptchaDiv) { |
| 479 | + recaptchaDiv.innerHTML = ""; |
| 480 | + } |
| 481 | + recaptchaWidgetId = null; |
| 482 | + } catch (error) { |
| 483 | + |
| 484 | + } |
448 | 485 | }
|
449 | 486 | recaptchaToken = "";
|
450 | 487 |
|
|
459 | 496 | });
|
460 | 497 | } finally {
|
461 | 498 | isSubmitting = false;
|
462 |
| - // Re-enable submit button |
| 499 | + // Show submit button again |
| 500 | + const buttonContainer = subscribeBtn.parentElement; |
| 501 | + buttonContainer.style.display = "block"; |
463 | 502 | subscribeBtn.disabled = false;
|
464 | 503 | subscribeBtn.textContent = "Subscribe";
|
465 | 504 | }
|
|
511 | 550 | return false; // Prevent further processing
|
512 | 551 | }
|
513 | 552 |
|
514 |
| - // Disable submit button to prevent multiple submissions |
515 |
| - subscribeBtn.disabled = true; |
516 |
| - subscribeBtn.textContent = "Processing..."; |
| 553 | + // Hide submit button after click |
| 554 | + const buttonContainer = subscribeBtn.parentElement; |
| 555 | + buttonContainer.style.display = "none"; |
517 | 556 |
|
518 | 557 | try {
|
519 | 558 | // Show reCAPTCHA (like Vue component submitForm)
|
520 | 559 | submitForm();
|
521 | 560 | } catch (error) {
|
522 | 561 | showToastMessage("An error occurred. Please try again.", "error");
|
523 | 562 |
|
524 |
| - // Re-enable submit button |
| 563 | + // Show submit button again on error |
| 564 | + const buttonContainer = subscribeBtn.parentElement; |
| 565 | + buttonContainer.style.display = "block"; |
525 | 566 | subscribeBtn.disabled = false;
|
526 | 567 | subscribeBtn.textContent = "Subscribe";
|
527 | 568 | }
|
|
535 | 576 | <!-- Toast -->
|
536 | 577 | <div
|
537 | 578 | id="newsletter-toast"
|
538 |
| - class="tw-fixed tw-bottom-5 tw-right-2 tw-transform tw-bg-[#7782FF] tw-text-white tw-p-6 tw-rounded-lg tw-shadow-lg tw-z-50 tw-hidden tw-transition-opacity tw-duration-300" |
| 579 | + class="tw-fixed tw-bottom-5 tw-right-2 tw-transform tw-bg-[#7782FF] tw-text-white tw-p-6 tw-rounded-lg tw-shadow-lg tw-z-50 tw-hidden tw-transition-opacity tw-duration-300 tw-text-[15px]" |
539 | 580 | ></div>
|
540 | 581 |
|
541 | 582 | <div class="tw-flex tw-justify-center lg:tw-justify-end">
|
|
0 commit comments