tooltip-promo.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /** @knipignore keep this file around even when there is no current promo using it */
  9. export default function TooltipPromotion({
  10. target,
  11. tutorialKey,
  12. eventData,
  13. className,
  14. content,
  15. header,
  16. placement = 'bottom',
  17. splitTestName,
  18. }: {
  19. target: HTMLElement | null
  20. tutorialKey: string
  21. eventData: Record<string, any>
  22. className?: string
  23. content: string
  24. header?: string
  25. placement?: OverlayProps['placement']
  26. splitTestName?: string
  27. }) {
  28. const { inactiveTutorials } = useEditorContext()
  29. const { showPopup, tryShowingPopup, hideUntilReload, dismissTutorial } =
  30. useTutorial(tutorialKey, eventData)
  31. useEffect(() => {
  32. if (!inactiveTutorials.includes(tutorialKey)) {
  33. tryShowingPopup()
  34. }
  35. }, [tryShowingPopup, inactiveTutorials, tutorialKey])
  36. const isInSplitTestIfNeeded = splitTestName
  37. ? isSplitTestEnabled(splitTestName)
  38. : true
  39. const onHide = useCallback(() => {
  40. hideUntilReload()
  41. }, [hideUntilReload])
  42. const onDismiss = useCallback(() => {
  43. dismissTutorial()
  44. }, [dismissTutorial])
  45. if (!target || !isInSplitTestIfNeeded) {
  46. return null
  47. }
  48. return (
  49. <Overlay
  50. placement={placement}
  51. show={showPopup}
  52. target={target}
  53. rootClose
  54. onHide={onHide}
  55. >
  56. <Popover>
  57. {header && (
  58. <Popover.Header>
  59. {header}
  60. <Close variant="dark" onDismiss={onDismiss} />
  61. </Popover.Header>
  62. )}
  63. <Popover.Body className={classNames(className)}>
  64. {content}
  65. {!header && <Close variant="dark" onDismiss={onDismiss} />}
  66. </Popover.Body>
  67. </Popover>
  68. </Overlay>
  69. )
  70. }