From 19803854e2378f570de18776baad330082672f93 Mon Sep 17 00:00:00 2001 From: Malachi Willey Date: Thu, 27 Feb 2025 13:32:23 -0800 Subject: [PATCH] feat(nav): Open zendesk when clicking 'contact support' --- static/app/components/nav/primary/help.tsx | 44 +++++++++++++++++++--- static/app/utils/zendesk.tsx | 14 +++++++ static/gsApp/components/zendeskLink.tsx | 5 ++- 3 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 static/app/utils/zendesk.tsx diff --git a/static/app/components/nav/primary/help.tsx b/static/app/components/nav/primary/help.tsx index 0086abf2862b77..c867a01d005908 100644 --- a/static/app/components/nav/primary/help.tsx +++ b/static/app/components/nav/primary/help.tsx @@ -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 ( { 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});