From 823c27e5ca367857f12c905a1b2c0c73d13bef8d Mon Sep 17 00:00:00 2001 From: Oleh Omelchenko Date: Thu, 30 Jan 2025 16:58:41 +0200 Subject: [PATCH] Add random quiz version selection and update webhook integration --- public/index.html | 12 ++++++++++++ public/js/app.js | 2 +- public/js/questionnaire.js | 33 +++++++++++++++------------------ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/public/index.html b/public/index.html index ba89676..1a85306 100644 --- a/public/index.html +++ b/public/index.html @@ -31,6 +31,18 @@

+ \ No newline at end of file diff --git a/public/js/app.js b/public/js/app.js index 3b8aebb..b1e0079 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -42,7 +42,7 @@ function initResultsPage() { } function loadQuestions(version) { - fetch('../data/questions.json') + fetch('data/questions.json') .then(response => response.json()) .then(data => { const questions = data.quizzes[version]; diff --git a/public/js/questionnaire.js b/public/js/questionnaire.js index c2e9450..f32c967 100644 --- a/public/js/questionnaire.js +++ b/public/js/questionnaire.js @@ -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; }); });