"use client"; import type { JiraTicket } from "@/lib/types/jira"; import type { LinearIssue } from "@/lib/types/linear"; import { Dialog, DialogContent, DialogHeader, DialogFooter } from "@kandev/ui/dialog"; import type { AgentProfileOption } from "@/lib/state/slices"; import type { useKeyboardShortcutHandler } from "@/hooks/use-keyboard-shortcut"; import { TaskCreateDialogFooter } from "@/components/task-create-dialog-footer"; import { DiscardLocalChangesDialog } from "@/components/discard-local-changes-dialog"; import { DialogHeaderContent } from "@/components/task-create-dialog-header"; import { CreateEditSelectors, SessionSelectors, WorkflowSection, DialogPromptSection, } from "@/components/task-create-dialog-form-body"; import { useBranchOptions, useAgentProfileOptions } from "@/components/task-create-dialog-options"; import { BranchSelector, AgentSelector, ExecutorProfileSelector, } from "@/components/task-create-dialog-selectors"; import { useTaskSubmitHandlers } from "@/components/task-create-dialog-submit"; import { type DialogFormState } from "@/components/task-create-dialog-state"; import { useTaskCreateDialogSetup, type TaskCreateDialogProps, } from "@/components/task-create-dialog-setup"; type DialogFormBodyProps = { isSessionMode: boolean; isCreateMode: boolean; isTaskStarted: boolean; isPassthroughProfile: boolean; initialDescription: string; hasDescription: boolean; workspaceId: string | null; onJiraImport?: (ticket: JiraTicket) => void; onLinearImport?: (issue: LinearIssue) => void; branchOptions: ReturnType; branchesLoading: boolean; onRefreshBranches: () => void; branchesFetchedAt?: string; branchesFetchError?: string; agentProfileOptions: ReturnType; executorProfileOptions: Array<{ value: string; label: string; renderLabel?: () => React.ReactNode; }>; agentProfiles: AgentProfileOption[]; agentProfilesLoading: boolean; executorsLoading: boolean; isCreatingSession: boolean; workflows: unknown[]; snapshots: unknown; effectiveWorkflowId: string | null; fs: DialogFormState; handleKeyDown: ReturnType; onBranchChange: (v: string) => void; onAgentProfileChange: (v: string) => void; onExecutorProfileChange: (v: string) => void; onWorkflowChange: (v: string) => void; hasRepositorySelection: boolean; isLocalExecutor: boolean; enhance?: { onEnhance: () => void; isLoading: boolean; isConfigured: boolean }; workflowAgentLocked: boolean; onToggleFreshBranch: (enabled: boolean) => void; extraFormSlot?: React.ReactNode; lockedFields?: TaskCreateDialogProps["lockedFields"]; descriptionPlaceholder?: string; aboveDescriptionSlot?: React.ReactNode; bottomSlot?: React.ReactNode; }; // eslint-disable-next-line max-lines-per-function -- thin pass-through; each section already factored into its own component function DialogFormBody(p: DialogFormBodyProps) { const { isSessionMode, isCreateMode, isTaskStarted, branchOptions, branchesLoading, onRefreshBranches, branchesFetchedAt, branchesFetchError, agentProfileOptions, executorProfileOptions, agentProfiles, agentProfilesLoading, executorsLoading, isCreatingSession, workflows, snapshots, effectiveWorkflowId, fs, onBranchChange, onAgentProfileChange, onExecutorProfileChange, onWorkflowChange, hasRepositorySelection, isLocalExecutor, workflowAgentLocked, onToggleFreshBranch, lockedFields, } = p; return (
{!isSessionMode && renderCreateEditSelectors({ isTaskStarted, hasRepositorySelection, branchOptions, branchesLoading, onRefreshBranches, branchesFetchedAt, branchesFetchError, agentProfiles, agentProfilesLoading, agentProfileOptions, isCreatingSession, executorProfileOptions, executorsLoading, isLocalExecutor, workflowAgentLocked, fs, onBranchChange, onAgentProfileChange, onExecutorProfileChange, onToggleFreshBranch, branchLocked: !!lockedFields?.branch, })} {!lockedFields?.workflow && ( [0]["workflows"]} snapshots={snapshots as Parameters[0]["snapshots"]} effectiveWorkflowId={effectiveWorkflowId} onWorkflowChange={onWorkflowChange} agentProfiles={agentProfiles} /> )} {isSessionMode && ( )} {p.bottomSlot}
); } type CreateEditSelectorsRenderArgs = Pick< DialogFormBodyProps, | "isTaskStarted" | "hasRepositorySelection" | "branchOptions" | "branchesLoading" | "onRefreshBranches" | "branchesFetchedAt" | "branchesFetchError" | "agentProfiles" | "agentProfilesLoading" | "agentProfileOptions" | "isCreatingSession" | "executorProfileOptions" | "executorsLoading" | "isLocalExecutor" | "workflowAgentLocked" | "fs" | "onBranchChange" | "onAgentProfileChange" | "onExecutorProfileChange" | "onToggleFreshBranch" > & { branchLocked?: boolean }; function renderCreateEditSelectors(args: CreateEditSelectorsRenderArgs) { const { fs } = args; return ( ); } type DialogFormProps = { setup: ReturnType; workspaceId: string | null; extraFormSlot?: React.ReactNode; lockedFields?: TaskCreateDialogProps["lockedFields"]; descriptionPlaceholder?: string; aboveDescriptionSlot?: React.ReactNode; bottomSlot?: React.ReactNode; }; function DialogForm({ setup, workspaceId, extraFormSlot, lockedFields, descriptionPlaceholder, aboveDescriptionSlot, bottomSlot, }: DialogFormProps) { const { fs, isSessionMode, isCreateMode, isTaskStarted, workflows, agentProfiles } = setup; const { snapshots, branchesLoading, computed, handlers, handleKeyDown } = setup; const { handleJiraImport, handleLinearImport, refreshBranches, branchesFetchedAt } = setup; const { branchesFetchError } = setup; const { handleSubmit, handleUpdateWithoutAgent, handleCreateWithoutAgent } = setup.submitHandlers; const { handleCreateWithPlanMode, handleCancel } = setup.submitHandlers; return (
); } export function TaskCreateDialog(props: TaskCreateDialogProps) { const setup = useTaskCreateDialogSetup(props); const { fs, computed, handlers } = setup; return ( ); } type RenderHeaderProps = { initialTitle: string | undefined; workspaceId: string | null | undefined; isCreateMode: boolean; isEditMode: boolean; isTaskStarted: boolean; sessionRepoName: string | null | undefined; fs: ReturnType["fs"]; repositoriesLoading: boolean; computed: ReturnType["computed"]; handlers: ReturnType["handlers"]; repositoryLocked?: boolean; }; function RenderHeader(props: RenderHeaderProps) { const { fs, computed, handlers } = props; return ( ); } function PendingDiscardModal({ pending, }: { pending: ReturnType["pendingDiscard"]; }) { if (!pending) return null; return ( { if (!next) pending.resolve(false); }} dirtyFiles={pending.dirtyFiles} repoPath={pending.repoPath} onConfirm={() => pending.resolve(true)} onCancel={() => pending.resolve(false)} /> ); }