import { useState, useCallback } from "react"; import { GitPullRequest, ExternalLink, RefreshCw, Plus, MessageSquare, CircleDot, XCircle, GitMerge } from "lucide-react"; import type { PrInfo } from "@fusion/core"; import { createPr, refreshPrStatus, type PrRefreshResponse } from "../api"; import type { ToastType } from "../hooks/useToast"; interface PrSectionProps { taskId: string; projectId?: string; prInfo?: PrInfo; automationStatus?: string | null; hasGitHubToken: boolean; onPrCreated: (prInfo: PrInfo) => void; onPrUpdated: (prInfo: PrInfo) => void; addToast: (message: string, type?: ToastType) => void; } const STATUS_ICONS: Record = { open: , closed: , merged: , }; export function PrSection({ taskId, projectId, prInfo, automationStatus, hasGitHubToken, onPrCreated, onPrUpdated, addToast, }: PrSectionProps) { const [showCreateForm, setShowCreateForm] = useState(false); const [prTitle, setPrTitle] = useState(""); const [prBody, setPrBody] = useState(""); const [isCreating, setIsCreating] = useState(false); const [isRefreshing, setIsRefreshing] = useState(false); const [refreshState, setRefreshState] = useState(null); const handleCreate = useCallback(async () => { if (!prTitle.trim()) return; setIsCreating(true); try { const newPr = await createPr(taskId, { title: prTitle.trim(), body: prBody.trim() || undefined, }, projectId); onPrCreated(newPr); setShowCreateForm(false); setPrTitle(""); setPrBody(""); addToast(`Created PR #${newPr.number}`, "success"); } catch (err: any) { addToast(err.message || "Failed to create PR", "error"); } finally { setIsCreating(false); } }, [taskId, prTitle, prBody, projectId, onPrCreated, addToast]); const handleRefresh = useCallback(async () => { if (!prInfo) return; setIsRefreshing(true); try { const updated = await refreshPrStatus(taskId, projectId); setRefreshState(updated); onPrUpdated(updated.prInfo); addToast("PR status refreshed", "success"); } catch (err: any) { addToast(err.message || "Failed to refresh PR", "error"); } finally { setIsRefreshing(false); } }, [taskId, prInfo, projectId, onPrUpdated, addToast]); // No PR yet - show create button or automation state if (!prInfo) { if (automationStatus === "creating-pr") { return (

Pull Request

fn is creating a pull request automatically for this task.
); } if (showCreateForm) { return (

Create Pull Request

setPrTitle(e.target.value)} disabled={isCreating} className="pr-input" />