import { useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import { goalsApi } from "../api/goals"; import { useCompany } from "../context/CompanyContext"; import { useBreadcrumbs } from "../context/BreadcrumbContext"; import { queryKeys } from "../lib/queryKeys"; import { GoalTree } from "../components/GoalTree"; import { EmptyState } from "../components/EmptyState"; import { Target } from "lucide-react"; export function Goals() { const { selectedCompanyId } = useCompany(); const { setBreadcrumbs } = useBreadcrumbs(); const navigate = useNavigate(); 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 ; } return (
{isLoading &&

Loading...

} {error &&

{error.message}

} {goals && goals.length === 0 && ( {/* TODO: goal creation */}} /> )} {goals && goals.length > 0 && ( navigate(`/goals/${goal.id}`)} /> )}
); }