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';
|
2025-01-11 06:04:43 +00:00
|
|
|
import { BoardLiveblocks } from './_components/board-liveblocks';
|
2025-01-19 06:36:59 +00:00
|
|
|
import { unstable_cache } from 'next/cache';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2024-10-15 23:55:03 +00:00
|
|
|
export async function generateMetadata(props: {
|
|
|
|
params: Promise<{ boardId: string }>;
|
2024-02-15 02:30:10 +00:00
|
|
|
}) {
|
2024-10-15 23:55:03 +00:00
|
|
|
const params = await props.params;
|
2024-10-23 23:17:45 +00:00
|
|
|
const { orgId } = await auth();
|
2024-02-15 02:30:10 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-10-15 23:55:03 +00:00
|
|
|
const BoardIdLayout = async (props: {
|
2024-02-15 02:30:10 +00:00
|
|
|
children: React.ReactNode;
|
2024-10-15 23:55:03 +00:00
|
|
|
params: Promise<{ boardId: string }>;
|
2024-02-15 02:30:10 +00:00
|
|
|
}) => {
|
2024-10-15 23:55:03 +00:00
|
|
|
const params = await props.params;
|
|
|
|
|
|
|
|
const { children } = props;
|
|
|
|
|
2024-10-23 23:17:45 +00:00
|
|
|
const { orgId } = await auth();
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2024-02-16 01:49:19 +00:00
|
|
|
if (!orgId) redirect('/select-org');
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2025-01-19 06:36:59 +00:00
|
|
|
const getBoard = unstable_cache(
|
|
|
|
async () => {
|
|
|
|
return await db.board.findUnique({
|
|
|
|
where: {
|
|
|
|
id: params.boardId,
|
|
|
|
orgId,
|
|
|
|
},
|
|
|
|
});
|
2024-02-15 02:30:10 +00:00
|
|
|
},
|
2025-01-19 06:36:59 +00:00
|
|
|
[`board-${params.boardId}`],
|
|
|
|
{
|
|
|
|
tags: [`board-${params.boardId}`],
|
|
|
|
revalidate: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const board = await getBoard();
|
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' />
|
2025-01-11 06:04:43 +00:00
|
|
|
<main className='relative h-full pt-28'>
|
|
|
|
<BoardLiveblocks boardId={params.boardId}>{children}</BoardLiveblocks>
|
|
|
|
</main>
|
2024-02-15 02:30:10 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default BoardIdLayout;
|