feat: Added prefill for consent question type and fixed the loader bug

This commit is contained in:
Piyush Gupta
2023-07-04 13:54:40 +05:30
parent 175736bb4b
commit 751d729242

View File

@@ -22,7 +22,7 @@ export const useLinkSurvey = (surveyId: string) => {
export const useLinkSurveyUtils = (survey: Survey) => {
const [currentQuestion, setCurrentQuestion] = useState<Question | null>(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;
}