@@ -9,16 +9,28 @@ import {
99 type BuildInfo ,
1010 OrganizationSettingsSideMenu ,
1111} from "~/components/navigation/OrganizationSettingsSideMenu" ;
12+ import { prisma } from "~/db.server" ;
1213import { useOrganization } from "~/hooks/useOrganizations" ;
1314import { rbac } from "~/services/rbac.server" ;
15+ import { getUserId } from "~/services/session.server" ;
1416import { ssoController } from "~/services/sso.server" ;
17+ import { isSupportChannelEnabled } from "~/services/supportChannelFlag.server" ;
1518
1619const SETTINGS_ROUTE_ID = "routes/_app.orgs.$organizationSlug.settings" ;
1720
1821export const loader = async ( { request, params } : LoaderFunctionArgs ) => {
19- const [ isUsingPlugin , isSsoUsingPlugin ] = await Promise . all ( [
22+ const userId = await getUserId ( request ) ;
23+ const organization = userId
24+ ? await prisma . organization . findFirst ( {
25+ where : { slug : params . organizationSlug ?? "" , members : { some : { userId } } } ,
26+ select : { id : true } ,
27+ } )
28+ : null ;
29+
30+ const [ isUsingPlugin , isSsoUsingPlugin , supportChannelEnabled ] = await Promise . all ( [
2031 rbac . isUsingPlugin ( ) ,
2132 ssoController . isUsingPlugin ( ) ,
33+ organization ? isSupportChannelEnabled ( organization . id ) : Promise . resolve ( false ) ,
2234 ] ) ;
2335 return typedjson ( {
2436 buildInfo : {
@@ -30,18 +42,21 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
3042 } satisfies BuildInfo ,
3143 isUsingPlugin,
3244 isSsoUsingPlugin,
45+ supportChannelEnabled,
3346 } ) ;
3447} ;
3548
3649function SettingsChrome ( {
3750 buildInfo,
3851 isUsingPlugin,
3952 isSsoUsingPlugin,
53+ supportChannelEnabled,
4054 children,
4155} : {
4256 buildInfo : BuildInfo ;
4357 isUsingPlugin : boolean ;
4458 isSsoUsingPlugin : boolean ;
59+ supportChannelEnabled : boolean ;
4560 children : ReactNode ;
4661} ) {
4762 const organization = useOrganization ( ) ;
@@ -54,6 +69,7 @@ function SettingsChrome({
5469 buildInfo = { buildInfo }
5570 isUsingPlugin = { isUsingPlugin }
5671 isSsoUsingPlugin = { isSsoUsingPlugin }
72+ supportChannelEnabled = { supportChannelEnabled }
5773 />
5874 < MainBody > { children } </ MainBody >
5975 </ div >
@@ -62,13 +78,15 @@ function SettingsChrome({
6278}
6379
6480export default function Page ( ) {
65- const { buildInfo, isUsingPlugin, isSsoUsingPlugin } = useTypedLoaderData < typeof loader > ( ) ;
81+ const { buildInfo, isUsingPlugin, isSsoUsingPlugin, supportChannelEnabled } =
82+ useTypedLoaderData < typeof loader > ( ) ;
6683
6784 return (
6885 < SettingsChrome
6986 buildInfo = { buildInfo }
7087 isUsingPlugin = { isUsingPlugin }
7188 isSsoUsingPlugin = { isSsoUsingPlugin }
89+ supportChannelEnabled = { supportChannelEnabled }
7290 >
7391 < Outlet />
7492 </ SettingsChrome >
@@ -81,7 +99,12 @@ export default function Page() {
8199// available via useRouteLoaderData.
82100export function ErrorBoundary ( ) {
83101 const data = useRouteLoaderData ( SETTINGS_ROUTE_ID ) as
84- | { buildInfo : BuildInfo ; isUsingPlugin : boolean ; isSsoUsingPlugin : boolean }
102+ | {
103+ buildInfo : BuildInfo ;
104+ isUsingPlugin : boolean ;
105+ isSsoUsingPlugin : boolean ;
106+ supportChannelEnabled : boolean ;
107+ }
85108 | undefined ;
86109
87110 if ( ! data ) {
@@ -93,6 +116,7 @@ export function ErrorBoundary() {
93116 buildInfo = { data . buildInfo }
94117 isUsingPlugin = { data . isUsingPlugin }
95118 isSsoUsingPlugin = { data . isSsoUsingPlugin }
119+ supportChannelEnabled = { data . supportChannelEnabled }
96120 >
97121 < RouteErrorDisplay />
98122 </ SettingsChrome >
0 commit comments