58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
import type { Metadata } from 'next'
|
|
import { getServerSession } from 'next-auth'
|
|
import { notFound } from 'next/navigation'
|
|
import CoreMetricDetail from '@/components/department-dashboard/CoreMetricDetail'
|
|
import { getCoreMetric } from '@/components/department-dashboard/core-metrics'
|
|
import { authOptions } from '@/lib/auth'
|
|
import {
|
|
getMonthlyLaunchInsights,
|
|
getOngoingDingWorkflowInsights,
|
|
} from '@/lib/ding-workflow-sync'
|
|
import {
|
|
getFirstPassReviewProjects,
|
|
} from '@/lib/work-review-service'
|
|
|
|
type CoreMetricPageProps = {
|
|
params: { section: string; item: string; metric: string }
|
|
searchParams?: { page?: string; q?: string }
|
|
}
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export function generateMetadata({ params }: CoreMetricPageProps): Metadata {
|
|
const metric = getCoreMetric(params.metric)
|
|
if (params.section !== 'dashboard' || params.item !== 'core-metrics' || !metric) return {}
|
|
return {
|
|
title: `${metric.label} | 核心指标 | 品牌中心部门看板`,
|
|
description: metric.detailDescription,
|
|
}
|
|
}
|
|
|
|
export default async function CoreMetricPage({ params, searchParams }: CoreMetricPageProps) {
|
|
const metric = getCoreMetric(params.metric)
|
|
if (params.section !== 'dashboard' || params.item !== 'core-metrics' || !metric) notFound()
|
|
|
|
const page = Math.max(1, Number(searchParams?.page || 1) || 1)
|
|
const query = String(searchParams?.q || '').trim().slice(0, 100)
|
|
|
|
if (metric.key === 'ongoing-projects') {
|
|
const session = await getServerSession(authOptions)
|
|
const projectInsights = await getOngoingDingWorkflowInsights(session)
|
|
return <CoreMetricDetail metric={metric} projectInsights={projectInsights} />
|
|
}
|
|
|
|
if (metric.key === 'monthly-launches') {
|
|
const session = await getServerSession(authOptions)
|
|
const monthlyLaunches = await getMonthlyLaunchInsights(session)
|
|
return <CoreMetricDetail metric={metric} monthlyLaunches={monthlyLaunches} />
|
|
}
|
|
|
|
if (metric.key === 'first-pass-rate') {
|
|
const session = await getServerSession(authOptions)
|
|
const firstPassPage = await getFirstPassReviewProjects(session, { page, pageSize: 20, query })
|
|
return <CoreMetricDetail metric={metric} query={query} firstPassPage={firstPassPage} />
|
|
}
|
|
|
|
return <CoreMetricDetail metric={metric} />
|
|
}
|