new-editor-promo-modal.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import {
  2. OLModal,
  3. OLModalBody,
  4. OLModalFooter,
  5. OLModalHeader,
  6. OLModalTitle,
  7. } from '@/shared/components/ol/ol-modal'
  8. import { useSwitchEnableNewEditorState } from '../hooks/use-switch-enable-new-editor-state'
  9. import { useCallback, useEffect, useState } from 'react'
  10. import useTutorial from '@/shared/hooks/promotions/use-tutorial'
  11. import OLButton from '@/shared/components/ol/ol-button'
  12. import { Trans, useTranslation } from 'react-i18next'
  13. import { useEditorContext } from '@/shared/context/editor-context'
  14. import {
  15. canUseNewEditorAsExistingUser,
  16. useIsNewEditorEnabled,
  17. } from '../utils/new-editor-utils'
  18. import promoVideo from './new-editor-promo-video.mp4'
  19. const TUTORIAL_KEY = 'new-editor-opt-in'
  20. export default function NewEditorPromoModal() {
  21. const { inactiveTutorials } = useEditorContext()
  22. const {
  23. tryShowingPopup,
  24. showPopup: showModal,
  25. dismissTutorial,
  26. completeTutorial,
  27. clearPopup,
  28. } = useTutorial(TUTORIAL_KEY, {
  29. name: TUTORIAL_KEY,
  30. })
  31. const { setEditorRedesignStatus } = useSwitchEnableNewEditorState()
  32. const { t } = useTranslation()
  33. const newEditor = useIsNewEditorEnabled()
  34. const canShow = canUseNewEditorAsExistingUser() && !newEditor
  35. const [hasShown, setHasShown] = useState(false)
  36. useEffect(() => {
  37. if (canShow && !hasShown && !inactiveTutorials.includes(TUTORIAL_KEY)) {
  38. tryShowingPopup('notification-prompt')
  39. setHasShown(true)
  40. }
  41. }, [tryShowingPopup, inactiveTutorials, canShow, hasShown])
  42. const switchToNewEditor = useCallback(() => {
  43. setEditorRedesignStatus(true)
  44. completeTutorial({ event: 'notification-click', action: 'complete' })
  45. clearPopup()
  46. }, [setEditorRedesignStatus, completeTutorial, clearPopup])
  47. const closeModal = useCallback(() => {
  48. dismissTutorial('notification-dismiss')
  49. clearPopup()
  50. }, [dismissTutorial, clearPopup])
  51. if (!canShow) {
  52. return null
  53. }
  54. return (
  55. <OLModal show={showModal} onHide={closeModal}>
  56. <OLModalHeader>
  57. <OLModalTitle>{t('overleafs_new_look_is_here')}</OLModalTitle>
  58. </OLModalHeader>
  59. <OLModalBody className="new-editor-promo-modal-body">
  60. <div>
  61. {t(
  62. 'be_one_of_the_first_to_try_out_the_new_and_improved_overleaf_editor'
  63. )}
  64. </div>
  65. {/* eslint-disable-next-line jsx-a11y/media-has-caption */}
  66. <video autoPlay loop muted>
  67. <source src={promoVideo} type="video/mp4" />
  68. </video>
  69. <div>
  70. <Trans
  71. i18nKey="try_out_the_new_editor_now"
  72. components={[
  73. /* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */
  74. <a
  75. href="https://www.overleaf.com/blog/introducing-overleafs-new-look"
  76. target="_blank"
  77. rel="noopener noreferrer"
  78. key="link"
  79. />,
  80. ]}
  81. />
  82. </div>
  83. </OLModalBody>
  84. <OLModalFooter>
  85. <OLButton onClick={closeModal} variant="secondary">
  86. {t('not_now')}
  87. </OLButton>
  88. <OLButton onClick={switchToNewEditor} variant="primary">
  89. {t('try_the_new_look')}
  90. </OLButton>
  91. </OLModalFooter>
  92. </OLModal>
  93. )
  94. }