beta-modal.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import { useIdeRedesignSwitcherContext } from '@/features/ide-react/context/ide-redesign-switcher-context'
  2. import OLButton from '@/features/ui/components/ol/ol-button'
  3. import OLModal, {
  4. OLModalBody,
  5. OLModalFooter,
  6. OLModalHeader,
  7. OLModalTitle,
  8. } from '@/features/ui/components/ol/ol-modal'
  9. import { FC, useCallback, useEffect } from 'react'
  10. import {
  11. canUseNewEditor,
  12. useIsNewEditorEnabled,
  13. } from '../../utils/new-editor-utils'
  14. import Notification from '@/shared/components/notification'
  15. import { useSwitchEnableNewEditorState } from '../../hooks/use-switch-enable-new-editor-state'
  16. import { useTranslation } from 'react-i18next'
  17. import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
  18. import { useSurveyUrl } from '../../hooks/use-survey-url'
  19. import useTutorial from '@/shared/hooks/promotions/use-tutorial'
  20. import { useEditorContext } from '@/shared/context/editor-context'
  21. const TUTORIAL_KEY = 'ide-redesign-beta-intro'
  22. export const IdeRedesignIntroModal: FC = () => {
  23. const { t } = useTranslation()
  24. const { inactiveTutorials } = useEditorContext()
  25. const { showPopup, tryShowingPopup, dismissTutorial } = useTutorial(
  26. TUTORIAL_KEY,
  27. {
  28. name: TUTORIAL_KEY,
  29. }
  30. )
  31. useEffect(() => {
  32. if (!inactiveTutorials.includes(TUTORIAL_KEY)) {
  33. tryShowingPopup()
  34. }
  35. }, [tryShowingPopup, inactiveTutorials])
  36. const hasAccess = canUseNewEditor()
  37. if (!hasAccess) {
  38. return null
  39. }
  40. return (
  41. <OLModal
  42. show={showPopup}
  43. onHide={dismissTutorial}
  44. className="ide-redesign-switcher-modal"
  45. >
  46. <OLModalHeader closeButton>
  47. <OLModalTitle>
  48. {t('the_new_overleaf_editor_try_now_in_beta')}
  49. </OLModalTitle>
  50. </OLModalHeader>
  51. <OLModalBody>
  52. <p>
  53. {t(
  54. 'weve_redesigned_our_editor_to_make_it_easier_to_use_and_future_ready'
  55. )}{' '}
  56. {t('you_can_switch_back_to_the_old_editor_at_any_time')}
  57. </p>
  58. <SwitcherWhatsDifferent />
  59. </OLModalBody>
  60. <OLModalFooter>
  61. <OLButton onClick={dismissTutorial} variant="secondary">
  62. {t('close')}
  63. </OLButton>
  64. </OLModalFooter>
  65. </OLModal>
  66. )
  67. }
  68. export const IdeRedesignSwitcherModal = () => {
  69. const { t } = useTranslation()
  70. const { showSwitcherModal, setShowSwitcherModal } =
  71. useIdeRedesignSwitcherContext()
  72. const onHide = useCallback(
  73. () => setShowSwitcherModal(false),
  74. [setShowSwitcherModal]
  75. )
  76. const { loading, error, setEditorRedesignStatus } =
  77. useSwitchEnableNewEditorState()
  78. const enabled = useIsNewEditorEnabled()
  79. const hasAccess = canUseNewEditor()
  80. if (!hasAccess) {
  81. return null
  82. }
  83. const Content = enabled
  84. ? SwitcherModalContentEnabled
  85. : SwitcherModalContentDisabled
  86. return (
  87. <OLModal
  88. show={showSwitcherModal}
  89. onHide={onHide}
  90. className="ide-redesign-switcher-modal"
  91. >
  92. <OLModalHeader closeButton>
  93. <OLModalTitle>
  94. {enabled
  95. ? t('beta_program_the_new_overleaf_editor')
  96. : t('the_new_overleaf_editor_try_now_in_beta')}
  97. </OLModalTitle>
  98. </OLModalHeader>
  99. {error && <Notification type="error" content={error} isDismissible />}
  100. <Content
  101. setEditorRedesignStatus={setEditorRedesignStatus}
  102. hide={onHide}
  103. loading={loading}
  104. />
  105. </OLModal>
  106. )
  107. }
  108. type ModalContentProps = {
  109. setEditorRedesignStatus: (enabled: boolean) => Promise<void>
  110. hide: () => void
  111. loading: boolean
  112. }
  113. const SwitcherModalContentEnabled: FC<ModalContentProps> = ({
  114. setEditorRedesignStatus,
  115. hide,
  116. loading,
  117. }) => {
  118. const { t } = useTranslation()
  119. const { sendEvent } = useEditorAnalytics()
  120. const disable = useCallback(() => {
  121. sendEvent('editor-redesign-toggle', {
  122. action: 'disable',
  123. location: 'modal',
  124. })
  125. setEditorRedesignStatus(false)
  126. .then(hide)
  127. .catch(() => {
  128. // do nothing, we're already showing the error
  129. })
  130. }, [setEditorRedesignStatus, hide, sendEvent])
  131. const surveyURL = useSurveyUrl()
  132. return (
  133. <>
  134. <OLModalBody>
  135. <p>
  136. {t(
  137. 'weve_redesigned_our_editor_to_make_it_easier_to_use_and_future_ready'
  138. )}
  139. </p>
  140. <SwitcherWhatsDifferent />
  141. </OLModalBody>
  142. <OLModalFooter>
  143. <OLButton
  144. onClick={disable}
  145. variant="secondary"
  146. className="me-auto"
  147. disabled={loading}
  148. >
  149. {t('switch_to_old_editor')}
  150. </OLButton>
  151. <OLButton onClick={hide} variant="secondary">
  152. {t('cancel')}
  153. </OLButton>
  154. <OLButton
  155. href={surveyURL}
  156. target="_blank"
  157. rel="noopener noreferrer"
  158. variant="primary"
  159. >
  160. {t('give_feedback')}
  161. </OLButton>
  162. </OLModalFooter>
  163. </>
  164. )
  165. }
  166. const SwitcherModalContentDisabled: FC<ModalContentProps> = ({
  167. setEditorRedesignStatus,
  168. hide,
  169. loading,
  170. }) => {
  171. const { t } = useTranslation()
  172. const { sendEvent } = useEditorAnalytics()
  173. const enable = useCallback(() => {
  174. sendEvent('editor-redesign-toggle', {
  175. action: 'enable',
  176. location: 'modal',
  177. })
  178. setEditorRedesignStatus(true)
  179. .then(hide)
  180. .catch(() => {
  181. // do nothing, we're already showing the error
  182. })
  183. }, [setEditorRedesignStatus, hide, sendEvent])
  184. return (
  185. <>
  186. <OLModalBody>
  187. <p>
  188. {t(
  189. 'weve_redesigned_our_editor_to_make_it_easier_to_use_and_future_ready'
  190. )}
  191. </p>
  192. <SwitcherWhatsDifferent />
  193. <LeavingNote />
  194. </OLModalBody>
  195. <OLModalFooter>
  196. <OLButton onClick={hide} variant="secondary">
  197. {t('cancel')}
  198. </OLButton>
  199. <OLButton onClick={enable} variant="primary" disabled={loading}>
  200. {t('switch_to_new_editor')}
  201. </OLButton>
  202. </OLModalFooter>
  203. </>
  204. )
  205. }
  206. const SwitcherWhatsDifferent = () => {
  207. const { t } = useTranslation()
  208. return (
  209. <div className="ide-redesign-switcher-modal-whats-new">
  210. <h4>{t('whats_different')}</h4>
  211. <ul>
  212. <li>{t('new_look_and_feel')}</li>
  213. <li>
  214. {t('new_navigation_introducing_left_hand_side_rail_and_top_menus')}
  215. </li>
  216. <li>{t('new_look_and_placement_of_the_settings')}</li>
  217. <li>{t('improved_dark_mode')}</li>
  218. <li>{t('review_panel_and_error_logs_moved_to_the_left')}</li>
  219. </ul>
  220. </div>
  221. )
  222. }
  223. const LeavingNote = () => {
  224. const { t } = useTranslation()
  225. return <p>{t('you_can_switch_back_to_the_old_editor_at_any_time')}</p>
  226. }