From 2c5a537d75e0c846b804bc18cd792bc2cb6cff3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C6=B0=E1=BB=9Dng=20An?= Date: Thu, 9 Jul 2020 10:18:41 +0700 Subject: [PATCH] chore: #1918 remove unused code from marketplace login page (#2008) --- .../marketplace/src/actions/__tests__/auth.ts | 14 -- packages/marketplace/src/actions/auth.ts | 7 - .../src/components/pages/login.tsx | 138 -------------- .../__snapshots__/login.test.tsx.snap | 3 +- .../{ => login}/__tests__/login.test.tsx | 25 +-- .../src/components/pages/login/index.ts | 1 + .../src/components/pages/login/login.tsx | 94 ++++++++++ packages/marketplace/src/constants/routes.ts | 2 +- .../__tests__/__snapshots__/router.tsx.snap | 8 +- .../core/__tests__/private-route-wrapper.tsx | 28 +-- .../src/core/private-route-wrapper.tsx | 54 ++---- packages/marketplace/src/core/router.tsx | 8 +- .../marketplace/src/sagas/__tests__/auth.ts | 117 +----------- packages/marketplace/src/sagas/auth.ts | 57 +----- .../src/tests/badges/badge-branches.svg | 2 +- .../src/tests/badges/badge-functions.svg | 2 +- .../src/tests/badges/badge-lines.svg | 2 +- .../src/tests/badges/badge-statements.svg | 2 +- .../src/utils/__tests__/auth-route.ts | 177 ++---------------- packages/marketplace/src/utils/auth-route.ts | 127 ++----------- 20 files changed, 168 insertions(+), 700 deletions(-) delete mode 100644 packages/marketplace/src/components/pages/login.tsx rename packages/marketplace/src/components/pages/{ => login}/__tests__/__snapshots__/login.test.tsx.snap (97%) rename packages/marketplace/src/components/pages/{ => login}/__tests__/login.test.tsx (68%) create mode 100644 packages/marketplace/src/components/pages/login/index.ts create mode 100644 packages/marketplace/src/components/pages/login/login.tsx diff --git a/packages/marketplace/src/actions/__tests__/auth.ts b/packages/marketplace/src/actions/__tests__/auth.ts index 1941a201ba..f49f13c9c0 100644 --- a/packages/marketplace/src/actions/__tests__/auth.ts +++ b/packages/marketplace/src/actions/__tests__/auth.ts @@ -7,8 +7,6 @@ import { authChangeLoginType, authSetRefreshSession, authClear, - setInitDeveloperTermsAcceptedStateFromCookie, - setDeveloperTermAcceptedCookieAndState, setInitClientTermsAcceptedStateFromCookie, setClientTermAcceptedCookieAndState, } from '../auth' @@ -32,18 +30,6 @@ describe('auth actions', () => { expect(authLoginSuccess(loginSession).data).toEqual(loginSession) }) - it('should create a setInitDeveloperTermsAcceptedStateFromCookie action', () => { - expect(setInitDeveloperTermsAcceptedStateFromCookie.type).toEqual( - ActionTypes.SET_INIT_DEVELOPER_TERMS_ACCEPTED_STATE_FROM_COOKIE, - ) - }) - - it('should create a setDeveloperTermAcceptedCookieAndState action', () => { - expect(setDeveloperTermAcceptedCookieAndState.type).toEqual( - ActionTypes.SET_DEVELOPER_TERM_ACCEPTED_COOKIE_AND_STATE, - ) - }) - it('should create a setInitClientTermsAcceptedStateFromCookie action', () => { expect(setInitClientTermsAcceptedStateFromCookie.type).toEqual( ActionTypes.SET_INIT_CLIENT_TERMS_ACCEPTED_STATE_FROM_COOKIE, diff --git a/packages/marketplace/src/actions/auth.ts b/packages/marketplace/src/actions/auth.ts index fdd7035211..13129296ba 100644 --- a/packages/marketplace/src/actions/auth.ts +++ b/packages/marketplace/src/actions/auth.ts @@ -11,13 +11,6 @@ export const authSetRefreshSession = actionCreator(ActionTypes.AU export const authChangeLoginType = actionCreator(ActionTypes.AUTH_CHANGE_LOGIN_TYPE) export const authClear = actionCreator(ActionTypes.AUTH_CLEAR) -export const setInitDeveloperTermsAcceptedStateFromCookie = actionCreator( - ActionTypes.SET_INIT_DEVELOPER_TERMS_ACCEPTED_STATE_FROM_COOKIE, -) -export const setDeveloperTermAcceptedCookieAndState = actionCreator( - ActionTypes.SET_DEVELOPER_TERM_ACCEPTED_COOKIE_AND_STATE, -) - export const setInitClientTermsAcceptedStateFromCookie = actionCreator( ActionTypes.SET_INIT_CLIENT_TERMS_ACCEPTED_STATE_FROM_COOKIE, ) diff --git a/packages/marketplace/src/components/pages/login.tsx b/packages/marketplace/src/components/pages/login.tsx deleted file mode 100644 index f318e11885..0000000000 --- a/packages/marketplace/src/components/pages/login.tsx +++ /dev/null @@ -1,138 +0,0 @@ -import * as React from 'react' -import { useLocation, useRouteMatch } from 'react-router' -import { Link, Redirect } from 'react-router-dom' -import { Dispatch } from 'redux' -import { useSelector, useDispatch } from 'react-redux' -import { authChangeLoginType } from '@/actions/auth' -import { showNotificationMessage } from '@/actions/notification-message' -import { selectLoginSession, selectRefreshSession, selectLoginType, selectIsDesktopMode } from '@/selector/auth' -import { LoginType, redirectToLogin } from '@reapit/cognito-auth' -import { Button, Level, FlexContainerBasic, Section } from '@reapit/elements' -import { getLoginTypeByPath, getDefaultPathByLoginType, getDefaultRouteByLoginType } from '@/utils/auth-route' -import Routes from '@/constants/routes' -import messages from '@/constants/messages' -import { - getCookieString, - COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE, - COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE, -} from '@/utils/cookie' -import loginStyles from '@/styles/pages/login.scss?mod' -import logoImage from '@/assets/images/reapit-graphic.jpg' -import connectImage from '@/assets/images/reapit-connect.png' - -const { wrapper, container, image, register, registerLevel, loginButton } = loginStyles - -export type LoginProps = {} - -export const handleShowNotificationAfterPasswordChanged = ( - isPasswordChanged: boolean, - localStorage: Storage, - dispatch: Dispatch, -) => { - return () => { - if (isPasswordChanged) { - dispatch(showNotificationMessage({ variant: 'info', message: messages.PASSWORD_CHANGED_SUCCESSFULLY })) - localStorage.removeItem('isPasswordChanged') - } - } -} - -export const handleChangeLoginType = (dispatch: Dispatch, loginType: LoginType) => { - return () => { - dispatch(authChangeLoginType(loginType)) - } -} - -export const onLoginButtonClick = ( - loginType: LoginType, - isDeveloperFirstTimeLoginComplete: boolean, - isClientFirstTimeLoginComplete: boolean, -) => { - return () => { - const redirectRoute = getDefaultRouteByLoginType({ - loginType, - isDeveloperFirstTimeLoginComplete, - isClientFirstTimeLoginComplete, - }) - - redirectToLogin(window.reapit.config.cognitoClientId, redirectRoute, loginType) - } -} - -export const Login: React.FunctionComponent = () => { - const location = useLocation() - let developerLoginRouteMatch = useRouteMatch(Routes.DEVELOPER_LOGIN) - let clientLoginRouteMatch = useRouteMatch(Routes.CLIENT_LOGIN) - const dispatch = useDispatch() - const loginType = useSelector(selectLoginType) - const loginSession = useSelector(selectLoginSession) - const refreshSession = useSelector(selectRefreshSession) - const isDesktopMode = useSelector(selectIsDesktopMode) - - const isPasswordChanged = localStorage.getItem('isPasswordChanged') === 'true' - const hasSession = !!loginSession || !!refreshSession - const currentLoginType = getLoginTypeByPath(location.pathname) - const isDeveloperFirstTimeLoginComplete = Boolean(getCookieString(COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE)) - const isClientFirstTimeLoginComplete = Boolean(getCookieString(COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE)) - - React.useEffect(handleChangeLoginType(dispatch, currentLoginType), [dispatch, currentLoginType]) - - React.useEffect(handleShowNotificationAfterPasswordChanged(isPasswordChanged, localStorage, dispatch), [ - isPasswordChanged, - localStorage, - dispatch, - ]) - - if (hasSession) { - const redirectRoute = getDefaultPathByLoginType({ - loginType: currentLoginType, - developerLoginRouteMatch, - clientLoginRouteMatch, - isDeveloperFirstTimeLoginComplete, - isClientFirstTimeLoginComplete, - isDesktopMode, - }) - return - } - - return ( -
-
- - Reapit Connect Graphic - -
-

Welcome to Reapit {`${loginType === 'CLIENT' ? 'Marketplace' : 'Foundations'}`}

-
- - - {loginType === 'DEVELOPER' && ( -
- Don't have an account yet?  - Register -
- )} -
- - {process.env.APP_VERSION} - -
-
- Reapit Graphic -
-
- ) -} - -export default Login diff --git a/packages/marketplace/src/components/pages/__tests__/__snapshots__/login.test.tsx.snap b/packages/marketplace/src/components/pages/login/__tests__/__snapshots__/login.test.tsx.snap similarity index 97% rename from packages/marketplace/src/components/pages/__tests__/__snapshots__/login.test.tsx.snap rename to packages/marketplace/src/components/pages/login/__tests__/__snapshots__/login.test.tsx.snap index 75de8814cf..23ce94b40a 100644 --- a/packages/marketplace/src/components/pages/__tests__/__snapshots__/login.test.tsx.snap +++ b/packages/marketplace/src/components/pages/login/__tests__/__snapshots__/login.test.tsx.snap @@ -75,8 +75,7 @@ exports[`Login should match a snapshot 1`] = ` data-test="" >

- Welcome to Reapit - Foundations + Welcome to Reapit Marketplace

diff --git a/packages/marketplace/src/components/pages/__tests__/login.test.tsx b/packages/marketplace/src/components/pages/login/__tests__/login.test.tsx similarity index 68% rename from packages/marketplace/src/components/pages/__tests__/login.test.tsx rename to packages/marketplace/src/components/pages/login/__tests__/login.test.tsx index 226571c12a..25d06d179e 100644 --- a/packages/marketplace/src/components/pages/__tests__/login.test.tsx +++ b/packages/marketplace/src/components/pages/login/__tests__/login.test.tsx @@ -3,11 +3,9 @@ import { MemoryRouter } from 'react-router' import * as ReactRedux from 'react-redux' import { mount } from 'enzyme' import configureStore from 'redux-mock-store' -import { Login, handleShowNotificationAfterPasswordChanged, handleChangeLoginType, onLoginButtonClick } from '../login' +import { Login, handleShowNotificationAfterPasswordChanged, onLoginButtonClick } from '../login' import appState from '@/reducers/__stubs__/app-state' import { showNotificationMessage } from '@/actions/notification-message' -import { authChangeLoginType } from '@/actions/auth' -import { LoginType } from '@reapit/cognito-auth' import * as cognito from '@reapit/cognito-auth' import messages from '@/constants/messages' import Routes from '@/constants/routes' @@ -38,7 +36,7 @@ describe('Login', () => { expect( mount( - + , @@ -56,25 +54,12 @@ describe('Login', () => { expect(spyLocalStorageRemoveItem).toBeCalledWith('isPasswordChanged') }) }) - describe('handleChangeLoginType', () => { - it('should run correctly', () => { - const mockLoginType: LoginType = 'CLIENT' - const fn = handleChangeLoginType(spyDispatch, mockLoginType) - fn() - expect(spyDispatch).toBeCalledWith(authChangeLoginType(mockLoginType)) - }) - }) + describe('onLoginButtonClick', () => { it('should run correctly', () => { const spyRedirectToLogin = jest.spyOn(cognito, 'redirectToLogin') - const mockLoginType: LoginType = 'CLIENT' - const mockIsDeveloperFirstTimeLoginComplete = true - const mockIsClientFirstTimeLoginComplete = true - const fn = onLoginButtonClick( - mockLoginType, - mockIsDeveloperFirstTimeLoginComplete, - mockIsClientFirstTimeLoginComplete, - ) + const mockIsFirstTimeLoginComplete = true + const fn = onLoginButtonClick(mockIsFirstTimeLoginComplete) fn() expect(spyRedirectToLogin).toBeCalled() }) diff --git a/packages/marketplace/src/components/pages/login/index.ts b/packages/marketplace/src/components/pages/login/index.ts new file mode 100644 index 0000000000..29ce61fdfa --- /dev/null +++ b/packages/marketplace/src/components/pages/login/index.ts @@ -0,0 +1 @@ +export { Login as default } from './login' diff --git a/packages/marketplace/src/components/pages/login/login.tsx b/packages/marketplace/src/components/pages/login/login.tsx new file mode 100644 index 0000000000..9dc2c0bc46 --- /dev/null +++ b/packages/marketplace/src/components/pages/login/login.tsx @@ -0,0 +1,94 @@ +import * as React from 'react' +import { Redirect } from 'react-router-dom' +import { Dispatch } from 'redux' +import { useSelector, useDispatch } from 'react-redux' +import { showNotificationMessage } from '@/actions/notification-message' +import { selectLoginSession, selectRefreshSession, selectIsDesktopMode } from '@/selector/auth' +import { redirectToLogin } from '@reapit/cognito-auth' +import { Button, Level, FlexContainerBasic, Section } from '@reapit/elements' +import { getDefaultRoute, getDefaultPath } from '@/utils/auth-route' +import messages from '@/constants/messages' +import { getCookieString, COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE } from '@/utils/cookie' +import loginStyles from '@/styles/pages/login.scss?mod' +import logoImage from '@/assets/images/reapit-graphic.jpg' +import connectImage from '@/assets/images/reapit-connect.png' + +const { wrapper, container, image, registerLevel, loginButton } = loginStyles + +export type LoginProps = {} + +export const handleShowNotificationAfterPasswordChanged = ( + isPasswordChanged: boolean, + localStorage: Storage, + dispatch: Dispatch, +) => { + return () => { + if (isPasswordChanged) { + dispatch(showNotificationMessage({ variant: 'info', message: messages.PASSWORD_CHANGED_SUCCESSFULLY })) + localStorage.removeItem('isPasswordChanged') + } + } +} + +export const onLoginButtonClick = (isFirstTimeLoginComplete: boolean) => { + return () => { + const redirectRoute = getDefaultRoute({ isFirstTimeLoginComplete }) + redirectToLogin(window.reapit.config.cognitoClientId, redirectRoute) + } +} + +export const Login: React.FunctionComponent = () => { + const dispatch = useDispatch() + const loginSession = useSelector(selectLoginSession) + const refreshSession = useSelector(selectRefreshSession) + const isDesktopMode = useSelector(selectIsDesktopMode) + + const isPasswordChanged = localStorage.getItem('isPasswordChanged') === 'true' + const hasSession = !!loginSession || !!refreshSession + const isFirstTimeLoginComplete = Boolean(getCookieString(COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE)) + React.useEffect(handleShowNotificationAfterPasswordChanged(isPasswordChanged, localStorage, dispatch), [ + isPasswordChanged, + localStorage, + dispatch, + ]) + + if (hasSession) { + const redirectRoute = getDefaultPath({ isDesktopMode, isFirstTimeLoginComplete }) + return + } + + return ( +
+
+ + Reapit Connect Graphic + +
+

Welcome to Reapit Marketplace

+
+ + + + + {process.env.APP_VERSION} + +
+
+ Reapit Graphic +
+
+ ) +} + +export default Login diff --git a/packages/marketplace/src/constants/routes.ts b/packages/marketplace/src/constants/routes.ts index 312692e4b6..771c3a2264 100644 --- a/packages/marketplace/src/constants/routes.ts +++ b/packages/marketplace/src/constants/routes.ts @@ -39,7 +39,7 @@ const Routes = { ADMIN_LOGIN: '/admin/login', ADMIN_STATS: '/admin/stats', ADMIN_BILLING: '/admin/billing', - CLIENT_LOGIN: '/client/login', + LOGIN: '/client/login', DEVELOPER_LOGIN: '/developer/login', FOUR_O_FOUR: '/404', FORGOT_PASSWORD: '/developer/forgot-password', diff --git a/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap b/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap index 7955ba91c7..f495e0f0e8 100644 --- a/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap +++ b/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap @@ -29,13 +29,7 @@ exports[`Router should match a snapshot 1`] = ` ({ })) jest.mock('@/utils/auth-route', () => ({ - getDefaultRouteByLoginType: jest.fn(() => 'login-type-route'), - getAuthRouteByLoginType: jest.fn(() => 'auth-route'), + getDefaultRoute: jest.fn(() => 'login-type-route'), + getAuthRoute: jest.fn(() => 'auth-route'), })) jest.mock('@/utils/cookie', () => ({ @@ -82,9 +74,7 @@ describe('PrivateRouteWrapper', () => { expect(useDispatch).toHaveBeenCalled() expect(useSelector).toHaveBeenCalledWith(selectLoginSession) expect(useSelector).toHaveBeenCalledWith(selectRefreshSession) - expect(useSelector).toHaveBeenCalledWith(selectLoginType) expect(useLocation).toHaveBeenCalled() - expect(getCookieString).toHaveBeenCalledWith(COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE) expect(getCookieString).toHaveBeenCalledWith(COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE) expect(getTokenFromQueryString).toHaveBeenCalledWith( locationMock.search, @@ -120,7 +110,7 @@ describe('PrivateRouteWrapper', () => { , ) - expect(getAuthRouteByLoginType).toHaveBeenCalledWith('CLIENT') + expect(getAuthRoute).toHaveBeenCalled() }) it('should call correct functions with !hasSession case', () => { @@ -136,7 +126,7 @@ describe('PrivateRouteWrapper', () => { , ) - expect(redirectToOAuth).toHaveBeenCalledWith(window.reapit.config.cognitoClientId, 'login-type-route', 'CLIENT') + expect(redirectToOAuth).toHaveBeenCalledWith(window.reapit.config.cognitoClientId, 'login-type-route') }) }) @@ -145,10 +135,8 @@ describe('handleSetTermsAcceptFromCookie', () => { const fn = handleSetTermsAcceptFromCookie({ dispatch, setInitClientTermsAcceptedStateFromCookie, - setInitDeveloperTermsAcceptedStateFromCookie, }) fn() expect(dispatch).toHaveBeenCalledWith(setInitClientTermsAcceptedStateFromCookie()) - expect(dispatch).toHaveBeenCalledWith(setInitDeveloperTermsAcceptedStateFromCookie()) }) }) diff --git a/packages/marketplace/src/core/private-route-wrapper.tsx b/packages/marketplace/src/core/private-route-wrapper.tsx index f0b979786c..8b23a2f5e1 100644 --- a/packages/marketplace/src/core/private-route-wrapper.tsx +++ b/packages/marketplace/src/core/private-route-wrapper.tsx @@ -6,19 +6,11 @@ import { Loader, Section, FlexContainerResponsive, AppNavContainer, FlexContaine import { getTokenFromQueryString, redirectToOAuth } from '@reapit/cognito-auth' import { Dispatch } from 'redux' import { Redirect, useLocation } from 'react-router' -import { getDefaultRouteByLoginType, getAuthRouteByLoginType } from '@/utils/auth-route' -import { - authSetRefreshSession, - setInitDeveloperTermsAcceptedStateFromCookie, - setInitClientTermsAcceptedStateFromCookie, -} from '@/actions/auth' - -import { - getCookieString, - COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE, - COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE, -} from '@/utils/cookie' -import { selectLoginSession, selectRefreshSession, selectLoginType } from '@/selector/auth' +import { getAuthRoute, getDefaultRoute } from '@/utils/auth-route' +import { authSetRefreshSession, setInitClientTermsAcceptedStateFromCookie } from '@/actions/auth' + +import { getCookieString, COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE } from '@/utils/cookie' +import { selectLoginSession, selectRefreshSession } from '@/selector/auth' import { ActionCreator } from '@/types/core' import Routes from '@/constants/routes' @@ -41,14 +33,11 @@ export type PrivateRouteWrapperProps = { export const handleSetTermsAcceptFromCookie = ({ dispatch, setInitClientTermsAcceptedStateFromCookie, - setInitDeveloperTermsAcceptedStateFromCookie, }: { dispatch: Dispatch setInitClientTermsAcceptedStateFromCookie: ActionCreator - setInitDeveloperTermsAcceptedStateFromCookie: ActionCreator }) => () => { dispatch(setInitClientTermsAcceptedStateFromCookie()) - dispatch(setInitDeveloperTermsAcceptedStateFromCookie()) } export const PrivateRouteWrapper: React.FunctionComponent = ({ @@ -60,7 +49,6 @@ export const PrivateRouteWrapper: React.FunctionComponent use state in url param (this was setted by cognito) - * -> save the valid type to logintype - * further works will use loginType in reducer if param state isn't specificied in url param - */ - loginType: type || loginType, + + const isFirstTimeLoginComplete = Boolean(getCookieString(COOKIE_CLIENT_FIRST_TIME_LOGIN_COMPLETE)) + + const route = getDefaultRoute({ + isFirstTimeLoginComplete, }) const cognitoClientId = window.reapit.config.cognitoClientId - const refreshParams = getTokenFromQueryString(location.search, cognitoClientId, type, route) + const refreshParams = getTokenFromQueryString(location.search, cognitoClientId, 'CLIENT', route) if (refreshParams && !hasSession) { dispatch(authSetRefreshSession(refreshParams)) return null } - if (type && location.pathname === '/') { - const path = getAuthRouteByLoginType(type || loginType) + if (location.pathname === '/') { + const path = getAuthRoute() return } if (!hasSession) { - redirectToOAuth(cognitoClientId, route, type) + redirectToOAuth(cognitoClientId, route) return null } diff --git a/packages/marketplace/src/core/router.tsx b/packages/marketplace/src/core/router.tsx index 6a72a07768..ac423cfd48 100644 --- a/packages/marketplace/src/core/router.tsx +++ b/packages/marketplace/src/core/router.tsx @@ -57,16 +57,12 @@ const DeveloperEditionDownloadPage = React.lazy(() => const Router = () => { const isProduction = window.reapit.config.appEnv === 'production' - const paths = [Routes.DEVELOPER_LOGIN, Routes.ADMIN_LOGIN] - if (!isProduction) { - paths.push(Routes.CLIENT_LOGIN) - } return ( - } /> + } /> } /> } /> @@ -206,7 +202,7 @@ const Router = () => { } /> - + diff --git a/packages/marketplace/src/sagas/__tests__/auth.ts b/packages/marketplace/src/sagas/__tests__/auth.ts index 5545caf103..228960e2cc 100644 --- a/packages/marketplace/src/sagas/__tests__/auth.ts +++ b/packages/marketplace/src/sagas/__tests__/auth.ts @@ -1,14 +1,8 @@ -import { select, put, all, takeLatest, call, fork } from '@redux-saga/core/effects' +import { put, all, takeLatest, call, fork } from '@redux-saga/core/effects' import { setUserSession, removeSession, LoginParams, LoginSession, redirectToLogout } from '@reapit/cognito-auth' import { Action } from '@/types/core' import { cloneableGenerator } from '@redux-saga/testing-utils' -import { - getCookieString, - setCookieString, - COOKIE_MAX_AGE_INFINITY, - COOKIE_DEVELOPER_TERMS_ACCEPTED, - COOKIE_CLIENT_TERMS_ACCEPTED, -} from '@/utils/cookie' +import { getCookieString, setCookieString, COOKIE_MAX_AGE_INFINITY, COOKIE_CLIENT_TERMS_ACCEPTED } from '@/utils/cookie' import authSagas, { doLogin, doLogout, @@ -16,10 +10,6 @@ import authSagas, { logoutListen, clearAuthListen, clearAuth, - setInitDeveloperTermsAcceptedStateFromCookie, - setDeveloperTermAcceptedCookieAndState, - setInitDeveloperTermsAcceptedStateFromCookieListen, - setDeveloperTermAcceptedCookieAndStateListen, setClientTermAcceptedCookieAndState, setInitClientTermsAcceptedStateFromCookieListen, setInitClientTermsAcceptedStateFromCookie, @@ -30,7 +20,6 @@ import { authLoginSuccess, authLogoutSuccess, authLoginFailure, setTermsAccepted import Routes from '../../constants/routes' import { ActionType } from '../../types/core' import { COOKIE_SESSION_KEY_MARKETPLACE } from '../../constants/api' -import { selectLoginType } from '@/selector/auth' jest.mock('../../utils/session') jest.mock('../../core/router', () => ({ @@ -108,11 +97,7 @@ describe('auth thunks', () => { const gen = doLogout() expect(gen.next().value).toEqual(call(removeSession, COOKIE_SESSION_KEY_MARKETPLACE, 'development')) expect(gen.next().value).toEqual( - call( - redirectToLogout, - window.reapit.config.marketplaceApiUrl, - `${window.location.origin}${Routes.CLIENT_LOGIN}`, - ), + call(redirectToLogout, window.reapit.config.marketplaceApiUrl, `${window.location.origin}${Routes.LOGIN}`), ) expect(gen.next().done).toBe(true) }) @@ -154,8 +139,6 @@ describe('auth thunks', () => { fork(loginListen), fork(logoutListen), fork(clearAuthListen), - fork(setInitDeveloperTermsAcceptedStateFromCookieListen), - fork(setDeveloperTermAcceptedCookieAndStateListen), fork(setInitClientTermsAcceptedStateFromCookieListen), fork(setClientTermAcceptedCookieAndStateListen), ]), @@ -176,17 +159,10 @@ describe('auth thunks', () => { describe('setInitClientTermsAcceptedStateFromCookie', () => { it('should run correctly with developer login type', () => { const gen = cloneableGenerator(setInitClientTermsAcceptedStateFromCookie)() - expect(gen.next().value).toEqual(select(selectLoginType)) - expect(gen.next('CLIENT').value).toEqual(call(getCookieString, COOKIE_CLIENT_TERMS_ACCEPTED)) + expect(gen.next().value).toEqual(call(getCookieString, COOKIE_CLIENT_TERMS_ACCEPTED)) expect(gen.next('2019-12-18T16:30:00').value).toEqual(put(setTermsAcceptedState(true))) expect(gen.next().done).toBe(true) }) - - it('should run correctly with other login type', () => { - const gen = cloneableGenerator(setInitClientTermsAcceptedStateFromCookie)() - expect(gen.next().value).toEqual(select(selectLoginType)) - expect(gen.next('DEVELOPER').done).toBe(true) - }) }) describe('setClientTermAcceptedCookieAndState', () => { @@ -205,89 +181,4 @@ describe('auth thunks', () => { expect(gen.next().done).toBe(true) }) }) - - describe('setInitDeveloperTermsAcceptedStateFromCookie', () => { - it('should run correctly with developer login type', () => { - const gen = cloneableGenerator(setInitDeveloperTermsAcceptedStateFromCookie)() - expect(gen.next().value).toEqual(select(selectLoginType)) - expect(gen.next('DEVELOPER').value).toEqual(call(getCookieString, COOKIE_DEVELOPER_TERMS_ACCEPTED)) - expect(gen.next('2019-12-18T16:30:00').value).toEqual(put(setTermsAcceptedState(true))) - expect(gen.next().done).toBe(true) - }) - - it('should run correctly with other login type', () => { - const gen = cloneableGenerator(setInitDeveloperTermsAcceptedStateFromCookie)() - expect(gen.next().value).toEqual(select(selectLoginType)) - expect(gen.next('CLIENT').done).toBe(true) - }) - }) - - describe('setDeveloperTermAcceptedCookieAndState', () => { - it('should run correctly with true', () => { - const gen = cloneableGenerator(setDeveloperTermAcceptedCookieAndState)({ data: true }) - expect(gen.next().value).toEqual( - call(setCookieString, COOKIE_DEVELOPER_TERMS_ACCEPTED, new Date(), COOKIE_MAX_AGE_INFINITY), - ) - expect(gen.next().value).toEqual(put(setTermsAcceptedState(true))) - expect(gen.next().done).toBe(true) - }) - - it('should run correctly with false', () => { - const gen = cloneableGenerator(setDeveloperTermAcceptedCookieAndState)({ data: false }) - expect(gen.next().value).toEqual(put(setTermsAcceptedState(false))) - expect(gen.next().done).toBe(true) - }) - }) - - describe('setInitDeveloperTermsAcceptedStateFromCookieListen', () => { - it('should run correctly', () => { - const gen = setInitDeveloperTermsAcceptedStateFromCookieListen() - expect(gen.next().value).toEqual( - takeLatest( - ActionTypes.SET_INIT_DEVELOPER_TERMS_ACCEPTED_STATE_FROM_COOKIE, - setInitDeveloperTermsAcceptedStateFromCookie, - ), - ) - expect(gen.next().done).toBe(true) - }) - }) - - describe('setDeveloperTermAcceptedCookieAndStateListen', () => { - it('should run correctly', () => { - const gen = setDeveloperTermAcceptedCookieAndStateListen() - expect(gen.next().value).toEqual( - takeLatest>( - ActionTypes.SET_DEVELOPER_TERM_ACCEPTED_COOKIE_AND_STATE, - setDeveloperTermAcceptedCookieAndState, - ), - ) - expect(gen.next().done).toBe(true) - }) - }) - - describe('setInitClientTermsAcceptedStateFromCookieListen', () => { - it('should run correctly', () => { - const gen = setInitDeveloperTermsAcceptedStateFromCookieListen() - expect(gen.next().value).toEqual( - takeLatest( - ActionTypes.SET_INIT_DEVELOPER_TERMS_ACCEPTED_STATE_FROM_COOKIE, - setInitDeveloperTermsAcceptedStateFromCookie, - ), - ) - expect(gen.next().done).toBe(true) - }) - }) - - describe('setClientTermAcceptedCookieAndStateListen', () => { - it('should run correctly', () => { - const gen = setDeveloperTermAcceptedCookieAndStateListen() - expect(gen.next().value).toEqual( - takeLatest>( - ActionTypes.SET_DEVELOPER_TERM_ACCEPTED_COOKIE_AND_STATE, - setDeveloperTermAcceptedCookieAndState, - ), - ) - expect(gen.next().done).toBe(true) - }) - }) }) diff --git a/packages/marketplace/src/sagas/auth.ts b/packages/marketplace/src/sagas/auth.ts index 89d0c2a155..a46b74acef 100644 --- a/packages/marketplace/src/sagas/auth.ts +++ b/packages/marketplace/src/sagas/auth.ts @@ -1,19 +1,11 @@ -import { takeLatest, put, call, all, fork, select } from '@redux-saga/core/effects' +import { takeLatest, put, call, all, fork } from '@redux-saga/core/effects' import ActionTypes from '../constants/action-types' import { authLoginSuccess, authLoginFailure, authLogoutSuccess, setTermsAcceptedState } from '../actions/auth' import { Action } from '@/types/core.ts' import { LoginSession, LoginParams, setUserSession, removeSession, redirectToLogout } from '@reapit/cognito-auth' -import store from '../core/store' -import { getAuthRouteByLoginType } from '@/utils/auth-route' -import { - getCookieString, - setCookieString, - COOKIE_DEVELOPER_TERMS_ACCEPTED, - COOKIE_CLIENT_TERMS_ACCEPTED, - COOKIE_MAX_AGE_INFINITY, -} from '@/utils/cookie' +import { getAuthRoute } from '@/utils/auth-route' +import { getCookieString, setCookieString, COOKIE_CLIENT_TERMS_ACCEPTED, COOKIE_MAX_AGE_INFINITY } from '@/utils/cookie' import { COOKIE_SESSION_KEY_MARKETPLACE } from '../constants/api' -import { selectLoginType } from '@/selector/auth' import { logger } from '@reapit/utils' export const doLogin = function*({ data }: Action) { @@ -32,8 +24,7 @@ export const doLogin = function*({ data }: Action) { export const doLogout = function*() { try { - const loginType = store?.state?.auth?.loginSession?.loginType || 'CLIENT' - const authRoute = getAuthRouteByLoginType(loginType) + const authRoute = getAuthRoute() yield call(removeSession, COOKIE_SESSION_KEY_MARKETPLACE, window.reapit.config.appEnv) yield call(redirectToLogout, window.reapit.config.cognitoClientId, `${window.location.origin}${authRoute}`) @@ -51,29 +42,9 @@ export const clearAuth = function*() { } } -export const setInitDeveloperTermsAcceptedStateFromCookie = function*() { - const loginType = yield select(selectLoginType) - - if (loginType === 'DEVELOPER') { - const isTermAccepted = yield call(getCookieString, COOKIE_DEVELOPER_TERMS_ACCEPTED) - yield put(setTermsAcceptedState(!!isTermAccepted)) - } -} - -export const setDeveloperTermAcceptedCookieAndState = function*({ data: isAccepted }) { - if (isAccepted) { - yield call(setCookieString, COOKIE_DEVELOPER_TERMS_ACCEPTED, new Date(), COOKIE_MAX_AGE_INFINITY) - } - yield put(setTermsAcceptedState(isAccepted)) -} - export const setInitClientTermsAcceptedStateFromCookie = function*() { - const loginType = yield select(selectLoginType) - // for now only check when login as developer - if (loginType === 'CLIENT') { - const isTermAccepted = yield call(getCookieString, COOKIE_CLIENT_TERMS_ACCEPTED) - yield put(setTermsAcceptedState(!!isTermAccepted)) - } + const isTermAccepted = yield call(getCookieString, COOKIE_CLIENT_TERMS_ACCEPTED) + yield put(setTermsAcceptedState(!!isTermAccepted)) } export const setClientTermAcceptedCookieAndState = function*({ data: isAccepted }) { @@ -95,20 +66,6 @@ export const clearAuthListen = function*() { yield takeLatest(ActionTypes.AUTH_CLEAR, clearAuth) } -export const setInitDeveloperTermsAcceptedStateFromCookieListen = function*() { - yield takeLatest( - ActionTypes.SET_INIT_DEVELOPER_TERMS_ACCEPTED_STATE_FROM_COOKIE, - setInitDeveloperTermsAcceptedStateFromCookie, - ) -} - -export const setDeveloperTermAcceptedCookieAndStateListen = function*() { - yield takeLatest>( - ActionTypes.SET_DEVELOPER_TERM_ACCEPTED_COOKIE_AND_STATE, - setDeveloperTermAcceptedCookieAndState, - ) -} - export const setInitClientTermsAcceptedStateFromCookieListen = function*() { yield takeLatest( ActionTypes.SET_INIT_CLIENT_TERMS_ACCEPTED_STATE_FROM_COOKIE, @@ -128,8 +85,6 @@ const authSaga = function*() { fork(loginListen), fork(logoutListen), fork(clearAuthListen), - fork(setInitDeveloperTermsAcceptedStateFromCookieListen), - fork(setDeveloperTermAcceptedCookieAndStateListen), fork(setInitClientTermsAcceptedStateFromCookieListen), fork(setClientTermAcceptedCookieAndStateListen), ]) diff --git a/packages/marketplace/src/tests/badges/badge-branches.svg b/packages/marketplace/src/tests/badges/badge-branches.svg index 3b7d4185df..f38060621e 100644 --- a/packages/marketplace/src/tests/badges/badge-branches.svg +++ b/packages/marketplace/src/tests/badges/badge-branches.svg @@ -1 +1 @@ -Coverage:branchesCoverage:branches70.18%70.18% \ No newline at end of file +Coverage:branchesCoverage:branches69.94%69.94% \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-functions.svg b/packages/marketplace/src/tests/badges/badge-functions.svg index 254aa95085..c9db508047 100644 --- a/packages/marketplace/src/tests/badges/badge-functions.svg +++ b/packages/marketplace/src/tests/badges/badge-functions.svg @@ -1 +1 @@ -Coverage:functionsCoverage:functions81.9%81.9% \ No newline at end of file +Coverage:functionsCoverage:functions81.78%81.78% \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-lines.svg b/packages/marketplace/src/tests/badges/badge-lines.svg index e4889efa95..b9a4e35aae 100644 --- a/packages/marketplace/src/tests/badges/badge-lines.svg +++ b/packages/marketplace/src/tests/badges/badge-lines.svg @@ -1 +1 @@ -Coverage:linesCoverage:lines91.26%91.26% \ No newline at end of file +Coverage:linesCoverage:lines91.22%91.22% \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-statements.svg b/packages/marketplace/src/tests/badges/badge-statements.svg index 8329f9351e..b95b1351af 100644 --- a/packages/marketplace/src/tests/badges/badge-statements.svg +++ b/packages/marketplace/src/tests/badges/badge-statements.svg @@ -1 +1 @@ -Coverage:statementsCoverage:statements90.26%90.26% \ No newline at end of file +Coverage:statementsCoverage:statements90.21%90.21% \ No newline at end of file diff --git a/packages/marketplace/src/utils/__tests__/auth-route.ts b/packages/marketplace/src/utils/__tests__/auth-route.ts index a64ec7edbb..73c04a3f9f 100644 --- a/packages/marketplace/src/utils/__tests__/auth-route.ts +++ b/packages/marketplace/src/utils/__tests__/auth-route.ts @@ -1,175 +1,28 @@ -import { - getAuthRouteByLoginType, - getLoginTypeByPath, - getDefaultRouteByLoginType, - getDefaultPathByLoginType, -} from '../auth-route' +import { getAuthRoute, getDefaultRoute, getDefaultPath } from '../auth-route' import Routes from '../../constants/routes' -import { match } from 'react-router' -const mockRouteMatch: match<{}> = { - isExact: true, - params: '', - path: '', - url: '', -} - -describe('getAuthRouteByLoginType', () => { +describe('getAuthRoute', () => { it('should return correct route', () => { - expect(getAuthRouteByLoginType('ADMIN')).toEqual(Routes.ADMIN_LOGIN) - expect(getAuthRouteByLoginType('DEVELOPER')).toEqual(Routes.DEVELOPER_LOGIN) - expect(getAuthRouteByLoginType('CLIENT')).toEqual(Routes.CLIENT_LOGIN) - }) -}) - -describe('getLoginTypeByPath', () => { - it('should return correct login type', () => { - expect(getLoginTypeByPath(Routes.ADMIN_LOGIN)).toEqual('ADMIN') - expect(getLoginTypeByPath(Routes.DEVELOPER_LOGIN)).toEqual('DEVELOPER') - expect(getLoginTypeByPath(Routes.CLIENT_LOGIN)).toEqual('CLIENT') + expect(getAuthRoute()).toEqual(Routes.LOGIN) }) }) -describe('getDefaultRouteByLoginType', () => { - it('should return origin url + Routes.ADMIN_APPROVALS if loginType = ADMIN ', () => { - expect( - getDefaultRouteByLoginType({ - loginType: 'ADMIN', - }), - ).toEqual(`${window.location.origin}${Routes.ADMIN_APPROVALS}`) - }) - - /* eslint-disable max-len */ - it('should return origin url + Routes.DEVELOPER_MY_APPS if loginType = DEVELOPER and isDeveloperFirstTimeLoginComplete is true', () => { - expect( - getDefaultRouteByLoginType({ - loginType: 'DEVELOPER', - isDeveloperFirstTimeLoginComplete: true, - }), - ).toEqual(`${window.location.origin}${Routes.DEVELOPER_MY_APPS}`) - }) - - it('should return origin url + Routes.DEVELOPER_WELCOME if loginType = DEVELOPER and isDeveloperFirstTimeLoginComplete is false', () => { - expect( - getDefaultRouteByLoginType({ - loginType: 'DEVELOPER', - }), - ).toEqual(`${window.location.origin}${Routes.DEVELOPER_WELCOME}`) - }) - - it('should return origin url + Routes.INSTALLED_APPS if loginType = CLIENT and isClientFirstTimeLoginComplete is true', () => { - expect( - getDefaultRouteByLoginType({ - loginType: 'CLIENT', - isClientFirstTimeLoginComplete: true, - }), - ).toEqual(`${window.location.origin}${Routes.INSTALLED_APPS}`) - }) - - it('should return origin url + Routes.CLIENT_WELCOME if loginType = CLIENT and isClientFirstTimeLoginComplete is false', () => { - expect( - getDefaultRouteByLoginType({ - loginType: 'CLIENT', - }), - ).toEqual(`${window.location.origin}${Routes.CLIENT_WELCOME}`) +describe('getDefaultRoute', () => { + it('should return correct route', () => { + expect(getDefaultRoute({ isFirstTimeLoginComplete: true })).toEqual( + `${window.location.origin}${Routes.INSTALLED_APPS}`, + ) }) - /* eslint-enable*/ }) -describe('getDefaultPathByLoginType', () => { - it('should return Routes.ADMIN_APPROVALS if loginType = ADMIN ', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'ADMIN', - developerLoginRouteMatch: null, - clientLoginRouteMatch: null, - }), - ).toEqual(Routes.ADMIN_APPROVALS) - }) - - /* eslint-disable max-len */ - it('should return Routes.DEVELOPER_MY_APPS if loginType = DEVELOPER and isDeveloperFirstTimeLoginComplete is true', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'DEVELOPER', - developerLoginRouteMatch: null, - clientLoginRouteMatch: null, - isDeveloperFirstTimeLoginComplete: true, - }), - ).toEqual(Routes.DEVELOPER_MY_APPS) - }) - - it('should return Routes.DEVELOPER_WELCOME if loginType = DEVELOPER and isDeveloperFirstTimeLoginComplete is false', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'DEVELOPER', - developerLoginRouteMatch: null, - clientLoginRouteMatch: null, - }), - ).toEqual(Routes.DEVELOPER_WELCOME) - }) - - it('should return Routes.INSTALLED_APPS if loginType = CLIENT and isClientFirstTimeLoginComplete is true', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'CLIENT', - developerLoginRouteMatch: null, - clientLoginRouteMatch: null, - isClientFirstTimeLoginComplete: true, - }), - ).toEqual(Routes.INSTALLED_APPS) - }) - - it('should return Routes.CLIENT_WELCOME if loginType = CLIENT and isClientFirstTimeLoginComplete is false', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'CLIENT', - developerLoginRouteMatch: null, - clientLoginRouteMatch: null, - }), - ).toEqual(Routes.CLIENT_WELCOME) - }) - - it('should return Routes.CLIENT_WELCOME if loginType = DEVELOPER and clientLoginRouteMatch is existed and isClientFirstTimeLoginComplete is false', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'DEVELOPER', - clientLoginRouteMatch: mockRouteMatch, - developerLoginRouteMatch: null, - isClientFirstTimeLoginComplete: false, - }), - ).toEqual(Routes.CLIENT_WELCOME) - }) - it('should return Routes.INSTALLED_APPS if loginType = DEVELOPER and clientLoginRouteMatch is existed and isClientFirstTimeLoginComplete is true', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'DEVELOPER', - clientLoginRouteMatch: mockRouteMatch, - developerLoginRouteMatch: null, - isClientFirstTimeLoginComplete: true, - }), - ).toEqual(Routes.INSTALLED_APPS) +describe('getDefaultPath', () => { + it('should return INSTALLED_APPS ', () => { + expect(getDefaultPath({ isDesktopMode: true, isFirstTimeLoginComplete: false })).toEqual(Routes.INSTALLED_APPS) }) - //---- - it('should return Routes.DEVELOPER_WELCOME if loginType = CLIENT and developerLoginRouteMatch is existed and isDeveloperFirstTimeLoginComplete is false', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'CLIENT', - clientLoginRouteMatch: null, - developerLoginRouteMatch: mockRouteMatch, - isDeveloperFirstTimeLoginComplete: false, - }), - ).toEqual(Routes.DEVELOPER_WELCOME) + it('should return INSTALLED_APPS ', () => { + expect(getDefaultPath({ isDesktopMode: false, isFirstTimeLoginComplete: true })).toEqual(Routes.INSTALLED_APPS) }) - it('should return Routes.DEVELOPER_MY_APPS if loginType = DEVELOPER and developerLoginRouteMatch is existed and isDeveloperFirstTimeLoginComplete is true', () => { - expect( - getDefaultPathByLoginType({ - loginType: 'CLIENT', - clientLoginRouteMatch: null, - developerLoginRouteMatch: mockRouteMatch, - isDeveloperFirstTimeLoginComplete: true, - }), - ).toEqual(Routes.DEVELOPER_MY_APPS) + it('should return INSTALLED_APPS ', () => { + expect(getDefaultPath({ isDesktopMode: false, isFirstTimeLoginComplete: false })).toEqual(Routes.CLIENT_WELCOME) }) - /* eslint-enable*/ }) diff --git a/packages/marketplace/src/utils/auth-route.ts b/packages/marketplace/src/utils/auth-route.ts index b970945ecc..e62b0872e6 100644 --- a/packages/marketplace/src/utils/auth-route.ts +++ b/packages/marketplace/src/utils/auth-route.ts @@ -1,128 +1,25 @@ -import { LoginType } from '@reapit/cognito-auth' import Routes from '../constants/routes' -import { match } from 'react-router' import { getMarketplaceGlobalsByKey } from '@reapit/elements' -export function getAuthRouteByLoginType(loginType: LoginType) { - switch (loginType) { - case 'ADMIN': - return Routes.ADMIN_LOGIN - case 'DEVELOPER': - return Routes.DEVELOPER_LOGIN - default: - return Routes.CLIENT_LOGIN - } -} - -export function getDefaultRouteByLoginType({ - loginType, - isDeveloperFirstTimeLoginComplete, - isClientFirstTimeLoginComplete, -}: { - loginType: LoginType - isDeveloperFirstTimeLoginComplete?: boolean - isClientFirstTimeLoginComplete?: boolean -}) { - switch (loginType) { - case 'ADMIN': - return `${window.location.origin}${Routes.ADMIN_APPROVALS}` - case 'DEVELOPER': { - if (window.location.pathname === Routes.DEVELOPER_EDITION_DOWNLOAD) { - return `${window.location.origin}${Routes.DEVELOPER_EDITION_DOWNLOAD}` - } - return !isDeveloperFirstTimeLoginComplete - ? `${window.location.origin}${Routes.DEVELOPER_WELCOME}` - : `${window.location.origin}${Routes.DEVELOPER_MY_APPS}` - } - default: - return !isClientFirstTimeLoginComplete && !getMarketplaceGlobalsByKey() - ? `${window.location.origin}${Routes.CLIENT_WELCOME}` - : `${window.location.origin}${Routes.INSTALLED_APPS}` - } -} - -export function getLoginTypeByPath(path: string) { - switch (path) { - case Routes.ADMIN_LOGIN: - return 'ADMIN' - case Routes.DEVELOPER_LOGIN: - return 'DEVELOPER' - default: - return 'CLIENT' - } -} - -function getDefaultPathForDeveloper( - clientLoginRouteMatch: match<{}> | null, - isDesktopMode?: boolean, - isClientFirstTimeLoginComplete?: boolean, - isDeveloperFirstTimeLoginComplete?: boolean, -) { - if (clientLoginRouteMatch) { - if (isDesktopMode) { - return Routes.INSTALLED_APPS - } - // when we logged in to developer portal and then tried to navigate to client login page - // we should be redirected back to either Routes.CLIENT_WELCOME or Routes.INSTALLED_APPS - return !isClientFirstTimeLoginComplete ? Routes.CLIENT_WELCOME : Routes.INSTALLED_APPS - } - if (isDesktopMode) { - return Routes.DEVELOPER_MY_APPS - } - return !isDeveloperFirstTimeLoginComplete ? Routes.DEVELOPER_WELCOME : Routes.DEVELOPER_MY_APPS +export function getAuthRoute() { + return Routes.LOGIN } -function getDefaultPathForClient( - developerLoginRouteMatch: match<{}> | null, - isDesktopMode?: boolean, - isDeveloperFirstTimeLoginComplete?: boolean, - isClientFirstTimeLoginComplete?: boolean, -) { - if (developerLoginRouteMatch) { - if (isDesktopMode) { - return Routes.DEVELOPER_MY_APPS - } - // when we logged in to client portal and then tried to navigate to developer login page - // we should be redirected back to either Routes.DEVELOPER_WELCOME or Routes.DEVELOPER_MY_APPS - return !isDeveloperFirstTimeLoginComplete ? Routes.DEVELOPER_WELCOME : Routes.DEVELOPER_MY_APPS - } - if (isDesktopMode) { - return Routes.INSTALLED_APPS - } - return !isClientFirstTimeLoginComplete ? Routes.CLIENT_WELCOME : Routes.INSTALLED_APPS +export function getDefaultRoute({ isFirstTimeLoginComplete }) { + return !isFirstTimeLoginComplete && !getMarketplaceGlobalsByKey() + ? `${window.location.origin}${Routes.CLIENT_WELCOME}` + : `${window.location.origin}${Routes.INSTALLED_APPS}` } -export function getDefaultPathByLoginType({ - loginType, - developerLoginRouteMatch, - clientLoginRouteMatch, - isDeveloperFirstTimeLoginComplete, - isClientFirstTimeLoginComplete, +export function getDefaultPath({ isDesktopMode, + isFirstTimeLoginComplete, }: { - loginType: LoginType - developerLoginRouteMatch: match<{}> | null - clientLoginRouteMatch: match<{}> | null - isDeveloperFirstTimeLoginComplete?: boolean - isClientFirstTimeLoginComplete?: boolean isDesktopMode?: boolean + isFirstTimeLoginComplete?: boolean }) { - switch (loginType) { - case 'ADMIN': - return Routes.ADMIN_APPROVALS - case 'DEVELOPER': - return getDefaultPathForDeveloper( - clientLoginRouteMatch, - isDesktopMode, - isClientFirstTimeLoginComplete, - isDeveloperFirstTimeLoginComplete, - ) - default: - return getDefaultPathForClient( - developerLoginRouteMatch, - isDesktopMode, - isDeveloperFirstTimeLoginComplete, - isClientFirstTimeLoginComplete, - ) + if (isDesktopMode) { + return Routes.INSTALLED_APPS } + return !isFirstTimeLoginComplete ? Routes.CLIENT_WELCOME : Routes.INSTALLED_APPS }