@@ -2,11 +2,17 @@ import type { Metadata } from 'next'
22import { notFound , redirect } from 'next/navigation'
33import { slackSearchOnboardingInputSchema } from '@/lib/api/contracts/knowledge/slack'
44import { getSession } from '@/lib/auth'
5+ import {
6+ searchConnectionPath ,
7+ searchConnectionTargetSchema ,
8+ } from '@/lib/knowledge/search/connection-target'
59import { organizationRoutes } from '@/lib/navigation/paths'
610import { getOrganizationSurfaceContext } from '@/lib/organizations/surface'
11+ import { SEARCH_CONNECTORS } from '@/lib/sim-search/connectors'
712import { slackSearchIntegrationsPath } from '@/lib/slack-search/onboarding'
813import { buildAuthCrossLink } from '@/app/(auth)/auth-redirect'
914import { OrganizationIntegrations } from '@/app/o/[organizationId]/integrations/integrations'
15+ import { loadIntegrationConnectionParams } from '@/app/o/[organizationId]/integrations/search-params'
1016
1117export const metadata : Metadata = {
1218 title : 'Integrations' ,
@@ -15,15 +21,35 @@ export const metadata: Metadata = {
1521
1622interface OrganizationIntegrationsPageProps {
1723 params : Promise < { organizationId : string } >
18- searchParams : Promise < { slack ?: string | string [ ] } >
24+ searchParams : Promise < {
25+ slack ?: string | string [ ]
26+ connectorType ?: string | string [ ]
27+ connectorId ?: string | string [ ]
28+ credentialId ?: string | string [ ]
29+ } >
1930}
2031
2132export default async function OrganizationIntegrationsPage ( {
2233 params,
2334 searchParams,
2435} : OrganizationIntegrationsPageProps ) {
2536 const { organizationId } = await params
26- const { slack } = await searchParams
37+ const query = await searchParams
38+ const { slack } = query
39+ const selection = loadIntegrationConnectionParams ( query )
40+ const connector = SEARCH_CONNECTORS . find ( ( entry ) => entry . type === selection . connectorType )
41+ const requested =
42+ selection . connectorType || selection . connectorId || selection . credentialId
43+ ? searchConnectionTargetSchema . safeParse ( {
44+ type : 'link' ,
45+ provider : connector ?. providerId ,
46+ connectorType : selection . connectorType ,
47+ ...( selection . connectorId ? { connectorId : selection . connectorId } : { } ) ,
48+ ...( selection . credentialId ? { credentialId : selection . credentialId } : { } ) ,
49+ } )
50+ : undefined
51+ if ( requested && ! requested . success ) notFound ( )
52+ const connectionTarget = requested ?. data
2753 const context =
2854 slack === undefined ? undefined : slackSearchOnboardingInputSchema . safeParse ( { token : slack } )
2955 if ( context && ! context . success ) notFound ( )
@@ -32,16 +58,21 @@ export default async function OrganizationIntegrationsPage({
3258 if ( ! session ?. user )
3359 redirect (
3460 buildAuthCrossLink ( '/login' , {
35- callbackUrl : slackToken
36- ? slackSearchIntegrationsPath ( organizationId , slackToken )
37- : organizationRoutes ( organizationId ) . integrations ,
61+ callbackUrl : connectionTarget
62+ ? searchConnectionPath ( organizationId , connectionTarget )
63+ : slackToken
64+ ? slackSearchIntegrationsPath ( organizationId , slackToken )
65+ : organizationRoutes ( organizationId ) . integrations ,
3866 isInviteFlow : false ,
3967 } )
4068 )
4169 const organizationContext = await getOrganizationSurfaceContext ( organizationId , session . user . id )
4270 if ( ! organizationContext ?. searchAccess . memberScoped ) notFound ( )
4371 return (
4472 < OrganizationIntegrations
73+ connectionRequest = {
74+ connectionTarget ? { target : connectionTarget , userId : session . user . id } : undefined
75+ }
4576 slackOnboarding = { slackToken ? { token : slackToken , userId : session . user . id } : undefined }
4677 />
4778 )
0 commit comments