96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import { notFound } from 'next/navigation'
|
|
import { getItem } from '@/lib/actions'
|
|
import { canEditList } from '@/lib/permissions'
|
|
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/pages/api/auth/[...nextauth]'
|
|
import ItemDetail from '@/components/ItemDetail'
|
|
import Link from 'next/link'
|
|
import { ArrowLeft, Edit } from 'lucide-react'
|
|
import DeleteItemButton from '@/components/DeleteItemButton'
|
|
import ToggleItemButton from '@/components/ToggleItemButton'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
interface PageProps {
|
|
params: {
|
|
id: string
|
|
itemId: string
|
|
}
|
|
}
|
|
|
|
export default async function ItemDetailPage({ params }: PageProps) {
|
|
const session = await getServerSession(authOptions)
|
|
if (!session?.user?.id) {
|
|
notFound()
|
|
}
|
|
|
|
const itemData = await getItem(params.itemId)
|
|
|
|
if (!itemData || itemData.listId !== params.id) {
|
|
notFound()
|
|
}
|
|
|
|
// Type assertion for the item with list relation
|
|
const item = itemData as typeof itemData & {
|
|
list: {
|
|
title: string
|
|
color: string
|
|
ownerId: string
|
|
}
|
|
}
|
|
|
|
// Check if user can edit this list
|
|
const canEdit = await canEditList(session.user.id, params.id)
|
|
|
|
return (
|
|
<main className="container mx-auto px-4 sm:px-6 py-6 sm:py-8 max-w-4xl">
|
|
{/* Header Actions */}
|
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-6">
|
|
<Link
|
|
href={`/list/${params.id}`}
|
|
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 active:text-black transition-colors tap-target-sm text-sm sm:text-base"
|
|
>
|
|
<ArrowLeft size={20} className="flex-shrink-0" />
|
|
<span>Back to List</span>
|
|
</Link>
|
|
|
|
<div className="flex items-center gap-2 w-full sm:w-auto">
|
|
{canEdit && (
|
|
<>
|
|
<ToggleItemButton itemId={item.id} completed={item.completed} />
|
|
<Link
|
|
href={`/list/${params.id}/item/${params.itemId}/edit`}
|
|
className="flex items-center gap-2 px-4 sm:px-5 py-2.5 sm:py-3 bg-blue-500 hover:bg-blue-600 active:bg-blue-700 text-white rounded-lg transition-colors tap-target text-sm sm:text-base font-medium"
|
|
>
|
|
<Edit size={18} className="flex-shrink-0" />
|
|
<span>Edit</span>
|
|
</Link>
|
|
<DeleteItemButton itemId={item.id} listId={params.id} />
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Item Detail */}
|
|
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-5 sm:p-6 lg:p-8">
|
|
<ItemDetail
|
|
item={{
|
|
id: item.id,
|
|
title: item.title,
|
|
description: item.description,
|
|
completed: item.completed,
|
|
priority: item.priority,
|
|
dueDate: item.dueDate,
|
|
tags: item.tags,
|
|
notes: item.notes,
|
|
createdAt: item.createdAt,
|
|
updatedAt: item.updatedAt,
|
|
listId: item.listId,
|
|
}}
|
|
listTitle={item.list.title}
|
|
/>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|