@@ -20,6 +20,7 @@ import type { WorkspaceCredential } from '@/lib/api/contracts'
2020import type { OrganizationCredential } from '@/lib/api/contracts/organization-credentials'
2121import { resourceScopeFields , resourceScopeFromOwner } from '@/lib/core/resource-scope'
2222import {
23+ hasSlackSearchUserScopes ,
2324 resolveSlackManagedUserScopes ,
2425 SLACK_MANAGED_USER_SCOPES ,
2526 SLACK_SEARCH_USER_SCOPES ,
@@ -32,6 +33,7 @@ import {
3233 organizationAccountsKeys ,
3334 useOrganizationAccounts ,
3435} from '@/hooks/queries/organization-accounts'
36+ import { useSearchIntegrations } from '@/hooks/queries/search-integrations'
3537import { useSlackSearchInstallations } from '@/hooks/queries/slack-search'
3638import { credentialGroupKeys } from '@/hooks/queries/utils/credential-group-queries'
3739
@@ -107,11 +109,15 @@ export function SlackManagedUsersModal({
107109 availableApps . find ( ( app ) => app . appId === appId ) ??
108110 ( availableApps . length === 1 && ! appId ? availableApps [ 0 ] : undefined )
109111 const sharedAppInstalled = organizationSetup && selectedApp ?. appKind === 'shared'
112+ const searchPolicies = useSearchIntegrations ( organizationId ?? '' , {
113+ enabled : open && sharedAppInstalled ,
114+ } )
115+ const searchApproved = searchPolicies . data ?. some (
116+ ( policy ) => policy . connectorType === 'slack' && policy . approved
117+ )
110118 const accounts = useOrganizationAccounts ( open && sharedAppInstalled ? organizationId : undefined )
111119 const memberGroup = accounts . data ?. credentialGroup
112- const memberOption = memberGroup ?. options . find (
113- ( option ) => option . provider === 'slack' && option . status === 'active'
114- )
120+ const memberOption = memberGroup ?. options . find ( ( option ) => option . provider === 'slack' )
115121 const sharedAppCanAuthorize = Boolean (
116122 sharedAppInstalled &&
117123 apps . isSuccess &&
@@ -123,11 +129,22 @@ export function SlackManagedUsersModal({
123129 accounts . isSuccess &&
124130 ! accounts . isFetching &&
125131 ! accounts . error &&
126- memberGroup ?. id === credentialGroupId
132+ searchPolicies . isSuccess &&
133+ ! searchPolicies . isFetching &&
134+ ! searchPolicies . error &&
135+ memberGroup ?. id === credentialGroupId &&
136+ memberOption ?. status === 'active'
127137 )
128- const sharedAppReady = sharedAppCanAuthorize && memberOption ?. configurationStatus === 'ready'
138+ const searchPermissionsMissing =
139+ searchApproved && ! hasSlackSearchUserScopes ( memberOption ?. requiredScopes )
140+ const sharedAppReady =
141+ sharedAppCanAuthorize &&
142+ memberOption ?. configurationStatus === 'ready' &&
143+ ! searchPermissionsMissing
129144 const sharedAppNeedsUpdate =
130- sharedAppCanAuthorize && memberOption ?. configurationStatus === 'needs_update'
145+ sharedAppCanAuthorize &&
146+ ( memberOption ?. configurationStatus === 'needs_update' ||
147+ ( memberOption ?. configurationStatus === 'ready' && searchPermissionsMissing ) )
131148 const [ clientId , setClientId ] = useState ( '' )
132149 const [ clientSecret , setClientSecret ] = useState ( '' )
133150 const [ pending , setPending ] = useState ( false )
@@ -389,8 +406,19 @@ export function SlackManagedUsersModal({
389406 const needsApp = organizationSetup && apps . isSuccess && availableApps . length === 0
390407 const checkingSetup =
391408 apps . isPending ||
392- ( sharedAppInstalled && ( apps . isFetching || accounts . isPending || accounts . isFetching ) )
393- const failedSetup = apps . error ? apps : sharedAppInstalled && accounts . error ? accounts : null
409+ ( sharedAppInstalled &&
410+ ( apps . isFetching ||
411+ accounts . isPending ||
412+ accounts . isFetching ||
413+ searchPolicies . isPending ||
414+ searchPolicies . isFetching ) )
415+ const failedSetup = apps . error
416+ ? apps
417+ : sharedAppInstalled && searchPolicies . error
418+ ? searchPolicies
419+ : sharedAppInstalled && accounts . error
420+ ? accounts
421+ : null
394422 const title = organizationSetup ? 'Set up Slack app' : 'Set up Slack'
395423 const primaryLabel = isLoading
396424 ? 'Loading...'
@@ -405,7 +433,7 @@ export function SlackManagedUsersModal({
405433 ( ! organizationSetup && ! selectedBot ) ||
406434 pending ||
407435 ( organizationSetup
408- ? apps . isPending || Boolean ( apps . error ) || ! selectedApp || ! requiredScopes . length
436+ ? checkingSetup || Boolean ( failedSetup ) || ! selectedApp || ! requiredScopes . length
409437 : ! clientId . trim ( ) || ! clientSecret . trim ( ) )
410438
411439 return (
@@ -472,9 +500,9 @@ export function SlackManagedUsersModal({
472500 < p className = 'text-[var(--text-secondary)] text-sm' >
473501 { sharedAppInstalled
474502 ? sharedAppNeedsUpdate
475- ? 'Member access is outdated. Update it so members can reconnect their Slack accounts .'
503+ ? 'Verify member permissions. Members will need to reconnect if their app or permissions change .'
476504 : 'The Sim Search installation needs attention. Manage the app to finish setup.'
477- : 'Verify member authorization for the installed app . Members can then search the Slack conversations they can access .' }
505+ : 'Verify member permissions . Members will need to reconnect if their app or permissions change .' }
478506 </ p >
479507 { selectedApp && (
480508 < Chip onClick = { ( ) => setAppSetupOpen ( true ) } disabled = { pending } >
0 commit comments