From 4723a428e72e176b09a8e55863c672b0e0f502a4 Mon Sep 17 00:00:00 2001 From: pandeymangg Date: Thu, 27 Nov 2025 11:55:33 +0530 Subject: [PATCH] fixes coderabbit feedback --- .../(analysis)/summary/lib/surveySummary.ts | 4 +- .../components/ElementSkip.tsx | 34 +++++++------- .../components/SingleResponseCardBody.tsx | 16 +++---- .../email/components/email-element-header.tsx | 4 +- .../components/preview-email-template.tsx | 30 ++++++------- .../emails/survey/response-finished-email.tsx | 12 ++--- .../editor/components/elements-view.tsx | 6 +-- .../multiple-choice-element-form.tsx | 2 +- .../components/ranking-element-form.tsx | 2 +- .../editor/components/update-element-id.tsx | 11 +++-- .../follow-ups/components/follow-up-email.tsx | 14 +++--- .../follow-ups/components/follow-up-modal.tsx | 45 ++++++++++--------- .../components/template-container.tsx | 6 +-- .../components/elements/rating-element.tsx | 2 +- packages/types/surveys/validation.ts | 14 ++---- 15 files changed, 101 insertions(+), 101 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts index f26ed15c28..08362eaac2 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary.ts @@ -103,7 +103,7 @@ const evaluateLogicAndGetNextElementId = ( data: TResponseData, localVariables: TResponseVariables, currentElementIndex: number, - currQuesTemp: TSurveyElement, + currElementTemp: TSurveyElement, selectedLanguage: string | null ): { nextElementId: string | undefined; @@ -115,7 +115,7 @@ const evaluateLogicAndGetNextElementId = ( let firstJumpTarget: string | undefined; - const { block: currentBlock } = findElementLocation(localSurvey, currQuesTemp.id); + const { block: currentBlock } = findElementLocation(localSurvey, currElementTemp.id); if (currentBlock?.logic && currentBlock.logic.length > 0) { for (const logic of currentBlock.logic) { diff --git a/apps/web/modules/analysis/components/SingleResponseCard/components/ElementSkip.tsx b/apps/web/modules/analysis/components/SingleResponseCard/components/ElementSkip.tsx index a6034f9fe8..988ac0dc25 100644 --- a/apps/web/modules/analysis/components/SingleResponseCard/components/ElementSkip.tsx +++ b/apps/web/modules/analysis/components/SingleResponseCard/components/ElementSkip.tsx @@ -10,35 +10,35 @@ import { parseRecallInfo } from "@/lib/utils/recall"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/modules/ui/components/tooltip"; interface ElementSkipProps { - skippedQuestions: string[] | undefined; + skippedElements: string[] | undefined; status: string; - questions: TSurveyElement[]; - isFirstQuestionAnswered?: boolean; + elements: TSurveyElement[]; + isFirstElementAnswered?: boolean; responseData: TResponseData; } export const ElementSkip = ({ - skippedQuestions, + skippedElements, status, - questions, - isFirstQuestionAnswered, + elements, + isFirstElementAnswered, responseData, }: ElementSkipProps) => { const { t } = useTranslation(); return (
- {skippedQuestions && ( + {skippedElements && (
{status === "welcomeCard" && (
{
@@ -52,9 +52,9 @@ export const ElementSkip = ({ className="flex w-0.5 items-center justify-center" style={{ background: - "repeating-linear-gradient(to bottom, rgb(148 163 184), rgb(148 163 184) 8px, transparent 5px, transparent 15px)", // adjust the values to fit your design + "repeating-linear-gradient(to bottom, rgb(148 163 184), rgb(148 163 184) 8px, transparent 5px, transparent 15px)", }}> - {skippedQuestions.length > 1 && ( + {skippedElements.length > 1 && ( @@ -70,13 +70,13 @@ export const ElementSkip = ({ )}
- {skippedQuestions?.map((questionId) => { + {skippedElements?.map((questionId) => { return (

{getTextContent( parseRecallInfo( getLocalizedValue( - questions.find((question) => question.id === questionId)?.headline ?? { + elements.find((question) => question.id === questionId)?.headline ?? { default: "", }, "default" @@ -96,7 +96,7 @@ export const ElementSkip = ({ className="flex w-0.5 flex-grow items-start justify-center" style={{ background: - "repeating-linear-gradient(to bottom, rgb(148 163 184), rgb(148 163 184) 2px, transparent 2px, transparent 10px)", // adjust the 2px to change dot size and 10px to change space between dots + "repeating-linear-gradient(to bottom, rgb(148 163 184), rgb(148 163 184) 2px, transparent 2px, transparent 10px)", }}>

@@ -108,14 +108,14 @@ export const ElementSkip = ({ className="mb-2 w-fit rounded-lg bg-slate-100 px-2 font-medium text-slate-700"> {t("environments.surveys.responses.survey_closed")}

- {skippedQuestions && - skippedQuestions.map((questionId) => { + {skippedElements && + skippedElements.map((questionId) => { return (

{getTextContent( parseRecallInfo( getLocalizedValue( - questions.find((question) => question.id === questionId)?.headline ?? { + elements.find((question) => question.id === questionId)?.headline ?? { default: "", }, "default" diff --git a/apps/web/modules/analysis/components/SingleResponseCard/components/SingleResponseCardBody.tsx b/apps/web/modules/analysis/components/SingleResponseCard/components/SingleResponseCardBody.tsx index cb1ae47f00..8bd7163424 100644 --- a/apps/web/modules/analysis/components/SingleResponseCard/components/SingleResponseCardBody.tsx +++ b/apps/web/modules/analysis/components/SingleResponseCard/components/SingleResponseCardBody.tsx @@ -27,8 +27,8 @@ export const SingleResponseCardBody = ({ response, skippedQuestions, }: SingleResponseCardBodyProps) => { - const questions = getElementsFromBlocks(survey.blocks); - const isFirstQuestionAnswered = questions[0] ? !!response.data[questions[0].id] : false; + const elements = getElementsFromBlocks(survey.blocks); + const isFirstElementAnswered = elements[0] ? !!response.data[elements[0].id] : false; const { t } = useTranslation(); const formatTextWithSlashes = (text: string) => { // Updated regex to match content between #/ and \# @@ -55,10 +55,10 @@ export const SingleResponseCardBody = ({

{survey.welcomeCard.enabled && ( )} @@ -66,7 +66,7 @@ export const SingleResponseCardBody = ({ {survey.isVerifyEmailEnabled && response.data["verifiedEmail"] && ( )} - {questions.map((question) => { + {elements.map((question) => { const skipped = skippedQuestions.find((skippedQuestionElement) => skippedQuestionElement.includes(question.id) ); @@ -104,8 +104,8 @@ export const SingleResponseCardBody = ({
) : ( diff --git a/apps/web/modules/email/components/preview-email-template.tsx b/apps/web/modules/email/components/preview-email-template.tsx index ee821d9d79..567f64f233 100644 --- a/apps/web/modules/email/components/preview-email-template.tsx +++ b/apps/web/modules/email/components/preview-email-template.tsx @@ -24,7 +24,7 @@ import { isLight, mixColor } from "@/lib/utils/colors"; import { parseRecallInfo } from "@/lib/utils/recall"; import { RatingSmiley } from "@/modules/analysis/components/RatingSmiley"; import { getNPSOptionColor, getRatingNumberOptionColor } from "../lib/utils"; -import { QuestionHeader } from "./email-element-header"; +import { ElementHeader } from "./email-element-header"; interface PreviewEmailTemplateProps { survey: TSurvey; @@ -92,7 +92,7 @@ export async function PreviewEmailTemplate({ case TSurveyElementTypeEnum.OpenText: return ( - +
@@ -100,7 +100,7 @@ export async function PreviewEmailTemplate({ case TSurveyElementTypeEnum.Consent: return ( - + {getLocalizedValue(firstQuestion.label, defaultLanguageCode)} @@ -130,7 +130,7 @@ export async function PreviewEmailTemplate({ return (
- +
- + {ctaElement.buttonExternal && ctaElement.ctaButtonLabel && ctaElement.buttonUrl && (
- +
@@ -252,7 +252,7 @@ export async function PreviewEmailTemplate({ case TSurveyElementTypeEnum.MultipleChoiceMulti: return ( - + {firstQuestion.choices.map((choice) => (
- + {firstQuestion.choices.map((choice) => (
- + {firstQuestion.choices.map((choice) => ( - +
{firstQuestion.choices.map((choice) => firstQuestion.allowMulti ? ( @@ -328,7 +328,7 @@ export async function PreviewEmailTemplate({ return ( - + - +
@@ -356,7 +356,7 @@ export async function PreviewEmailTemplate({ case TSurveyElementTypeEnum.Matrix: return ( - +
@@ -398,7 +398,7 @@ export async function PreviewEmailTemplate({ case TSurveyElementTypeEnum.ContactInfo: return ( - + {["First Name", "Last Name", "Email", "Phone", "Company"].map((label) => (
- +
diff --git a/apps/web/modules/email/emails/survey/response-finished-email.tsx b/apps/web/modules/email/emails/survey/response-finished-email.tsx index f9335807c8..3c9adac87f 100644 --- a/apps/web/modules/email/emails/survey/response-finished-email.tsx +++ b/apps/web/modules/email/emails/survey/response-finished-email.tsx @@ -26,7 +26,7 @@ export async function ResponseFinishedEmail({ environmentId, organization, }: ResponseFinishedEmailProps): Promise { - const questions = getElementResponseMapping(survey, response); + const elements = getElementResponseMapping(survey, response); const t = await getTranslate(); return ( @@ -41,13 +41,13 @@ export async function ResponseFinishedEmail({ })}
- {questions.map((question) => { - if (!question.response) return; + {elements.map((e) => { + if (!e.response) return; return ( - + - {question.element} - {renderEmailResponseValue(question.response, question.type, t)} + {e.element} + {renderEmailResponseValue(e.response, e.type, t)} ); diff --git a/apps/web/modules/survey/editor/components/elements-view.tsx b/apps/web/modules/survey/editor/components/elements-view.tsx index afb843c45b..9255c74d34 100644 --- a/apps/web/modules/survey/editor/components/elements-view.tsx +++ b/apps/web/modules/survey/editor/components/elements-view.tsx @@ -205,12 +205,12 @@ export const ElementsView = ({ useEffect(() => { if (!invalidElements) return; - let updatedInvalidElements: string[] = invalidElements; + let updatedInvalidElements: string[] = { ...invalidElements }; // Check welcome card if (localSurvey.welcomeCard.enabled && !isWelcomeCardValid(localSurvey.welcomeCard, surveyLanguages)) { if (!updatedInvalidElements.includes("start")) { - updatedInvalidElements.push("start"); + updatedInvalidElements = [...updatedInvalidElements, "start"]; } } else { updatedInvalidElements = updatedInvalidElements.filter((elementId) => elementId !== "start"); @@ -220,7 +220,7 @@ export const ElementsView = ({ localSurvey.endings.forEach((ending) => { if (!isEndingCardValid(ending, surveyLanguages)) { if (!updatedInvalidElements.includes(ending.id)) { - updatedInvalidElements.push(ending.id); + updatedInvalidElements = [...updatedInvalidElements, ending.id]; } } else { updatedInvalidElements = updatedInvalidElements.filter((elementId) => elementId !== ending.id); diff --git a/apps/web/modules/survey/editor/components/multiple-choice-element-form.tsx b/apps/web/modules/survey/editor/components/multiple-choice-element-form.tsx index 7707536e32..b11fe0d839 100644 --- a/apps/web/modules/survey/editor/components/multiple-choice-element-form.tsx +++ b/apps/web/modules/survey/editor/components/multiple-choice-element-form.tsx @@ -142,7 +142,7 @@ export const MultipleChoiceElementForm = ({ if (choiceToDelete !== "other" && choiceToDelete !== "none") { const idx = findOptionUsedInLogic(localSurvey, element.id, choiceToDelete); - if (elementIdx !== -1) { + if (idx !== -1) { toast.error( t("environments.surveys.edit.option_used_in_logic_error", { questionIndex: idx + 1, diff --git a/apps/web/modules/survey/editor/components/ranking-element-form.tsx b/apps/web/modules/survey/editor/components/ranking-element-form.tsx index 61f6cec106..ce543c59a9 100644 --- a/apps/web/modules/survey/editor/components/ranking-element-form.tsx +++ b/apps/web/modules/survey/editor/components/ranking-element-form.tsx @@ -90,7 +90,7 @@ export const RankingElementForm = ({ }; const deleteChoice = (choiceIdx: number) => { - const newChoices = !element.choices ? [] : element.choices.filter((_, idx) => idx !== choiceIdx); + const newChoices = element.choices.filter((_, idx) => idx !== choiceIdx); const choiceValue = element.choices[choiceIdx].label[selectedLanguageCode]; if (isInvalidValue === choiceValue) { diff --git a/apps/web/modules/survey/editor/components/update-element-id.tsx b/apps/web/modules/survey/editor/components/update-element-id.tsx index 6a01299959..f35acd9f16 100644 --- a/apps/web/modules/survey/editor/components/update-element-id.tsx +++ b/apps/web/modules/survey/editor/components/update-element-id.tsx @@ -11,14 +11,19 @@ import { Button } from "@/modules/ui/components/button"; import { Input } from "@/modules/ui/components/input"; import { Label } from "@/modules/ui/components/label"; -interface UpdatElementIdProps { +interface UpdateElementIdProps { localSurvey: TSurvey; element: TSurveyElement; elementIdx: number; updateElement: (elementIdx: number, updatedAttributes: any) => void; } -export const UpdateElementId = ({ localSurvey, element, elementIdx, updateElement }: UpdatElementIdProps) => { +export const UpdateElementId = ({ + localSurvey, + element, + elementIdx, + updateElement, +}: UpdateElementIdProps) => { const { t } = useTranslation(); const [currentValue, setCurrentValue] = useState(element.id); const [prevValue, setPrevValue] = useState(element.id); @@ -37,7 +42,7 @@ export const UpdateElementId = ({ localSurvey, element, elementIdx, updateElemen const endingCardIds = localSurvey.endings.map((e) => e.id); const hiddenFieldIds = localSurvey.hiddenFields.fieldIds ?? []; - const validateIdError = validateId("Element", currentValue, elementIds, endingCardIds, hiddenFieldIds); + const validateIdError = validateId("Question", currentValue, elementIds, endingCardIds, hiddenFieldIds); if (validateIdError) { setIsInputInvalid(true); diff --git a/apps/web/modules/survey/follow-ups/components/follow-up-email.tsx b/apps/web/modules/survey/follow-ups/components/follow-up-email.tsx index 7bd5b404e8..1def712b65 100644 --- a/apps/web/modules/survey/follow-ups/components/follow-up-email.tsx +++ b/apps/web/modules/survey/follow-ups/components/follow-up-email.tsx @@ -36,7 +36,7 @@ export async function FollowUpEmail(props: FollowUpEmailProps): Promise - {questions.length > 0 ?
: null} + {elements.length > 0 ?
: null} - {questions.map((question) => { - if (!question.response) return; + {elements.map((e) => { + if (!e.response) return; return ( - + - {question.element} - {renderEmailResponseValue(question.response, question.type, t, true)} + {e.element} + {renderEmailResponseValue(e.response, e.type, t, true)} ); diff --git a/apps/web/modules/survey/follow-ups/components/follow-up-modal.tsx b/apps/web/modules/survey/follow-ups/components/follow-up-modal.tsx index 86031475bb..d9df27f5fe 100644 --- a/apps/web/modules/survey/follow-ups/components/follow-up-modal.tsx +++ b/apps/web/modules/survey/follow-ups/components/follow-up-modal.tsx @@ -78,7 +78,7 @@ interface AddFollowUpModalProps { } type EmailSendToOption = { - type: "openTextQuestion" | "contactInfoQuestion" | "hiddenField" | "user"; + type: "openTextElement" | "contactInfoElement" | "hiddenField" | "user"; label: string; id: string; }; @@ -97,21 +97,20 @@ export const FollowUpModal = ({ locale, }: AddFollowUpModalProps) => { const { t } = useTranslation(); - const QUESTIONS_ICON_MAP = getElementIconMap(t); + const ELEMENTS_ICON_MAP = getElementIconMap(t); const containerRef = useRef(null); const [firstRender, setFirstRender] = useState(true); const emailSendToOptions: EmailSendToOption[] = useMemo(() => { - // Derive questions from blocks - const questions = getElementsFromBlocks(localSurvey.blocks); + const elements = getElementsFromBlocks(localSurvey.blocks); - const openTextAndContactQuestions = questions.filter((question) => { - if (question.type === TSurveyElementTypeEnum.ContactInfo) { - return question.email.show; + const openTextAndContactElements = elements.filter((element) => { + if (element.type === TSurveyElementTypeEnum.ContactInfo) { + return element.email.show; } - if (question.type === TSurveyElementTypeEnum.OpenText) { - if (question.inputType === "email") { + if (element.type === TSurveyElementTypeEnum.OpenText) { + if (element.inputType === "email") { return true; } @@ -142,15 +141,15 @@ export const FollowUpModal = ({ : [...updatedTeamMemberDetails, { email: userEmail, name: "Yourself" }]; return [ - ...openTextAndContactQuestions.map((question) => ({ + ...openTextAndContactElements.map((element) => ({ label: getTextContent( - recallToHeadline(question.headline, localSurvey, false, selectedLanguageCode)[selectedLanguageCode] + recallToHeadline(element.headline, localSurvey, false, selectedLanguageCode)[selectedLanguageCode] ), - id: question.id, + id: element.id, type: - question.type === TSurveyElementTypeEnum.OpenText - ? "openTextQuestion" - : ("contactInfoQuestion" as EmailSendToOption["type"]), + element.type === TSurveyElementTypeEnum.OpenText + ? "openTextElement" + : ("contactInfoElement" as EmailSendToOption["type"]), })), ...hiddenFields.fieldIds.map((fieldId: string) => ({ @@ -164,7 +163,7 @@ export const FollowUpModal = ({ id: member.email, type: "user" as EmailSendToOption["type"], })), - ]; + ] satisfies EmailSendToOption[]; }, [localSurvey, selectedLanguageCode, teamMemberDetails, userEmail]); const form = useForm({ @@ -373,8 +372,8 @@ export const FollowUpModal = ({ setOpen(open); }; - const emailSendToQuestionOptions = emailSendToOptions.filter( - (option) => option.type === "openTextQuestion" || option.type === "contactInfoQuestion" + const emailSendToElementOptions = emailSendToOptions.filter( + (option) => option.type === "openTextElement" || option.type === "contactInfoElement" ); const emailSendToHiddenFieldOptions = emailSendToOptions.filter((option) => option.type === "hiddenField"); const userSendToEmailOptions = emailSendToOptions.filter((option) => option.type === "user"); @@ -395,7 +394,7 @@ export const FollowUpModal = ({ ) : (
- {QUESTIONS_ICON_MAP[option.type === "openTextQuestion" ? "openText" : "contactInfo"]} + {ELEMENTS_ICON_MAP[option.type === "openTextElement" ? "openText" : "contactInfo"]}
{option.label}
@@ -649,13 +648,15 @@ export const FollowUpModal = ({ - {emailSendToQuestionOptions.length > 0 ? ( + {emailSendToElementOptions.length > 0 ? (
-

Questions

+

+ {t("common.questions")} +

- {emailSendToQuestionOptions.map((option) => + {emailSendToElementOptions.map((option) => renderSelectItem(option) )}
diff --git a/apps/web/modules/survey/templates/components/template-container.tsx b/apps/web/modules/survey/templates/components/template-container.tsx index bc46732cc7..1c0c3580cb 100644 --- a/apps/web/modules/survey/templates/components/template-container.tsx +++ b/apps/web/modules/survey/templates/components/template-container.tsx @@ -27,7 +27,7 @@ export const TemplateContainerWithPreview = ({ const { t } = useTranslation(); const initialTemplate = customSurveyTemplate(t); const [activeTemplate, setActiveTemplate] = useState(initialTemplate); - const [activeQuestionId, setActiveQuestionId] = useState( + const [activeElementId, setActiveElementId] = useState( initialTemplate.preset.blocks[0]?.elements[0]?.id || "" ); const [templateSearch, setTemplateSearch] = useState(null); @@ -58,7 +58,7 @@ export const TemplateContainerWithPreview = ({ userId={userId} templateSearch={templateSearch ?? ""} onTemplateClick={(template) => { - setActiveQuestionId(template.preset.blocks[0]?.elements[0]?.id || ""); + setActiveElementId(template.preset.blocks[0]?.elements[0]?.id || ""); setActiveTemplate(template); }} /> @@ -67,7 +67,7 @@ export const TemplateContainerWithPreview = ({ {activeTemplate && ( { setHoveredNumber(number); - }} + }} // NOSONAR onMouseLeave={() => { setHoveredNumber(0); }} diff --git a/packages/types/surveys/validation.ts b/packages/types/surveys/validation.ts index 9dfbd6b1a0..dd9ae6fdb8 100644 --- a/packages/types/surveys/validation.ts +++ b/packages/types/surveys/validation.ts @@ -300,23 +300,17 @@ const findJumpToQuestionActions = (actions: TSurveyLogicAction[]): TActionJumpTo // function to validate hidden field or question id or element id export const validateId = ( - type: "Hidden field" | "Question" | "Element", + type: "Hidden field" | "Question", // TODO: Change this to "Element" when we're ready to change the UI field: string, - existingQuestionIds: string[], + existingElementIds: string[], existingEndingCardIds: string[], - existingHiddenFieldIds: string[], - existingElementIds?: string[] + existingHiddenFieldIds: string[] ): string | null => { if (field.trim() === "") { return `Please enter a ${type} Id.`; } - const combinedIds = [ - ...existingQuestionIds, - ...existingHiddenFieldIds, - ...existingEndingCardIds, - ...(existingElementIds ?? []), - ]; + const combinedIds = [...existingElementIds, ...existingHiddenFieldIds, ...existingEndingCardIds]; if (combinedIds.findIndex((id) => id.toLowerCase() === field.toLowerCase()) !== -1) { return `${type} ID already exists in questions, hidden fields, or elements.`;