mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-05 21:32:02 -06:00
Fix Logic Jumps issues in in-product survey (#667)
This commit is contained in:
committed by
GitHub
parent
b072d3b549
commit
580e51dcea
@@ -54,7 +54,7 @@ export default function DeleteTeam({ environmentId }) {
|
||||
{!isDeleteDisabled && (
|
||||
<div>
|
||||
<p className="text-sm text-slate-900">
|
||||
This action cannot be undone. If it's gone, it's gone.
|
||||
This action cannot be undone. If it's gone, it's gone.
|
||||
</p>
|
||||
<Button
|
||||
disabled={isDeleteDisabled}
|
||||
|
||||
@@ -162,18 +162,31 @@ export default function SurveyView({ config, survey, close, errorHandler }: Surv
|
||||
}
|
||||
}
|
||||
|
||||
function getNextQuestionId() {
|
||||
function getNextQuestionId(data: TResponseData): string {
|
||||
const questions = survey.questions;
|
||||
const currentQuestionIndex = questions.findIndex((q) => q.id === activeQuestionId);
|
||||
const currentQuestion = questions[currentQuestionIndex];
|
||||
const responseValue = data[activeQuestionId];
|
||||
|
||||
if (currentQuestionIndex === -1) throw new Error("Question not found");
|
||||
|
||||
if (currentQuestion?.logic && currentQuestion?.logic.length > 0) {
|
||||
for (let logic of currentQuestion.logic) {
|
||||
if (!logic.destination) continue;
|
||||
|
||||
if (evaluateCondition(logic, responseValue)) {
|
||||
return logic.destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return questions[currentQuestionIndex + 1]?.id || "end";
|
||||
}
|
||||
|
||||
function goToNextQuestion(answer: TResponseData): string {
|
||||
setLoadingElement(true);
|
||||
const questions = survey.questions;
|
||||
const nextQuestionId = getNextQuestionId();
|
||||
const nextQuestionId = getNextQuestionId(answer);
|
||||
|
||||
if (nextQuestionId === "end") {
|
||||
submitResponse(answer);
|
||||
@@ -212,21 +225,7 @@ export default function SurveyView({ config, survey, close, errorHandler }: Surv
|
||||
|
||||
const submitResponse = async (data: TResponseData) => {
|
||||
setLoadingElement(true);
|
||||
const questions = survey.questions;
|
||||
const nextQuestionId = getNextQuestionId();
|
||||
const currentQuestion = questions[activeQuestionId];
|
||||
const responseValue = data[activeQuestionId];
|
||||
|
||||
if (currentQuestion?.logic && currentQuestion?.logic.length > 0) {
|
||||
for (let logic of currentQuestion.logic) {
|
||||
if (!logic.destination) continue;
|
||||
|
||||
if (evaluateCondition(logic, responseValue)) {
|
||||
return logic.destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nextQuestionId = getNextQuestionId(data);
|
||||
const finished = nextQuestionId === "end";
|
||||
// build response
|
||||
const responseRequest: TResponseInput = {
|
||||
|
||||
Reference in New Issue
Block a user