Sahanabg commited on
Commit
fd40a84
·
verified ·
1 Parent(s): de9919b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +123 -45
index.html CHANGED
@@ -10,7 +10,6 @@
10
  <body>
11
  <div class="container">
12
  <h2>Book a meeting with SumUp</h2>
13
- <!-- SumUp Logo -->
14
  <form id="booking-form" aria-labelledby="form-heading">
15
  <input type="text" id="name" placeholder="Your First Name" required />
16
  <input type="email" id="email" placeholder="Your Email" required />
@@ -30,60 +29,139 @@
30
  <p><strong>Time:</strong> <span id="conf-slot"></span></p>
31
  </div>
32
  </div>
33
- <!-- Embed the SVG directly in the HTML -->
34
- <!-- svg class="logo" xmlns="http://www.w3.org/2000/svg" width="80" height="auto" viewBox="0 0 100 100"-->
35
- <!-- Paste the entire SVG content here -->
36
- <!-- Example of a simple SVG (replace with your actual SVG code) -->
37
- <!-- path d="M58.2.5H5.1C2.7.5.7 2.5.7 4.9v52.8c0 2.4 2 4.4 4.4 4.4h53.1c2.4 0 4.4-2 4.4-4.4V4.9c0-2.5-2-4.4-4.4-4.4zM39.5 46.8c-5.4 5.4-14 5.6-19.7.7l-.1-.1c-.3-.3-.4-.9 0-1.3L38.9 27c.4-.3.9-.3 1.3 0 5 5.8 4.8 14.4-.7 19.8zm4-30.5L24.3 35.4c-.4.3-.9.3-1.3 0-5-5.7-4.8-14.3.6-19.7 5.4-5.4 14-5.6 19.7-.7 0 0 .1 0 .1.1.5.3.5.9.1 1.2z" stroke="black" fill="transparent"/-->
38
- <!-- /svg-->
39
- <img src="SumUp logo.png" alt="SumUp logo" class="logo" />
40
-
41
  <script>
42
- // Read query parameters from URL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  const urlParams = new URLSearchParams(window.location.search);
44
  const leadName = urlParams.get("ln") || "";
45
  const leadEmail = urlParams.get("le") || "";
46
  const salesRepEmailParam = urlParams.get("oe") || "";
47
-
48
- // Pre-fill the form
49
  document.getElementById("name").value = leadName;
50
  document.getElementById("email").value = leadEmail;
51
-
52
- // If all parameters exist, auto-fetch available slots
53
- if (leadName && leadEmail && salesRepEmailParam) {
54
  showSpinner();
55
  setStatus("Loading available slots...", "info");
56
- fetch(`/available?name=${encodeURIComponent(leadName)}&email=${encodeURIComponent(leadEmail)}&salesRepEmail=${encodeURIComponent(salesRepEmailParam)}`)
57
- .then(res => res.json())
58
- .then(data => {
59
- hideSpinner();
60
- if (data.error) {
61
- setStatus(data.error, "error");
62
- return;
63
- }
64
- repEmail = data.repEmail;
65
- const slots = data.slots;
66
- slotsDropdown.innerHTML = "";
67
- if (slots.length === 0) {
68
- setStatus("No available time slots found.", "error");
69
- return;
70
- }
71
- slots.forEach(slot => {
72
- const option = document.createElement("option");
73
- option.value = slot.start;
74
- option.text = new Date(slot.start).toLocaleString();
75
- slotsDropdown.appendChild(option);
76
- });
77
- slotsDropdown.style.display = "block";
78
- bookBtn.style.display = "inline-block";
79
- setStatus("Select a time slot to book.", "success");
80
- })
81
- .catch(err => {
82
- hideSpinner();
83
- setStatus("Failed to fetch available slots.", "error");
84
  });
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
86
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  </script>
88
  </body>
89
- </html>
 
10
  <body>
11
  <div class="container">
12
  <h2>Book a meeting with SumUp</h2>
 
13
  <form id="booking-form" aria-labelledby="form-heading">
14
  <input type="text" id="name" placeholder="Your First Name" required />
15
  <input type="email" id="email" placeholder="Your Email" required />
 
29
  <p><strong>Time:</strong> <span id="conf-slot"></span></p>
30
  </div>
31
  </div>
32
+
33
+ <img src="sumup-logo.png" alt="SumUp logo" class="logo" />
34
+
 
 
 
 
 
35
  <script>
36
+ let repEmail = "";
37
+ const slotsDropdown = document.getElementById("slots");
38
+ const bookBtn = document.getElementById("bookBtn");
39
+ const statusEl = document.getElementById("status");
40
+ const spinner = document.getElementById("spinner");
41
+
42
+ function showSpinner() { spinner.style.display = "block"; }
43
+ function hideSpinner() { spinner.style.display = "none"; }
44
+
45
+ function setStatus(message, type="info") {
46
+ statusEl.className = "";
47
+ statusEl.classList.add(`status-${type}`);
48
+ statusEl.innerText = message;
49
+ statusEl.style.display = "block";
50
+ }
51
+
52
+ // -------------------------------
53
+ // Auto-fill form from query params
54
+ // -------------------------------
55
  const urlParams = new URLSearchParams(window.location.search);
56
  const leadName = urlParams.get("ln") || "";
57
  const leadEmail = urlParams.get("le") || "";
58
  const salesRepEmailParam = urlParams.get("oe") || "";
59
+
 
60
  document.getElementById("name").value = leadName;
61
  document.getElementById("email").value = leadEmail;
62
+
63
+ async function fetchSlots(name, email, repEmailParam) {
 
64
  showSpinner();
65
  setStatus("Loading available slots...", "info");
66
+ try {
67
+ const res = await fetch(`/available?name=${encodeURIComponent(name)}&email=${encodeURIComponent(email)}&salesRepEmail=${encodeURIComponent(repEmailParam)}`);
68
+ const data = await res.json();
69
+ hideSpinner();
70
+ if (data.error) {
71
+ setStatus(data.error, "error");
72
+ return;
73
+ }
74
+ repEmail = data.repEmail;
75
+ const slots = data.slots;
76
+ slotsDropdown.innerHTML = "";
77
+ if (!slots || slots.length === 0) {
78
+ setStatus("No available time slots found.", "error");
79
+ return;
80
+ }
81
+ slots.forEach(slot => {
82
+ const option = document.createElement("option");
83
+ option.value = slot.start;
84
+ option.text = new Date(slot.start).toLocaleString();
85
+ slotsDropdown.appendChild(option);
 
 
 
 
 
 
 
 
86
  });
87
+ slotsDropdown.style.display = "block";
88
+ bookBtn.style.display = "inline-block";
89
+ setStatus("Select a time slot to book.", "success");
90
+ } catch (error) {
91
+ hideSpinner();
92
+ setStatus("Failed to fetch available slots.", "error");
93
+ }
94
+ }
95
+
96
+ // Auto-fetch slots if all query params are present
97
+ if (leadName && leadEmail && salesRepEmailParam) {
98
+ fetchSlots(leadName, leadEmail, salesRepEmailParam);
99
  }
100
+
101
+ // -------------------------------
102
+ // Form submit manually (optional)
103
+ // -------------------------------
104
+ const form = document.getElementById("booking-form");
105
+ form.addEventListener("submit", async (e) => {
106
+ e.preventDefault();
107
+ const name = document.getElementById("name").value;
108
+ const email = document.getElementById("email").value;
109
+ if (!name || !email) {
110
+ setStatus("Please enter your name and email.", "error");
111
+ return;
112
+ }
113
+ fetchSlots(name, email, salesRepEmailParam || repEmail);
114
+ });
115
+
116
+ // -------------------------------
117
+ // Booking
118
+ // -------------------------------
119
+ bookBtn.addEventListener("click", async () => {
120
+ const name = document.getElementById("name").value;
121
+ const email = document.getElementById("email").value;
122
+ const selectedSlot = slotsDropdown.value;
123
+
124
+ if (!selectedSlot || !repEmail) {
125
+ setStatus("Please select a time slot first.", "error");
126
+ return;
127
+ }
128
+
129
+ showSpinner();
130
+ setStatus("Booking your meeting...", "info");
131
+
132
+ try {
133
+ const res = await fetch("/book", {
134
+ method: "POST",
135
+ headers: { "Content-Type": "application/json" },
136
+ body: JSON.stringify({
137
+ name,
138
+ email,
139
+ salesRepEmail: repEmail,
140
+ selectedSlot
141
+ })
142
+ });
143
+ const result = await res.json();
144
+ hideSpinner();
145
+ if (result.message) setStatus(result.message, "success");
146
+
147
+ const confirmationPanel = document.getElementById("confirmation");
148
+ confirmationPanel.classList.add("visible");
149
+
150
+ document.getElementById("conf-name").innerText = name;
151
+ document.getElementById("conf-email").innerText = email;
152
+ document.getElementById("conf-slot").innerText = new Date(selectedSlot).toLocaleString();
153
+
154
+ slotsDropdown.style.display = "none";
155
+ bookBtn.style.display = "none";
156
+ form.reset();
157
+
158
+ setTimeout(() => { statusEl.style.display = "none"; }, 3000);
159
+
160
+ } catch (error) {
161
+ hideSpinner();
162
+ setStatus("Booking failed. Please try again.", "error");
163
+ }
164
+ });
165
  </script>
166
  </body>
167
+ </html>