add-comment-action.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { FC, useCallback } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import MaterialIcon from '@/shared/components/material-icon'
  4. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  5. import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
  6. import { sendMB } from '@/infrastructure/event-tracking'
  7. const AddCommentAction: FC = () => {
  8. const { t } = useTranslation()
  9. const permissions = usePermissionsContext()
  10. const handleClick = useCallback(() => {
  11. sendMB('add-comment', { location: 'tooltip' })
  12. window.dispatchEvent(new Event('add-new-review-comment'))
  13. }, [])
  14. if (!permissions.comment) {
  15. return null
  16. }
  17. return (
  18. <OLTooltip
  19. id="editor-floating-menu-add-comment"
  20. description={t('add_comment')}
  21. overlayProps={{ placement: 'right' }}
  22. >
  23. <button
  24. className="editor-floating-menu-button"
  25. onClick={handleClick}
  26. aria-label={t('add_comment')}
  27. >
  28. <MaterialIcon type="chat" />
  29. </button>
  30. </OLTooltip>
  31. )
  32. }
  33. export default AddCommentAction