{"version":3,"file":"AdminPortalOrgSettingsContainer.mjs","sources":["../../../../../../../../web/src/adminPortal/settings/AdminPortalOrgSettingsContainer.tsx"],"sourcesContent":["import { EnumOrStringLiteral } from '@stytch/core';\nimport { B2BMFAProducts, StytchProjectConfigurationInput } from '@stytch/core/public';\nimport React, { useEffect, useRef } from 'react';\n\nimport { readB2BInternals } from '../../utils/internal';\nimport { AdminPortalB2BProducts } from '../AdminPortalB2BProducts';\nimport { AdminPortalWrapper } from '../AdminPortalWrapper';\nimport { MappedPropsFromRouteMap, RouterStateEntry } from '../Router';\nimport { useAdminPortalOrgUIConfig } from '../StytchClientContext';\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 { useSelf } from '../utils/useSelf';\nimport { OrgSettingsRouter, OrgSettingsRouterProvider } from './AdminPortalOrgRouter';\nimport { OrgSettingsScreen } from './OrgSettingsScreen';\n\nconst validateConfig = (config?: AdminPortalOrgUIConfig) => {\n  if (!config) return;\n  if (config.allowedAuthMethods?.length === 0) {\n    throw new Error('allowedAuthMethods must contain at least one value');\n  }\n  if (config.allowedMfaAuthMethods?.length === 0) {\n    throw new Error('mfaAuthMethods must contain at least one value');\n  }\n};\n/**\n * The UI configuration object for organization used in the Admin Portal.\n */\nexport interface AdminPortalOrgUIConfig extends AdminPortalUIConfigRoleDisplayProvider {\n  /**\n   * Specify the auth methods that a member can choose to enable when restricting the organization's allowed auth methods.\n   * If not specified, all auth methods are shown.\n   */\n  allowedAuthMethods?: EnumOrStringLiteral<AdminPortalB2BProducts>[];\n  /**\n   * Specify the MFA auth methods that a member can choose to enable when restricting the organization's allowed auth methods.\n   * If not specified, all auth methods are shown.\n   */\n  allowedMfaAuthMethods?: B2BMFAProducts[];\n}\nexport interface AdminPortalOrgSettingsMountOptions<\n  TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends AdminPortalCommonProps<TProjectConfiguration> {\n  /**\n   * An {@link AdminPortalOrgUIConfig} object containing custom configuration.\n   */\n  config?: AdminPortalOrgUIConfig;\n}\n\nconst routeMap = {\n  orgSettingsScreen: OrgSettingsScreen,\n};\n\nexport type OrgSettingsRouterMappedProps = MappedPropsFromRouteMap<typeof routeMap>;\n\nconst initialRoute = { screen: 'orgSettingsScreen' } satisfies RouterStateEntry<OrgSettingsRouterMappedProps>;\n\nexport const Content = () => {\n  const { self, fromCache } = useSelf();\n  const { error: adminPortalConfigError } = useAdminPortalConfig({\n    shouldFetch: !!self,\n  });\n\n  const orgSettingsState = getFeatureState({\n    self,\n    fromCache,\n    adminPortalConfigError: adminPortalConfigError,\n    isFeatureEnabled: true,\n    hasPermission: true,\n  });\n  return (\n    <FeatureStateComponent\n      featureState={orgSettingsState}\n      notLoggedInValue={'Please log in to manage Authentication & Access.'}\n      errorValue={\n        'Authentication & Access Settings could not be loaded. Please contact your admin if you think this is a mistake.'\n      }\n      featureNotEnabledValue={\n        'Authentication & Access is not supported. Please contact your admin if you think this is a mistake.'\n      }\n      noPermissionValue={\n        'You do not have permission to view Authentication & Access. Please contact your admin if you think this is a mistake.'\n      }\n    >\n      <OrgSettingsRouterProvider initialRoute={initialRoute}>\n        <OrgSettingsRouter routeMap={routeMap} />\n      </OrgSettingsRouterProvider>\n    </FeatureStateComponent>\n  );\n};\n\nexport const AdminPortalOrgSettingsContainer = <TProjectConfiguration extends StytchProjectConfigurationInput>(\n  props: AdminPortalOrgSettingsMountOptions<TProjectConfiguration>,\n) => {\n  const uiConfig = useAdminPortalOrgUIConfig();\n  const initialClient = useRef(props.client);\n  // only send an event on initial mount, even if the client changes\n  useEffect(() => {\n    readB2BInternals(initialClient.current).networkClient.logEvent({\n      name: 'render_b2b_admin_portal_org_settings',\n      details: {},\n    });\n  }, []);\n\n  useEffect(() => {\n    validateConfig(uiConfig);\n  }, [uiConfig]);\n\n  return (\n    <AdminPortalWrapper options={props}>\n      <Content />\n    </AdminPortalWrapper>\n  );\n};\n"],"names":["validateConfig","config","allowedAuthMethods","length","Error","allowedMfaAuthMethods","routeMap","orgSettingsScreen","OrgSettingsScreen","initialRoute","screen","Content","self","fromCache","useSelf","error","adminPortalConfigError","useAdminPortalConfig","shouldFetch","orgSettingsState","getFeatureState","isFeatureEnabled","hasPermission","React","FeatureStateComponent","featureState","notLoggedInValue","errorValue","featureNotEnabledValue","noPermissionValue","OrgSettingsRouterProvider","OrgSettingsRouter","AdminPortalOrgSettingsContainer","props","uiConfig","useAdminPortalOrgUIConfig","initialClient","useRef","client","useEffect","readB2BInternals","current","networkClient","logEvent","name","details","AdminPortalWrapper","options"],"mappings":";;;;;;;;;;;;AAkBA,MAAMA,iBAAiB,CAACC,MAAAA,GAAAA;AACtB,IAAA,IAAI,CAACA,MAAAA,EAAQ;AACb,IAAA,IAAIA,MAAAA,CAAOC,kBAAkB,EAAEC,MAAAA,KAAW,CAAA,EAAG;AAC3C,QAAA,MAAM,IAAIC,KAAAA,CAAM,oDAAA,CAAA;AAClB,IAAA;AACA,IAAA,IAAIH,MAAAA,CAAOI,qBAAqB,EAAEF,MAAAA,KAAW,CAAA,EAAG;AAC9C,QAAA,MAAM,IAAIC,KAAAA,CAAM,gDAAA,CAAA;AAClB,IAAA;AACF,CAAA;AAyBA,MAAME,UAAAA,GAAW;IACfC,iBAAAA,EAAmBC;AACrB,CAAA;AAIA,MAAMC,cAAAA,GAAe;IAAEC,MAAAA,EAAQ;AAAoB,CAAA;MAEtCC,SAAAA,GAAU,IAAA;AACrB,IAAA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGC,OAAAA,EAAAA;AAC5B,IAAA,MAAM,EAAEC,KAAAA,EAAOC,sBAAsB,EAAE,GAAGC,oBAAAA,CAAqB;AAC7DC,QAAAA,WAAAA,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