Skip to content

Commit

Permalink
feat: remove Intercom usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Jan 11, 2024
1 parent d59484a commit 361d07c
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 255 deletions.
19 changes: 0 additions & 19 deletions apps/client/components/APM.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import { useAuth0 } from '@auth0/auth0-react'
import { useIntercom } from '@maybe-finance/client/shared'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import * as Sentry from '@sentry/react'

export default function APM() {
const { user } = useAuth0()
const router = useRouter()
const intercom = useIntercom()

// Boot intercom
useEffect(() => {
const isBooted = intercom.boot()

const handleRouteChange = () => {
if (isBooted) {
intercom.update()
}
}

router.events.on('routeChangeComplete', handleRouteChange)

return () => router.events.off('routeChangeComplete', handleRouteChange)
}, [intercom, router.events])

// Identify Sentry user
useEffect(() => {
Expand Down
9 changes: 0 additions & 9 deletions apps/client/components/Meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ export default function Meta() {
href="https://cdn.jsdelivr.net/npm/[email protected]/fonts/remixicon.css"
rel="stylesheet"
/>

{/* Intercom */}
<script
type="text/javascript"
dangerouslySetInnerHTML={{
__html: `window.INTERCOM_APP_ID='${env.NEXT_PUBLIC_INTERCOM_APP_ID}';(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/' + window.INTERCOM_APP_ID;var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();`,
}}
/>
{/* End Intercom */}
</Head>
)
}
1 change: 0 additions & 1 deletion apps/client/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const env = {
process.env.NEXT_PUBLIC_LD_CLIENT_SIDE_ID || 'REPLACE_THIS',
NEXT_PUBLIC_SENTRY_DSN: process.env.NEXT_PUBLIC_SENTRY_DSN,
NEXT_PUBLIC_SENTRY_ENV: process.env.NEXT_PUBLIC_SENTRY_ENV,
NEXT_PUBLIC_INTERCOM_APP_ID: process.env.NEXT_PUBLIC_INTERCOM_APP_ID || 'REPLACE_THIS',
}

export default env
11 changes: 3 additions & 8 deletions apps/client/pages/oauth.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserUtil, usePlaid } from '@maybe-finance/client/shared'
import { usePlaid } from '@maybe-finance/client/shared'
import { Disclosure, Transition } from '@headlessui/react'
import { RiArrowUpSFill } from 'react-icons/ri'
import { Button, LoadingSpinner } from '@maybe-finance/design-system'
Expand Down Expand Up @@ -56,14 +56,9 @@ export default function OAuth() {
</li>
<li>
Still not working?{' '}
<button
onClick={() =>
BrowserUtil.showIntercom()
}
className="underline text-cyan"
>
<a className="underline text-cyan" href="mailto:[email protected]">
Let us know!
</button>
</a>
</li>
</ul>
</Disclosure.Panel>
Expand Down
13 changes: 0 additions & 13 deletions apps/server/src/app/routes/users.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,6 @@ router.get(
})
)

router.get(
'/intercom',
endpoint.create({
resolve: async ({ ctx }) => {
if (!ctx.user || !ctx.user.id) {
throw new Error('User not found')
}

return ctx.userService.getIntercomMetadata(ctx.user.id, env.NX_INTERCOM_SECRET)
},
})
)

router.put(
'/',
endpoint.create({
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const envSchema = z.object({
.string()
.default(process.env.NODE_ENV === 'development' ? 'dev' : 'combined'),

NX_INTERCOM_SECRET: z.string().optional(),

NX_STRIPE_SECRET_KEY: z.string().default('REPLACE_THIS'),
NX_STRIPE_WEBHOOK_SECRET: z.string().default('whsec_REPLACE_THIS'),
NX_STRIPE_PREMIUM_MONTHLY_PRICE_ID: z.string().default('price_REPLACE_THIS'),
Expand Down
9 changes: 0 additions & 9 deletions aws/maybe-app/lib/stacks/server-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,6 @@ export class ServerStack extends Stack {
}
)
),
NX_INTERCOM_SECRET: ECSSecret.fromSsmParameter(
StringParameter.fromSecureStringParameterAttributes(
this,
'IntercomSecretParam',
{
parameterName: '/providers/NX_INTERCOM_SECRET',
}
)
),
NX_STRIPE_SECRET_KEY: ECSSecret.fromSsmParameter(
StringParameter.fromSecureStringParameterAttributes(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
RiMore2Fill,
} from 'react-icons/ri'
import { HiOutlineSparkles } from 'react-icons/hi'
import { BrowserUtil } from '@maybe-finance/client/shared'
import Link from 'next/link'
import { AnimatePresence, motion } from 'framer-motion'

Expand Down Expand Up @@ -399,13 +398,11 @@ export function SidebarOnboarding({ onClose, onHide }: Props) {
</Disclosure>

<p className="text-sm text-gray-100">
If you have any issues with connecting accounts, please let us know{' '}
<button
onClick={() => BrowserUtil.showIntercom()}
className="text-cyan cursor-pointer hover:underline"
>
via live chat
</button>
If you have any issues with connecting accounts,{' '}
<a className="text-cyan underline" href="mailto:[email protected]">
please let us know
</a>
.
</p>
</>
)
Expand Down
9 changes: 3 additions & 6 deletions libs/client/features/src/user-details/LinkAccountFlow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAuth0 } from '@auth0/auth0-react'
import { BoxIcon, BrowserUtil, linkAuth0AccountCtx, useUserApi } from '@maybe-finance/client/shared'
import { BoxIcon, linkAuth0AccountCtx, useUserApi } from '@maybe-finance/client/shared'
import { Button, DialogV2 } from '@maybe-finance/design-system'
import { useQueryClient } from '@tanstack/react-query'
import { useState } from 'react'
Expand Down Expand Up @@ -253,12 +253,9 @@ function LinkError({ onClose, error }: { onClose(): void; error: string }) {

<p className="mb-2 text-gray-50 text-base">{error}</p>

<button
className="underline text-cyan text-base mb-6"
onClick={BrowserUtil.showIntercom}
>
<a className="underline text-cyan text-base mb-6" href="mailto:[email protected]">
Please contact us.
</button>
</a>

<div className="flex w-full gap-4">
<Button fullWidth onClick={onClose}>
Expand Down
11 changes: 1 addition & 10 deletions libs/client/shared/src/api/useAccountApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import type {
} from '@tanstack/react-query'

import { useMemo } from 'react'
import sumBy from 'lodash/sumBy'
import toast from 'react-hot-toast'
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useAxiosWithAuth, useIntercom } from '..'
import { useAxiosWithAuth } from '..'
import { invalidateAccountQueries } from '../utils'

const AccountApi = (axios: AxiosInstance) => ({
Expand Down Expand Up @@ -135,7 +134,6 @@ export function useAccountApi() {
const queryClient = useQueryClient()
const { axios } = useAxiosWithAuth()
const api = useMemo(() => AccountApi(axios), [axios])
const { update: updateIntercom } = useIntercom()

const useAccounts = (
options?: Omit<
Expand All @@ -152,13 +150,6 @@ export function useAccountApi() {
staleTime: staleTimes.accounts,
onSuccess: (...args) => {
if (options?.onSuccess) options.onSuccess(...args)

const [{ accounts, connections }] = args
updateIntercom({
'Manual Accounts': accounts.length,
'Connected Accounts': sumBy(connections, (c) => c.accounts.length),
Connections: connections.length,
})
},
...options,
})
Expand Down
22 changes: 0 additions & 22 deletions libs/client/shared/src/api/useUserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ const UserApi = (
return data
},

async getIntercomMetadata() {
const { data } = await axios.get<SharedType.UserIntercomMetadata>('/users/intercom')
return data
},

async update(userData: SharedType.UpdateUser) {
const { data } = await axios.put<SharedType.User>('/users', userData)
return data
Expand Down Expand Up @@ -254,22 +249,6 @@ export function useUserApi() {
staleTime: staleTimes.insights,
})

const useIntercomMetadata = (
options?: Omit<
UseQueryOptions<
SharedType.UserIntercomMetadata,
unknown,
SharedType.UserIntercomMetadata,
any[]
>,
'queryKey' | 'queryFn'
>
) =>
useQuery(['users', 'intercom-metadata'], api.getIntercomMetadata, {
refetchOnWindowFocus: false,
...options,
})

const useProfile = (
options?: Omit<
UseQueryOptions<SharedType.User, unknown, SharedType.User, any[]>,
Expand Down Expand Up @@ -471,7 +450,6 @@ export function useUserApi() {
useNetWorthSeries,
useInsights,
useCurrentNetWorth,
useIntercomMetadata,
useProfile,
useUpdateProfile,
useAuth0Profile,
Expand Down
1 change: 0 additions & 1 deletion libs/client/shared/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './useAxiosWithAuth'
export * from './useDebounce'
export * from './useFinicity'
export * from './useIntercom'
export * from './useInterval'
export * from './useLastUpdated'
export * from './useLocalStorage'
Expand Down
23 changes: 4 additions & 19 deletions libs/client/shared/src/hooks/useFinicity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import type {
ConnectCancelEvent,
ConnectDoneEvent,
ConnectErrorEvent,
ConnectRouteEvent,
} from '@finicity/connect-web-sdk'
import { useFinicityApi } from '../api'
import { useAccountContext, useUserAccountContext } from '../providers'
import { useLogger } from './useLogger'
import { BrowserUtil } from '..'

export function useFinicity() {
const logger = useLogger()
Expand All @@ -35,9 +33,6 @@ export function useFinicity() {
FinicityConnect.launch(link, {
onDone(evt: ConnectDoneEvent) {
logger.debug(`Finicity Connect onDone event`, evt)
BrowserUtil.trackIntercomEvent('FINICITY_CONNECT_DONE', {
...evt,
})
setExpectingAccounts(true)
},
onError(evt: ConnectErrorEvent) {
Expand All @@ -50,25 +45,15 @@ export function useFinicity() {
'finicity.error.reason': evt.reason,
},
})
BrowserUtil.trackIntercomEvent('FINICITY_CONNECT_ERROR', {
...evt,
})
},
onCancel(evt: ConnectCancelEvent) {
logger.debug(`Finicity Connect onCancel event`, evt)
BrowserUtil.trackIntercomEvent('FINICITY_CONNECT_CANCEL', {
...evt,
})
},
onUser(evt: any) {
BrowserUtil.trackIntercomEvent('FINICITY_CONNECT_USER_ACTION', {
...evt,
})
onUser() {
// ...
},
onRoute(evt: ConnectRouteEvent) {
BrowserUtil.trackIntercomEvent('FINICITY_CONNECT_ROUTE_EVENT', {
...evt,
})
onRoute() {
// ...
},
})
},
Expand Down
50 changes: 0 additions & 50 deletions libs/client/shared/src/hooks/useIntercom.ts

This file was deleted.

Loading

0 comments on commit 361d07c

Please sign in to comment.