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:
@@ -31,6 +31,18 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<button id="consentButton">Погоджуюсь з умовами, розпочати тест</button>
|
<button id="consentButton">Погоджуюсь з умовами, розпочати тест</button>
|
||||||
|
<script>
|
||||||
|
document.getElementById('consentButton').addEventListener('click', function() {
|
||||||
|
fetch('data/questions.json')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const quizVersions = Object.keys(data.quizzes);
|
||||||
|
const randomVersion = quizVersions[Math.floor(Math.random() * quizVersions.length)];
|
||||||
|
localStorage.setItem('quizVersion', randomVersion);
|
||||||
|
window.location.href = 'quiz.html';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -42,7 +42,7 @@ function initResultsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadQuestions(version) {
|
function loadQuestions(version) {
|
||||||
fetch('../data/questions.json')
|
fetch('data/questions.json')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const questions = data.quizzes[version];
|
const questions = data.quizzes[version];
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// This file handles the logic for the questionnaire, including collecting additional participant information after the quiz.
|
// 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() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const questionnaireForm = document.getElementById('questionnaire-form');
|
const questionnaireForm = document.getElementById('questionnaire-form');
|
||||||
|
|
||||||
@@ -39,35 +41,30 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
const quizId = 'quiz';
|
const quizId = 'quiz';
|
||||||
if (allQuizzes[quizId]) {
|
if (allQuizzes[quizId]) {
|
||||||
allQuizzes[quizId].participantData = participantData;
|
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));
|
localStorage.setItem('allQuizzes', JSON.stringify(allQuizzes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send data to the backend
|
// Combine quiz results and questionnaire data
|
||||||
fetch('/api/responses', {
|
const combinedData = {
|
||||||
|
allQuizzes: allQuizzes
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send combined data to webhook
|
||||||
|
fetch(WEBHOOK_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(allQuizzes)
|
body: JSON.stringify(allQuizzes)
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(() => {
|
||||||
if (!response.ok) {
|
alert('Анкету надіслано успішно');
|
||||||
throw new Error('Network response was not ok');
|
window.location.href = 'results.html';
|
||||||
}
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error:', error);
|
console.error('Error sending data:', error);
|
||||||
showError('Failed to submit the form. Please try again.');
|
alert('Сталася помилка при надсиланні анкети');
|
||||||
submitButton.disabled = false;
|
submitButton.disabled = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user