| 1 | import { headers } from 'next/headers' |
| 2 | import { redirect } |
| 3 | import { |
| 4 | getCachedActiveOrgMember, |
| 5 | getCachedOrganization, |
| 6 | getCachedUserSession, |
| 7 | } from '@/app/(organization)/[org]/cache' |
| 8 | import { projectsService } |
| 9 | import { ApplicationHeader } |
| 10 | import { FloatingTimer } |
| 11 | import { Separator } |
| 12 | import { authClient } |
| 13 | import OrgNavServer from './nav.server |
| 14 | |
| 15 | export default async function |
| 16 | children, |
| 17 | params, |
| 18 | }: LayoutProps< |
| 19 | const { org, |
| 20 | const session = |
| 21 | if (!session) |
| 22 | return redirect( |
| 23 | `/auth/sign-in?redirectTo=${encodeURIComponent(`/ |
| 24 | ) |
| 25 | } |
| 26 | |
| 27 | const organization = |
| 28 | if (!organization) |
| 29 | return redirect( |
| 30 | `/error/404?message=${encodeURIComponent('Workspace not found |
| 31 | ) |
| 32 | } |
| 33 | |
| 34 | const orgMember = |
| 35 | if (!orgMember) |
| 36 | return redirect( |
| 37 | `/error/403?message=${encodeURIComponent('You are not a member of this workspace |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | const [allOrganizations, |
| 42 | authClient.organization.list |
| 43 | projectsService.listAccessible(organization |
| 44 | projectsService.getBySlug(organization |
| 45 | ]) |
| 46 | |
| 47 | if (!currentProject) |
| 48 | return redirect( |
| 49 | `/error/404?message=${encodeURIComponent('Project not found |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | return ( |
| 54 | <div className='flex flex-1 flex-col |
| 55 | <header className='flex w-full shrink-0 flex-col items-center bg-secondary transition-[width,height] ease-linear |
| 56 | <div className='flex w-full items-center gap-2 px-4 |
| 57 | <ApplicationHeader |
| 58 | allOrganizations={allOrganizations.data |
| 59 | allProjects={allProjects} |
| 60 | organizationId={organization.id |
| 61 | organizationName={organization.name |
| 62 | organizationSlug={org} |
| 63 | projectName={currentProject.name |
| 64 | /> |
| 65 | </div> |
| 66 | <Separator className=' |
| 67 | <OrgNavServer slug={ |
| 68 | </header> |
| 69 | <div className='flex w-full items-center justify-center |
| 70 | <div className='flex max-w-7xl flex-1 items-center justify-center p-4 |
| 71 | {children} |
| 72 | </div> |
| 73 | </div> |
| 74 | <FloatingTimer /> |
| 75 | </div> |
| 76 | ) |
| 77 | } |