diff --git a/src/app/dashboard/[teamId]/_components/dashboard-metric-card.tsx b/src/app/dashboard/[teamId]/_components/dashboard-metric-card.tsx index 50a84364..f1a1a758 100644 --- a/src/app/dashboard/[teamId]/_components/dashboard-metric-card.tsx +++ b/src/app/dashboard/[teamId]/_components/dashboard-metric-card.tsx @@ -12,12 +12,15 @@ import { } from "@/components/ui/tooltip"; import { isDevMode } from "@/lib/dev-mode"; import type { ChartTransformResult } from "@/lib/metrics/transformer-types"; -import type { DashboardChartWithRelations } from "@/types/dashboard"; +import { type RouterOutputs } from "@/trpc/react"; import { useDashboard } from "./dashboard-context"; import { DashboardMetricChart } from "./dashboard-metric-chart"; import { MetricSettingsDrawer } from "./metric-settings-drawer"; +type DashboardChartWithRelations = + RouterOutputs["dashboard"]["getDashboardCharts"][number]; + interface DashboardMetricCardProps { dashboardChart: DashboardChartWithRelations; teamId: string; diff --git a/src/app/dashboard/[teamId]/_components/dashboard-metric-drawer.tsx b/src/app/dashboard/[teamId]/_components/dashboard-metric-drawer.tsx index 18f31082..497317a7 100644 --- a/src/app/dashboard/[teamId]/_components/dashboard-metric-drawer.tsx +++ b/src/app/dashboard/[teamId]/_components/dashboard-metric-drawer.tsx @@ -8,7 +8,7 @@ import { Loader2 } from "lucide-react"; import { getLatestMetricValue } from "@/lib/metrics/get-latest-value"; import type { ChartTransformResult } from "@/lib/metrics/transformer-types"; import { cn } from "@/lib/utils"; -import { api } from "@/trpc/react"; +import { type RouterOutputs, api } from "@/trpc/react"; import { useDashboard } from "./dashboard-context"; import { DashboardMetricChart } from "./dashboard-metric-chart"; @@ -20,6 +20,9 @@ import { SettingsTabContent, } from "./drawer"; +type DashboardChartWithRelations = + RouterOutputs["dashboard"]["getDashboardCharts"][number]; + interface DashboardMetricDrawerProps { dashboardChartId: string; teamId: string; diff --git a/src/app/dashboard/[teamId]/_components/metric-settings-drawer.tsx b/src/app/dashboard/[teamId]/_components/metric-settings-drawer.tsx index 640b8805..b8f4b4d6 100644 --- a/src/app/dashboard/[teamId]/_components/metric-settings-drawer.tsx +++ b/src/app/dashboard/[teamId]/_components/metric-settings-drawer.tsx @@ -31,12 +31,15 @@ import { import type { ChartTransformResult } from "@/lib/metrics/transformer-types"; import { getPlatformConfig } from "@/lib/platform-config"; import { cn } from "@/lib/utils"; -import type { DashboardChartWithRelations } from "@/types/dashboard"; +import { type RouterOutputs } from "@/trpc/react"; import { useDashboard } from "./dashboard-context"; import { DashboardMetricDrawer } from "./dashboard-metric-drawer"; import { useMetricDrawerMutations } from "./use-metric-drawer-mutations"; +type DashboardChartWithRelations = + RouterOutputs["dashboard"]["getDashboardCharts"][number]; + interface MetricSettingsDrawerProps { dashboardChart: DashboardChartWithRelations; teamId: string; diff --git a/src/app/dashboard/[teamId]/_components/use-dashboard-charts.ts b/src/app/dashboard/[teamId]/_components/use-dashboard-charts.ts index 271a65c1..cfee2f7f 100644 --- a/src/app/dashboard/[teamId]/_components/use-dashboard-charts.ts +++ b/src/app/dashboard/[teamId]/_components/use-dashboard-charts.ts @@ -2,8 +2,10 @@ import { useCallback } from "react"; -import { api } from "@/trpc/react"; -import type { DashboardChartWithRelations } from "@/types/dashboard"; +import { type RouterOutputs, api } from "@/trpc/react"; + +type DashboardChartWithRelations = + RouterOutputs["dashboard"]["getDashboardCharts"][number]; export interface UseDashboardChartsReturn { charts: DashboardChartWithRelations[]; diff --git a/src/app/metric/_components/base/MetricDialogBase.tsx b/src/app/metric/_components/base/MetricDialogBase.tsx index 9333b257..aa7bdd27 100644 --- a/src/app/metric/_components/base/MetricDialogBase.tsx +++ b/src/app/metric/_components/base/MetricDialogBase.tsx @@ -14,8 +14,10 @@ import { DialogTrigger, } from "@/components/ui/dialog"; import { cn } from "@/lib/utils"; -import { api } from "@/trpc/react"; -import type { DashboardChartWithRelations } from "@/types/dashboard"; +import { type RouterOutputs, api } from "@/trpc/react"; + +type DashboardChartWithRelations = + RouterOutputs["dashboard"]["getDashboardCharts"][number]; export interface MetricCreateInput { templateId: string; diff --git a/src/app/metric/_components/manual/ManualMetricContent.tsx b/src/app/metric/_components/manual/ManualMetricContent.tsx index d712a07a..4c273747 100644 --- a/src/app/metric/_components/manual/ManualMetricContent.tsx +++ b/src/app/metric/_components/manual/ManualMetricContent.tsx @@ -8,11 +8,13 @@ import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; -import { api } from "@/trpc/react"; -import type { DashboardChartWithRelations } from "@/types/dashboard"; +import { type RouterOutputs, api } from "@/trpc/react"; import { type PeriodRange, PeriodRangeStep } from "./period-range-step"; +type DashboardChartWithRelations = + RouterOutputs["dashboard"]["getDashboardCharts"][number]; + type UnitType = "number" | "percentage"; type Cadence = "daily" | "weekly" | "monthly"; diff --git a/src/lib/goals/types.ts b/src/lib/goals/types.ts index 4a0fc6db..2dbbb0a0 100644 --- a/src/lib/goals/types.ts +++ b/src/lib/goals/types.ts @@ -1,5 +1,9 @@ -export type Cadence = "DAILY" | "WEEKLY" | "MONTHLY"; -export type GoalType = "ABSOLUTE" | "RELATIVE"; +import { Cadence, GoalType } from "@prisma/client"; + +// Re-export Prisma enums for convenience +export { Cadence, GoalType }; + +// Custom status type (not in Prisma) export type GoalStatus = | "exceeded" | "on_track" diff --git a/src/lib/metrics/transformer-types.ts b/src/lib/metrics/transformer-types.ts index d2fd29c9..34433db0 100644 --- a/src/lib/metrics/transformer-types.ts +++ b/src/lib/metrics/transformer-types.ts @@ -2,11 +2,16 @@ * Types for AI-generated transformer code * Used by both MetricTransformer and ChartTransformer */ +import { Cadence } from "@prisma/client"; + import type { ChartType } from "./utils"; // Re-export ChartType for convenience export type { ChartType } from "./utils"; +// Re-export Prisma enum for convenience +export { Cadence }; + // ============================================================================= // Data Point Types // ============================================================================= @@ -83,14 +88,10 @@ export type MetricTransformFn = ( context: TransformContext, ) => DataPoint[]; -/** - * Cadence determines how data is aggregated for chart display - */ -export type Cadence = "DAILY" | "WEEKLY" | "MONTHLY"; - /** * Function signature for ChartTransformer code * Transforms DataPoints into chart-ready configuration + * Cadence is re-exported from Prisma above */ export type ChartTransformFn = ( dataPoints: DataPoint[], diff --git a/src/server/api/utils/enrich-charts-with-goal-progress.ts b/src/server/api/utils/enrich-charts-with-goal-progress.ts index b6e074ab..c2c4bd6a 100644 --- a/src/server/api/utils/enrich-charts-with-goal-progress.ts +++ b/src/server/api/utils/enrich-charts-with-goal-progress.ts @@ -10,6 +10,8 @@ import type { ChartTransformResult } from "@/lib/metrics/transformer-types"; /** * Dashboard chart with metric and chartTransformer included + * NOTE: This type must be manually defined here to avoid circular dependency. + * Cannot use tRPC RouterOutputs because AppRouter depends on this util file. */ type DashboardChartWithRelations = { id: string; diff --git a/src/types/dashboard.ts b/src/types/dashboard.ts deleted file mode 100644 index e94be7c3..00000000 --- a/src/types/dashboard.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { RouterOutputs } from "@/trpc/react"; - -export type DashboardChartWithRelations = - RouterOutputs["dashboard"]["getDashboardCharts"][number];