make questions default optional, sonarqube less verbose

This commit is contained in:
Johannes
2025-05-17 12:13:58 +07:00
parent 03ddf3d09a
commit 5356ce4ed2
6 changed files with 54 additions and 54 deletions

View File

@@ -66,7 +66,7 @@ export const buildMultipleChoiceQuestion = ({
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
shuffleOption: shuffleOption || "none",
required: required ?? true,
required: required ?? false,
logic,
};
};
@@ -105,7 +105,7 @@ export const buildOpenTextQuestion = ({
headline: { default: headline },
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
required: required ?? true,
required: required ?? false,
longAnswer,
logic,
charLimit: {
@@ -153,7 +153,7 @@ export const buildRatingQuestion = ({
range,
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
required: required ?? true,
required: required ?? false,
isColorCodingEnabled,
lowerLabel: lowerLabel ? { default: lowerLabel } : undefined,
upperLabel: upperLabel ? { default: upperLabel } : undefined,
@@ -194,7 +194,7 @@ export const buildNPSQuestion = ({
headline: { default: headline },
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
required: required ?? true,
required: required ?? false,
isColorCodingEnabled,
lowerLabel: lowerLabel ? { default: lowerLabel } : undefined,
upperLabel: upperLabel ? { default: upperLabel } : undefined,
@@ -230,7 +230,7 @@ export const buildConsentQuestion = ({
headline: { default: headline },
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
required: required ?? true,
required: required ?? false,
label: { default: label },
logic,
};
@@ -269,7 +269,7 @@ export const buildCTAQuestion = ({
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
dismissButtonLabel: dismissButtonLabel ? { default: dismissButtonLabel } : undefined,
required: required ?? true,
required: required ?? false,
buttonExternal,
buttonUrl,
logic,

View File

@@ -341,7 +341,7 @@ export const getCXQuestionNameMap = (t: TFnType) =>
) as Record<TSurveyQuestionTypeEnum, string>;
export const universalQuestionPresets = {
required: true,
required: false,
};
export const getQuestionDefaults = (id: string, project: any, t: TFnType) => {

View File

@@ -14,21 +14,21 @@ import { FileInput } from "../general/file-input";
import { Subheader } from "../general/subheader";
interface FileUploadQuestionProps {
readonly question: TSurveyFileUploadQuestion;
readonly value: string[];
readonly onChange: (responseData: TResponseData) => void;
readonly onSubmit: (data: TResponseData, ttc: TResponseTtc) => void;
readonly onBack: () => void;
readonly onFileUpload: (file: TJsFileUploadParams["file"], config?: TUploadFileConfig) => Promise<string>;
readonly isFirstQuestion: boolean;
readonly isLastQuestion: boolean;
readonly surveyId: string;
readonly languageCode: string;
readonly ttc: TResponseTtc;
readonly setTtc: (ttc: TResponseTtc) => void;
readonly autoFocusEnabled: boolean;
readonly currentQuestionId: TSurveyQuestionId;
readonly isBackButtonHidden: boolean;
question: TSurveyFileUploadQuestion;
value: string[];
onChange: (responseData: TResponseData) => void;
onSubmit: (data: TResponseData, ttc: TResponseTtc) => void;
onBack: () => void;
onFileUpload: (file: TJsFileUploadParams["file"], config?: TUploadFileConfig) => Promise<string>;
isFirstQuestion: boolean;
isLastQuestion: boolean;
surveyId: string;
languageCode: string;
ttc: TResponseTtc;
setTtc: (ttc: TResponseTtc) => void;
autoFocusEnabled: boolean;
currentQuestionId: TSurveyQuestionId;
isBackButtonHidden: boolean;
}
export function FileUploadQuestion({
@@ -46,7 +46,7 @@ export function FileUploadQuestion({
setTtc,
currentQuestionId,
isBackButtonHidden,
}: FileUploadQuestionProps) {
}: Readonly<FileUploadQuestionProps>) {
const [startTime, setStartTime] = useState(performance.now());
const isMediaAvailable = question.imageUrl || question.videoUrl;
useTtc(question.id, ttc, setTtc, startTime, setStartTime, question.id === currentQuestionId);

View File

@@ -12,19 +12,19 @@ import { type TResponseData, type TResponseTtc } from "@formbricks/types/respons
import type { TSurveyOpenTextQuestion, TSurveyQuestionId } from "@formbricks/types/surveys/types";
interface OpenTextQuestionProps {
readonly question: TSurveyOpenTextQuestion;
readonly value: string;
readonly onChange: (responseData: TResponseData) => void;
readonly onSubmit: (data: TResponseData, ttc: TResponseTtc) => void;
readonly onBack: () => void;
readonly isFirstQuestion: boolean;
readonly isLastQuestion: boolean;
readonly languageCode: string;
readonly ttc: TResponseTtc;
readonly setTtc: (ttc: TResponseTtc) => void;
readonly autoFocusEnabled: boolean;
readonly currentQuestionId: TSurveyQuestionId;
readonly isBackButtonHidden: boolean;
question: TSurveyOpenTextQuestion;
value: string;
onChange: (responseData: TResponseData) => void;
onSubmit: (data: TResponseData, ttc: TResponseTtc) => void;
onBack: () => void;
isFirstQuestion: boolean;
isLastQuestion: boolean;
languageCode: string;
ttc: TResponseTtc;
setTtc: (ttc: TResponseTtc) => void;
autoFocusEnabled: boolean;
currentQuestionId: TSurveyQuestionId;
isBackButtonHidden: boolean;
}
export function OpenTextQuestion({

View File

@@ -11,14 +11,14 @@ import { StackedCard } from "./stacked-card";
// offset < 0 -> Question cards that are already answered
// offset > 0 -> Question that aren't answered yet
interface StackedCardsContainerProps {
readonly cardArrangement: TCardArrangementOptions;
readonly currentQuestionId: TSurveyQuestionId;
readonly survey: TJsEnvironmentStateSurvey;
readonly getCardContent: (questionIdxTemp: number, offset: number) => JSX.Element | undefined;
readonly styling: TProjectStyling | TSurveyStyling;
readonly setQuestionId: (questionId: TSurveyQuestionId) => void;
readonly shouldResetQuestionId?: boolean;
readonly fullSizeCards: boolean;
cardArrangement: TCardArrangementOptions;
currentQuestionId: TSurveyQuestionId;
survey: TJsEnvironmentStateSurvey;
getCardContent: (questionIdxTemp: number, offset: number) => JSX.Element | undefined;
styling: TProjectStyling | TSurveyStyling;
setQuestionId: (questionId: TSurveyQuestionId) => void;
shouldResetQuestionId?: boolean;
fullSizeCards: boolean;
}
export function StackedCardsContainer({
@@ -30,7 +30,7 @@ export function StackedCardsContainer({
setQuestionId,
shouldResetQuestionId = true,
fullSizeCards = false,
}: StackedCardsContainerProps) {
}: Readonly<StackedCardsContainerProps>) {
const [hovered, setHovered] = useState(false);
const highlightBorderColor = survey.styling?.overwriteThemeStyling
? survey.styling?.highlightBorderColor?.light

View File

@@ -3,14 +3,14 @@ import { useEffect, useRef, useState } from "preact/hooks";
import { type TPlacement } from "@formbricks/types/common";
interface SurveyContainerProps {
readonly mode: "modal" | "inline";
readonly placement?: TPlacement;
readonly darkOverlay?: boolean;
readonly children: React.ReactNode;
readonly onClose?: () => void;
readonly clickOutside?: boolean;
readonly isOpen?: boolean;
readonly style?: React.CSSProperties;
mode: "modal" | "inline";
placement?: TPlacement;
darkOverlay?: boolean;
children: React.ReactNode;
onClose?: () => void;
clickOutside?: boolean;
isOpen?: boolean;
style?: React.CSSProperties;
}
export function SurveyContainer({
@@ -22,7 +22,7 @@ export function SurveyContainer({
clickOutside,
isOpen = true,
style,
}: SurveyContainerProps) {
}: Readonly<SurveyContainerProps>) {
const [show, setShow] = useState(false);
const modalRef = useRef<HTMLDivElement>(null);