From e967146b31cc1eaa62bec4c4ceef822729a413b5 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2026 18:01:48 +0000 Subject: [PATCH 1/2] Stop duplicating dates when duplicating questions When duplicating a question (mode='create' with existing post), skip copying scheduling date fields (open_time, scheduled_close_time, scheduled_resolve_time, cp_reveal_time, published_at) so they start empty. Bounds (range_min, range_max) and zero_point for date range questions are still duplicated as before. Fixes #4456 Co-authored-by: Sylvain --- .../(main)/questions/components/group_form.tsx | 13 +++++++++---- .../questions/components/question_form.tsx | 16 +++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/front_end/src/app/(main)/questions/components/group_form.tsx b/front_end/src/app/(main)/questions/components/group_form.tsx index ca92c65879..c30870f2bb 100644 --- a/front_end/src/app/(main)/questions/components/group_form.tsx +++ b/front_end/src/app/(main)/questions/components/group_form.tsx @@ -210,6 +210,7 @@ const GroupForm: React.FC = ({ }) => { const router = useRouter(); const t = useTranslations(); + const isDuplicate = mode === "create" && !!post; const isDraftMounted = useRef(false); const draftKey = `group_${subtype}`; const [isLoading, setIsLoading] = useState(); @@ -388,10 +389,14 @@ const GroupForm: React.FC = ({ id: x.id, type: x.type as QuestionType, clientId: crypto.randomUUID(), - scheduled_close_time: x.scheduled_close_time, - scheduled_resolve_time: x.scheduled_resolve_time, - open_time: x.open_time, - cp_reveal_time: x.cp_reveal_time, + scheduled_close_time: isDuplicate + ? undefined + : x.scheduled_close_time, + scheduled_resolve_time: isDuplicate + ? undefined + : x.scheduled_resolve_time, + open_time: isDuplicate ? undefined : x.open_time, + cp_reveal_time: isDuplicate ? undefined : x.cp_reveal_time, label: x.label, unit: x.unit, scaling: x.scaling, diff --git a/front_end/src/app/(main)/questions/components/question_form.tsx b/front_end/src/app/(main)/questions/components/question_form.tsx index 2e142b8146..bb6e919f2b 100644 --- a/front_end/src/app/(main)/questions/components/question_form.tsx +++ b/front_end/src/app/(main)/questions/components/question_form.tsx @@ -463,14 +463,16 @@ const QuestionForm: FC = ({ | DiscreteQuestionType | DateQuestionType; + const isDuplicate = mode === "create" && !!post; + // TODO: refactor validation schema setup to properly populate useForm generic const form = useForm({ mode: "all", resolver: zodResolver(getFormSchema(questionType)), defaultValues: { - open_time: post?.question?.open_time, - published_at: post?.published_at, - cp_reveal_time: post?.question?.cp_reveal_time, + open_time: isDuplicate ? undefined : post?.question?.open_time, + published_at: isDuplicate ? undefined : post?.published_at, + cp_reveal_time: isDuplicate ? undefined : post?.question?.cp_reveal_time, include_bots_in_aggregates: post?.question?.include_bots_in_aggregates ?? false, options_order: @@ -872,7 +874,7 @@ const QuestionForm: FC = ({ } name="scheduled_close_time" - defaultValue={post?.question?.scheduled_close_time} + defaultValue={isDuplicate ? undefined : post?.question?.scheduled_close_time} errors={form.formState.errors.scheduled_close_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" /> @@ -885,7 +887,7 @@ const QuestionForm: FC = ({ } name="scheduled_resolve_time" - defaultValue={post?.question?.scheduled_resolve_time} + defaultValue={isDuplicate ? undefined : post?.question?.scheduled_resolve_time} errors={form.formState.errors.scheduled_resolve_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" /> @@ -901,7 +903,7 @@ const QuestionForm: FC = ({ } name="open_time" - defaultValue={post?.question?.open_time} + defaultValue={isDuplicate ? undefined : post?.question?.open_time} errors={form.formState.errors.open_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" /> @@ -914,7 +916,7 @@ const QuestionForm: FC = ({ } name="cp_reveal_time" - defaultValue={post?.question?.cp_reveal_time} + defaultValue={isDuplicate ? undefined : post?.question?.cp_reveal_time} errors={form.formState.errors.cp_reveal_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" /> From 3edd1be2c87fb4e55acad6fbb7762841aa00b385 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:12:21 +0000 Subject: [PATCH 2/2] Fix Prettier formatting for date field changes Co-authored-by: Sylvain --- .../app/(main)/questions/components/group_form.tsx | 4 +--- .../(main)/questions/components/question_form.tsx | 12 +++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/front_end/src/app/(main)/questions/components/group_form.tsx b/front_end/src/app/(main)/questions/components/group_form.tsx index c30870f2bb..94768b5823 100644 --- a/front_end/src/app/(main)/questions/components/group_form.tsx +++ b/front_end/src/app/(main)/questions/components/group_form.tsx @@ -389,9 +389,7 @@ const GroupForm: React.FC = ({ id: x.id, type: x.type as QuestionType, clientId: crypto.randomUUID(), - scheduled_close_time: isDuplicate - ? undefined - : x.scheduled_close_time, + scheduled_close_time: isDuplicate ? undefined : x.scheduled_close_time, scheduled_resolve_time: isDuplicate ? undefined : x.scheduled_resolve_time, diff --git a/front_end/src/app/(main)/questions/components/question_form.tsx b/front_end/src/app/(main)/questions/components/question_form.tsx index bb6e919f2b..80e5600c22 100644 --- a/front_end/src/app/(main)/questions/components/question_form.tsx +++ b/front_end/src/app/(main)/questions/components/question_form.tsx @@ -874,7 +874,9 @@ const QuestionForm: FC = ({ } name="scheduled_close_time" - defaultValue={isDuplicate ? undefined : post?.question?.scheduled_close_time} + defaultValue={ + isDuplicate ? undefined : post?.question?.scheduled_close_time + } errors={form.formState.errors.scheduled_close_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" /> @@ -887,7 +889,9 @@ const QuestionForm: FC = ({ } name="scheduled_resolve_time" - defaultValue={isDuplicate ? undefined : post?.question?.scheduled_resolve_time} + defaultValue={ + isDuplicate ? undefined : post?.question?.scheduled_resolve_time + } errors={form.formState.errors.scheduled_resolve_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" /> @@ -916,7 +920,9 @@ const QuestionForm: FC = ({ } name="cp_reveal_time" - defaultValue={isDuplicate ? undefined : post?.question?.cp_reveal_time} + defaultValue={ + isDuplicate ? undefined : post?.question?.cp_reveal_time + } errors={form.formState.errors.cp_reveal_time} className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark" />