-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathlayout.tsx
More file actions
130 lines (119 loc) · 4.54 KB
/
layout.tsx
File metadata and controls
130 lines (119 loc) · 4.54 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
127
128
129
130
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 { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
import { withAuthV2 } from "@/withAuthV2";
interface LayoutProps {
children: React.ReactNode;
params: Promise<{ domain: string }>;
}
export const metadata: Metadata = {
title: "Settings",
}
export default async function SettingsLayout(
props: LayoutProps
) {
const params = await props.params;
const {
domain
} = params;
const {
children
} = props;
const session = await auth();
if (!session) {
return redirect(`/${domain}`);
}
const sidebarNavItems = await getSidebarNavItems();
if (isServiceError(sidebarNavItems)) {
throw new ServiceErrorException(sidebarNavItems);
}
return (
<div className="min-h-screen flex flex-col">
<NavigationMenu domain={domain} />
<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 () =>
withAuthV2(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: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/access`,
}
] : []),
...(role === OrgRole.OWNER ? [{
title: "Members",
isNotificationDotVisible: numJoinRequests !== undefined && numJoinRequests > 0,
href: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/members`,
}] : []),
...(role === OrgRole.OWNER ? [
{
title: "Connections",
href: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/connections`,
hrefRegex: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/connections(/[^/]+)?$`,
isNotificationDotVisible: connectionStats.numberOfConnectionsWithFirstTimeSyncJobsInProgress > 0,
}
] : []),
...(env.DISABLE_API_KEY_USAGE_FOR_NON_OWNER_USERS === 'false' || role === OrgRole.OWNER ? [
{
title: "API Keys",
href: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/apiKeys`,
}
] : []),
...(role === OrgRole.OWNER ? [
{
title: "Analytics",
href: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/analytics`,
},
] : []),
...(hasEntitlement("sso") ? [
{
title: "Linked Accounts",
href: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/linked-accounts`,
}
] : []),
...(role === OrgRole.OWNER ? [
{
title: "License",
href: `/${SINGLE_TENANT_ORG_DOMAIN}/settings/license`,
}
] : []),
]
});