Skip to content

Commit

Permalink
fix: add back gleap
Browse files Browse the repository at this point in the history
  • Loading branch information
gagdiez committed Jul 25, 2024
1 parent b52c731 commit e5189ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/hooks/useGatewayEvents.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import Gleap from 'gleap';
import { useCallback } from 'react';

import { useSidebarLayoutEnabled } from '@/components/sidebar-navigation/hooks';
import { useNavigationStore } from '@/components/sidebar-navigation/store';
import type { PinnedApp } from '@/components/sidebar-navigation/utils';

type GleapGatewayEvent = {
type: 'GLEAP';
action: 'CLOSE' | 'OPEN';
};

type PinnedAppsGatewayEvent = {
type: 'PINNED_APPS';
app?: PinnedApp;
action: 'FEATURE_ENABLED' | 'PINNED' | 'UNPINNED';
};

type GatewayEvent = PinnedAppsGatewayEvent;
type GatewayEvent = GleapGatewayEvent | PinnedAppsGatewayEvent;

const COMPONENT_AUTHOR_ID_WHITELIST = ['near', 'discom.testnet', 'discom-dev.testnet'];

export function useGatewayEvents() {
const { sidebarLayoutEnabled } = useSidebarLayoutEnabled();
const modifyPinnedApps = useNavigationStore((store) => store.modifyPinnedApps);

const handleGleapEvent = useCallback((event: GleapGatewayEvent) => {
if (event.action === 'CLOSE') {
Gleap.close();
} else if (event.action === 'OPEN') {
Gleap.open();
} else {
console.error('Unimplemented gleap gateway event recorded:', event);
}
}, []);

const handlePinnedAppsEvent = useCallback(
(event: PinnedAppsGatewayEvent) => {
if (event.action === 'FEATURE_ENABLED') {
Expand All @@ -34,13 +50,15 @@ export function useGatewayEvents() {
const emitGatewayEvent = useCallback(
(event: GatewayEvent) => {
switch (event.type) {
case 'GLEAP':
return handleGleapEvent(event);
case 'PINNED_APPS':
return handlePinnedAppsEvent(event);
default:
console.error('Unimplemented gateway event recorded:', event);
}
},
[handlePinnedAppsEvent],
[handleGleapEvent, handlePinnedAppsEvent],
);

const shouldPassGatewayEventProps = useCallback((componentAuthorId: string) => {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@near-wallet-selector/modal-ui/styles.css';
import 'react-bootstrap-typeahead/css/Typeahead.css';
import 'react-bootstrap-typeahead/css/Typeahead.bs5.css';

import Gleap from 'gleap';
import type { AppProps } from 'next/app';
import dynamic from 'next/dynamic';
import Head from 'next/head';
Expand All @@ -21,6 +22,7 @@ import { useHashUrlBackwardsCompatibility } from '@/hooks/useHashUrlBackwardsCom
import { usePageAnalytics } from '@/hooks/usePageAnalytics';
import { useAuthStore } from '@/stores/auth';
import { init as initializeAnalytics, recordHandledError, setReferrer } from '@/utils/analytics';
import { gleapSdkToken } from '@/utils/config';
import { setNotificationsLocalStorage } from '@/utils/notificationsLocalStorage';
import type { NextPageWithLayout } from '@/utils/types';
import { styleZendesk } from '@/utils/zendesk';
Expand All @@ -33,6 +35,10 @@ type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};

if (typeof window !== 'undefined') {
if (gleapSdkToken) Gleap.initialize(gleapSdkToken);
}

export default function App({ Component, pageProps }: AppPropsWithLayout) {
useBosLoaderInitializer();
useHashUrlBackwardsCompatibility();
Expand Down

0 comments on commit e5189ce

Please sign in to comment.