1- import { getConnectionStats , getRepos , getReposStats } from "@/actions" ;
1+ import { getConnectionStats , getCurrentUserRole , getOrgAccountRequests , getRepos , getReposStats } from "@/actions" ;
22import { SourcebotLogo } from "@/app/components/sourcebotLogo" ;
33import { auth } from "@/auth" ;
44import { Button } from "@/components/ui/button" ;
@@ -10,7 +10,7 @@ import { env } from "@sourcebot/shared";
1010import { ServiceErrorException } from "@/lib/serviceError" ;
1111import { isServiceError } from "@/lib/utils" ;
1212import { DiscordLogoIcon , GitHubLogoIcon } from "@radix-ui/react-icons" ;
13- import { RepoIndexingJobStatus , RepoIndexingJobType } from "@sourcebot/db" ;
13+ import { OrgRole , RepoIndexingJobStatus , RepoIndexingJobType } from "@sourcebot/db" ;
1414import Link from "next/link" ;
1515import { redirect } from "next/navigation" ;
1616import { OrgSelector } from "../orgSelector" ;
@@ -39,11 +39,32 @@ export const NavigationMenu = async ({
3939 throw new ServiceErrorException ( repoStats ) ;
4040 }
4141
42- const connectionStats = isAuthenticated ? await getConnectionStats ( ) : null ;
43- if ( isServiceError ( connectionStats ) ) {
44- throw new ServiceErrorException ( connectionStats ) ;
42+ const role = isAuthenticated ? await getCurrentUserRole ( domain ) : null ;
43+ if ( isServiceError ( role ) ) {
44+ throw new ServiceErrorException ( role ) ;
4545 }
4646
47+ const stats = await ( async ( ) => {
48+ if ( ! isAuthenticated || role !== OrgRole . OWNER ) {
49+ return null ;
50+ }
51+
52+ const joinRequests = await getOrgAccountRequests ( domain ) ;
53+ if ( isServiceError ( joinRequests ) ) {
54+ throw new ServiceErrorException ( joinRequests ) ;
55+ }
56+
57+ const connectionStats = await getConnectionStats ( ) ;
58+ if ( isServiceError ( connectionStats ) ) {
59+ throw new ServiceErrorException ( connectionStats ) ;
60+ }
61+
62+ return {
63+ numJoinRequests : joinRequests . length ,
64+ connectionStats,
65+ } ;
66+ } ) ( ) ;
67+
4768 const sampleRepos = await getRepos ( {
4869 where : {
4970 jobs : {
@@ -100,9 +121,10 @@ export const NavigationMenu = async ({
100121 numberOfRepos = { numberOfRepos }
101122 isReposButtonNotificationDotVisible = { numberOfReposWithFirstTimeIndexingJobsInProgress > 0 }
102123 isSettingsButtonNotificationDotVisible = {
103- connectionStats ?
104- connectionStats . numberOfConnectionsWithFirstTimeSyncJobsInProgress > 0 :
105- false
124+ stats ? (
125+ stats . connectionStats . numberOfConnectionsWithFirstTimeSyncJobsInProgress > 0 ||
126+ stats . numJoinRequests > 0
127+ ) : false
106128 }
107129 isAuthenticated = { isAuthenticated }
108130 />
0 commit comments