1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import {Component} from 'react';
- import type {Organization} from 'sentry/types/organization';
- import withOrganization from 'sentry/utils/withOrganization';
- import {activateZendesk, zendeskIsLoaded} from 'sentry/utils/zendesk';
- import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
- type AnchorProps = {
- href: string;
- onClick: (e: React.MouseEvent) => void;
- };
- type Props = {
- organization: Organization;
- Component?: React.ComponentType<AnchorProps>;
- address?: string;
- children?: React.ReactNode;
- className?: string;
- source?: string;
- subject?: string;
- };
- class ZendeskLink extends Component<Props> {
- componentDidMount() {
- const {organization, source} = this.props;
- if (organization) {
- trackGetsentryAnalytics('zendesk_link.viewed', {organization, source});
- }
- }
- activateSupportWidget = (e: React.MouseEvent) => {
- const {organization, source} = this.props;
- if (zendeskIsLoaded()) {
- e.preventDefault();
- activateZendesk();
- }
- trackGetsentryAnalytics('zendesk_link.clicked', {organization, source});
- };
- render() {
- const {
- Component: LinkComponent,
- subject,
- address,
- source: _source,
- organization: _organization,
- ...props
- } = this.props;
- let mailto = `mailto:${address ?? 'support'}@sentry.io`;
- if (subject) {
- mailto = `${mailto}?subject=${window.encodeURIComponent(subject)}`;
- }
- const Link = LinkComponent ?? 'a';
- return (
- <Link href={mailto} onClick={this.activateSupportWidget} {...props}>
- {this.props.children}
- </Link>
- );
- }
- }
- export default withOrganization(ZendeskLink);
|