diff --git a/archon-ui-main/src/features/agent-work-orders/components/CreateWorkOrderDialog.tsx b/archon-ui-main/src/features/agent-work-orders/components/CreateWorkOrderDialog.tsx new file mode 100644 index 00000000..a3ed9bf6 --- /dev/null +++ b/archon-ui-main/src/features/agent-work-orders/components/CreateWorkOrderDialog.tsx @@ -0,0 +1,237 @@ +/** + * CreateWorkOrderDialog Component + * + * Modal dialog for creating new agent work orders with form validation. + * Includes repository URL, sandbox type, user request, and command selection. + */ + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useId, useState } from "react"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; +import { Button } from "@/features/ui/primitives/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/features/ui/primitives/dialog"; +import { useCreateWorkOrder } from "../hooks/useAgentWorkOrderQueries"; +import type { WorkflowStep } from "../types"; + +const workOrderSchema = z.object({ + repository_url: z.string().url("Must be a valid URL"), + sandbox_type: z.enum(["git_branch", "git_worktree"]), + user_request: z.string().min(10, "Request must be at least 10 characters"), + github_issue_number: z.string().optional(), +}); + +type WorkOrderFormData = z.infer; + +interface CreateWorkOrderDialogProps { + /** Whether dialog is open */ + open: boolean; + /** Callback when dialog should close */ + onClose: () => void; + /** Callback when work order is created */ + onSuccess?: (workOrderId: string) => void; +} + +const ALL_COMMANDS: WorkflowStep[] = ["create-branch", "planning", "execute", "commit", "create-pr"]; + +const COMMAND_LABELS: Record = { + "create-branch": "Create Branch", + planning: "Planning", + execute: "Execute", + commit: "Commit", + "create-pr": "Create PR", + "prp-review": "PRP Review", +}; + +export function CreateWorkOrderDialog({ open, onClose, onSuccess }: CreateWorkOrderDialogProps) { + const [selectedCommands, setSelectedCommands] = useState(ALL_COMMANDS); + const createWorkOrder = useCreateWorkOrder(); + const formId = useId(); + + const { + register, + handleSubmit, + formState: { errors }, + reset, + } = useForm({ + resolver: zodResolver(workOrderSchema), + defaultValues: { + sandbox_type: "git_branch", + }, + }); + + const handleClose = () => { + reset(); + setSelectedCommands(ALL_COMMANDS); + onClose(); + }; + + const onSubmit = async (data: WorkOrderFormData) => { + createWorkOrder.mutate( + { + ...data, + selected_commands: selectedCommands, + github_issue_number: data.github_issue_number || null, + }, + { + onSuccess: (result) => { + handleClose(); + onSuccess?.(result.agent_work_order_id); + }, + }, + ); + }; + + const toggleCommand = (command: WorkflowStep) => { + setSelectedCommands((prev) => (prev.includes(command) ? prev.filter((c) => c !== command) : [...prev, command])); + }; + + const setPreset = (preset: "full" | "planning" | "no-pr") => { + switch (preset) { + case "full": + setSelectedCommands(ALL_COMMANDS); + break; + case "planning": + setSelectedCommands(["create-branch", "planning"]); + break; + case "no-pr": + setSelectedCommands(["create-branch", "planning", "execute", "commit"]); + break; + } + }; + + return ( + + + + Create Agent Work Order + Configure and launch a new AI-driven development workflow + + +
+
+ + + {errors.repository_url &&

{errors.repository_url.message}

} +
+ +
+ + +
+ +
+ +