From 41eaa061feec865e812bd5d115adee3a712abb26 Mon Sep 17 00:00:00 2001 From: Gabriel Gordon-Hall Date: Tue, 7 Oct 2025 14:56:56 +0100 Subject: [PATCH] fix: create multiple tasks bug (#958) * fix create multi task bug (cherry picked from commit e44bf08cd16bf9f93ce8e774c5e8ccea782e8b55) * fmt --- .../dialogs/tasks/TaskFormDialog.tsx | 90 +++++++++++-------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx b/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx index decbdcb7..9bfbcf56 100644 --- a/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx +++ b/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx @@ -302,7 +302,9 @@ export const TaskFormDialog = NiceModal.create( }, []); const handleSubmit = useCallback(async () => { - if (!title.trim() || !projectId) return; + if (!title.trim() || !projectId || isSubmitting || isSubmittingAndStart) { + return; + } setIsSubmitting(true); try { @@ -321,7 +323,7 @@ export const TaskFormDialog = NiceModal.create( } if (isEditMode && task) { - updateTask.mutate( + await updateTask.mutateAsync( { taskId: task.id, data: { @@ -339,7 +341,7 @@ export const TaskFormDialog = NiceModal.create( } ); } else { - createTask.mutate( + await createTask.mutateAsync( { project_id: projectId, title, @@ -354,6 +356,8 @@ export const TaskFormDialog = NiceModal.create( } ); } + } catch (error) { + // Error already handled by mutation onError } finally { setIsSubmitting(false); } @@ -369,48 +373,59 @@ export const TaskFormDialog = NiceModal.create( images, createTask, updateTask, + isSubmitting, + isSubmittingAndStart, + parentTaskAttemptId, ]); const handleCreateAndStart = useCallback(async () => { - if (!title.trim() || !projectId) return; + if ( + !title.trim() || + !projectId || + isEditMode || + isSubmitting || + isSubmittingAndStart + ) { + return; + } setIsSubmittingAndStart(true); try { - if (!isEditMode) { - const imageIds = - newlyUploadedImageIds.length > 0 - ? newlyUploadedImageIds - : undefined; + const imageIds = + newlyUploadedImageIds.length > 0 ? newlyUploadedImageIds : undefined; - // Use selected executor profile or fallback to config default - const finalExecutorProfile = - selectedExecutorProfile || system.config?.executor_profile; - if (!finalExecutorProfile || !selectedBranch) { - console.warn( - `Missing ${!finalExecutorProfile ? 'executor profile' : 'branch'} for Create & Start` - ); - return; - } - - createAndStart.mutate( - { - task: { - project_id: projectId, - title, - description: description, - parent_task_attempt: parentTaskAttemptId || null, - image_ids: imageIds || null, - }, - executor_profile_id: finalExecutorProfile, - base_branch: selectedBranch, - }, - { - onSuccess: () => { - modal.hide(); - }, - } + // Use selected executor profile or fallback to config default + const finalExecutorProfile = + selectedExecutorProfile || system.config?.executor_profile; + if (!finalExecutorProfile || !selectedBranch) { + console.warn( + `Missing ${ + !finalExecutorProfile ? 'executor profile' : 'branch' + } for Create & Start` ); + return; } + + await createAndStart.mutateAsync( + { + task: { + project_id: projectId, + title, + description: description, + parent_task_attempt: parentTaskAttemptId || null, + image_ids: imageIds || null, + }, + executor_profile_id: finalExecutorProfile, + base_branch: selectedBranch, + }, + { + onSuccess: () => { + modal.hide(); + }, + } + ); + } catch (error) { + // Error already handled by mutation onError } finally { setIsSubmittingAndStart(false); } @@ -425,6 +440,9 @@ export const TaskFormDialog = NiceModal.create( selectedExecutorProfile, selectedBranch, system.config?.executor_profile, + isSubmitting, + isSubmittingAndStart, + parentTaskAttemptId, ]); const handleCancel = useCallback(() => {