From 751d7292427b02dc76f13e7b214c0fe163491e87 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Tue, 4 Jul 2023 13:54:40 +0530 Subject: [PATCH] feat: Added prefill for consent question type and fixed the loader bug --- apps/web/lib/linkSurvey/linkSurvey.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/web/lib/linkSurvey/linkSurvey.ts b/apps/web/lib/linkSurvey/linkSurvey.ts index 5692dd50c9..8c251209de 100644 --- a/apps/web/lib/linkSurvey/linkSurvey.ts +++ b/apps/web/lib/linkSurvey/linkSurvey.ts @@ -22,7 +22,7 @@ export const useLinkSurvey = (surveyId: string) => { export const useLinkSurveyUtils = (survey: Survey) => { const [currentQuestion, setCurrentQuestion] = useState(null); - const [prefilling, setPrefilling] = useState(false); + const [prefilling, setPrefilling] = useState(true); const [progress, setProgress] = useState(0); // [0, 1] const [finished, setFinished] = useState(false); const [loadingElement, setLoadingElement] = useState(false); @@ -166,7 +166,6 @@ export const useLinkSurveyUtils = (survey: Survey) => { if (!currentQuestion) return; const firstQuestionId = survey.questions[0].id; if (currentQuestion.id !== firstQuestionId) return; - setPrefilling(true); const question = survey.questions.find((q) => q.id === firstQuestionId); if (!question) throw new Error("Question not found"); @@ -239,6 +238,11 @@ const checkValidity = (question: Question, answer: any): boolean => { if (answer !== "clicked" && answer !== "dismissed") return false; return true; } + case QuestionType.Consent: { + if (question.required && answer === "dismissed") return false; + if (answer !== "accepted" && answer !== "dismissed") return false; + return true; + } case QuestionType.Rating: { answer = answer.replace(/&/g, ";"); const answerNumber = Number(JSON.parse(answer)); @@ -257,6 +261,7 @@ const createAnswer = (question: Question, answer: string): string | number | str switch (question.type) { case QuestionType.OpenText: case QuestionType.MultipleChoiceSingle: + case QuestionType.Consent: case QuestionType.CTA: { return answer; }