{"version":3,"file":"EmailConfirmation.mjs","sources":["../../../../../../../../../../web/src/ui/b2c/screens/Secondary/EmailConfirmation.tsx"],"sourcesContent":["import { EmailSentType } from '@stytch/core';\nimport React, { useEffect, useState } from 'react';\n\nimport { readB2CInternals } from '../../../../utils/internal';\nimport { useCountdown } from '../../../components/atoms/Countdown';\nimport { EmailConfirmationView } from '../../../components/organisms/EmailConfirmationView';\nimport { AppScreens, useConfig, useGlobalReducer, useStytch } from '../../GlobalContextProvider';\nimport { usePasswordlessAuthenticate } from './usePasswordlessAuthenticate';\n\n/**\n * Resolves the best email domain to use as a hint for login\n */\nexport const useEmailDomain = () => {\n  const stytch = useStytch();\n  const config = useConfig();\n  /**\n   * Read the emailDomains out of sync storage, then read out of async storage\n   * TODO - Should all bootstrap data live in the config somewhere?\n   */\n  const [emailDomains, setEmailDomains] = useState(() => {\n    const { emailDomains } = readB2CInternals(stytch).bootstrap.getSync();\n    return emailDomains;\n  });\n\n  useEffect(() => {\n    readB2CInternals(stytch)\n      .bootstrap.getAsync()\n      .then(({ emailDomains }) => {\n        setEmailDomains(emailDomains);\n      });\n  }, [stytch]);\n\n  // If a domain is explicitly passed in, use it!\n  if (config.emailMagicLinksOptions?.domainHint) {\n    return config.emailMagicLinksOptions?.domainHint;\n  }\n  // If there can only be one logical choice, use it!\n  if (emailDomains?.length === 1) {\n    return emailDomains[0];\n  }\n  // If it isn't clear who sent the email\n  // we simply won't provide a hint!\n  return null;\n};\n\nexport const EmailConfirmation = ({ showGoBack = true }: { showGoBack?: boolean }) => {\n  const stytchClient = useStytch();\n  const [state, dispatch] = useGlobalReducer();\n  const emailDomain = useEmailDomain();\n  const countdown = useCountdown();\n  const { sendLink, isSubmitting } = usePasswordlessAuthenticate();\n\n  const email =\n    state.formState.magicLinkState.email !== ''\n      ? state.formState.magicLinkState.email\n      : state.formState.passwordState.email;\n\n  const goBack = () => {\n    dispatch({ type: 'set_magic_link_email', email: '' });\n    dispatch({ type: 'transition', screen: AppScreens.Main });\n    readB2CInternals(stytchClient).networkClient.logEvent({\n      name: 'email_try_again_clicked',\n      details: { email: email, type: EmailSentType.LoginOrCreateEML },\n    });\n  };\n\n  return (\n    <EmailConfirmationView\n      emailDomain={emailDomain}\n      email={email}\n      goBack={showGoBack ? goBack : undefined}\n      resend={sendLink}\n      countdown={countdown}\n      isSubmitting={isSubmitting}\n    />\n  );\n};\n"],"names":["useEmailDomain","stytch","useStytch","config","useConfig","emailDomains","setEmailDomains","useState","readB2CInternals","bootstrap","getSync","useEffect","getAsync","then","emailMagicLinksOptions","domainHint","length","EmailConfirmation","showGoBack","stytchClient","state","dispatch","useGlobalReducer","emailDomain","countdown","useCountdown","sendLink","isSubmitting","usePasswordlessAuthenticate","email","formState","magicLinkState","passwordState","goBack","type","screen","AppScreens","Main","networkClient","logEvent","name","details","EmailSentType","LoginOrCreateEML","React","EmailConfirmationView","undefined","resend"],"mappings":";;;;;;;;;AASA;;UAGaA,cAAAA,GAAiB,IAAA;AAC5B,IAAA,MAAMC,MAAAA,GAASC,SAAAA,EAAAA;AACf,IAAA,MAAMC,MAAAA,GAASC,SAAAA,EAAAA;AACf;;;AAGC,MACD,MAAM,CAACC,YAAAA,EAAcC,eAAAA,CAAgB,GAAGC,CAAAA,CAAS,IAAA;QAC/C,MAAM,EAAEF,YAAY,EAAE,GAAGG,iBAAiBP,MAAAA,CAAAA,CAAQQ,SAAS,CAACC,OAAO,EAAA;QACnE,OAAOL,YAAAA;AACT,IAAA,CAAA,CAAA;IAEAM,CAAAA,CAAU,IAAA;QACRH,gBAAAA,CAAiBP,MAAAA,CAAAA,CACdQ,SAAS,CAACG,QAAQ,EAAA,CAClBC,IAAI,CAAC,CAAC,EAAER,YAAY,EAAE,GAAA;YACrBC,eAAAA,CAAgBD,YAAAA,CAAAA;AAClB,QAAA,CAAA,CAAA;IACJ,CAAA,EAAG;AAACJ,QAAAA;AAAO,KAAA,CAAA;;IAGX,IAAIE,MAAAA,CAAOW,sBAAsB,EAAEC,UAAAA,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