diff --git a/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx b/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx index 3078ae0e..c145ff53 100644 --- a/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx +++ b/frontend/src/components/dialogs/tasks/TaskFormDialog.tsx @@ -38,7 +38,12 @@ import { useImageUpload, useTaskMutations, } from '@/hooks'; -import { useKeySubmitTask, useKeyExit, Scope } from '@/keyboard'; +import { + useKeySubmitTask, + useKeySubmitTaskAlt, + useKeyExit, + Scope, +} from '@/keyboard'; import { useHotkeysContext } from 'react-hotkeys-hook'; import { cn } from '@/lib/utils'; import type { @@ -96,6 +101,7 @@ const TaskFormDialogImpl = NiceModal.create((props) => { const [showDiscardWarning, setShowDiscardWarning] = useState(false); const imageUploadRef = useRef(null); const [pendingFiles, setPendingFiles] = useState(null); + const forceCreateOnlyRef = useRef(false); const { data: branches, isLoading: branchesLoading } = useProjectBranches(projectId); @@ -184,7 +190,8 @@ const TaskFormDialogImpl = NiceModal.create((props) => { image_ids: imageIds, shared_task_id: null, }; - if (value.autoStart) { + const shouldAutoStart = value.autoStart && !forceCreateOnlyRef.current; + if (shouldAutoStart) { await createAndStart.mutateAsync( { task, @@ -201,7 +208,11 @@ const TaskFormDialogImpl = NiceModal.create((props) => { const validator = (value: TaskFormValues): string | undefined => { if (!value.title.trim().length) return 'need title'; - if (value.autoStart && (!value.executorProfileId || !value.branch)) { + if ( + value.autoStart && + !forceCreateOnlyRef.current && + (!value.executorProfileId || !value.branch) + ) { return 'need executor profile or branch;'; } }; @@ -309,6 +320,26 @@ const TaskFormDialogImpl = NiceModal.create((props) => { preventDefault: true, }); + const canSubmitAlt = useStore( + form.store, + (state) => state.values.title.trim().length > 0 && !state.isSubmitting + ); + + const handleSubmitCreateOnly = useCallback(() => { + forceCreateOnlyRef.current = true; + const promise = form.handleSubmit(); + Promise.resolve(promise).finally(() => { + forceCreateOnlyRef.current = false; + }); + }, [form]); + + useKeySubmitTaskAlt(handleSubmitCreateOnly, { + enabled: modal.visible && canSubmitAlt && !showDiscardWarning, + scope: Scope.DIALOG, + enableOnFormTags: ['input', 'INPUT', 'textarea', 'TEXTAREA'], + preventDefault: true, + }); + // Dialog close handling const handleDialogClose = (open: boolean) => { if (open) return;