Skip to content

Commit 87170bd

Browse files
authored
Merge pull request #227 from mxenabled/jameson/CT-prop_drill_refactor_1
Jameson/prop drill refactor 1
2 parents 12a6d83 + 21dd120 commit 87170bd

File tree

14 files changed

+341
-358
lines changed

14 files changed

+341
-358
lines changed

src/Connect.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ export const Connect: React.FC<ConnectProps> = ({
211211
}
212212
}, [isLoading, step, props.clientConfig])
213213

214-
const _handleAddManualAccountClick = () => {
215-
dispatch(connectActions.stepToAddManualAccount())
216-
}
217-
218214
const _handleConsentGoBack = () => {
219215
// If returnToMicrodeposits is true, we came from MDV and clicking go back should return to MDV
220216
if (state.returnToMicrodeposits) {
@@ -327,7 +323,6 @@ export const Connect: React.FC<ConnectProps> = ({
327323
/>
328324
<RenderConnectStep
329325
availableAccountTypes={availableAccountTypes}
330-
handleAddManualAccountClick={_handleAddManualAccountClick}
331326
handleConsentGoBack={_handleConsentGoBack}
332327
handleCredentialsGoBack={_handleCredentialsGoBack}
333328
handleOAuthGoBack={_handleOAuthGoBack}

src/components/RenderConnectStep.js

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useContext } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
33
import PropTypes from 'prop-types'
44

5-
import _pick from 'lodash/pick'
65
import _isEmpty from 'lodash/isEmpty'
76

87
import { useTokens } from '@kyper/tokenprovider'
@@ -15,8 +14,6 @@ import {
1514
selectConnectConfig,
1615
selectIsMobileWebView,
1716
selectUIMessageVersion,
18-
addAggregationData,
19-
addVerificationData,
2017
selectInitialConfig,
2118
} from 'src/redux/reducers/configSlice'
2219

@@ -46,8 +43,6 @@ import { POST_MESSAGES } from 'src/const/postMessages'
4643
import { PostMessageContext } from 'src/ConnectWidget'
4744
import useSelectInstitution from 'src/hooks/useSelectInstitution'
4845
import { DynamicDisclosure } from 'src/views/consent/DynamicDisclosure'
49-
import { COMBO_JOB_DATA_TYPES } from 'src/const/comboJobDataTypes'
50-
import { isConsentEnabled } from 'src/redux/reducers/userFeaturesSlice'
5146
import { canHandleActionableError } from 'src/views/actionableError/consts'
5247

5348
const RenderConnectStep = (props) => {
@@ -73,7 +68,6 @@ const RenderConnectStep = (props) => {
7368
const selectedInstitution = useSelector(getSelectedInstitution)
7469
const updateCredentials = useSelector((state) => state.connect.updateCredentials)
7570
const verifyMemberError = useSelector((state) => state.connect.error)
76-
const consentIsEnabled = useSelector((state) => isConsentEnabled(state))
7771

7872
const { handleSelectInstitution } = useSelectInstitution()
7973

@@ -91,118 +85,35 @@ const RenderConnectStep = (props) => {
9185

9286
const hasAtriumAPI = client.has_atrium_api
9387

94-
/**
95-
* To show the add manual accounts option, you have to have the profile enabled,
96-
* be in agg mode, and not be an atrium client.
97-
*/
98-
const isManualAccountsEnabled =
99-
widgetProfile.enable_manual_accounts && mode === AGG_MODE && !hasAtriumAPI
100-
10188
const showSupport = widgetProfile.enable_support_requests && mode === AGG_MODE
102-
const usePopularOnly =
103-
(clientProfile.uses_custom_popular_institution_list ?? false) ||
104-
(client.has_limited_institutions ?? false)
10589
const isDeleteInstitutionOptionEnabled = widgetProfile?.display_delete_option_in_connect ?? true
10690

107-
const handleInstitutionSelect = (institution) => {
108-
postMessageFunctions.onPostMessage(
109-
'connect/selectedInstitution',
110-
_pick(institution, ['name', 'guid', 'url', 'code']),
111-
)
112-
113-
// The institution doesn't have credentials until we request it again from server
114-
handleSelectInstitution(institution)
115-
}
116-
11791
let connectStepView = null
11892

11993
if (step === STEPS.DISCLOSURE) {
120-
connectStepView = (
121-
<Disclosure
122-
mode={mode}
123-
onContinue={() =>
124-
dispatch({ type: connectActions.ActionTypes.ACCEPT_DISCLOSURE, payload: connectConfig })
125-
}
126-
ref={props.navigationRef}
127-
size={size}
128-
/>
129-
)
94+
connectStepView = <Disclosure ref={props.navigationRef} />
13095
} else if (step === STEPS.SEARCH) {
131-
connectStepView = (
132-
<Search
133-
connectConfig={connectConfig}
134-
connectedMembers={connectedMembers}
135-
enableManualAccounts={isManualAccountsEnabled}
136-
enableSupportRequests={showSupport}
137-
isMicrodepositsEnabled={isMicrodepositsEnabled}
138-
onAddManualAccountClick={props.handleAddManualAccountClick}
139-
onInstitutionSelect={handleInstitutionSelect}
140-
ref={props.navigationRef}
141-
size={size}
142-
stepToMicrodeposits={() => dispatch(connectActions.stepToMicrodeposits())}
143-
usePopularOnly={usePopularOnly}
144-
/>
145-
)
96+
connectStepView = <Search ref={props.navigationRef} />
14697
} else if (step === STEPS.INSTITUTION_DISABLED) {
14798
connectStepView = <InstitutionDisabled ref={props.navigationRef} />
14899
} else if (step === STEPS.CONSENT) {
149100
connectStepView = (
150101
<div>
151102
<DynamicDisclosure
152-
onConsentClick={() => {
153-
dispatch({ type: connectActions.ActionTypes.USER_CONSENTED })
154-
}}
155-
onGoBackClick={() => {
156-
props.handleConsentGoBack()
157-
}}
103+
onGoBackClick={() => props.handleConsentGoBack()}
158104
ref={props.navigationRef}
159105
/>
160106
</div>
161107
)
162108
} else if (step === STEPS.ADDITIONAL_PRODUCT) {
163-
if (!ADDITIONAL_PRODUCT_OPTIONS.includes(connectConfig?.additional_product_option)) {
109+
if (!ADDITIONAL_PRODUCT_OPTIONS.includes(connectConfig?.additional_product_option))
164110
throw new Error('invalid product offer')
165-
}
166-
167-
const onNoClick = () => {
168-
// Go to the next step in the flow without changing the configuration
169-
dispatch({
170-
type: connectActions.ActionTypes.REJECT_ADDITIONAL_PRODUCT,
171-
payload: {
172-
consentIsEnabled,
173-
},
174-
})
175-
}
176-
177-
let onYesClick = null
178-
if (connectConfig?.additional_product_option === COMBO_JOB_DATA_TYPES.ACCOUNT_NUMBER) {
179-
onYesClick = () => {
180-
dispatch(addVerificationData({ consentIsEnabled }))
181-
}
182-
} else if (connectConfig?.additional_product_option === COMBO_JOB_DATA_TYPES.TRANSACTIONS) {
183-
onYesClick = () => {
184-
dispatch(addAggregationData({ consentIsEnabled }))
185-
}
186-
}
187111

188-
connectStepView = (
189-
<AdditionalProductStep
190-
additionalProductName={connectConfig.additional_product_option}
191-
onNoClick={onNoClick}
192-
onYesClick={onYesClick}
193-
ref={props.navigationRef}
194-
/>
195-
)
112+
connectStepView = <AdditionalProductStep ref={props.navigationRef} />
196113
} else if (step === STEPS.ADD_MANUAL_ACCOUNT) {
197114
connectStepView = (
198115
<ManualAccountConnect
199116
availableAccountTypes={props.availableAccountTypes}
200-
onClose={() =>
201-
dispatch({
202-
type: connectActions.ActionTypes.GO_BACK_MANUAL_ACCOUNT,
203-
payload: initialConfig,
204-
})
205-
}
206117
onManualAccountAdded={props.onManualAccountAdded}
207118
ref={props.navigationRef}
208119
/>
@@ -374,7 +285,6 @@ const RenderConnectStep = (props) => {
374285

375286
RenderConnectStep.propTypes = {
376287
availableAccountTypes: PropTypes.array,
377-
handleAddManualAccountClick: PropTypes.func.isRequired,
378288
handleConsentGoBack: PropTypes.func.isRequired,
379289
handleCredentialsGoBack: PropTypes.func.isRequired,
380290
handleOAuthGoBack: PropTypes.func.isRequired,

src/redux/reducers/configSlice.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
REWARD_MODE,
99
STEPS,
1010
COLOR_SCHEME,
11+
TAX_MODE,
1112
} from 'src/const/Connect'
1213
import { COMBO_JOB_DATA_TYPES } from 'src/const/comboJobDataTypes'
1314

@@ -42,7 +43,8 @@ const configSlice = createSlice({
4243
name: 'config',
4344
initialState,
4445
reducers: {
45-
addVerificationData: (state) => {
46+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
47+
addVerificationData: (state, _) => {
4648
// If the current mode is AGG_MODE, we need to set the include_transactions flag to true
4749
// in order to continue getting transactions for new connections
4850
if (state.mode === AGG_MODE) {
@@ -57,7 +59,8 @@ const configSlice = createSlice({
5759
state.use_cases = ['MONEY_MOVEMENT']
5860
}
5961
},
60-
addAggregationData: (state) => {
62+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
63+
addAggregationData: (state, _) => {
6164
state.include_transactions = true
6265

6366
if (Array.isArray(state.use_cases)) {
@@ -182,6 +185,13 @@ export const selectConnectConfig = createSelector(selectConfig, (config) => ({
182185
use_cases: config.use_cases,
183186
additional_product_option: config.additional_product_option,
184187
}))
188+
export const selectCurrentMode = createSelector(selectConfig, (config) => ({
189+
mode: config.mode,
190+
isInAggMode: config.mode === AGG_MODE,
191+
isInVerifyMode: config.mode === VERIFY_MODE,
192+
isInTaxMode: config.mode === TAX_MODE,
193+
isInRewardMode: config.mode === REWARD_MODE,
194+
}))
185195

186196
export const selectColorScheme = (state: RootState) => state.config.color_scheme
187197

src/redux/reducers/userFeaturesSlice.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import * as UserFeatures from 'src/utilities/UserFeatures'
33
import { CONNECT_COMBO_JOBS, CONNECT_CONSENT } from 'src/const/UserFeatures'
44
import { RootState } from 'src/redux/Store'
55

6-
export const initialState = {
6+
type UserFeaturesSlice = {
7+
items: { feature_name: string; is_enabled: boolean }[]
8+
}
9+
10+
export const initialState: UserFeaturesSlice = {
711
items: [],
812
}
913

src/services/mockedData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const initialState = {
119119
},
120120
connect: connectDefaultState,
121121
profiles: { loading: false, ...masterData },
122-
userFeatures: { items: [] },
122+
userFeatures: { items: [] } as { items: { feature_name: string; is_enabled: boolean }[] },
123123
}
124124

125125
export const member = {

0 commit comments

Comments
 (0)