The smokesignal.events web application
56
fork

Configure Feed

Select the types of activity you want to include in your feed.

bug: quick-create-event form code dupe caused date issue

+1 -85
+1 -85
templates/en-us/index.common.html
··· 49 49 <span>Quick Start: Create Your Event</span> 50 50 </span> 51 51 </h3> 52 - <form id="quick-event-form"> 52 + <form id="quick-event-form" data-authenticated="{{ 'true' if current_handle else 'false' }}"> 53 53 <div class="field"> 54 54 <label class="label is-small">Event Title</label> 55 55 <div class="control has-icons-left"> ··· 217 217 </div> 218 218 </section> 219 219 220 - <script> 221 - (function() { 222 - const STORAGE_KEY = 'smokesignal_quick_event'; 223 - const form = document.getElementById('quick-event-form'); 224 - const isAuthenticated = {{ 'true' if current_handle else 'false' }}; 225 - 226 - if (!form) return; 227 - 228 - form.addEventListener('submit', function(e) { 229 - e.preventDefault(); 230 - 231 - const titleInput = document.getElementById('home-quick-event-title'); 232 - const descriptionInput = document.getElementById('home-quick-event-description'); 233 - const startsInput = document.getElementById('home-quick-event-starts'); 234 - 235 - if (isAuthenticated) { 236 - // Get the datetime-local value and convert to UTC 237 - const localDateTime = startsInput.value; 238 - if (!localDateTime) { 239 - alert('Please select a start time'); 240 - return; 241 - } 242 - 243 - // Convert datetime-local to UTC ISO string 244 - // The datetime-local value is "YYYY-MM-DDTHH:MM" in local time 245 - const localDate = new Date(localDateTime); 246 - const utcISOString = localDate.toISOString(); 247 - 248 - // Create JSON payload for the API 249 - const eventData = { 250 - name: titleInput.value, 251 - description: descriptionInput.value, 252 - starts_at: utcISOString, 253 - status: 'scheduled', 254 - mode: 'inperson', 255 - locations: [], 256 - links: [], 257 - require_confirmed_email: false, 258 - send_notifications: true 259 - }; 260 - 261 - // Disable submit button 262 - const submitButton = form.querySelector('button[type="submit"]'); 263 - submitButton.disabled = true; 264 - submitButton.innerHTML = '<span class="icon"><i class="fas fa-spinner fa-pulse"></i></span><span>Creating...</span>'; 265 - 266 - fetch('/event', { 267 - method: 'POST', 268 - headers: { 269 - 'Content-Type': 'application/json', 270 - }, 271 - body: JSON.stringify(eventData) 272 - }) 273 - .then(async response => { 274 - const data = await response.json(); 275 - if (response.ok && data.url) { 276 - // Redirect to the created event 277 - window.location.href = data.url; 278 - } else { 279 - // Show error 280 - alert(data.error || 'Failed to create event. Please try again.'); 281 - submitButton.disabled = false; 282 - submitButton.innerHTML = '<strong>Create Event</strong>'; 283 - } 284 - }) 285 - .catch(error => { 286 - console.error('Error creating event:', error); 287 - alert('Failed to create event. Please try again.'); 288 - submitButton.disabled = false; 289 - submitButton.innerHTML = '<strong>Create Event</strong>'; 290 - }); 291 - } else { 292 - // User is not authenticated, save to localStorage and redirect 293 - const data = { 294 - name: titleInput.value, 295 - description: descriptionInput.value, 296 - starts_at: startsInput.value 297 - }; 298 - localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); 299 - window.location.href = '/quick-event'; 300 - } 301 - }); 302 - })(); 303 - </script> 304 220