Author SHA1 Message Date
JC Beasley 7762c9f308 Fix: Improve createSurvey error handling and user flow 2026-07-02 15:26:56 -07:00
+13 -7
View File
@@ -921,9 +921,6 @@ n .btn-secondary {
return;
}
// Check if we have question responses
const hasResponses = Object.keys(createSurveyResponses).length > 0;
try {
const response = await fetch('/api/surveys', {
method: 'POST',
@@ -932,23 +929,32 @@ n .btn-secondary {
name,
client_name: clientName,
site_name: siteName,
description,
responses: hasResponses ? createSurveyResponses : undefined
description
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to create survey');
}
const data = await response.json();
// Clear form
document.getElementById('surveyName').value = '';
document.getElementById('clientName').value = '';
document.getElementById('siteName').value = '';
document.getElementById('surveyDescription').value = '';
await loadSurveys();
loadSurvey(data.survey.id);
// Switch to surveys tab to show the new survey
switchTab('surveys');
alert('Survey created successfully! Click on it to take the survey.');
} catch (e) {
alert('Failed to create survey');
console.error('Error creating survey:', e);
alert('Failed to create survey: ' + e.message);
}
}