mirror of
https://github.com/olehomelchenko/minivlat-local-ua.git
synced 2025-12-21 21:22:24 +00:00
Add random quiz version selection and update webhook integration
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// This file handles the logic for the questionnaire, including collecting additional participant information after the quiz.
|
||||
|
||||
const WEBHOOK_URL = "https://n8n.olehomelchenko.com/webhook/kse-research";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const questionnaireForm = document.getElementById('questionnaire-form');
|
||||
|
||||
@@ -39,35 +41,30 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const quizId = 'quiz';
|
||||
if (allQuizzes[quizId]) {
|
||||
allQuizzes[quizId].participantData = participantData;
|
||||
allQuizzes[quizId].iterationVersion = 'v1.0.0'; // Add semantic versioning
|
||||
allQuizzes[quizId].iterationVersion = 'v1.0.1'; // Add semantic versioning
|
||||
localStorage.setItem('allQuizzes', JSON.stringify(allQuizzes));
|
||||
}
|
||||
|
||||
// Send data to the backend
|
||||
fetch('/api/responses', {
|
||||
// Combine quiz results and questionnaire data
|
||||
const combinedData = {
|
||||
allQuizzes: allQuizzes
|
||||
};
|
||||
|
||||
// Send combined data to webhook
|
||||
fetch(WEBHOOK_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(allQuizzes)
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
console.log('Success:', data);
|
||||
window.location.href = 'results.html';
|
||||
} else {
|
||||
throw new Error(data.message || 'Failed to submit the form');
|
||||
}
|
||||
.then(() => {
|
||||
alert('Анкету надіслано успішно');
|
||||
window.location.href = 'results.html';
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
showError('Failed to submit the form. Please try again.');
|
||||
console.error('Error sending data:', error);
|
||||
alert('Сталася помилка при надсиланні анкети');
|
||||
submitButton.disabled = false;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user