import { useState } from "react"; import { Link } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import type { Project } from "@paperclip/shared"; import { StatusBadge } from "./StatusBadge"; import { formatDate } from "../lib/utils"; import { goalsApi } from "../api/goals"; import { useCompany } from "../context/CompanyContext"; import { queryKeys } from "../lib/queryKeys"; import { Separator } from "@/components/ui/separator"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Plus, X } from "lucide-react"; interface ProjectPropertiesProps { project: Project; onUpdate?: (data: Record) => void; } function PropertyRow({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); } export function ProjectProperties({ project, onUpdate }: ProjectPropertiesProps) { const { selectedCompanyId } = useCompany(); const [goalOpen, setGoalOpen] = useState(false); const { data: allGoals } = useQuery({ queryKey: queryKeys.goals.list(selectedCompanyId!), queryFn: () => goalsApi.list(selectedCompanyId!), enabled: !!selectedCompanyId, }); const linkedGoalIds = project.goalIds.length > 0 ? project.goalIds : project.goalId ? [project.goalId] : []; const linkedGoals = project.goals.length > 0 ? project.goals : linkedGoalIds.map((id) => ({ id, title: allGoals?.find((g) => g.id === id)?.title ?? id.slice(0, 8), })); const availableGoals = (allGoals ?? []).filter((g) => !linkedGoalIds.includes(g.id)); const removeGoal = (goalId: string) => { if (!onUpdate) return; onUpdate({ goalIds: linkedGoalIds.filter((id) => id !== goalId) }); }; const addGoal = (goalId: string) => { if (!onUpdate || linkedGoalIds.includes(goalId)) return; onUpdate({ goalIds: [...linkedGoalIds, goalId] }); setGoalOpen(false); }; return (
{project.leadAgentId && ( {project.leadAgentId.slice(0, 8)} )}
Goals
{linkedGoals.length === 0 ? ( None ) : (
{linkedGoals.map((goal) => ( {goal.title} {onUpdate && ( )} ))}
)} {onUpdate && ( {availableGoals.length === 0 ? (
All goals linked.
) : ( availableGoals.map((goal) => ( )) )}
)}
{project.targetDate && ( {formatDate(project.targetDate)} )}
{formatDate(project.createdAt)} {formatDate(project.updatedAt)}
); }