Fix Logic Jumps issues in in-product survey (#667)

This commit is contained in:
Dhruwang Jariwala
2023-08-09 15:40:07 +05:30
committed by GitHub
parent b072d3b549
commit 580e51dcea
2 changed files with 17 additions and 18 deletions

View File

@@ -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&apos;s gone, it&apos;s gone.
This action cannot be undone. If it&apos;s gone, it&apos;s gone.
</p>
<Button
disabled={isDeleteDisabled}

View File

@@ -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 = {