Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions front_end/src/app/(main)/questions/components/group_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const GroupForm: React.FC<Props> = ({
}) => {
const router = useRouter();
const t = useTranslations();
const isDuplicate = mode === "create" && !!post;
const isDraftMounted = useRef(false);
const draftKey = `group_${subtype}`;
const [isLoading, setIsLoading] = useState<boolean>();
Expand Down Expand Up @@ -388,10 +389,12 @@ const GroupForm: React.FC<Props> = ({
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,
Expand Down
22 changes: 15 additions & 7 deletions front_end/src/app/(main)/questions/components/question_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,16 @@ const QuestionForm: FC<Props> = ({
| DiscreteQuestionType
| DateQuestionType;

const isDuplicate = mode === "create" && !!post;

// TODO: refactor validation schema setup to properly populate useForm generic
const form = useForm<FormSchemaType>({
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,
Comment on lines +473 to +475
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

published_at is cleared in useForm({ defaultValues }), but the corresponding still passes defaultValue={post?.published_at} – unchanged.

include_bots_in_aggregates:
post?.question?.include_bots_in_aggregates ?? false,
options_order:
Expand Down Expand Up @@ -872,7 +874,9 @@ const QuestionForm: FC<Props> = ({
<DateInput
control={form.control as unknown as Control<FieldValues>}
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"
/>
Expand All @@ -885,7 +889,9 @@ const QuestionForm: FC<Props> = ({
<DateInput
control={form.control as unknown as Control<FieldValues>}
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"
/>
Expand All @@ -901,7 +907,7 @@ const QuestionForm: FC<Props> = ({
<DateInput
control={form.control as unknown as Control<FieldValues>}
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"
/>
Expand All @@ -914,7 +920,9 @@ const QuestionForm: FC<Props> = ({
<DateInput
control={form.control as unknown as Control<FieldValues>}
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"
/>
Expand Down
Loading