Skip to content

Commit

Permalink
fix: Intercom chat not appearing for some users (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmar committed Aug 18, 2023
1 parent 24450f2 commit 753b837
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions assets/src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IntercomProps, useIntercom } from 'react-use-intercom'
import { useLocation } from 'react-router-dom'
import { WelcomeHeader } from 'components/utils/WelcomeHeader'
import { isValidEmail } from 'utils/email'
import { useMeQuery } from 'generated/graphql'
import { User, useMeQuery } from 'generated/graphql'
import { useHelpSpacing } from 'components/help/HelpLauncher'

import { GqlError } from '../utils/Alert'
Expand Down Expand Up @@ -138,15 +138,22 @@ function fudgedUser(name): IntercomUser {
type IntercomUser = Pick<IntercomProps, 'email' | 'name' | 'userId'>

function useIntercomAttributes(
user: IntercomUser | null | undefined
pluralUser: User | null | undefined
): IntercomProps | null | undefined {
const helpSpacing = useHelpSpacing()

if (!user) {
if (!pluralUser) {
return null
}
if (user.email === 'demo-user@plural.sh') {
return (user = fudgedUser(user.name))
const { email, name, pluralId, id } = pluralUser
let intercomUser: IntercomUser = {
email,
name,
userId: pluralId || id,
}

if (intercomUser.email === 'demo-user@plural.sh') {
return (intercomUser = fudgedUser(name))
}

return {
Expand All @@ -156,7 +163,7 @@ function useIntercomAttributes(
helpSpacing.padding.bottom +
helpSpacing.icon.height +
helpSpacing.gap.vertical,
...user,
...intercomUser,
}
}

Expand Down

0 comments on commit 753b837

Please sign in to comment.