From c50b46f715f232598c588785cd1d1318a33a0038 Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 18 Nov 2025 12:16:16 +0100 Subject: [PATCH] clean up block & question toggles for clarity --- apps/web/i18n.lock | 1 + apps/web/locales/de-DE.json | 1 + apps/web/locales/en-US.json | 1 + apps/web/locales/fr-FR.json | 1 + apps/web/locales/ja-JP.json | 1 + apps/web/locales/pt-BR.json | 1 + apps/web/locales/pt-PT.json | 1 + apps/web/locales/ro-RO.json | 1 + apps/web/locales/zh-Hans-CN.json | 1 + apps/web/locales/zh-Hant-TW.json | 1 + .../components/question-form-input/index.tsx | 93 +++++++++++++- .../survey/editor/components/block-card.tsx | 120 ++---------------- .../components/file-upload-question-form.tsx | 2 +- .../editor/components/open-question-form.tsx | 17 ++- .../modules/ui/components/tooltip/index.tsx | 7 +- 15 files changed, 135 insertions(+), 114 deletions(-) diff --git a/apps/web/i18n.lock b/apps/web/i18n.lock index caa5343f4f..b454d8be8a 100644 --- a/apps/web/i18n.lock +++ b/apps/web/i18n.lock @@ -1373,6 +1373,7 @@ checksums: environments/surveys/edit/logic_error_warning: 542fbb918ffdb29e6f9a4a6196ffb558 environments/surveys/edit/logic_error_warning_text: f2afad8852a95ed169a39959efbf592c environments/surveys/edit/long_answer: 3a97f8d2e90aba6e679917a0c5670c53 + environments/surveys/edit/long_answer_toggle_description: 86bcdfeb74d9825c2f2d5a215e92d111 environments/surveys/edit/lower_label: 45985bca022d4370bd6e013af75d5160 environments/surveys/edit/manage_languages: 9c56d5afee8a73dfc283a452470f3a10 environments/surveys/edit/matrix_all_fields: 187240509163b2f52a400a565e57c67f diff --git a/apps/web/locales/de-DE.json b/apps/web/locales/de-DE.json index 413c4edcdd..1c59c2cb4d 100644 --- a/apps/web/locales/de-DE.json +++ b/apps/web/locales/de-DE.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "Änderungen werden zu Logikfehlern führen", "logic_error_warning_text": "Das Ändern des Fragetypen entfernt die Logikbedingungen von dieser Frage", "long_answer": "Lange Antwort", + "long_answer_toggle_description": "Ermöglichen Sie den Befragten, längere Antworten über mehrere Zeilen zu schreiben.", "lower_label": "Unteres Label", "manage_languages": "Sprachen verwalten", "matrix_all_fields": "Alle Felder", diff --git a/apps/web/locales/en-US.json b/apps/web/locales/en-US.json index fa76760bea..569abd69ff 100644 --- a/apps/web/locales/en-US.json +++ b/apps/web/locales/en-US.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "Changing will cause logic errors", "logic_error_warning_text": "Changing the question type will remove the logic conditions from this question", "long_answer": "Long answer", + "long_answer_toggle_description": "Allow respondents to write longer, multi-line answers.", "lower_label": "Lower Label", "manage_languages": "Manage Languages", "matrix_all_fields": "All fields", diff --git a/apps/web/locales/fr-FR.json b/apps/web/locales/fr-FR.json index e59182054c..fd11f6167e 100644 --- a/apps/web/locales/fr-FR.json +++ b/apps/web/locales/fr-FR.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "Changer causera des erreurs logiques", "logic_error_warning_text": "Changer le type de question supprimera les conditions logiques de cette question.", "long_answer": "Longue réponse", + "long_answer_toggle_description": "Permettre aux répondants d'écrire des réponses plus longues et sur plusieurs lignes.", "lower_label": "Étiquette inférieure", "manage_languages": "Gérer les langues", "matrix_all_fields": "Tous les champs", diff --git a/apps/web/locales/ja-JP.json b/apps/web/locales/ja-JP.json index 83bf2f8b0e..55ddefe20b 100644 --- a/apps/web/locales/ja-JP.json +++ b/apps/web/locales/ja-JP.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "変更するとロジックエラーが発生します", "logic_error_warning_text": "質問の種類を変更すると、この質問のロジック条件が削除されます", "long_answer": "長文回答", + "long_answer_toggle_description": "回答者が長文の複数行の回答を書けるようにします。", "lower_label": "下限ラベル", "manage_languages": "言語を管理", "matrix_all_fields": "すべてのフィールド", diff --git a/apps/web/locales/pt-BR.json b/apps/web/locales/pt-BR.json index 733fbed37d..dda449e2ff 100644 --- a/apps/web/locales/pt-BR.json +++ b/apps/web/locales/pt-BR.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "Mudar vai causar erros de lógica", "logic_error_warning_text": "Mudar o tipo de pergunta vai remover as condições lógicas dessa pergunta", "long_answer": "resposta longa", + "long_answer_toggle_description": "Permitir que os respondentes escrevam respostas mais longas e com várias linhas.", "lower_label": "Etiqueta Inferior", "manage_languages": "Gerenciar Idiomas", "matrix_all_fields": "Todos os campos", diff --git a/apps/web/locales/pt-PT.json b/apps/web/locales/pt-PT.json index 1042a8fe4a..fc89e6e7c4 100644 --- a/apps/web/locales/pt-PT.json +++ b/apps/web/locales/pt-PT.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "A alteração causará erros de lógica", "logic_error_warning_text": "Alterar o tipo de pergunta irá remover as condições lógicas desta pergunta", "long_answer": "Resposta longa", + "long_answer_toggle_description": "Permitir que os inquiridos escrevam respostas mais longas e com várias linhas.", "lower_label": "Etiqueta Inferior", "manage_languages": "Gerir Idiomas", "matrix_all_fields": "Todos os campos", diff --git a/apps/web/locales/ro-RO.json b/apps/web/locales/ro-RO.json index 222fb77893..478b562450 100644 --- a/apps/web/locales/ro-RO.json +++ b/apps/web/locales/ro-RO.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "Schimbarea va provoca erori de logică", "logic_error_warning_text": "Schimbarea tipului de întrebare va elimina condițiile de logică din această întrebare", "long_answer": "Răspuns lung", + "long_answer_toggle_description": "Permite respondenților să scrie răspunsuri mai lungi, pe mai multe rânduri.", "lower_label": "Etichetă inferioară", "manage_languages": "Gestionați limbile", "matrix_all_fields": "Toate câmpurile", diff --git a/apps/web/locales/zh-Hans-CN.json b/apps/web/locales/zh-Hans-CN.json index d6264c5be1..e3483d9243 100644 --- a/apps/web/locales/zh-Hans-CN.json +++ b/apps/web/locales/zh-Hans-CN.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "更改 将 导致 逻辑 错误", "logic_error_warning_text": "更改问题类型 会 移除 此问题 的 逻辑条件", "long_answer": "长答案", + "long_answer_toggle_description": "允许受访者填写较长的多行答案。", "lower_label": "下限标签", "manage_languages": "管理 语言", "matrix_all_fields": "所有字段", diff --git a/apps/web/locales/zh-Hant-TW.json b/apps/web/locales/zh-Hant-TW.json index fa51f8d08e..1123f958c8 100644 --- a/apps/web/locales/zh-Hant-TW.json +++ b/apps/web/locales/zh-Hant-TW.json @@ -1458,6 +1458,7 @@ "logic_error_warning": "變更將導致邏輯錯誤", "logic_error_warning_text": "變更問題類型將會從此問題中移除邏輯條件", "long_answer": "長回答", + "long_answer_toggle_description": "允許受訪者撰寫較長的多行回答。", "lower_label": "下標籤", "manage_languages": "管理語言", "matrix_all_fields": "所有欄位", 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 13aa22f2b0..e473690e34 100644 --- a/apps/web/modules/survey/components/question-form-input/index.tsx +++ b/apps/web/modules/survey/components/question-form-input/index.tsx @@ -25,6 +25,7 @@ import { Button } from "@/modules/ui/components/button"; import { FileInput } from "@/modules/ui/components/file-input"; import { Input } from "@/modules/ui/components/input"; import { Label } from "@/modules/ui/components/label"; +import { Switch } from "@/modules/ui/components/switch"; import { TooltipRenderer } from "@/modules/ui/components/tooltip"; import { determineImageUploaderVisibility, @@ -310,6 +311,60 @@ export const QuestionFormInput = ({ return false; }; + const getIsRequiredToggleDisabled = (): boolean => { + if (!question) return false; + + if (question.type === TSurveyElementTypeEnum.Address) { + const allFieldsAreOptional = [ + question.addressLine1, + question.addressLine2, + question.city, + question.state, + question.zip, + question.country, + ] + .filter((field) => field.show) + .every((field) => !field.required); + + if (allFieldsAreOptional) { + return true; + } + + return [ + question.addressLine1, + question.addressLine2, + question.city, + question.state, + question.zip, + question.country, + ] + .filter((field) => field.show) + .some((condition) => condition.required === true); + } + + if (question.type === TSurveyElementTypeEnum.ContactInfo) { + const allFieldsAreOptional = [ + question.firstName, + question.lastName, + question.email, + question.phone, + question.company, + ] + .filter((field) => field.show) + .every((field) => !field.required); + + if (allFieldsAreOptional) { + return true; + } + + return [question.firstName, question.lastName, question.email, question.phone, question.company] + .filter((field) => field.show) + .some((condition) => condition.required === true); + } + + return false; + }; + const useRichTextEditor = id === "headline" || id === "subheader" || id === "html"; // For rich text editor fields, we need either updateQuestion or updateSurvey @@ -321,8 +376,23 @@ export const QuestionFormInput = ({ return (
{label && ( -
+
+ {id === "headline" && question && updateQuestion && ( +
+ + { + updateQuestion(questionIdx, { required: checked }); + }} + /> +
+ )}
)}
@@ -376,7 +446,9 @@ export const QuestionFormInput = ({
{id === "headline" && !isWelcomeCard && ( - +
diff --git a/apps/web/modules/survey/editor/components/file-upload-question-form.tsx b/apps/web/modules/survey/editor/components/file-upload-question-form.tsx index cbedb6ab18..941e785052 100644 --- a/apps/web/modules/survey/editor/components/file-upload-question-form.tsx +++ b/apps/web/modules/survey/editor/components/file-upload-question-form.tsx @@ -189,7 +189,7 @@ export const FileUploadQuestionForm = ({ )}
-
+
updateQuestion(questionIdx, { allowMultipleFiles: !question.allowMultipleFiles })} diff --git a/apps/web/modules/survey/editor/components/open-question-form.tsx b/apps/web/modules/survey/editor/components/open-question-form.tsx index f0008a7e0e..9512e70cbd 100644 --- a/apps/web/modules/survey/editor/components/open-question-form.tsx +++ b/apps/web/modules/survey/editor/components/open-question-form.tsx @@ -167,7 +167,7 @@ export const OpenQuestionForm = ({ />
-
+
{showCharLimits && ( )} +
+ { + updateQuestion(questionIdx, { + longAnswer: checked, + }); + }} + htmlId="longAnswer" + title={t("environments.surveys.edit.long_answer")} + description={t("environments.surveys.edit.long_answer_toggle_description")} + disabled={question.inputType !== "text"} + customContainerClass="p-0" + /> +
); diff --git a/apps/web/modules/ui/components/tooltip/index.tsx b/apps/web/modules/ui/components/tooltip/index.tsx index dc701ea45e..5f0a80d261 100644 --- a/apps/web/modules/ui/components/tooltip/index.tsx +++ b/apps/web/modules/ui/components/tooltip/index.tsx @@ -32,7 +32,7 @@ const TooltipContent: React.ComponentType )); TooltipContent.displayName = TooltipPrimitive.Content.displayName; -export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }; +export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }; interface TooltipRendererProps { tooltipContent: ReactNode; @@ -40,12 +40,13 @@ interface TooltipRendererProps { className?: string; triggerClass?: string; shouldRender?: boolean; + delayDuration?: number; } export const TooltipRenderer = (props: TooltipRendererProps) => { - const { children, shouldRender = true, tooltipContent, className, triggerClass } = props; + const { children, shouldRender = true, tooltipContent, className, triggerClass, delayDuration = 0 } = props; if (shouldRender) { return ( - + {children}