tasko/app/(platform)/(dashboard)/board/[boardId]/layout.tsx

62 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-02-16 01:49:19 +00:00
import { auth } from '@clerk/nextjs';
import { notFound, redirect } from 'next/navigation';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { db } from '@/lib/db';
import { BoardNavbar } from './_components/board-navbar';
2024-02-15 02:30:10 +00:00
export async function generateMetadata({
params,
}: {
params: { boardId: string };
}) {
const { orgId } = auth();
2024-02-16 01:49:19 +00:00
if (!orgId) return { title: 'Board' };
2024-02-15 02:30:10 +00:00
const board = await db.board.findUnique({
where: {
id: params.boardId,
orgId,
},
});
return {
2024-02-16 01:49:19 +00:00
title: board?.title ?? 'Board',
2024-02-15 02:30:10 +00:00
};
}
const BoardIdLayout = async ({
children,
params,
}: {
children: React.ReactNode;
params: { boardId: string };
}) => {
const { orgId } = auth();
2024-02-16 01:49:19 +00:00
if (!orgId) redirect('/select-org');
2024-02-15 02:30:10 +00:00
const board = await db.board.findUnique({
where: {
id: params.boardId,
orgId,
},
2024-03-17 04:48:01 +00:00
cacheStrategy: { ttl: 30, swr: 60 },
2024-02-15 02:30:10 +00:00
});
if (!board) notFound();
return (
<div
2024-02-16 01:49:19 +00:00
className='relative h-full bg-cover bg-center bg-no-repeat'
2024-02-15 02:30:10 +00:00
style={{ backgroundImage: `url(${board.imageFullUrl})` }}
>
<BoardNavbar data={board} />
2024-02-16 01:49:19 +00:00
<div className='absolute inset-0 bg-black/10' />
<main className='relative h-full pt-28'>{children}</main>
2024-02-15 02:30:10 +00:00
</div>
);
};
export default BoardIdLayout;