employeeFeedbackButton.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import useFeedbackWidget from 'sentry/components/feedback/widget/useFeedbackWidget';
  5. import {IconClose} from 'sentry/icons';
  6. import {IconMegaphone} from 'sentry/icons/iconMegaphone';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import {useSessionStorage} from 'sentry/utils/useSessionStorage';
  10. import {useUser} from 'sentry/utils/useUser';
  11. export default function EmployeeFeedbackButton() {
  12. const user = useUser();
  13. const buttonRef = useRef<HTMLButtonElement>(null);
  14. const feedback = useFeedbackWidget({
  15. buttonRef,
  16. messagePlaceholder: t(
  17. 'This feedback widget is only viewable by Sentry employees. Use this to quickly give feedback, especially useful if your replay captured something interesting.'
  18. ),
  19. formTitle: t('Internal Feedback'),
  20. });
  21. const [isHidden, setIsHidden] = useSessionStorage(
  22. 'hide_employee_feedback_button',
  23. false
  24. );
  25. if (!user?.isSuperuser || !feedback || isHidden) {
  26. return null;
  27. }
  28. return (
  29. <PositionedContainer>
  30. <FeedbackButton
  31. aria-label={t('Give feedback (Sentry employees only)')}
  32. icon={<IconMegaphone color="gray500" />}
  33. onClick={e => e.stopPropagation()}
  34. ref={buttonRef}
  35. size="md"
  36. title={t('Give feedback (Sentry employees only)')}
  37. />
  38. <HideButton
  39. aria-label={t('Hide for this session')}
  40. borderless
  41. icon={<IconClose color="gray500" isCircled />}
  42. onClick={() => {
  43. setIsHidden(true);
  44. }}
  45. size="xs"
  46. title={t('Hide for this session')}
  47. />
  48. </PositionedContainer>
  49. );
  50. }
  51. const PositionedContainer = styled('div')`
  52. position: fixed;
  53. top: 45%;
  54. right: ${space(2)};
  55. z-index: ${p => p.theme.zIndex.modal};
  56. :hover button {
  57. visibility: visible;
  58. }
  59. `;
  60. const FeedbackButton = styled(Button)`
  61. border-radius: 50%;
  62. width: 2.5rem;
  63. height: 2.5rem;
  64. `;
  65. const HideButton = styled(Button)`
  66. visibility: hidden;
  67. border-radius: 50%;
  68. width: 1.6rem;
  69. height: 1.6rem;
  70. position: absolute;
  71. top: -10px;
  72. right: -10px;
  73. z-index: ${p => p.theme.zIndex.initial};
  74. `;