feat: make identity call if user is logs in for first time or if identity call was not registered (#3612)

This commit is contained in:
Yunus M 2023-09-24 15:05:11 +05:30 committed by GitHub
parent dc4acc0730
commit d2d3c4bb36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 19 deletions

View File

@ -1,7 +1,10 @@
import { ConfigProvider } from 'antd'; import { ConfigProvider } from 'antd';
import getLocalStorageApi from 'api/browser/localstorage/get';
import setLocalStorageApi from 'api/browser/localstorage/set';
import NotFound from 'components/NotFound'; import NotFound from 'components/NotFound';
import Spinner from 'components/Spinner'; import Spinner from 'components/Spinner';
import { FeatureKeys } from 'constants/features'; import { FeatureKeys } from 'constants/features';
import { LOCALSTORAGE } from 'constants/localStorage';
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import AppLayout from 'container/AppLayout'; import AppLayout from 'container/AppLayout';
import { useThemeConfig } from 'hooks/useDarkMode'; import { useThemeConfig } from 'hooks/useDarkMode';
@ -75,14 +78,24 @@ function App(): JSX.Element {
}); });
useEffect(() => { useEffect(() => {
if (isLoggedInState && user && user.userId && user.email) { const isIdentifiedUser = getLocalStorageApi(LOCALSTORAGE.IS_IDENTIFIED_USER);
if (
isLoggedInState &&
user &&
user.userId &&
user.email &&
!isIdentifiedUser
) {
setLocalStorageApi(LOCALSTORAGE.IS_IDENTIFIED_USER, 'true');
window.analytics.identify(user?.email, { window.analytics.identify(user?.email, {
email: user?.email, email: user?.email,
name: user?.name, name: user?.name,
}); });
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoggedInState]); }, [isLoggedInState, user]);
useEffect(() => { useEffect(() => {
trackPageView(pathname); trackPageView(pathname);

View File

@ -14,7 +14,11 @@ import {
export const Logout = (): void => { export const Logout = (): void => {
deleteLocalStorageKey(LOCALSTORAGE.AUTH_TOKEN); deleteLocalStorageKey(LOCALSTORAGE.AUTH_TOKEN);
deleteLocalStorageKey(LOCALSTORAGE.IS_LOGGED_IN); deleteLocalStorageKey(LOCALSTORAGE.IS_LOGGED_IN);
deleteLocalStorageKey(LOCALSTORAGE.IS_IDENTIFIED_USER);
deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN); deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
deleteLocalStorageKey(LOCALSTORAGE.LOGGED_IN_USER_EMAIL);
deleteLocalStorageKey(LOCALSTORAGE.LOGGED_IN_USER_NAME);
deleteLocalStorageKey(LOCALSTORAGE.CHAT_SUPPORT);
store.dispatch({ store.dispatch({
type: LOGGED_IN, type: LOGGED_IN,

View File

@ -14,4 +14,5 @@ export enum LOCALSTORAGE {
LOGGED_IN_USER_NAME = 'LOGGED_IN_USER_NAME', LOGGED_IN_USER_NAME = 'LOGGED_IN_USER_NAME',
LOGGED_IN_USER_EMAIL = 'LOGGED_IN_USER_EMAIL', LOGGED_IN_USER_EMAIL = 'LOGGED_IN_USER_EMAIL',
CHAT_SUPPORT = 'CHAT_SUPPORT', CHAT_SUPPORT = 'CHAT_SUPPORT',
IS_IDENTIFIED_USER = 'IS_IDENTIFIED_USER',
} }

View File

@ -1,13 +1,9 @@
import { Button, Form, Input, Space, Tooltip, Typography } from 'antd'; import { Button, Form, Input, Space, Tooltip, Typography } from 'antd';
import setLocalStorageApi from 'api/browser/localstorage/set';
import getUserVersion from 'api/user/getVersion'; import getUserVersion from 'api/user/getVersion';
import loginApi from 'api/user/login'; import loginApi from 'api/user/login';
import loginPrecheckApi from 'api/user/loginPrecheck'; import loginPrecheckApi from 'api/user/loginPrecheck';
import afterLogin from 'AppRoutes/utils'; import afterLogin from 'AppRoutes/utils';
import { FeatureKeys } from 'constants/features';
import { LOCALSTORAGE } from 'constants/localStorage';
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import useFeatureFlag from 'hooks/useFeatureFlag';
import { useNotifications } from 'hooks/useNotifications'; import { useNotifications } from 'hooks/useNotifications';
import history from 'lib/history'; import history from 'lib/history';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
@ -42,9 +38,6 @@ function Login({
const { t } = useTranslation(['login']); const { t } = useTranslation(['login']);
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
const { user } = useSelector<AppState, AppReducer>((state) => state.app); const { user } = useSelector<AppState, AppReducer>((state) => state.app);
const isChatSupportEnabled: boolean | undefined = useFeatureFlag(
FeatureKeys.CHAT_SUPPORT,
)?.active;
const [precheckResult, setPrecheckResult] = useState<PrecheckResultType>({ const [precheckResult, setPrecheckResult] = useState<PrecheckResultType>({
sso: false, sso: false,
@ -165,21 +158,12 @@ function Login({
password, password,
}); });
if (response.statusCode === 200) { if (response.statusCode === 200) {
const user = await afterLogin( await afterLogin(
response.payload.userId, response.payload.userId,
response.payload.accessJwt, response.payload.accessJwt,
response.payload.refreshJwt, response.payload.refreshJwt,
); );
if (user) {
setLocalStorageApi(LOCALSTORAGE.LOGGED_IN_USER_NAME, user.payload?.name);
setLocalStorageApi(LOCALSTORAGE.LOGGED_IN_USER_EMAIL, user.payload?.email);
setLocalStorageApi(
LOCALSTORAGE.CHAT_SUPPORT,
(isChatSupportEnabled || '').toString(),
);
}
history.push(ROUTES.APPLICATION); history.push(ROUTES.APPLICATION);
} else { } else {
notifications.error({ notifications.error({