File size: 2,532 Bytes
a71cbc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function () {
  var API_URL = 'https://cfjphnpbvvappqlwhktc.supabase.co/functions/v1/promptproof';
  function submitHandler(formId, emailId, roleId, btnId, msgId, cardId, titleId) {
    var form = document.getElementById(formId);
    if (!form) return;
    form.addEventListener('submit', function (e) {
      e.preventDefault();
      var emailEl = document.getElementById(emailId);
      var btn = document.getElementById(btnId);
      var msg = document.getElementById(msgId);
      var email = (emailEl.value || '').trim();
      var role = '';
      if (roleId) {
        var roleEl = document.getElementById(roleId);
        if (roleEl) role = roleEl.value || '';
      }
      msg.className = 'form-msg';
      if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) {
        msg.textContent = 'Enter a valid email address.';
        msg.className = 'form-msg err';
        return;
      }
      btn.disabled = true;
      btn.textContent = 'Joining...';
      fetch(API_URL, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ email: email, role: role })
      }).then(function (r) { return r.json(); }).then(function (data) {
        if (data && data.ok) {
          form.style.display = 'none';
          var card = document.getElementById(cardId);
          var title = document.getElementById(titleId);
          if (data.position) {
            title.textContent = "You're in. #" + data.position + ' on the list.';
          }
          card.style.display = 'block';
        } else {
          msg.textContent = (data && data.error) ? data.error : 'Something went wrong. Try again.';
          msg.className = 'form-msg err';
          btn.disabled = false;
          btn.textContent = 'Join the waitlist';
        }
      }).catch(function () {
        msg.textContent = 'Could not reach the server. Try again in a moment.';
        msg.className = 'form-msg err';
        btn.disabled = false;
        btn.textContent = 'Join the waitlist';
      });
    });
  }
  submitHandler('waitlist-form', 'email', 'role', 'join-btn', 'form-msg', 'success-card', 'success-title');
  submitHandler('waitlist-form-2', 'email-2', null, 'join-btn-2', 'form-msg-2', 'success-card-2', 'success-title-2');

  var obs = new IntersectionObserver(function (entries) {
    entries.forEach(function (en) { if (en.isIntersecting) en.target.classList.add('in'); });
  }, { threshold: 0.12 });
  document.querySelectorAll('.reveal').forEach(function (el) { obs.observe(el); });
})();