"use client"; import { memo } from "react"; import { IconLoader2, IconFileInvoice, IconSend, IconChevronDown, IconPlus, } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { DialogClose } from "@kandev/ui/dialog"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@kandev/ui/dropdown-menu"; import { SHORTCUTS } from "@/lib/keyboard/constants"; import { KeyboardShortcutTooltip } from "@/components/keyboard-shortcut-tooltip"; type UpdateButtonProps = { isCreatingTask: boolean; hasTitle: boolean; onUpdate: () => void; }; function UpdateButton({ isCreatingTask, hasTitle, onUpdate }: UpdateButtonProps) { return ( ); } type StartTaskSplitButtonProps = { isCreatingTask: boolean; disabled: boolean; altDisabled: boolean; isEditMode: boolean; onAltAction: () => void; onPlanModeAction?: () => void; }; function StartTaskSplitButton({ isCreatingTask, disabled, altDisabled, isEditMode, onAltAction, onPlanModeAction, }: StartTaskSplitButtonProps) { const altLabel = isEditMode ? "Update task" : "Create only"; return (
{onPlanModeAction && ( Start task in plan mode )} {isEditMode ? "Update task" : "Create without starting agent"}
{/* Mobile-only: visible buttons for plan mode and creating without agent */} {onPlanModeAction && ( )}
); } type DefaultSubmitButtonProps = { isCreatingSession: boolean; isCreatingTask: boolean; isSessionMode: boolean; isCreateMode: boolean; isEditMode: boolean; hasDescription: boolean; disabled: boolean; }; function DefaultSubmitButton({ isCreatingSession, isCreatingTask, isSessionMode, isCreateMode, isEditMode, hasDescription, disabled, }: DefaultSubmitButtonProps) { const planModeStyle = isCreateMode && !hasDescription ? "bg-blue-600 border-blue-500 text-white hover:bg-blue-700 hover:text-white" : ""; return ( ); } export type TaskCreateDialogFooterProps = { isSessionMode: boolean; isCreateMode: boolean; isEditMode: boolean; isTaskStarted: boolean; isCreatingSession: boolean; isCreatingTask: boolean; hasTitle: boolean; hasDescription: boolean; hasRepositorySelection: boolean; /** * True when every selected repo has a base branch picked (and the URL flow's * branch, if active). Was previously `branch: string` for the single-repo * primary; now aggregated upstream because each row has its own branch. */ hasAllBranches: boolean; agentProfileId: string; workspaceId: string | null; effectiveWorkflowId: string | null; executorHint: string | null; noCompatibleAgent: boolean; executorProfileName: string | null; onCancel: () => void; onUpdateWithoutAgent: () => void; onCreateWithoutAgent: () => void; onCreateWithPlanMode?: () => void; /** * Externally-supplied reason that the submit buttons are disabled (e.g. an * async bootstrap step from a feature wrapper hasn't finished yet). When set, * every submit variant is disabled and the tooltip shows this string instead * of the usual missing-field reason. */ submitBlockedReason?: string | null; }; function isMissingWorkflowCtx( isCreateMode: boolean, workspaceId: string | null, effectiveWorkflowId: string | null, ) { return isCreateMode && (!workspaceId || !effectiveWorkflowId); } function computeBaseDisabled(props: TaskCreateDialogFooterProps) { const missingCtx = isMissingWorkflowCtx( props.isCreateMode, props.workspaceId, props.effectiveWorkflowId, ); return ( props.isCreatingTask || !props.hasTitle || !props.hasRepositorySelection || !props.hasAllBranches || missingCtx || props.noCompatibleAgent ); } export type ButtonKind = "update" | "start-task" | "default"; export const REASON_TITLE = "Add a task title"; export const REASON_REPO = "Select a repository"; export const REASON_BRANCH = "Select a branch"; export const REASON_WORKSPACE = "Select a workspace"; export const REASON_WORKFLOW = "Select a workflow"; export const REASON_AGENT = "Select an agent"; export const REASON_DESCRIPTION = "Add a session description"; function noCompatibleAgentReason(executorProfileName: string | null): string { const target = executorProfileName ? `“${executorProfileName}”` : "this executor"; return `No compatible agent profile is configured for ${target}. Configure agent credentials in Settings → Executors.`; } function baseReason(props: TaskCreateDialogFooterProps): string | null { if (!props.hasTitle) return REASON_TITLE; if (!props.hasRepositorySelection) return REASON_REPO; if (!props.hasAllBranches) return REASON_BRANCH; if (props.isCreateMode && !props.workspaceId) return REASON_WORKSPACE; if (props.isCreateMode && !props.effectiveWorkflowId) return REASON_WORKFLOW; if (props.noCompatibleAgent) return noCompatibleAgentReason(props.executorProfileName); return null; } function sessionDefaultReason(props: TaskCreateDialogFooterProps): string | null { if (props.noCompatibleAgent) return noCompatibleAgentReason(props.executorProfileName); if (!props.agentProfileId) return REASON_AGENT; if (!props.hasDescription) return REASON_DESCRIPTION; return null; } export function computeDisabledReason( props: TaskCreateDialogFooterProps, kind: ButtonKind, ): string | null { if (props.isCreatingTask) return null; if (props.submitBlockedReason) return props.submitBlockedReason; if (kind === "update") return props.hasTitle ? null : REASON_TITLE; if (kind === "default" && props.isSessionMode) return sessionDefaultReason(props); const base = baseReason(props); if (base) return base; if (kind === "start-task" && !props.agentProfileId) return REASON_AGENT; return null; } function resolveButtonKind(props: TaskCreateDialogFooterProps, showStartTask: boolean): ButtonKind { if (props.isTaskStarted) return "update"; if (showStartTask) return "start-task"; return "default"; } function computeFooterState(props: TaskCreateDialogFooterProps) { const showStartTask = (props.isCreateMode && props.hasDescription) || Boolean(props.isEditMode && props.agentProfileId); const blocked = Boolean(props.submitBlockedReason); const altDisabled = computeBaseDisabled(props) || blocked; const splitDisabled = altDisabled || !props.agentProfileId; // Session mode previously only gated on missing agent — it ignored // noCompatibleAgent, so a user who switched executor after picking an // agent could still submit a known-incompatible combination. The reason // text already surfaces noCompatibleAgentReason in this branch (see // sessionDefaultReason), so the disable gate needs to match. const sessionDisabled = !props.agentProfileId || props.noCompatibleAgent; const defaultDisabled = (props.isSessionMode ? sessionDisabled : altDisabled) || blocked; const disabledReason = computeDisabledReason(props, resolveButtonKind(props, showStartTask)); return { showStartTask, splitDisabled, altDisabled, defaultDisabled, disabledReason }; } export const TaskCreateDialogFooter = memo(function TaskCreateDialogFooter( props: TaskCreateDialogFooterProps, ) { const { isSessionMode, isCreateMode, isEditMode, isTaskStarted, isCreatingSession, isCreatingTask, hasTitle, hasDescription, executorHint, onCancel, onUpdateWithoutAgent, onCreateWithoutAgent, onCreateWithPlanMode, } = props; const { showStartTask, splitDisabled, altDisabled, defaultDisabled, disabledReason } = computeFooterState(props); return ( <> {!isSessionMode && !isTaskStarted && executorHint && (
{executorHint}
)} {(() => { if (isTaskStarted) { return ( ); } if (showStartTask) { return ( ); } return ( ); })()} ); });