tooltip-promo.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import Close from '@/shared/components/close'
  2. import { useEditorContext } from '@/shared/context/editor-context'
  3. import useTutorial from '@/shared/hooks/promotions/use-tutorial'
  4. import { isSplitTestEnabled } from '@/utils/splitTestUtils'
  5. import classNames from 'classnames'
  6. import { useCallback, useEffect } from 'react'
  7. import { Overlay, OverlayProps, Popover } from 'react-bootstrap'
  8. export default function TooltipPromotion({
  9. target,
  10. tutorialKey,
  11. eventData,
  12. className,
  13. content,
  14. header,
  15. placement = 'bottom',
  16. splitTestName,
  17. }: {
  18. target: HTMLElement | null
  19. tutorialKey: string
  20. eventData: Record<string, any>
  21. className?: string
  22. content: string
  23. header?: string
  24. placement?: OverlayProps['placement']
  25. splitTestName?: string
  26. }) {
  27. const { inactiveTutorials } = useEditorContext()
  28. const { showPopup, tryShowingPopup, hideUntilReload, dismissTutorial } =
  29. useTutorial(tutorialKey, eventData)
  30. useEffect(() => {
  31. if (!inactiveTutorials.includes(tutorialKey)) {
  32. tryShowingPopup()
  33. }
  34. }, [tryShowingPopup, inactiveTutorials, tutorialKey])
  35. const isInSplitTestIfNeeded = splitTestName
  36. ? isSplitTestEnabled(splitTestName)
  37. : true
  38. const onHide = useCallback(() => {
  39. hideUntilReload()
  40. }, [hideUntilReload])
  41. if (!target || !isInSplitTestIfNeeded) {
  42. return null
  43. }
  44. return (
  45. <Overlay
  46. placement={placement}
  47. show={showPopup}
  48. target={target}
  49. rootClose
  50. onHide={onHide}
  51. >
  52. <Popover>
  53. {header && (
  54. <Popover.Header>
  55. {header}
  56. <Close variant="dark" onDismiss={dismissTutorial} />
  57. </Popover.Header>
  58. )}
  59. <Popover.Body className={classNames(className)}>
  60. {content}
  61. {!header && <Close variant="dark" onDismiss={dismissTutorial} />}
  62. </Popover.Body>
  63. </Popover>
  64. </Overlay>
  65. )
  66. }