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

chore(refactor): sofi email refactor #6327

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
@@ -1,7 +1,8 @@
import React, { useEffect } from 'react'
import { FormattedMessage } from 'react-intl'
import { useSelector } from 'react-redux'
import { Field } from 'redux-form'
import { useDispatch, useSelector } from 'react-redux'
import { push } from 'connected-react-router'
import { Field, formValueSelector, InjectedFormProps } from 'redux-form'
import styled from 'styled-components'

import { SofiMigrationStatusResponseType } from '@core/network/api/sofi/types'
Expand All @@ -10,12 +11,12 @@ import FormGroup from 'components/Form/FormGroup'
import FormItem from 'components/Form/FormItem'
import TextBox from 'components/Form/TextBox'
import { Wrapper } from 'components/Public'
import { RootState } from 'data/rootReducer'
import { LOGIN_FORM } from 'data/auth/model'
import { getSofiUserData } from 'data/modules/profile/selectors'
import { required, validEmail } from 'services/forms'
import { removeWhitespace } from 'services/forms/normalizers'
import { media } from 'services/styles'

import { Props } from '../..'
import { ActionButton, LinkRow, LoginFormLabel, SoFiWrapperWithPadding } from '../../model'

const LoginWrapper = styled(Wrapper)`
Expand All @@ -42,23 +43,32 @@ const HelperText = styled(Text)`
color: ${(props) => props.theme.grey600};
`

const Email = (props: Props) => {
const { busy, formValues, invalid, routerActions, submitting } = props
type Props = {
busy: boolean
} & Pick<InjectedFormProps, 'invalid' | 'submitting'>

const { sofiJwtPayload } = useSelector((state: RootState) => state.profile.sofiData).getOrElse(
const Email = ({ busy, invalid, submitting }: Props) => {
const dispatch = useDispatch()
const { sofiJwtPayload } = useSelector(getSofiUserData).getOrElse(
{}
) as SofiMigrationStatusResponseType

const sofiLoginEmail = useSelector((state) =>
formValueSelector(LOGIN_FORM)(state, 'sofiLoginEmail')
)

const onBack = () => dispatch(push('/sofi'))

useEffect(() => {
if (!sofiJwtPayload) {
routerActions.push('/sofi-error')
dispatch(push('/sofi-error'))
}
}, [])

return (
<LoginWrapper>
<SoFiWrapperWithPadding>
<BackArrow onClick={() => routerActions.push('/sofi')}>
<BackArrow onClick={onBack}>
<Icon
data-e2e='signupBack'
name='arrow-back'
Expand Down Expand Up @@ -131,7 +141,7 @@ const Email = (props: Props) => {
nature='primary'
fullwidth
height='48px'
disabled={submitting || invalid || busy || !formValues?.sofiLoginEmail}
disabled={submitting || invalid || busy || !sofiLoginEmail}
data-e2e='loginButton'
style={{ marginBottom: '16px' }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import React from 'react'
import { getAuthorizeVerifyDevice } from 'data/auth/selectors'
import { useRemote } from 'hooks'

import { Props } from '..'
import Error from './template.error'
import Loading from './template.loading'
import Success from './template.success'

const VerifyMagicLink = (props: Props) => {
const VerifyMagicLink = () => {
const { data, error, isLoading, isNotAsked } = useRemote(getAuthorizeVerifyDevice)

if (isLoading || isNotAsked) return <Loading />

if (error) return <Error error={error} />
return <Success {...props} {...data} />
return <Success {...data} />
}

export default VerifyMagicLink
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const Login = (props: Props) => {
const getComponentByStep = () => {
switch (step) {
case LoginSteps.SOFI_EMAIL:
return <Email {...loginProps} />
return <Email busy={busy} invalid={props.invalid} submitting={props.submitting} />
case LoginSteps.INSTITUTIONAL_PORTAL:
return <InstitutionalPortal {...loginProps} />
case LoginSteps.ENTER_PASSWORD_EXCHANGE:
Expand Down Expand Up @@ -179,7 +179,7 @@ const Login = (props: Props) => {
case LoginSteps.CHECK_EMAIL:
return <CheckEmail {...loginProps} handleSubmit={handleSubmit} />
case LoginSteps.VERIFY_MAGIC_LINK:
return <VerifyMagicLink {...loginProps} />
return <VerifyMagicLink />
case LoginSteps.SOFI_SUCCESS:
return <SofiSuccess />

Expand Down
Loading