flowstate/app/(app)/trash/page.tsx

42 lines
1.2 KiB
TypeScript

/**
* @file trash/page.tsx
* @description Server component rendering the trash management view using the TaskService.
*/
import { auth } from "@/auth";
import { redirect } from "next/navigation";
import TrashList from "../trash/TrashList";
import TrashHeader from "../trash/components/TrashHeader";
import { TaskService } from "@/services/task.service";
import { Task } from "@/types/task";
/**
* Renders the trash page verifying user authentication, querying soft-deleted tasks,
* and passing them down to the list and header components.
*
* @async
* @returns {Promise<JSX.Element>} The rendered trash page component.
*/
export default async function TrashPage() {
const session = await auth();
if (!session?.user?.id) redirect("/login");
const currentUserId = session.user.id;
const rawTrashedTasks =
await TaskService.findTrashTasksForUser(currentUserId);
const tasks: Task[] = rawTrashedTasks.map(({ task, user }) => ({
...task,
creator: user,
assignees: [],
isCreator: task.userId === currentUserId,
}));
return (
<div className="space-y-8 max-w-7xl mx-auto pb-12">
<TrashHeader />
<TrashList tasks={tasks} />
</div>
);
}