From a2a6870a2107a2e37da7a888774d3575629c1999 Mon Sep 17 00:00:00 2001 From: pandeymangg Date: Fri, 21 Nov 2025 11:41:55 +0530 Subject: [PATCH] fixes coderabbit feedback --- .../components/rating-question-form.tsx | 24 ---- .../components/general/block-conditional.tsx | 3 - .../general/element-conditional.tsx | 2 - .../surveys/src/components/general/survey.tsx | 1 - .../src/components/icons/link-icon.tsx | 2 +- .../components/questions/address-question.tsx | 122 ++++++++++-------- .../src/components/questions/cal-question.tsx | 3 +- .../components/questions/consent-question.tsx | 2 +- .../components/questions/date-question.tsx | 13 ++ .../multiple-choice-multi-question.tsx | 7 +- .../multiple-choice-single-question.tsx | 8 +- .../questions/open-text-question.tsx | 2 +- .../wrappers/stacked-cards-container.tsx | 4 +- 13 files changed, 97 insertions(+), 96 deletions(-) diff --git a/apps/web/modules/survey/editor/components/rating-question-form.tsx b/apps/web/modules/survey/editor/components/rating-question-form.tsx index ce1161da54..0e221d9aeb 100644 --- a/apps/web/modules/survey/editor/components/rating-question-form.tsx +++ b/apps/web/modules/survey/editor/components/rating-question-form.tsx @@ -3,7 +3,6 @@ import { useAutoAnimate } from "@formkit/auto-animate/react"; import { HashIcon, PlusIcon, SmileIcon, StarIcon } from "lucide-react"; import { useTranslation } from "react-i18next"; -import { TI18nString } from "@formbricks/types/i18n"; import { TSurveyRatingElement } from "@formbricks/types/surveys/elements"; import { TSurvey } from "@formbricks/types/surveys/types"; import { TUserLocale } from "@formbricks/types/user"; @@ -26,7 +25,6 @@ interface RatingQuestionFormProps { locale: TUserLocale; isStorageConfigured: boolean; isExternalUrlsAllowed?: boolean; - buttonLabel?: TI18nString; } export const RatingQuestionForm = ({ @@ -40,7 +38,6 @@ export const RatingQuestionForm = ({ locale, isStorageConfigured = true, isExternalUrlsAllowed, - buttonLabel, }: RatingQuestionFormProps) => { const { t } = useTranslation(); const surveyLanguageCodes = extractLanguageCodes(localSurvey.languages); @@ -181,27 +178,6 @@ export const RatingQuestionForm = ({ -
- {!question.required && ( -
- -
- )} -
- {question.scale !== "star" && ( void; surveyId: string; autoFocusEnabled: boolean; - currentBlockId: string; isBackButtonHidden: boolean; onOpenExternalURL?: (url: string) => void | Promise; dir?: "ltr" | "rtl" | "auto"; @@ -208,8 +207,6 @@ export function BlockConditional({ onChange={(responseData) => handleElementChange(element.id, responseData)} onBack={() => {}} onFileUpload={onFileUpload} - isFirstElement={false} - isLastElement={false} languageCode={languageCode} prefilledElementValue={prefilledResponseData?.[element.id]} skipPrefilled={skipPrefilled} diff --git a/packages/surveys/src/components/general/element-conditional.tsx b/packages/surveys/src/components/general/element-conditional.tsx index 030f0f5262..a7e1c30d9e 100644 --- a/packages/surveys/src/components/general/element-conditional.tsx +++ b/packages/surveys/src/components/general/element-conditional.tsx @@ -30,8 +30,6 @@ interface ElementConditionalProps { onChange: (responseData: TResponseData) => void; onBack: () => void; onFileUpload: (file: TJsFileUploadParams["file"], config?: TUploadFileConfig) => Promise; - isFirstElement: boolean; - isLastElement: boolean; languageCode: string; prefilledElementValue?: TResponseDataValue; skipPrefilled?: boolean; diff --git a/packages/surveys/src/components/general/survey.tsx b/packages/surveys/src/components/general/survey.tsx index ca5892719a..a8911fadda 100644 --- a/packages/surveys/src/components/general/survey.tsx +++ b/packages/surveys/src/components/general/survey.tsx @@ -777,7 +777,6 @@ export function Survey({ isLastBlock={block.id === localSurvey.blocks[localSurvey.blocks.length - 1].id} languageCode={selectedLanguage} autoFocusEnabled={autoFocusEnabled} - currentBlockId={blockId} isBackButtonHidden={localSurvey.isBackButtonHidden} onOpenExternalURL={onOpenExternalURL} dir={dir} diff --git a/packages/surveys/src/components/icons/link-icon.tsx b/packages/surveys/src/components/icons/link-icon.tsx index 8f1781a5dd..76e78f2887 100644 --- a/packages/surveys/src/components/icons/link-icon.tsx +++ b/packages/surveys/src/components/icons/link-icon.tsx @@ -11,7 +11,7 @@ export const LinkIcon = ({ className }: LinkIconProps) => { viewBox="0 0 24 24" fill="none" stroke="currentColor" - stroke-width="2" + strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}> diff --git a/packages/surveys/src/components/questions/address-question.tsx b/packages/surveys/src/components/questions/address-question.tsx index 8e8c1b069d..31b046c1a3 100644 --- a/packages/surveys/src/components/questions/address-question.tsx +++ b/packages/surveys/src/components/questions/address-question.tsx @@ -36,44 +36,58 @@ export function AddressQuestion({ const [startTime, setStartTime] = useState(performance.now()); const isMediaAvailable = question.imageUrl || question.videoUrl; const formRef = useRef(null); + useTtc(question.id, ttc, setTtc, startTime, setStartTime, question.id === currentQuestionId); + const safeValue = useMemo(() => { return Array.isArray(value) ? value : ["", "", "", "", "", ""]; }, [value]); + const isCurrent = question.id === currentQuestionId; - const fields = [ - { - id: "addressLine1", - ...question.addressLine1, - label: question.addressLine1.placeholder[languageCode], - }, - { - id: "addressLine2", - ...question.addressLine2, - label: question.addressLine2.placeholder[languageCode], - }, - { - id: "city", - ...question.city, - label: question.city.placeholder[languageCode], - }, - { - id: "state", - ...question.state, - label: question.state.placeholder[languageCode], - }, - { - id: "zip", - ...question.zip, - label: question.zip.placeholder[languageCode], - }, - { - id: "country", - ...question.country, - label: question.country.placeholder[languageCode], - }, - ]; + const fields = useMemo( + () => [ + { + id: "addressLine1", + ...question.addressLine1, + label: question.addressLine1.placeholder[languageCode], + }, + { + id: "addressLine2", + ...question.addressLine2, + label: question.addressLine2.placeholder[languageCode], + }, + { + id: "city", + ...question.city, + label: question.city.placeholder[languageCode], + }, + { + id: "state", + ...question.state, + label: question.state.placeholder[languageCode], + }, + { + id: "zip", + ...question.zip, + label: question.zip.placeholder[languageCode], + }, + { + id: "country", + ...question.country, + label: question.country.placeholder[languageCode], + }, + ], + [ + question.addressLine1, + question.addressLine2, + question.city, + question.state, + question.zip, + question.country, + languageCode, + ] + ); const handleChange = (fieldId: string, fieldValue: string) => { const newValue = fields.map((field) => { @@ -102,6 +116,25 @@ export function AddressQuestion({ [question.id, autoFocusEnabled, currentQuestionId] ); + const isFieldRequired = useCallback( + (field: (typeof fields)[number]) => { + if (field.required) { + return true; + } + + // if all fields are optional and the question is required, then the fields should be required + if ( + fields.filter((currField) => currField.show).every((currField) => !currField.required) && + question.required + ) { + return true; + } + + return false; + }, + [fields, question.required] + ); + return (
@@ -118,32 +151,17 @@ export function AddressQuestion({
{fields.map((field, index) => { - const isFieldRequired = () => { - if (field.required) { - return true; - } - - // if all fields are optional and the question is required, then the fields should be required - if ( - fields.filter((currField) => currField.show).every((currField) => !currField.required) && - question.required - ) { - return true; - } - - return false; - }; + const isRequired = isFieldRequired(field); return ( field.show && ( -
-