-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1348 from flanksource/973-intercom-support
973-intercom-support
- Loading branch information
Showing
22 changed files
with
324 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/api/query-hooks/mutations/useSettingsResourcesMutations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useAuth, useUser } from "@clerk/nextjs"; | ||
import { useEffect } from "react"; | ||
import { useIntercom } from "react-use-intercom"; | ||
import { useUser as useContextUser } from "../../context"; | ||
import useDetermineAuthSystem from "../Authentication/useDetermineAuthSystem"; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
function BootIntercomForClerk({ children }: Props) { | ||
const { boot, shutdown } = useIntercom(); | ||
const { user } = useContextUser(); | ||
const { user: clerkUser } = useUser(); | ||
const { isSignedIn, isLoaded } = useAuth(); | ||
|
||
useEffect(() => { | ||
boot({ | ||
name: user?.name, | ||
email: user?.email, | ||
userId: user?.id, | ||
avatar: { | ||
type: "avatar", | ||
imageUrl: user?.avatar | ||
}, | ||
companies: clerkUser?.organizationMemberships.map((membership) => ({ | ||
companyId: membership.id, | ||
name: membership.organization.name | ||
})) | ||
}); | ||
}, [boot, clerkUser, user]); | ||
|
||
// on sign out, shutdown intercom | ||
useEffect(() => { | ||
if (!isSignedIn && isLoaded) { | ||
shutdown(); | ||
} | ||
}, [isSignedIn, isLoaded, shutdown]); | ||
|
||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
return <>{children}</>; | ||
} | ||
|
||
function BootIntercomForKratos({ children }: Props) { | ||
const { boot } = useIntercom(); | ||
const { user } = useContextUser(); | ||
|
||
useEffect(() => { | ||
boot({ | ||
name: user?.name, | ||
email: user?.email, | ||
userId: user?.id, | ||
avatar: { | ||
type: "avatar", | ||
imageUrl: user?.avatar | ||
} | ||
}); | ||
}, [boot, user]); | ||
|
||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
return <>{children}</>; | ||
} | ||
|
||
export default function BootIntercom({ children }: Props) { | ||
const authSystem = useDetermineAuthSystem(); | ||
|
||
if (authSystem === "clerk") { | ||
return <BootIntercomForClerk>{children}</BootIntercomForClerk>; | ||
} | ||
|
||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
return <BootIntercomForKratos>{children}</BootIntercomForKratos>; | ||
} |
Oops, something went wrong.