-
Notifications
You must be signed in to change notification settings - Fork 314
Expand file tree
/
Copy pathlayout.tsx
More file actions
126 lines (117 loc) · 4.24 KB
/
Copy pathlayout.tsx
File metadata and controls
126 lines (117 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React from "react"
import { Metadata } from "next"
import { SidebarNav } from "./components/sidebar-nav"
import { NavigationMenu } from "../components/navigationMenu"
import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { isServiceError } from "@/lib/utils";
import { getConnectionStats, getOrgAccountRequests } from "@/actions";
import { ServiceErrorException } from "@/lib/serviceError";
import { OrgRole } from "@prisma/client";
import { env, hasEntitlement } from "@sourcebot/shared";
import { withAuth } from "@/middleware/withAuth";
interface LayoutProps {
children: React.ReactNode;
}
export const metadata: Metadata = {
title: "Settings",
}
export default async function SettingsLayout(
props: LayoutProps
) {
const {
children
} = props;
const session = await auth();
if (!session) {
return redirect('/');
}
const sidebarNavItems = await getSidebarNavItems();
if (isServiceError(sidebarNavItems)) {
throw new ServiceErrorException(sidebarNavItems);
}
return (
<div className="min-h-screen flex flex-col">
<NavigationMenu />
<main className="flex-grow flex justify-center p-4 bg-backgroundSecondary relative">
<div className="w-full max-w-6xl rounded-lg p-6">
<div className="container mx-auto">
<div className="mb-16">
<h1 className="text-3xl font-semibold">Settings</h1>
</div>
<div className="flex flex-row gap-10">
<aside className="lg:w-48">
<SidebarNav items={sidebarNavItems} />
</aside>
<div className="w-full rounded-lg">{children}</div>
</div>
</div>
</div>
</main>
</div>
)
}
export const getSidebarNavItems = async () =>
withAuth(async ({ role }) => {
let numJoinRequests: number | undefined;
if (role === OrgRole.OWNER) {
const requests = await getOrgAccountRequests();
if (isServiceError(requests)) {
throw new ServiceErrorException(requests);
}
numJoinRequests = requests.length;
}
const connectionStats = await getConnectionStats();
if (isServiceError(connectionStats)) {
throw new ServiceErrorException(connectionStats);
}
return [
...(role === OrgRole.OWNER ? [
{
title: "Access",
href: `/settings/access`,
}
] : []),
...(role === OrgRole.OWNER ? [{
title: "Members",
isNotificationDotVisible: numJoinRequests !== undefined && numJoinRequests > 0,
href: `/settings/members`,
}] : []),
...(role === OrgRole.OWNER ? [
{
title: "Connections",
href: `/settings/connections`,
hrefRegex: `/settings/connections(/[^/]+)?$`,
isNotificationDotVisible: connectionStats.numberOfConnectionsWithFirstTimeSyncJobsInProgress > 0,
}
] : []),
...(env.DISABLE_API_KEY_USAGE_FOR_NON_OWNER_USERS === 'false' || role === OrgRole.OWNER ? [
{
title: "API Keys",
href: `/settings/apiKeys`,
}
] : []),
{
title: "Chat Preferences",
href: `/settings/chatPreferences`,
},
...(role === OrgRole.OWNER ? [
{
title: "Analytics",
href: `/settings/analytics`,
},
] : []),
...(hasEntitlement("sso") ? [
{
title: "Linked Accounts",
href: `/settings/linked-accounts`,
}
] : []),
...(role === OrgRole.OWNER ? [
{
title: "License",
href: `/settings/license`,
}
] : []),
]
});