diff --git a/index.html b/index.html
index ae844e6..54b614c 100644
--- a/index.html
+++ b/index.html
@@ -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);
}
}