SakibAhmed commited on
Commit
722108b
·
verified ·
1 Parent(s): a6f8728

Upload index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +36 -33
templates/index.html CHANGED
@@ -163,7 +163,7 @@
163
  padding: 15px 20px;
164
  margin-bottom: 25px;
165
  border-radius: 8px;
166
- display: none;
167
  font-size: 0.9rem;
168
  animation: slideIn 0.3s ease-out;
169
  }
@@ -177,7 +177,9 @@
177
  color: #721c24;
178
  border-left: 4px solid #dc3545;
179
  }
180
- .alert.show { display: block; }
 
 
181
 
182
  @keyframes slideIn {
183
  from {
@@ -200,11 +202,17 @@
200
  </head>
201
  <body>
202
 
 
 
 
 
 
203
  <div class="card">
204
  <!-- Left Side: General Info -->
205
  <div class="left-panel">
206
  <h2>General Information</h2>
207
 
 
208
  <div id="alertBox" class="alert"></div>
209
 
210
  <form id="leadForm">
@@ -323,73 +331,60 @@
323
  </div>
324
  </div>
325
 
 
326
  <script>
327
  async function submitData() {
328
  const form = document.getElementById('leadForm');
329
  const alertBox = document.getElementById('alertBox');
330
 
331
- // Reset alert
332
- alertBox.className = 'alert';
333
  alertBox.style.display = 'none';
334
 
335
- // Validate form
336
  if (!form.checkValidity()) {
337
  showAlert("Please fill in all required fields marked with *", "error");
338
  form.reportValidity();
339
  return;
340
  }
341
 
342
- // Gather form data
343
  const formData = new FormData(form);
344
  const data = Object.fromEntries(formData.entries());
345
 
346
- // UI feedback
347
  const btn = document.querySelector('.btn-submit');
348
  const originalText = btn.innerText;
349
  btn.innerText = "Submitting...";
350
  btn.disabled = true;
351
 
352
  try {
353
- console.log("Sending data:", data); // Debug
354
-
355
  const response = await fetch('/submit', {
356
  method: 'POST',
357
  headers: { 'Content-Type': 'application/json' },
358
  body: JSON.stringify(data)
359
  });
360
 
361
- console.log("Response status:", response.status); // Debug
362
-
363
  const result = await response.json();
364
- console.log("Response data:", result); // Debug
365
 
366
  if (response.ok) {
367
- // Success!
368
- const successMsg = result.message || "✅ Lead submitted successfully! We'll be in touch soon.";
369
  showAlert(successMsg, "success");
370
 
371
- // Reset form after success
372
- setTimeout(() => {
373
- form.reset();
374
- }, 500);
375
-
376
- // Log for debugging
377
- if (result.data) {
378
- console.log("Lead ID:", result.data.meta?.lead_id);
379
- console.log("Full Response:", result);
380
- }
381
  } else {
382
- // Error response
383
- const errorMsg = result.error?.reason || result.message || "❌ Failed to submit lead";
384
  showAlert(`Error: ${errorMsg}`, "error");
385
- console.error("Error Response:", result);
386
  }
387
  } catch (error) {
388
- // Network/connection error
389
- showAlert(`❌ Connection error: ${error.message}. Please check your connection and try again.`, "error");
390
- console.error("Network Error:", error);
391
  } finally {
392
- // Always reset button
393
  btn.innerText = originalText;
394
  btn.disabled = false;
395
  }
@@ -397,21 +392,29 @@
397
 
398
  function showAlert(message, type) {
399
  const alertBox = document.getElementById('alertBox');
 
 
400
  alertBox.textContent = message;
 
 
401
  alertBox.className = `alert ${type} show`;
402
 
403
- // Scroll to alert if not visible
 
 
 
404
  alertBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
405
 
406
  // Auto-hide success messages after 7 seconds
407
  if (type === 'success') {
408
  setTimeout(() => {
 
409
  alertBox.className = 'alert';
410
  }, 7000);
411
  }
412
  }
413
 
414
- // Add enter key support
415
  document.getElementById('leadForm').addEventListener('keypress', function(e) {
416
  if (e.key === 'Enter' && e.target.tagName !== 'TEXTAREA') {
417
  e.preventDefault();
 
163
  padding: 15px 20px;
164
  margin-bottom: 25px;
165
  border-radius: 8px;
166
+ display: none; /* Hidden by default */
167
  font-size: 0.9rem;
168
  animation: slideIn 0.3s ease-out;
169
  }
 
177
  color: #721c24;
178
  border-left: 4px solid #dc3545;
179
  }
180
+ .alert.show {
181
+ display: block; /* Visible when class 'show' is added */
182
+ }
183
 
184
  @keyframes slideIn {
185
  from {
 
202
  </head>
203
  <body>
204
 
205
+ <!-- Link to Dashboard for Hugging Face Space -->
206
+ <div style="position: absolute; top: 20px; right: 20px; z-index: 100;">
207
+ <a href="/" style="background: white; padding: 10px 20px; border-radius: 20px; text-decoration: none; font-weight: bold; color: #4d4dff; box-shadow: 0 2px 10px rgba(0,0,0,0.1); font-size: 0.9rem;">View CRM Dashboard &rarr;</a>
208
+ </div>
209
+
210
  <div class="card">
211
  <!-- Left Side: General Info -->
212
  <div class="left-panel">
213
  <h2>General Information</h2>
214
 
215
+ <!-- Alert Box for Success/Error -->
216
  <div id="alertBox" class="alert"></div>
217
 
218
  <form id="leadForm">
 
331
  </div>
332
  </div>
333
 
334
+ <!-- JavaScript Handling Submission and Alerts -->
335
  <script>
336
  async function submitData() {
337
  const form = document.getElementById('leadForm');
338
  const alertBox = document.getElementById('alertBox');
339
 
340
+ // 1. Reset Alert State (Important for re-submission)
341
+ alertBox.className = 'alert';
342
  alertBox.style.display = 'none';
343
 
344
+ // 2. Client-side Validation
345
  if (!form.checkValidity()) {
346
  showAlert("Please fill in all required fields marked with *", "error");
347
  form.reportValidity();
348
  return;
349
  }
350
 
351
+ // 3. Gather Form Data
352
  const formData = new FormData(form);
353
  const data = Object.fromEntries(formData.entries());
354
 
355
+ // 4. UI Feedback (Disable Button)
356
  const btn = document.querySelector('.btn-submit');
357
  const originalText = btn.innerText;
358
  btn.innerText = "Submitting...";
359
  btn.disabled = true;
360
 
361
  try {
362
+ // 5. Send POST Request
 
363
  const response = await fetch('/submit', {
364
  method: 'POST',
365
  headers: { 'Content-Type': 'application/json' },
366
  body: JSON.stringify(data)
367
  });
368
 
 
 
369
  const result = await response.json();
 
370
 
371
  if (response.ok) {
372
+ // --- SUCCESS ---
373
+ const successMsg = result.message || "✅ Success! Lead submitted successfully.";
374
  showAlert(successMsg, "success");
375
 
376
+ // Reset form fields
377
+ form.reset();
 
 
 
 
 
 
 
 
378
  } else {
379
+ // --- SERVER/n8n ERROR ---
380
+ const errorMsg = result.error?.reason || result.message || "❌ Submission failed";
381
  showAlert(`Error: ${errorMsg}`, "error");
 
382
  }
383
  } catch (error) {
384
+ // --- NETWORK ERROR ---
385
+ showAlert(`❌ Connection Error: ${error.message}`, "error");
 
386
  } finally {
387
+ // 6. Reset Button State
388
  btn.innerText = originalText;
389
  btn.disabled = false;
390
  }
 
392
 
393
  function showAlert(message, type) {
394
  const alertBox = document.getElementById('alertBox');
395
+
396
+ // Set message text
397
  alertBox.textContent = message;
398
+
399
+ // Apply CSS classes (This triggers the visible styling)
400
  alertBox.className = `alert ${type} show`;
401
 
402
+ // Ensure element is visible (Overrides any inline 'display: none')
403
+ alertBox.style.display = 'block';
404
+
405
+ // Scroll user to the message
406
  alertBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
407
 
408
  // Auto-hide success messages after 7 seconds
409
  if (type === 'success') {
410
  setTimeout(() => {
411
+ alertBox.style.display = 'none'; // Clean hide
412
  alertBox.className = 'alert';
413
  }, 7000);
414
  }
415
  }
416
 
417
+ // Allow submitting via Enter key
418
  document.getElementById('leadForm').addEventListener('keypress', function(e) {
419
  if (e.key === 'Enter' && e.target.tagName !== 'TEXTAREA') {
420
  e.preventDefault();