-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasswordReset.js
43 lines (40 loc) · 1.18 KB
/
passwordReset.js
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
import { fromJS } from 'immutable';
import * as constants from '../constants';
import createReducer from '../utils/createReducer';
const initialState = {
error: null,
loading: false,
requesting: false,
userId: null,
userName: null,
userEmail: null,
connection: null
};
export const passwordReset = createReducer(fromJS(initialState), { // eslint-disable-line import/prefer-default-export
[constants.REQUEST_PASSWORD_RESET]: (state, action) =>
state.merge({
...initialState,
userId: action.user.user_id,
userName: action.user.name || action.user.user_name || action.user.email,
userEmail: action.user.email,
connection: action.connection,
requesting: true
}),
[constants.CANCEL_PASSWORD_RESET]: (state) =>
state.merge({
...initialState
}),
[constants.PASSWORD_RESET_PENDING]: (state) =>
state.merge({
loading: true
}),
[constants.PASSWORD_RESET_REJECTED]: (state, action) =>
state.merge({
loading: false,
error: `An error occured while resetting the password: ${action.errorMessage}`
}),
[constants.PASSWORD_RESET_FULFILLED]: (state) =>
state.merge({
...initialState
})
});