Files
formbricks-formbricks/apps/web/components/preview/QuestionConditional.tsx
Dhruwang Jariwala 15fde11804 Use Server Components for Link Survey to improve loading speed (#676)
* moved link LinkSurvey to RSC

* made some code refactors

* made requested changes

* ran pnpm build and added configured inactive survey

* fixed a build issue

* made some code refactors

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-08-16 10:56:15 +02:00

105 lines
3.4 KiB
TypeScript

import { QuestionType, type Question } from "@formbricks/types/questions";
import OpenTextQuestion from "./OpenTextQuestion";
import MultipleChoiceSingleQuestion from "./MultipleChoiceSingleQuestion";
import MultipleChoiceMultiQuestion from "./MultipleChoiceMultiQuestion";
import NPSQuestion from "./NPSQuestion";
import CTAQuestion from "./CTAQuestion";
import RatingQuestion from "./RatingQuestion";
import ConsentQuestion from "./ConsentQuestion";
import { TSurveyQuestion } from "@formbricks/types/v1/surveys";
interface QuestionConditionalProps {
question: Question | TSurveyQuestion;
onSubmit: (data: { [x: string]: any }) => void;
lastQuestion: boolean;
brandColor: string;
storedResponseValue: any;
goToNextQuestion: (answer: any) => void;
goToPreviousQuestion?: (answer: any) => void;
autoFocus: boolean;
}
export default function QuestionConditional({
question,
onSubmit,
lastQuestion,
brandColor,
storedResponseValue,
goToNextQuestion,
goToPreviousQuestion,
autoFocus,
}: QuestionConditionalProps) {
return question.type === QuestionType.OpenText ? (
<OpenTextQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
autoFocus={autoFocus}
/>
) : question.type === QuestionType.MultipleChoiceSingle ? (
<MultipleChoiceSingleQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
/>
) : question.type === QuestionType.MultipleChoiceMulti ? (
<MultipleChoiceMultiQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
/>
) : question.type === QuestionType.NPS ? (
<NPSQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
/>
) : question.type === QuestionType.CTA ? (
<CTAQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
/>
) : question.type === QuestionType.Rating ? (
<RatingQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
/>
) : question.type === "consent" ? (
<ConsentQuestion
question={question}
onSubmit={onSubmit}
lastQuestion={lastQuestion}
brandColor={brandColor}
storedResponseValue={storedResponseValue}
goToNextQuestion={goToNextQuestion}
goToPreviousQuestion={goToPreviousQuestion}
/>
) : null;
}