root.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { useEffect } from 'react'
  2. import { Alert } from 'react-bootstrap'
  3. import { useTranslation } from 'react-i18next'
  4. import getMeta from '../../../utils/meta'
  5. import EmailsSection from './emails-section'
  6. import AccountInfoSection from './account-info-section'
  7. import PasswordSection from './password-section'
  8. import LinkingSection from './linking-section'
  9. import BetaProgramSection from './beta-program-section'
  10. import SessionsSection from './sessions-section'
  11. import NewsletterSection from './newsletter-section'
  12. import LeaveSection from './leave-section'
  13. import * as eventTracking from '../../../infrastructure/event-tracking'
  14. import { UserProvider } from '../../../shared/context/user-context'
  15. import { SSOProvider } from '../context/sso-context'
  16. import useWaitForI18n from '../../../shared/hooks/use-wait-for-i18n'
  17. import useScrollToIdOnLoad from '../../../shared/hooks/use-scroll-to-id-on-load'
  18. import { ExposedSettings } from '../../../../../types/exposed-settings'
  19. function SettingsPageRoot() {
  20. const { isReady } = useWaitForI18n()
  21. useScrollToIdOnLoad()
  22. useEffect(() => {
  23. eventTracking.sendMB('settings-view')
  24. }, [])
  25. return (
  26. <div className="container">
  27. <div className="row">
  28. <div className="col-md-12 col-lg-10 col-lg-offset-1">
  29. {isReady ? <SettingsPageContent /> : null}
  30. </div>
  31. </div>
  32. </div>
  33. )
  34. }
  35. function SettingsPageContent() {
  36. const { t } = useTranslation()
  37. const ssoError = getMeta('ol-ssoError') as string
  38. const { isOverleaf } = getMeta('ol-ExposedSettings') as ExposedSettings
  39. return (
  40. <UserProvider>
  41. {ssoError ? (
  42. <Alert bsStyle="danger">
  43. {t('sso_link_error')}: {t(ssoError)}
  44. </Alert>
  45. ) : null}
  46. <div className="card">
  47. <div className="page-header">
  48. <h1>{t('account_settings')}</h1>
  49. </div>
  50. <div>
  51. <EmailsSection />
  52. <div className="row">
  53. <div className="col-md-5">
  54. <AccountInfoSection />
  55. </div>
  56. <div className="col-md-5 col-md-offset-1">
  57. <PasswordSection />
  58. </div>
  59. </div>
  60. <hr />
  61. <SSOProvider>
  62. <LinkingSection />
  63. </SSOProvider>
  64. {isOverleaf ? (
  65. <>
  66. <BetaProgramSection />
  67. <hr />
  68. </>
  69. ) : null}
  70. <SessionsSection />
  71. {isOverleaf ? (
  72. <>
  73. <hr />
  74. <NewsletterSection />
  75. <hr />
  76. <LeaveSection />
  77. </>
  78. ) : null}
  79. </div>
  80. </div>
  81. </UserProvider>
  82. )
  83. }
  84. export default SettingsPageRoot