Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #1917 Remove unused code from register page in dev portal #2005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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