zendeskLink.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {Component} from 'react';
  2. import type {Organization} from 'sentry/types/organization';
  3. import withOrganization from 'sentry/utils/withOrganization';
  4. import {activateZendesk, zendeskIsLoaded} from 'sentry/utils/zendesk';
  5. import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
  6. type AnchorProps = {
  7. href: string;
  8. onClick: (e: React.MouseEvent) => void;
  9. };
  10. type Props = {
  11. organization: Organization;
  12. Component?: React.ComponentType<AnchorProps>;
  13. address?: string;
  14. children?: React.ReactNode;
  15. className?: string;
  16. source?: string;
  17. subject?: string;
  18. };
  19. class ZendeskLink extends Component<Props> {
  20. componentDidMount() {
  21. const {organization, source} = this.props;
  22. if (organization) {
  23. trackGetsentryAnalytics('zendesk_link.viewed', {organization, source});
  24. }
  25. }
  26. activateSupportWidget = (e: React.MouseEvent) => {
  27. const {organization, source} = this.props;
  28. if (zendeskIsLoaded()) {
  29. e.preventDefault();
  30. activateZendesk();
  31. }
  32. trackGetsentryAnalytics('zendesk_link.clicked', {organization, source});
  33. };
  34. render() {
  35. const {
  36. Component: LinkComponent,
  37. subject,
  38. address,
  39. source: _source,
  40. organization: _organization,
  41. ...props
  42. } = this.props;
  43. let mailto = `mailto:${address ?? 'support'}@sentry.io`;
  44. if (subject) {
  45. mailto = `${mailto}?subject=${window.encodeURIComponent(subject)}`;
  46. }
  47. const Link = LinkComponent ?? 'a';
  48. return (
  49. <Link href={mailto} onClick={this.activateSupportWidget} {...props}>
  50. {this.props.children}
  51. </Link>
  52. );
  53. }
  54. }
  55. export default withOrganization(ZendeskLink);