{"version":3,"file":"AdminPortalSSOContainer.mjs","sources":["../../../../../../../../web/src/adminPortal/sso/AdminPortalSSOContainer.tsx"],"sourcesContent":["import { StytchProjectConfigurationInput } from '@stytch/core/public';\nimport React, { useEffect, useRef } from 'react';\n\nimport { readB2BInternals } from '../../utils/internal';\nimport { AdminPortalWrapper } from '../AdminPortalWrapper';\nimport { MappedPropsFromRouteMap, RouterStateEntry } from '../Router';\nimport { AdminPortalCommonProps } from '../utils/AdminPortalCommonProps';\nimport { AdminPortalUIConfigRoleDisplayProvider } from '../utils/AdminPortalUIConfigRoleDisplayProvider';\nimport { FeatureStateComponent } from '../utils/FeatureStateComponent';\nimport { getFeatureState } from '../utils/getFeatureState';\nimport { useAdminPortalConfig } from '../utils/useAdminPortalConfig';\nimport { useRbac } from '../utils/useRbac';\nimport { useSelf } from '../utils/useSelf';\nimport { SSOConnectionDetailsScreen } from './SSOConnectionDetailsScreen';\nimport { SSOConnectionsScreen } from './SSOConnectionsScreen';\nimport { SSONewConnectionConfigureScreen } from './SSONewConnectionConfigureScreen';\nimport { SSONewConnectionScreen } from './SSONewConnectionScreen';\nimport { SsoRouter, SsoRouterProvider } from './SSORouter';\n\n/**\n * The UI configuration object for SSO configuration used in the Admin Portal.\n */\nexport type AdminPortalSSOUIConfig = AdminPortalUIConfigRoleDisplayProvider & {\n  /**\n   * The URL used when testing SSO connections via the test button on the SSO Connection Details screen.\n   * If this value is not passed, the default `login_redirect_url` that you set in your Dashboard is used.\n   */\n  testLoginRedirectURL?: string;\n\n  /**\n   * The URL used when testing SSO connections via the test button on the SSO Connection Details screen.\n   * If this value is not passed, the default `signup_redirect_url` that you set in your Dashboard is used.\n   */\n  testSignupRedirectURL?: string;\n};\n\nexport interface AdminPortalSSOMountOptions<\n  TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends AdminPortalCommonProps<TProjectConfiguration> {\n  /**\n   * An {@link AdminPortalSSOUIConfig} object containing custom configuration.\n   */\n  config?: AdminPortalSSOUIConfig;\n}\n\nconst routeMap = {\n  connectionDetails: SSOConnectionDetailsScreen,\n  connectionsList: SSOConnectionsScreen,\n  newConnection: SSONewConnectionScreen,\n  newConnectionConfigure: SSONewConnectionConfigureScreen,\n};\n\nexport type SsoRouterMappedProps = MappedPropsFromRouteMap<typeof routeMap>;\n\nconst initialRoute = { screen: 'connectionsList' } satisfies RouterStateEntry<SsoRouterMappedProps>;\n\nexport const Content = () => {\n  const { data: canGetSso } = useRbac('stytch.sso', 'get');\n  const { self, fromCache } = useSelf();\n  const { data: adminPortalConfig, error: adminPortalConfigError } = useAdminPortalConfig({ shouldFetch: !!self });\n  const isSsoEnabled = adminPortalConfig?.sso_config.sso_enabled;\n\n  const ssoState = getFeatureState({\n    self,\n    fromCache,\n    adminPortalConfigError: adminPortalConfigError,\n    isFeatureEnabled: isSsoEnabled,\n    hasPermission: canGetSso,\n  });\n  return (\n    <FeatureStateComponent\n      featureState={ssoState}\n      notLoggedInValue={'Please log in to manage SSO.'}\n      errorValue={'SSO Connections could not be loaded. Please contact your admin if you think this is a mistake.'}\n      featureNotEnabledValue={\n        'SSO Connections are not supported. Please contact your admin if you think this is a mistake.'\n      }\n      noPermissionValue={\n        'You do not have permission to view SSO Connections. Please contact your admin if you think this is a mistake.'\n      }\n    >\n      <SsoRouterProvider initialRoute={initialRoute}>\n        <SsoRouter routeMap={routeMap} />\n      </SsoRouterProvider>\n    </FeatureStateComponent>\n  );\n};\n\nexport const AdminPortalSSOContainer = <TProjectConfiguration extends StytchProjectConfigurationInput>(\n  props: AdminPortalSSOMountOptions<TProjectConfiguration>,\n) => {\n  // only send an event on initial mount, even if the client changes\n  const initialClient = useRef(props.client);\n  useEffect(() => {\n    readB2BInternals(initialClient.current).networkClient.logEvent({\n      name: 'render_b2b_admin_portal_sso',\n      details: {},\n    });\n  }, []);\n\n  return (\n    <AdminPortalWrapper options={props}>\n      <Content />\n    </AdminPortalWrapper>\n  );\n};\n"],"names":["routeMap","connectionDetails","SSOConnectionDetailsScreen","connectionsList","SSOConnectionsScreen","newConnection","SSONewConnectionScreen","newConnectionConfigure","SSONewConnectionConfigureScreen","initialRoute","screen","Content","data","canGetSso","useRbac","self","fromCache","useSelf","adminPortalConfig","error","adminPortalConfigError","useAdminPortalConfig","shouldFetch","isSsoEnabled","sso_config","sso_enabled","ssoState","getFeatureState","isFeatureEnabled","hasPermission","React","FeatureStateComponent","featureState","notLoggedInValue","errorValue","featureNotEnabledValue","noPermissionValue","SsoRouterProvider","SsoRouter","AdminPortalSSOContainer","props","initialClient","useRef","client","useEffect","readB2BInternals","current","networkClient","logEvent","name","details","AdminPortalWrapper","options"],"mappings":";;;;;;;;;;;;;;;AA6CA,MAAMA,QAAAA,GAAW;IACfC,iBAAAA,EAAmBC,0BAAAA;IACnBC,eAAAA,EAAiBC,oBAAAA;IACjBC,aAAAA,EAAeC,sBAAAA;IACfC,sBAAAA,EAAwBC;AAC1B,CAAA;AAIA,MAAMC,YAAAA,GAAe;IAAEC,MAAAA,EAAQ;AAAkB,CAAA;MAEpCC,OAAAA,GAAU,IAAA;AACrB,IAAA,MAAM,EAAEC,IAAAA,EAAMC,SAAS,EAAE,GAAGC,QAAQ,YAAA,EAAc,KAAA,CAAA;AAClD,IAAA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGC,OAAAA,EAAAA;IAC5B,MAAM,EAAEL,MAAMM,iBAAiB,EAAEC,OAAOC,sBAAsB,EAAE,GAAGC,oBAAAA,CAAqB;AAAEC,QAAAA,WAAAA,EAAa,CAAC,CAACP;AAAK,KAAA,CAAA;IAC9G,MAAMQ,YAAAA,GAAeL,mBAAmBM,UAAAA,CAAWC,WAAAA;AAEnD,IAAA,MAAMC,WAAWC,eAAAA,CAAgB;AAC/BZ,QAAAA,IAAAA;AACAC,QAAAA,SAAAA;QACAI,sBAAAA,EAAwBA,sBAAAA;QACxBQ,gBAAAA,EAAkBL,YAAAA;QAClBM,aAAAA,EAAehB;AACjB,KAAA,CAAA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