Skip to content

Commit

Permalink
feat: #1917 Remove unused code from register page in dev portal (#2005)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vu Nguyen authored Jul 9, 2020
1 parent 86f9f39 commit d9bec10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,24 +506,29 @@ exports[`Register should match a snapshot 1`] = `
</Component>
</div>
</Component>
<Link
className="is-pulled-right"
to="/client/apps"
>
<LinkAnchor
className="is-pulled-right"
href="/client/apps"
navigate={[Function]}
<Component>
<div
className=""
data-test=""
>
<a
className="is-pulled-right"
href="/client/apps"
onClick={[Function]}
Already have an account?
<Link
to="/developer/login"
>
Back to home
</a>
</LinkAnchor>
</Link>
<LinkAnchor
href="/developer/login"
navigate={[Function]}
>
<a
href="/developer/login"
onClick={[Function]}
>
Login
</a>
</LinkAnchor>
</Link>
</div>
</Component>
</div>
</Component>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as ReactRedux from 'react-redux'
import configureStore from 'redux-mock-store'
import { Register, onSubmit, onRegisterButtonClick, onDeclineTermsAndConditions, onLoginButtonClick } from '../register'
import { developerCreate } from '@/actions/developer'
import { authLogout } from '@/actions/auth'
import { DATE_TIME_FORMAT } from '@reapit/elements'
import MockDate from 'mockdate'
import appState from '@/reducers/__stubs__/app-state'
Expand Down Expand Up @@ -87,15 +86,9 @@ describe('Register', () => {
})
describe('onLoginButtonClick', () => {
it('should redirect to developer login page', () => {
const fn = onLoginButtonClick(history, spyDispatch, '')
const fn = onLoginButtonClick(history)
fn()
expect(history.replace).toBeCalledWith(`${Routes.LOGIN}`)
})
it('should run dispatch logout first and then redirect to developer login page', () => {
const fn = onLoginButtonClick(history, spyDispatch, 'testClientId')
fn()
expect(spyDispatch).toBeCalledWith(authLogout())
expect(history.replace).toBeCalledWith(`${Routes.LOGIN}`)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import TermsAndConditionsModal from '@/components/ui/terms-and-conditions-modal'
import Routes from '@/constants/routes'
import loginStyles from '@/styles/pages/login.scss?mod'
import logoImage from '@/assets/images/reapit-graphic.jpg'
import { selectClientId } from '@/selector/auth'
import { authLogout } from '@/actions/auth'
import { formFields } from './form-fields'
import { validationSchema } from './validation-schema'

Expand Down Expand Up @@ -83,11 +81,8 @@ export const onDeclineTermsAndConditions = (setTermsAndConditionsModalVisible: (
}
}

export const onLoginButtonClick = (history: History, dispatch: Dispatch, clientId: string) => {
export const onLoginButtonClick = (history: History) => {
return () => {
if (clientId) {
dispatch(authLogout())
}
history.replace(Routes.LOGIN)
}
}
Expand All @@ -97,7 +92,6 @@ export const Register: React.FunctionComponent<RegisterProps> = () => {
const dispatch = useDispatch()
const [visible, setVisible] = React.useState<boolean>(false)
const formState = useSelector(selectDeveloperFormState)
const clientId = useSelector(selectClientId) || ''
const isSubmitting = formState === 'SUBMITTING'

return (
Expand All @@ -110,7 +104,7 @@ export const Register: React.FunctionComponent<RegisterProps> = () => {
title="Success!"
buttonText="Login"
dataTest="register-success-message"
onButtonClick={onLoginButtonClick(history, dispatch, clientId)}
onButtonClick={onLoginButtonClick(history)}
isCenter
>
<div className="mb-3">Check your email to confirm your account</div>
Expand Down Expand Up @@ -183,15 +177,9 @@ export const Register: React.FunctionComponent<RegisterProps> = () => {
Register
</Button>
</Level>
{clientId ? (
<Link className="is-pulled-right" to={Routes.CLIENT}>
Back to home
</Link>
) : (
<Level>
Already have an account?<Link to={Routes.LOGIN}>Login</Link>
</Level>
)}
<Level>
Already have an account?<Link to={Routes.LOGIN}>Login</Link>
</Level>
{formState === 'ERROR' && (
<Alert message="Failed to register" type="danger" dataTest="register-error-message" />
)}
Expand Down

0 comments on commit d9bec10

Please sign in to comment.