Skip to content

Commit

Permalink
chore: #1918 remove unused code from marketplace login page (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trường An authored Jul 9, 2020
1 parent b2b8fb8 commit 2c5a537
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 700 deletions.
14 changes: 0 additions & 14 deletions packages/marketplace/src/actions/__tests__/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
authChangeLoginType,
authSetRefreshSession,
authClear,
setInitDeveloperTermsAcceptedStateFromCookie,
setDeveloperTermAcceptedCookieAndState,
setInitClientTermsAcceptedStateFromCookie,
setClientTermAcceptedCookieAndState,
} from '../auth'
Expand All @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions packages/marketplace/src/actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ export const authSetRefreshSession = actionCreator<RefreshParams>(ActionTypes.AU
export const authChangeLoginType = actionCreator<LoginType>(ActionTypes.AUTH_CHANGE_LOGIN_TYPE)
export const authClear = actionCreator<void>(ActionTypes.AUTH_CLEAR)

export const setInitDeveloperTermsAcceptedStateFromCookie = actionCreator<void>(
ActionTypes.SET_INIT_DEVELOPER_TERMS_ACCEPTED_STATE_FROM_COOKIE,
)
export const setDeveloperTermAcceptedCookieAndState = actionCreator<boolean>(
ActionTypes.SET_DEVELOPER_TERM_ACCEPTED_COOKIE_AND_STATE,
)

export const setInitClientTermsAcceptedStateFromCookie = actionCreator<void>(
ActionTypes.SET_INIT_CLIENT_TERMS_ACCEPTED_STATE_FROM_COOKIE,
)
Expand Down
138 changes: 0 additions & 138 deletions packages/marketplace/src/components/pages/login.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ exports[`Login should match a snapshot 1`] = `
data-test=""
>
<p>
Welcome to Reapit
Foundations
Welcome to Reapit Marketplace
</p>
</section>
</Component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -38,7 +36,7 @@ describe('Login', () => {
expect(
mount(
<ReactRedux.Provider store={store}>
<MemoryRouter initialEntries={[{ pathname: Routes.CLIENT_LOGIN, key: 'clientLoginRoute' }]}>
<MemoryRouter initialEntries={[{ pathname: Routes.LOGIN, key: 'clientLoginRoute' }]}>
<Login />
</MemoryRouter>
</ReactRedux.Provider>,
Expand All @@ -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()
})
Expand Down
1 change: 1 addition & 0 deletions packages/marketplace/src/components/pages/login/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Login as default } from './login'
94 changes: 94 additions & 0 deletions packages/marketplace/src/components/pages/login/login.tsx
Original file line number Diff line number Diff line change
@@ -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<LoginProps> = () => {
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 <Redirect to={redirectRoute} />
}

return (
<div className={container}>
<div className={wrapper}>
<Level>
<img src={connectImage} alt="Reapit Connect Graphic" />
</Level>
<Section>
<p>Welcome to Reapit Marketplace</p>
</Section>
<Level className={registerLevel}>
<Button
className={loginButton}
type="button"
onClick={onLoginButtonClick(isFirstTimeLoginComplete)}
loading={false}
variant="primary"
disabled={false}
fullWidth
dataTest="login-button"
>
Login
</Button>
</Level>
<FlexContainerBasic className="pt-8" centerContent>
{process.env.APP_VERSION}
</FlexContainerBasic>
</div>
<div className={image}>
<img src={logoImage} alt="Reapit Graphic" />
</div>
</div>
)
}

export default Login
2 changes: 1 addition & 1 deletion packages/marketplace/src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ exports[`Router should match a snapshot 1`] = `
<Switch>
<Route
exact={true}
path={
Array [
"/developer/login",
"/admin/login",
"/client/login",
]
}
path={Array []}
render={[Function]}
/>
<Route
Expand Down
Loading

0 comments on commit 2c5a537

Please sign in to comment.