import { useState } from "react"; import { Link } from "@/lib/router"; import { useQuery } from "@tanstack/react-query"; import type { Goal } from "@paperclipai/shared"; import { GOAL_STATUSES, GOAL_LEVELS } from "@paperclipai/shared"; import { agentsApi } from "../api/agents"; import { goalsApi } from "../api/goals"; import { useCompany } from "../context/CompanyContext"; import { queryKeys } from "../lib/queryKeys"; import { StatusBadge } from "./StatusBadge"; import { formatDate, cn, agentUrl } from "../lib/utils"; import { Separator } from "@/components/ui/separator"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; interface GoalPropertiesProps { goal: Goal; onUpdate?: (data: Record) => void; } function PropertyRow({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); } function label(s: string): string { return s.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()); } function PickerButton({ current, options, onChange, children, }: { current: string; options: readonly string[]; onChange: (value: string) => void; children: React.ReactNode; }) { const [open, setOpen] = useState(false); return ( {options.map((opt) => ( ))} ); } export function GoalProperties({ goal, onUpdate }: GoalPropertiesProps) { const { selectedCompanyId } = useCompany(); const { data: agents } = useQuery({ queryKey: queryKeys.agents.list(selectedCompanyId!), queryFn: () => agentsApi.list(selectedCompanyId!), enabled: !!selectedCompanyId, }); const { data: allGoals } = useQuery({ queryKey: queryKeys.goals.list(selectedCompanyId!), queryFn: () => goalsApi.list(selectedCompanyId!), enabled: !!selectedCompanyId, }); const ownerAgent = goal.ownerAgentId ? agents?.find((a) => a.id === goal.ownerAgentId) : null; const parentGoal = goal.parentId ? allGoals?.find((g) => g.id === goal.parentId) : null; return (
{onUpdate ? ( onUpdate({ status })} > ) : ( )} {onUpdate ? ( onUpdate({ level })} > {goal.level} ) : ( {goal.level} )} {ownerAgent ? ( {ownerAgent.name} ) : ( None )} {goal.parentId && ( {parentGoal?.title ?? goal.parentId.slice(0, 8)} )}
{formatDate(goal.createdAt)} {formatDate(goal.updatedAt)}
); }