|
1 | | -import { auth } from "@/auth"; |
2 | | -import { CreateTaskSheet } from "@/components/create-task-sheet"; |
3 | | -import { TasksView } from "@/components/tasks-view"; |
4 | | -import { can } from "@/lib/acl"; |
5 | | -import { prisma } from "@/lib/db"; |
6 | | -import type { TaskListItem } from "@/types/task"; |
7 | | -import { notFound, redirect } from "next/navigation"; |
| 1 | +import { auth } from '@/auth' |
| 2 | +import { CreateTaskSheet } from '@/components/create-task-sheet' |
| 3 | +import { TasksView } from '@/components/tasks-view' |
| 4 | +import { can } from '@/lib/acl' |
| 5 | +import { prisma } from '@/lib/db' |
| 6 | +import type { TaskListItem } from '@/types/task' |
| 7 | +import { notFound, redirect } from 'next/navigation' |
8 | 8 |
|
9 | 9 | interface ProjectDetailPageProps { |
10 | | - params: Promise<{ id: string }>; |
| 10 | + params: Promise<{ id: string }> |
11 | 11 | } |
12 | 12 |
|
13 | 13 | export default async function ProjectDetailPage({ |
14 | | - params, |
| 14 | + params, |
15 | 15 | }: ProjectDetailPageProps) { |
16 | | - const session = await auth(); |
17 | | - if (!session?.user?.id) { |
18 | | - redirect("/login"); |
19 | | - } |
| 16 | + const session = await auth() |
| 17 | + if (!session?.user?.id) { |
| 18 | + redirect('/login') |
| 19 | + } |
20 | 20 |
|
21 | | - const { id } = await params; |
| 21 | + const { id } = await params |
22 | 22 |
|
23 | | - const project = await prisma.project.findUnique({ |
24 | | - where: { id }, |
25 | | - }); |
| 23 | + const project = await prisma.project.findUnique({ |
| 24 | + where: { id }, |
| 25 | + }) |
26 | 26 |
|
27 | | - if (!project) { |
28 | | - notFound(); |
29 | | - } |
| 27 | + if (!project) { |
| 28 | + notFound() |
| 29 | + } |
30 | 30 |
|
31 | | - if ( |
32 | | - !can(session.user.id, "read", { |
33 | | - type: "project", |
34 | | - ownerId: project.userId, |
35 | | - }) |
36 | | - ) { |
37 | | - notFound(); |
38 | | - } |
| 31 | + if ( |
| 32 | + !can(session.user.id, 'read', { |
| 33 | + type: 'project', |
| 34 | + ownerId: project.userId, |
| 35 | + }) |
| 36 | + ) { |
| 37 | + notFound() |
| 38 | + } |
39 | 39 |
|
40 | | - const rows = await prisma.task.findMany({ |
41 | | - where: { projectId: id, userId: session.user.id }, |
42 | | - orderBy: { updatedAt: "desc" }, |
43 | | - include: { project: { select: { id: true, name: true } } }, |
44 | | - }); |
| 40 | + const rows = await prisma.task.findMany({ |
| 41 | + where: { projectId: id, userId: session.user.id }, |
| 42 | + orderBy: { updatedAt: 'desc' }, |
| 43 | + include: { project: { select: { id: true, name: true } } }, |
| 44 | + }) |
45 | 45 |
|
46 | | - const tasks: TaskListItem[] = rows.map((t) => ({ |
47 | | - id: t.id, |
48 | | - title: t.title, |
49 | | - description: t.description, |
50 | | - status: t.status, |
51 | | - priority: t.priority, |
52 | | - dueDate: t.dueDate?.toISOString() ?? null, |
53 | | - projectId: t.projectId, |
54 | | - project: t.project, |
55 | | - })); |
| 46 | + const tasks: TaskListItem[] = rows.map(t => ({ |
| 47 | + id: t.id, |
| 48 | + title: t.title, |
| 49 | + description: t.description, |
| 50 | + status: t.status, |
| 51 | + priority: t.priority, |
| 52 | + dueDate: t.dueDate?.toISOString() ?? null, |
| 53 | + projectId: t.projectId, |
| 54 | + project: t.project, |
| 55 | + })) |
56 | 56 |
|
57 | | - return ( |
58 | | - <main className="mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6 px-4 py-12"> |
59 | | - <section className="flex items-start justify-between gap-4"> |
60 | | - <div> |
61 | | - <p className="font-mono text-xs uppercase tracking-wider text-zinc-400"> |
62 | | - Project |
63 | | - </p> |
64 | | - <h1 className="mt-1 text-2xl font-semibold tracking-tight text-zinc-900"> |
65 | | - {project.name} |
66 | | - </h1> |
67 | | - <p className="mt-2 text-sm text-zinc-500"> |
68 | | - 仅项目所有者可访问;任务列表同样按用户隔离。 |
69 | | - </p> |
70 | | - </div> |
71 | | - <CreateTaskSheet |
72 | | - projects={[{ id: project.id, name: project.name }]} |
73 | | - defaultProjectId={project.id} |
74 | | - /> |
75 | | - </section> |
| 57 | + return ( |
| 58 | + <main className='mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6 px-4 py-12'> |
| 59 | + <section className='flex items-start justify-between gap-4'> |
| 60 | + <div> |
| 61 | + <p className='font-mono text-xs uppercase tracking-wider text-zinc-400'> |
| 62 | + Project |
| 63 | + </p> |
| 64 | + <h1 className='mt-1 text-2xl font-semibold tracking-tight text-zinc-900'> |
| 65 | + {project.name} |
| 66 | + </h1> |
| 67 | + <p className='mt-2 text-sm text-zinc-500'> |
| 68 | + 仅项目所有者可访问;任务列表同样按用户隔离。 |
| 69 | + </p> |
| 70 | + </div> |
| 71 | + <CreateTaskSheet |
| 72 | + projects={[{ id: project.id, name: project.name }]} |
| 73 | + defaultProjectId={project.id} |
| 74 | + /> |
| 75 | + </section> |
76 | 76 |
|
77 | | - <TasksView |
78 | | - tasks={tasks} |
79 | | - projects={[{ id: project.id, name: project.name }]} |
80 | | - currentQuery={{ |
81 | | - keyword: "", |
82 | | - status: "all", |
83 | | - projectId: project.id, |
84 | | - sort: "updated_desc", |
85 | | - dateFrom: "", |
86 | | - dateTo: "", |
87 | | - priority: "all", |
88 | | - }} |
89 | | - /> |
90 | | - </main> |
91 | | - ); |
| 77 | + <TasksView |
| 78 | + tasks={tasks} |
| 79 | + projects={[{ id: project.id, name: project.name }]} |
| 80 | + currentQuery={{ |
| 81 | + keyword: '', |
| 82 | + status: 'all', |
| 83 | + projectId: project.id, |
| 84 | + sort: 'updated_desc', |
| 85 | + dateFrom: '', |
| 86 | + dateTo: '', |
| 87 | + priority: 'all', |
| 88 | + view: 'list', |
| 89 | + }} |
| 90 | + /> |
| 91 | + </main> |
| 92 | + ) |
92 | 93 | } |
0 commit comments