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

62 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-03-21 21:15:27 +00:00
import { auth } from '@clerk/nextjs/server';
2024-02-16 01:49:19 +00:00
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(props: {
params: Promise<{ boardId: string }>;
2024-02-15 02:30:10 +00:00
}) {
const params = await props.params;
2024-02-15 02:30:10 +00:00
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 (props: {
2024-02-15 02:30:10 +00:00
children: React.ReactNode;
params: Promise<{ boardId: string }>;
2024-02-15 02:30:10 +00:00
}) => {
const params = await props.params;
const { children } = props;
2024-02-15 02:30:10 +00:00
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;