import { useEffect } from "react"; import { useQuery } from "@tanstack/react-query"; import { goalsApi } from "../api/goals"; import { useCompany } from "../context/CompanyContext"; import { useDialog } from "../context/DialogContext"; import { useBreadcrumbs } from "../context/BreadcrumbContext"; import { queryKeys } from "../lib/queryKeys"; import { GoalTree } from "../components/GoalTree"; import { EmptyState } from "../components/EmptyState"; import { PageSkeleton } from "../components/PageSkeleton"; import { Button } from "@/components/ui/button"; import { Target, Plus } from "lucide-react"; export function Goals() { const { selectedCompanyId } = useCompany(); const { openNewGoal } = useDialog(); const { setBreadcrumbs } = useBreadcrumbs(); useEffect(() => { setBreadcrumbs([{ label: "Goals" }]); }, [setBreadcrumbs]); const { data: goals, isLoading, error } = useQuery({ queryKey: queryKeys.goals.list(selectedCompanyId!), queryFn: () => goalsApi.list(selectedCompanyId!), enabled: !!selectedCompanyId, }); if (!selectedCompanyId) { return ; } if (isLoading) { return ; } return (
{error &&

{error.message}

} {goals && goals.length === 0 && ( openNewGoal()} /> )} {goals && goals.length > 0 && ( <>
`/goals/${goal.id}`} /> )}
); }