Skip to content

Commit f04d402

Browse files
Jon Tzengswansontec
authored andcommitted
Fix security check notification not reappearing after dismissal
PasswordReminderService unmounts on logout and remounts after LOGIN dispatches, so componentDidUpdate never fires for the initial LOGIN transition. Add componentDidMount to persist the reducer-computed passwordReminder state (including the incremented nonPasswordLoginsCount) on mount so the count advances on disk across login cycles.
1 parent 7cc1d0f commit f04d402

2 files changed

Lines changed: 29 additions & 44 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export default [
330330
'src/components/services/FioService.ts',
331331
'src/components/services/LoanManagerService.ts',
332332
'src/components/services/NetworkActivity.ts',
333-
'src/components/services/PasswordReminderService.ts',
333+
334334
'src/components/services/PermissionsManager.tsx',
335335
'src/components/services/Providers.tsx',
336336

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,36 @@
11
import * as React from 'react'
22

33
import { setPasswordReminder } from '../../actions/LocalSettingsActions'
4-
import { connect } from '../../types/reactRedux'
5-
import type { PasswordReminder } from '../../types/types'
4+
import { useAsyncEffect } from '../../hooks/useAsyncEffect'
5+
import {
6+
initialState,
7+
type PasswordReminderState
8+
} from '../../reducers/PasswordReminderReducer'
9+
import { useDispatch, useSelector } from '../../types/reactRedux'
610
import { matchJson } from '../../util/matchJson'
7-
import { showError } from './AirshipInstance'
811

9-
interface StateProps {
10-
settingsLoaded: boolean | null
11-
passwordReminder: PasswordReminder
12-
}
13-
interface DispatchProps {
14-
setPasswordReminder: (passwordReminder: PasswordReminder) => Promise<void>
15-
}
16-
type Props = StateProps & DispatchProps
12+
interface Props {}
1713

18-
class PasswordReminderComponent extends React.PureComponent<Props> {
19-
componentDidUpdate(prevProps: Props): void {
20-
if (
21-
this.props.settingsLoaded === true &&
22-
!matchJson(prevProps.passwordReminder, this.props.passwordReminder)
23-
) {
24-
this.props
25-
.setPasswordReminder(this.props.passwordReminder)
26-
.catch((error: unknown) => {
27-
showError(error)
28-
})
29-
}
30-
}
14+
export const PasswordReminderService: React.FC<Props> = props => {
15+
const settingsLoaded =
16+
useSelector(state => state.ui.settings.settingsLoaded) ?? false
17+
const passwordReminder = useSelector(state => state.ui.passwordReminder)
18+
const lastPasswordReminder = React.useRef<PasswordReminderState>(initialState)
19+
const dispatch = useDispatch()
3120

32-
render(): React.JSX.Element | null {
33-
return null
34-
}
35-
}
21+
useAsyncEffect(
22+
async () => {
23+
if (
24+
settingsLoaded &&
25+
!matchJson(passwordReminder, lastPasswordReminder.current)
26+
) {
27+
lastPasswordReminder.current = passwordReminder
28+
await dispatch(setPasswordReminder(passwordReminder))
29+
}
30+
},
31+
[settingsLoaded, passwordReminder],
32+
'PasswordReminderService'
33+
)
3634

37-
export const PasswordReminderService = connect<
38-
StateProps,
39-
DispatchProps,
40-
unknown
41-
>(
42-
state => ({
43-
settingsLoaded: state.ui.settings.settingsLoaded,
44-
passwordReminder: state.ui.passwordReminder
45-
}),
46-
dispatch => ({
47-
async setPasswordReminder(passwordReminder: PasswordReminder) {
48-
await dispatch(setPasswordReminder(passwordReminder))
49-
}
50-
})
51-
)(PasswordReminderComponent)
35+
return null
36+
}

0 commit comments

Comments
 (0)