|
| 1 | +/************************************************* |
| 2 | + * Feedback Modal Loader (Search-style) |
| 3 | + *************************************************/ |
| 4 | + |
| 5 | +const FEEDBACK_ENDPOINT = |
| 6 | + "https://script.google.com/macros/s/AKfycbwH1QM0zc4DcYXcG0CJIVoien-vj8VmCi0wEUxeEdZX0EbROxx6rWvLgIi2vSHtd9TBIQ/exec"; |
| 7 | + |
| 8 | +/* Wire button safely */ |
| 9 | +document.addEventListener("DOMContentLoaded", () => { |
| 10 | + const btn = document.querySelector(".feedback-btn"); |
| 11 | + if (!btn) return; |
| 12 | + btn.addEventListener("click", openFeedback); |
| 13 | +}); |
| 14 | + |
| 15 | +/* Open feedback modal */ |
| 16 | +window.openFeedback = function () { |
| 17 | + const overlay = document.getElementById("modal-overlay"); |
| 18 | + const modal = document.getElementById("modal-content"); |
| 19 | + |
| 20 | + if (!overlay || !modal) return; |
| 21 | + |
| 22 | + overlay.hidden = false; |
| 23 | + modal.hidden = false; |
| 24 | + document.body.style.overflow = "hidden"; |
| 25 | + |
| 26 | + modal.innerHTML = ` |
| 27 | + <div class="feedback-wrapper search-wrapper" role="dialog" aria-modal="true"> |
| 28 | +
|
| 29 | + <!-- Header --> |
| 30 | + <div class="sw-header"> |
| 31 | + <svg class="sw-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 32 | + <path d="M21 15a4 4 0 0 1-4 4H7l-4 4V7a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4z"></path> |
| 33 | + </svg> |
| 34 | + <h2 class="sw-title">Send Feedback</h2> |
| 35 | + <button class="sw-close" data-feedback-close aria-label="Close feedback"> |
| 36 | + <svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="3"> |
| 37 | + <line x1="18" y1="6" x2="6" y2="18"></line> |
| 38 | + <line x1="6" y1="6" x2="18" y2="18"></line> |
| 39 | + </svg> |
| 40 | + </button> |
| 41 | + </div> |
| 42 | +
|
| 43 | + <!-- Form --> |
| 44 | + <form id="feedbackForm" class="feedback-form"> |
| 45 | +
|
| 46 | + <div class="field"> |
| 47 | + <label>What is your role? *</label> |
| 48 | + <select name="role" required class="sw-input"> |
| 49 | + <option value="">Select</option> |
| 50 | + <option>Author</option> |
| 51 | + <option>Instructor</option> |
| 52 | + <option>Student</option> |
| 53 | + </select> |
| 54 | + </div> |
| 55 | +
|
| 56 | + <div class="field"> |
| 57 | + <label>Which part of the Launchpad are you commenting on? *</label> |
| 58 | + <input name="section" required class="sw-input" /> |
| 59 | + </div> |
| 60 | +
|
| 61 | + <div class="field"> |
| 62 | + <label>If you notice an issue, please explain it.</label> |
| 63 | + <textarea name="issue" class="sw-input"></textarea> |
| 64 | + </div> |
| 65 | +
|
| 66 | + <div class="field"> |
| 67 | + <label>Optional: Email or contact</label> |
| 68 | + <input name="contact" class="sw-input" /> |
| 69 | + </div> |
| 70 | +
|
| 71 | + <div class="sw-actions"> |
| 72 | + <button type="submit" class="sw-btn"> |
| 73 | + Submit Feedback |
| 74 | + <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 75 | + <path d="M9 18l6-6-6-6"></path> |
| 76 | + </svg> |
| 77 | + </button> |
| 78 | + </div> |
| 79 | +
|
| 80 | + </form> |
| 81 | + </div> |
| 82 | + `; |
| 83 | + |
| 84 | + attachFeedbackHandlers(); |
| 85 | +}; |
| 86 | + |
| 87 | +/* Submit + close logic */ |
| 88 | +function attachFeedbackHandlers() { |
| 89 | + const overlay = document.getElementById("modal-overlay"); |
| 90 | + const modal = document.getElementById("modal-content"); |
| 91 | + const form = modal.querySelector("#feedbackForm"); |
| 92 | + |
| 93 | + if (!form) return; |
| 94 | + |
| 95 | + form.addEventListener("submit", async (e) => { |
| 96 | + e.preventDefault(); |
| 97 | + |
| 98 | + const formData = new FormData(form); |
| 99 | + formData.append("timestamp_client", new Date().toISOString()); |
| 100 | + formData.append( |
| 101 | + "timezone", |
| 102 | + Intl.DateTimeFormat().resolvedOptions().timeZone |
| 103 | + ); |
| 104 | + formData.append("page", window.location.href); |
| 105 | + |
| 106 | + await fetch(FEEDBACK_ENDPOINT, { |
| 107 | + method: "POST", |
| 108 | + body: new URLSearchParams(formData), |
| 109 | + }); |
| 110 | + |
| 111 | + form.innerHTML = ` |
| 112 | + <div class="sw-results"> |
| 113 | + <p><strong>Thank you!</strong></p> |
| 114 | + <p>Your feedback has been submitted.</p> |
| 115 | + </div> |
| 116 | + `; |
| 117 | + }); |
| 118 | + |
| 119 | + const close = () => { |
| 120 | + overlay.hidden = true; |
| 121 | + modal.hidden = true; |
| 122 | + modal.innerHTML = ""; |
| 123 | + document.body.style.overflow = ""; |
| 124 | + }; |
| 125 | + |
| 126 | + overlay.addEventListener("click", close, { once: true }); |
| 127 | + modal |
| 128 | + .querySelectorAll("[data-feedback-close]") |
| 129 | + .forEach((btn) => btn.addEventListener("click", close)); |
| 130 | +} |
0 commit comments