From 8c05154a86cd0f3f3af091ec8d37c63e914a54da Mon Sep 17 00:00:00 2001 From: pandeymangg Date: Fri, 7 Nov 2025 12:30:25 +0530 Subject: [PATCH] fixes feedback --- .../survey/components/question-form-input/index.tsx | 8 ++++---- apps/web/modules/ui/components/file-input/index.tsx | 12 +++++++----- .../surveys/src/components/general/progress-bar.tsx | 4 ++-- .../components/general/response-error-component.tsx | 2 +- packages/surveys/src/components/general/survey.tsx | 9 +++++++-- packages/surveys/src/lib/recall.ts | 6 +++--- packages/surveys/src/lib/utils.ts | 12 +++++------- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/apps/web/modules/survey/components/question-form-input/index.tsx b/apps/web/modules/survey/components/question-form-input/index.tsx index f8e6c9b00f..f7969b0279 100644 --- a/apps/web/modules/survey/components/question-form-input/index.tsx +++ b/apps/web/modules/survey/components/question-form-input/index.tsx @@ -335,8 +335,8 @@ export const QuestionFormInput = ({ if (url) { const update = fileType === "video" - ? { videoUrl: url[0], imageUrl: "" } - : { imageUrl: url[0], videoUrl: "" }; + ? { videoUrl: url[0], imageUrl: undefined } + : { imageUrl: url[0], videoUrl: undefined }; if ((isWelcomeCard || isEndingCard) && updateSurvey) { updateSurvey(update); } else if (updateQuestion) { @@ -469,8 +469,8 @@ export const QuestionFormInput = ({ if (url) { const update = fileType === "video" - ? { videoUrl: url[0], imageUrl: "" } - : { imageUrl: url[0], videoUrl: "" }; + ? { videoUrl: url[0], imageUrl: undefined } + : { imageUrl: url[0], videoUrl: undefined }; if (isEndingCard && updateSurvey) { updateSurvey(update); } else if (updateQuestion) { diff --git a/apps/web/modules/ui/components/file-input/index.tsx b/apps/web/modules/ui/components/file-input/index.tsx index e3dea42f1c..e6d19bff32 100644 --- a/apps/web/modules/ui/components/file-input/index.tsx +++ b/apps/web/modules/ui/components/file-input/index.tsx @@ -200,21 +200,23 @@ export const FileInput = ({ setSelectedFiles(getSelectedFiles()); }, [fileUrl]); - // useEffect to handle the state when switching between 'image' and 'video' tabs. useEffect(() => { if (activeTab === "image" && typeof imageUrlTemp === "string") { // Temporarily store the current video URL before switching tabs. setVideoUrlTemp(videoUrl ?? ""); - // Re-upload the image using the temporary image URL. - onFileUpload([imageUrlTemp], "image"); + if (imageUrlTemp) { + onFileUpload([imageUrlTemp], "image"); + } } else if (activeTab === "video") { // Temporarily store the current image URL before switching tabs. setImageUrlTemp(fileUrl ?? ""); - // Re-upload the video using the temporary video URL. - onFileUpload([videoUrlTemp], "video"); + if (videoUrlTemp) { + onFileUpload([videoUrlTemp], "video"); + } } + // eslint-disable-next-line react-hooks/exhaustive-deps -- Only run when activeTab changes to avoid infinite loops }, [activeTab]); return ( diff --git a/packages/surveys/src/components/general/progress-bar.tsx b/packages/surveys/src/components/general/progress-bar.tsx index 662d7f6dff..b8c14ffd69 100644 --- a/packages/surveys/src/components/general/progress-bar.tsx +++ b/packages/surveys/src/components/general/progress-bar.tsx @@ -19,7 +19,7 @@ export function ProgressBar({ survey, questionId }: ProgressBarProps) { const calculateProgress = useCallback( (index: number) => { - let totalCards = questions.length; + let totalCards = survey.blocks.length; if (endingCardIds.length > 0) totalCards += 1; let idx = index; @@ -28,7 +28,7 @@ export function ProgressBar({ survey, questionId }: ProgressBarProps) { const elementIdx = calculateElementIdx(survey, idx, totalCards); return elementIdx / totalCards; }, - [survey, questions.length, endingCardIds.length] + [survey, endingCardIds.length] ); const progressArray = useMemo(() => { diff --git a/packages/surveys/src/components/general/response-error-component.tsx b/packages/surveys/src/components/general/response-error-component.tsx index 28aee5ea82..8e2a34cba3 100644 --- a/packages/surveys/src/components/general/response-error-component.tsx +++ b/packages/surveys/src/components/general/response-error-component.tsx @@ -1,6 +1,6 @@ import { useTranslation } from "react-i18next"; import { type TResponseData } from "@formbricks/types/responses"; -import { TSurveyElement } from "@formbricks/types/surveys/elements"; +import { type TSurveyElement } from "@formbricks/types/surveys/elements"; import { SubmitButton } from "@/components/buttons/submit-button"; import { processResponseData } from "@/lib/response"; diff --git a/packages/surveys/src/components/general/survey.tsx b/packages/surveys/src/components/general/survey.tsx index 628ae4b117..7fa6b8e46d 100644 --- a/packages/surveys/src/components/general/survey.tsx +++ b/packages/surveys/src/components/general/survey.tsx @@ -27,8 +27,13 @@ import { evaluateLogic, performActions } from "@/lib/logic"; import { parseRecallInformation } from "@/lib/recall"; import { ResponseQueue } from "@/lib/response-queue"; import { SurveyState } from "@/lib/survey-state"; -import { findBlockByElementId, getFirstElementIdInBlock, getQuestionsFromSurvey } from "@/lib/utils"; -import { cn, getDefaultLanguageCode } from "@/lib/utils"; +import { + cn, + findBlockByElementId, + getDefaultLanguageCode, + getFirstElementIdInBlock, + getQuestionsFromSurvey, +} from "@/lib/utils"; import { TResponseErrorCodesEnum } from "@/types/response-error-codes"; interface VariableStackEntry { diff --git a/packages/surveys/src/lib/recall.ts b/packages/surveys/src/lib/recall.ts index 1be78d67c9..a3358e6278 100644 --- a/packages/surveys/src/lib/recall.ts +++ b/packages/surveys/src/lib/recall.ts @@ -68,12 +68,12 @@ export const replaceRecallInfo = ( return modifiedText; }; -export const parseRecallInformation = ( - question: T, +export const parseRecallInformation = ( + question: TSurveyElement, languageCode: string, responseData: TResponseData, variables: TResponseVariables -): T => { +): TSurveyElement => { const modifiedQuestion = JSON.parse(JSON.stringify(question)); if (question.headline[languageCode].includes("recall:")) { modifiedQuestion.headline[languageCode] = replaceRecallInfo( diff --git a/packages/surveys/src/lib/utils.ts b/packages/surveys/src/lib/utils.ts index 2b681ed565..c51f092cf0 100644 --- a/packages/surveys/src/lib/utils.ts +++ b/packages/surveys/src/lib/utils.ts @@ -215,9 +215,8 @@ export const checkIfSurveyIsRTL = (survey: TJsEnvironmentStateSurvey, languageCo * @param survey The survey object with blocks * @returns An array of TSurveyElement (pure elements without block-level properties) */ -export const getQuestionsFromSurvey = (survey: TJsEnvironmentStateSurvey): TSurveyElement[] => { - return survey.blocks?.flatMap((block) => block.elements) ?? []; -}; +export const getQuestionsFromSurvey = (survey: TJsEnvironmentStateSurvey): TSurveyElement[] => + survey.blocks.flatMap((block) => block.elements); /** * Finds the parent block that contains the specified element ID. @@ -226,9 +225,8 @@ export const getQuestionsFromSurvey = (survey: TJsEnvironmentStateSurvey): TSurv * @param elementId The ID of the element to find * @returns The parent block or undefined if not found */ -export const findBlockByElementId = (survey: TJsEnvironmentStateSurvey, elementId: string) => { - return survey.blocks?.find((b) => b.elements.some((e) => e.id === elementId)); -}; +export const findBlockByElementId = (survey: TJsEnvironmentStateSurvey, elementId: string) => + survey.blocks.find((b) => b.elements.some((e) => e.id === elementId)); /** * Converts a block ID to the first element ID in that block. @@ -241,6 +239,6 @@ export const getFirstElementIdInBlock = ( survey: TJsEnvironmentStateSurvey, blockId: string ): string | undefined => { - const block = survey.blocks?.find((b) => b.id === blockId); + const block = survey.blocks.find((b) => b.id === blockId); return block?.elements[0]?.id; };