Skip to content

Commit

Permalink
recover pass immer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnojima authored Nov 21, 2019
1 parent a739803 commit 03dee34
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 60 deletions.
5 changes: 2 additions & 3 deletions shared/constants/recover-password.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as I from 'immutable'
import * as Types from './types/recover-password'
import HiddenString from '../util/hidden-string'

export const waitingKey = 'recover-password:waiting'

export const makeState = I.Record<Types._State>({
devices: I.List(),
export const makeState = (): Types.State => ({
devices: [],
error: new HiddenString(''),
explainedDevice: undefined,
paperKeyError: new HiddenString(''),
Expand Down
9 changes: 3 additions & 6 deletions shared/constants/types/recover-password.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as I from 'immutable'
import * as ProvisionTypes from './provision'
import * as RPCTypes from './rpc-gen'
import HiddenString from '../../util/hidden-string'

export type _State = {
devices: I.List<ProvisionTypes.Device>
export type State = Readonly<{
devices: Array<ProvisionTypes.Device>
error: HiddenString
explainedDevice?: {
name: string
Expand All @@ -14,6 +13,4 @@ export type _State = {
passwordError: HiddenString
resetEmailSent?: boolean
username: string
}

export type State = I.RecordOf<_State>
}>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type OwnProps = {}

const ConnectedDeviceSelector = Container.connect(
state => ({
devices: state.recoverPassword.devices.toArray(),
devices: state.recoverPassword.devices,
}),
dispatch => ({
_onSelect: (id: string) => dispatch(RecoverPasswordGen.createSubmitDeviceSelect({id})),
Expand Down
2 changes: 1 addition & 1 deletion shared/provision/select-other-device/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SelectOtherDevice extends React.Component<Props> {
_renderItem = (index, item: DeviceOrReset) => {
if (item === resetSignal) {
return (
<Kb.Box2 direction="vertical" fullWidth={true}>
<Kb.Box2 direction="vertical" fullWidth={true} key="reset">
<Kb.Text type="BodySmall" style={styles.or}>
or
</Kb.Text>
Expand Down
88 changes: 39 additions & 49 deletions shared/reducers/recover-password.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,47 @@
import * as I from 'immutable'
import * as Constants from '../constants/recover-password'
import * as Types from '../constants/types/recover-password'
import * as RecoverPasswordGen from '../actions/recover-password-gen'
import HiddenString from '../util/hidden-string'
import * as Container from '../util/container'

const emptyHiddenString = new HiddenString('')
const emptyHiddenString = new Container.HiddenString('')
const initialState = Constants.makeState()

type Actions = RecoverPasswordGen.Actions

export default function(state: Types.State = initialState, action: Actions): Types.State {
switch (action.type) {
case RecoverPasswordGen.startRecoverPassword:
return state.merge({
paperKeyError: new HiddenString(''),
username: action.payload.username,
})
case RecoverPasswordGen.displayDeviceSelect:
return state.merge({
devices: I.List(action.payload.devices),
})
case RecoverPasswordGen.showExplainDevice:
return state.merge({
explainedDevice: {
name: action.payload.name,
type: action.payload.type,
},
})
case RecoverPasswordGen.submitPaperKey:
return state.merge({paperKeyError: emptyHiddenString})
case RecoverPasswordGen.setPaperKeyError:
return state.merge({
paperKeyError: action.payload.error,
})
case RecoverPasswordGen.submitPassword:
return state.merge({passwordError: emptyHiddenString})
case RecoverPasswordGen.setPasswordError:
return state.merge({
passwordError: action.payload.error,
})
case RecoverPasswordGen.displayError:
return state.merge({
error: action.payload.error,
})
case RecoverPasswordGen.completeResetPassword:
return state.merge({
resetEmailSent: true,
})
case RecoverPasswordGen.resetResetPasswordState:
return state.merge({
resetEmailSent: false,
})
default:
return state
}
}
export default Container.makeReducer<Actions, Types.State>(initialState, {
[RecoverPasswordGen.resetStore]: () => initialState,
[RecoverPasswordGen.startRecoverPassword]: (draftState, action) => {
draftState.paperKeyError = emptyHiddenString
draftState.username = action.payload.username
},
[RecoverPasswordGen.displayDeviceSelect]: (draftState, action) => {
draftState.devices = action.payload.devices
},
[RecoverPasswordGen.showExplainDevice]: (draftState, action) => {
draftState.explainedDevice = {
name: action.payload.name,
type: action.payload.type,
}
},
[RecoverPasswordGen.submitPaperKey]: draftState => {
draftState.paperKeyError = emptyHiddenString
},
[RecoverPasswordGen.setPaperKeyError]: (draftState, action) => {
draftState.paperKeyError = action.payload.error
},
[RecoverPasswordGen.submitPassword]: draftState => {
draftState.passwordError = emptyHiddenString
},
[RecoverPasswordGen.setPasswordError]: (draftState, action) => {
draftState.passwordError = action.payload.error
},
[RecoverPasswordGen.displayError]: (draftState, action) => {
draftState.error = action.payload.error
},
[RecoverPasswordGen.completeResetPassword]: draftState => {
draftState.resetEmailSent = true
},
[RecoverPasswordGen.resetResetPasswordState]: draftState => {
draftState.resetEmailSent = false
},
})

0 comments on commit 03dee34

Please sign in to comment.