fix: wait for licenseData to resolve before the check to show chat support (#6091)

This commit is contained in:
Yunus M 2024-09-30 12:41:11 +05:30 committed by GitHub
parent 5a0a7c2c60
commit 3b7455ac4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,6 +12,7 @@ import useAnalytics from 'hooks/analytics/useAnalytics';
import { KeyboardHotkeysProvider } from 'hooks/hotkeys/useKeyboardHotkeys'; import { KeyboardHotkeysProvider } from 'hooks/hotkeys/useKeyboardHotkeys';
import { useIsDarkMode, useThemeConfig } from 'hooks/useDarkMode'; import { useIsDarkMode, useThemeConfig } from 'hooks/useDarkMode';
import { THEME_MODE } from 'hooks/useDarkMode/constant'; import { THEME_MODE } from 'hooks/useDarkMode/constant';
import useFeatureFlags from 'hooks/useFeatureFlag';
import useGetFeatureFlag from 'hooks/useGetFeatureFlag'; import useGetFeatureFlag from 'hooks/useGetFeatureFlag';
import useLicense, { LICENSE_PLAN_KEY } from 'hooks/useLicense'; import useLicense, { LICENSE_PLAN_KEY } from 'hooks/useLicense';
import { NotificationProvider } from 'hooks/useNotifications'; import { NotificationProvider } from 'hooks/useNotifications';
@ -58,23 +59,16 @@ function App(): JSX.Element {
const isDarkMode = useIsDarkMode(); const isDarkMode = useIsDarkMode();
const featureResponse = useGetFeatureFlag((allFlags) => {
const isOnboardingEnabled = const isOnboardingEnabled =
allFlags.find((flag) => flag.name === FeatureKeys.ONBOARDING)?.active || useFeatureFlags(FeatureKeys.ONBOARDING)?.active || false;
false;
const isChatSupportEnabled = const isChatSupportEnabled =
allFlags.find((flag) => flag.name === FeatureKeys.CHAT_SUPPORT)?.active || useFeatureFlags(FeatureKeys.CHAT_SUPPORT)?.active || false;
false;
const isPremiumSupportEnabled = const isPremiumSupportEnabled =
allFlags.find((flag) => flag.name === FeatureKeys.PREMIUM_SUPPORT)?.active || useFeatureFlags(FeatureKeys.PREMIUM_SUPPORT)?.active || false;
false;
const showAddCreditCardModal =
!isPremiumSupportEnabled &&
!licenseData?.payload?.trialConvertedToSubscription;
const featureResponse = useGetFeatureFlag((allFlags) => {
dispatch({ dispatch({
type: UPDATE_FEATURE_FLAG_RESPONSE, type: UPDATE_FEATURE_FLAG_RESPONSE,
payload: { payload: {
@ -90,16 +84,6 @@ function App(): JSX.Element {
setRoutes(newRoutes); setRoutes(newRoutes);
} }
if (isLoggedInState && isChatSupportEnabled && !showAddCreditCardModal) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.Intercom('boot', {
app_id: process.env.INTERCOM_APP_ID,
email: user?.email || '',
name: user?.name || '',
});
}
}); });
const isOnBasicPlan = const isOnBasicPlan =
@ -201,6 +185,26 @@ function App(): JSX.Element {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [pathname]); }, [pathname]);
useEffect(() => {
const showAddCreditCardModal =
!isPremiumSupportEnabled &&
!licenseData?.payload?.trialConvertedToSubscription;
if (isLoggedInState && isChatSupportEnabled && !showAddCreditCardModal) {
window.Intercom('boot', {
app_id: process.env.INTERCOM_APP_ID,
email: user?.email || '',
name: user?.name || '',
});
}
}, [
isLoggedInState,
isChatSupportEnabled,
user,
licenseData,
isPremiumSupportEnabled,
]);
useEffect(() => { useEffect(() => {
if (user && user?.email && user?.userId && user?.name) { if (user && user?.email && user?.userId && user?.name) {
try { try {