Skip to content

Commit

Permalink
track project id in intercom (#3941)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Nov 7, 2023
1 parent 615323b commit 0056bf8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
49 changes: 33 additions & 16 deletions dashboard/src/lib/hooks/useIntercom.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
// useIntercom contains all the utility methods related to the Intercom chat widget
export const useIntercom = () => {
const showIntercomWithMessageAfterDelay = (message: string, delaySeconds: number) => {
const func = () => {
if (typeof window.Intercom === 'function') {
window.Intercom('showNewMessage', message);
}
}
setTimeout(func, delaySeconds * 1000);
}
export const useIntercom = (): {
showIntercomWithMessage: ({
message,
delaySeconds,
}: {
message: string;
delaySeconds?: number | undefined;
}) => void;
} => {
const showIntercomWithMessageAfterDelay = (
message: string,
delaySeconds: number
): void => {
const func = (): void => {
if (typeof window.Intercom === "function") {
window.Intercom("showNewMessage", message);
}
};
setTimeout(func, delaySeconds * 1000);
};

const showIntercomWithMessage = ({ message, delaySeconds = 3 }: { message: string, delaySeconds?: number }) => {
showIntercomWithMessageAfterDelay(message, delaySeconds);
}
const showIntercomWithMessage = ({
message,
delaySeconds = 3,
}: {
message: string;
delaySeconds?: number;
}): void => {
showIntercomWithMessageAfterDelay(message, delaySeconds);
};

return {
showIntercomWithMessage,
}
}
return {
showIntercomWithMessage,
};
};
3 changes: 3 additions & 0 deletions dashboard/src/shared/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class ContextProvider extends Component<PropsType, StateType> {
this.setState({ currentProject }, () => {
callback && callback();
});
if (window.intercomSettings) {
window.intercomSettings["Project ID"] = currentProject.id;
}
},
projects: [],
setProjects: (projects: ProjectListType[]) => {
Expand Down

0 comments on commit 0056bf8

Please sign in to comment.