-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuseActionableErrorMap.tsx
More file actions
77 lines (72 loc) · 3.12 KB
/
Copy pathuseActionableErrorMap.tsx
File metadata and controls
77 lines (72 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { useContext, useMemo } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { PostMessageContext } from 'src/ConnectWidget'
import { ActionTypes } from 'src/redux/actions/Connect'
import { ACTIONABLE_ERROR_CODES } from 'src/views/actionableError/consts'
import { __ } from 'src/utilities/Intl'
import { selectInitialConfig } from 'src/redux/reducers/configSlice'
import { AGG_MODE } from 'src/const/Connect'
type ActionableErrorAction = {
label: string
action: () => void
}
type ActionableErrorMapEntry = {
title: string
primaryAction: ActionableErrorAction
secondaryActions: ActionableErrorAction
}
export const useActionableErrorMap = (
jobDetailCode: number,
setShowSupport: React.Dispatch<React.SetStateAction<boolean>>,
) => {
const postMessageFunctions = useContext(PostMessageContext)
const initialConfig = useSelector(selectInitialConfig)
const dispatch = useDispatch()
// Action options for mapping below
const goToSearch = () => {
postMessageFunctions.onPostMessage('connect/backToSearch')
dispatch({
type: ActionTypes.ACTIONABLE_ERROR_CONNECT_DIFFERENT_INSTITUTION,
payload: initialConfig.mode || AGG_MODE,
})
}
const goToSupport = () => setShowSupport(true)
const goToCredentials = () => dispatch({ type: ActionTypes.ACTIONABLE_ERROR_LOG_IN_AGAIN })
// AED Step 3: Add code mapping for new codes here
const messagingMap: Record<string, ActionableErrorMapEntry> = useMemo(
() => ({
[ACTIONABLE_ERROR_CODES.NO_ELIGIBLE_ACCOUNTS]: {
title: __('No eligible accounts'),
primaryAction: { label: __('Log in again'), action: goToCredentials },
secondaryActions: { label: __('Connect a different institution'), action: goToSearch },
},
[ACTIONABLE_ERROR_CODES.NO_ACCOUNTS]: {
title: __('No accounts found'),
primaryAction: { label: __('Return to institution selection'), action: goToSearch },
secondaryActions: { label: __('Get help'), action: goToSupport },
},
[ACTIONABLE_ERROR_CODES.ACCESS_DENIED]: {
title: __('Additional permissions needed'),
primaryAction: { label: __('Review instructions'), action: goToCredentials },
secondaryActions: { label: __('Get help'), action: goToSupport },
},
[ACTIONABLE_ERROR_CODES.INSTITUTION_DOWN]: {
title: __('Unable to connect'),
primaryAction: { label: __('Return to institution selection'), action: goToSearch },
secondaryActions: { label: __('Get help'), action: goToSupport },
},
[ACTIONABLE_ERROR_CODES.INSTITUTION_MAINTENANCE]: {
title: __('Maintenance in progress'),
primaryAction: { label: __('Return to institution selection'), action: goToSearch },
secondaryActions: { label: __('Get help'), action: goToSupport },
},
[ACTIONABLE_ERROR_CODES.INSTITUTION_UNAVAILABLE]: {
title: __('Unable to connect'),
primaryAction: { label: __('Return to institution selection'), action: goToSearch },
secondaryActions: { label: __('Get help'), action: goToSupport },
},
}),
[dispatch],
)
return messagingMap[jobDetailCode]
}