Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nav): Open zendesk when clicking 'contact support' #86068

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions static/app/components/nav/primary/help.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
import {openHelpSearchModal} from 'sentry/actionCreators/modal';
import type {MenuItemProps} from 'sentry/components/dropdownMenu';
import {SidebarMenu} from 'sentry/components/nav/primary/components';
import {IconQuestion} from 'sentry/icons';
import {t} from 'sentry/locale';
import ConfigStore from 'sentry/stores/configStore';
import type {Organization} from 'sentry/types/organization';
import {trackAnalytics} from 'sentry/utils/analytics';
import useMutateUserOptions from 'sentry/utils/useMutateUserOptions';
import useOrganization from 'sentry/utils/useOrganization';
import {activateZendesk, zendeskIsLoaded} from 'sentry/utils/zendesk';

import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';

function getContactSupportItem({
organization,
}: {
organization: Organization;
}): MenuItemProps | null {
const supportEmail = ConfigStore.get('supportEmail');

if (!supportEmail) {
return null;
}

if (zendeskIsLoaded()) {
return {
key: 'support',
label: t('Contact Support'),
onAction() {
activateZendesk();
trackGetsentryAnalytics('zendesk_link.clicked', {
organization,
source: 'sidebar',
});
},
};
}

return {
key: 'support',
label: t('Contact Support'),
externalHref: `mailto:${supportEmail}`,
};
}

export function PrimaryNavigationHelp() {
const organization = useOrganization();
const {mutate: mutateUserOptions} = useMutateUserOptions();
const contactSupportItem = getContactSupportItem({organization});

return (
<SidebarMenu
Expand Down Expand Up @@ -41,11 +79,7 @@ export function PrimaryNavigationHelp() {
key: 'help',
label: t('Get Help'),
children: [
{
key: 'support',
label: t('Contact Support'),
externalHref: `mailto:${ConfigStore.get('supportEmail')}`,
},
...(contactSupportItem ? [contactSupportItem] : []),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the menuItemProp supports a disabled prop for this use case — I also used to use this ternary + destructuring combo for the issue view nav, but I think the disabled prop should achieve the same behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does support disabled, but I don't want this to show up at all if you're self hosted and don't have a support email in the config

Copy link
Member

@MichaelSun48 MichaelSun48 Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my b I meant hidden. but now that I think about it, you'll still have to destructure the contactSupportItem anyways, so this might not make it much cleaner

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I didn't actually know about that property!

{
key: 'github',
label: t('Sentry on GitHub'),
Expand Down
14 changes: 14 additions & 0 deletions static/app/utils/zendesk.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Activates the Zendesk widget.
*
* Zendesk script is only loaded in SaaS. This will operate as a noop otherwise.
*/
export function activateZendesk() {
if (zendeskIsLoaded()) {
window.zE.activate({hideOnClose: true});
}
}

export function zendeskIsLoaded() {
return window.zE && typeof window.zE.activate === 'function';
}
5 changes: 3 additions & 2 deletions static/gsApp/components/zendeskLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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';

Expand Down Expand Up @@ -31,9 +32,9 @@ class ZendeskLink extends Component<Props> {
activateSupportWidget = (e: React.MouseEvent) => {
const {organization, source} = this.props;

if (window.zE && typeof window.zE.activate === 'function') {
if (zendeskIsLoaded()) {
e.preventDefault();
window.zE.activate({hideOnClose: true});
activateZendesk();
}

trackGetsentryAnalytics('zendesk_link.clicked', {organization, source});
Expand Down
Loading