Authored by 于良

修改密码成功后登出重新登录 review by yewanwan

@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 import React from 'react'; 3 import React from 'react';
4 import ReactNative from 'react-native'; 4 import ReactNative from 'react-native';
5 import Button from 'apsl-react-native-button'; 5 import Button from 'apsl-react-native-button';
  6 +import LoadingIndicator from './indicator/LoadingIndicator';
6 7
7 const { 8 const {
8 Component, 9 Component,
@@ -83,6 +84,10 @@ export default class ModifyPassword extends Component { @@ -83,6 +84,10 @@ export default class ModifyPassword extends Component {
83 > 84 >
84 确定 85 确定
85 </Button> 86 </Button>
  87 +
  88 + <LoadingIndicator
  89 + isVisible={this.props.isFetching}
  90 + />
86 </View> 91 </View>
87 ); 92 );
88 } 93 }
@@ -21,7 +21,9 @@ export default keyMirror({ @@ -21,7 +21,9 @@ export default keyMirror({
21 PWD_MODIFY_OLD:null, 21 PWD_MODIFY_OLD:null,
22 PWD_MODIFY_NEW:null, 22 PWD_MODIFY_NEW:null,
23 PWD_MODIFY_REPEAT:null, 23 PWD_MODIFY_REPEAT:null,
24 - PWD_MODIFY_SUBMIT:null, 24 + PWD_MODIFY_REQUEST:null,
  25 + PWD_MODIFY_SUCCESS:null,
  26 + PWD_MODIFY_FAILURE:null,
25 27
26 MESSAGE_DETAIL:null, 28 MESSAGE_DETAIL:null,
27 REQUEST_MSG_LIST: null, 29 REQUEST_MSG_LIST: null,
@@ -44,10 +46,6 @@ export default keyMirror({ @@ -44,10 +46,6 @@ export default keyMirror({
44 46
45 SET_SESSION_TOKEN: null, 47 SET_SESSION_TOKEN: null,
46 48
47 - RESET_PASSWORD_REQUEST: null,  
48 - RESET_PASSWORD_SUCCESS: null,  
49 - RESET_PASSWORD_FAILURE: null,  
50 -  
51 HOME_OVERVIEW_REQUEST: null, 49 HOME_OVERVIEW_REQUEST: null,
52 HOME_OVERVIEW_SUCCESS: null, 50 HOME_OVERVIEW_SUCCESS: null,
53 HOME_OVERVIEW_FAILURE: null, 51 HOME_OVERVIEW_FAILURE: null,
@@ -78,7 +78,7 @@ export default class ModifyPasswordContainer extends Component { @@ -78,7 +78,7 @@ export default class ModifyPasswordContainer extends Component {
78 } 78 }
79 79
80 componentWillUnmount() { 80 componentWillUnmount() {
81 - 81 +
82 } 82 }
83 83
84 onModifyOldPwd(text:string){ 84 onModifyOldPwd(text:string){
@@ -114,6 +114,7 @@ export default class ModifyPasswordContainer extends Component { @@ -114,6 +114,7 @@ export default class ModifyPasswordContainer extends Component {
114 onModifyNewPwd={this.onModifyNewPwd} 114 onModifyNewPwd={this.onModifyNewPwd}
115 onModifyRepeatPwd={this.onModifyRepeatPwd} 115 onModifyRepeatPwd={this.onModifyRepeatPwd}
116 onModifySubmitPress={this.onModifySubmitPress} 116 onModifySubmitPress={this.onModifySubmitPress}
  117 + isFetching={this.props.user.isFetching}
117 /> 118 />
118 119
119 ); 120 );
@@ -25,7 +25,9 @@ const { @@ -25,7 +25,9 @@ const {
25 PWD_MODIFY_OLD, 25 PWD_MODIFY_OLD,
26 PWD_MODIFY_NEW, 26 PWD_MODIFY_NEW,
27 PWD_MODIFY_REPEAT, 27 PWD_MODIFY_REPEAT,
28 - PWD_MODIFY_SUBMIT, 28 + PWD_MODIFY_REQUEST,
  29 + PWD_MODIFY_SUCCESS,
  30 + PWD_MODIFY_FAILURE,
29 31
30 LOGIN_REQUEST, 32 LOGIN_REQUEST,
31 LOGIN_SUCCESS, 33 LOGIN_SUCCESS,
@@ -37,11 +39,6 @@ const { @@ -37,11 +39,6 @@ const {
37 39
38 SET_SESSION_TOKEN, 40 SET_SESSION_TOKEN,
39 41
40 - RESET_PASSWORD_REQUEST,  
41 - RESET_PASSWORD_SUCCESS,  
42 - RESET_PASSWORD_FAILURE,  
43 -  
44 -  
45 PHONE_CALL, 42 PHONE_CALL,
46 ABOUT_US, 43 ABOUT_US,
47 USER_ITEMS_PRESSED, 44 USER_ITEMS_PRESSED,
@@ -193,29 +190,41 @@ export function pwdModifyRepeat(pwd) { @@ -193,29 +190,41 @@ export function pwdModifyRepeat(pwd) {
193 }; 190 };
194 } 191 }
195 192
  193 +export function modifySubmitRequest() {
  194 + return {
  195 + type: PWD_MODIFY_REQUEST
  196 + };
  197 +}
  198 +
  199 +export function modifySubmitSuccess() {
  200 + Actions.pop();
  201 + return {
  202 + type: PWD_MODIFY_SUCCESS
  203 + };
  204 +}
  205 +
  206 +export function modifySubmitFailure() {
  207 + return {
  208 + type: PWD_MODIFY_FAILURE
  209 + };
  210 +}
  211 +
196 export function pwdModifySubmit(pid, oldPwd, newPwd,newPwdConfirm) { 212 export function pwdModifySubmit(pid, oldPwd, newPwd,newPwdConfirm) {
197 let userService = new UserService(); 213 let userService = new UserService();
198 return dispatch => { 214 return dispatch => {
199 - dispatch(loginRequest()); 215 + dispatch(modifySubmitRequest());
200 return userService.modifyPassword(pid, oldPwd, newPwd,newPwdConfirm) 216 return userService.modifyPassword(pid, oldPwd, newPwd,newPwdConfirm)
201 .then(function (json) { 217 .then(function (json) {
202 - Alert.alert(  
203 - '修改成功',  
204 - '',  
205 - [  
206 - {text: 'OK', onPress: () => Actions.pop()},  
207 - ]  
208 - );  
209 - dispatch(modifySubmitDone());  
210 - 218 + dispatch(modifySubmitSuccess());
  219 + dispatch(logout());
211 }) 220 })
212 .catch((error) => { 221 .catch((error) => {
213 Alert.alert( 222 Alert.alert(
214 - error.message,  
215 - '',  
216 - [{text: 'OK'}]  
217 - );  
218 - dispatch(loginFailure(error)); 223 + error.message,
  224 + '',
  225 + [{text: 'OK'}]
  226 + );
  227 + dispatch(modifySubmitFailure(error));
219 }); 228 });
220 }; 229 };
221 } 230 }
@@ -230,7 +239,7 @@ export function login(account, password) { @@ -230,7 +239,7 @@ export function login(account, password) {
230 return userService.storeUserInfo(json) 239 return userService.storeUserInfo(json)
231 .then(() => { 240 .then(() => {
232 dispatch(loginSuccess(json)); 241 dispatch(loginSuccess(json));
233 - dispatch(setupHomeDefaultBrand(json.shops[0].shopsId, json.shops[0].shopName)) 242 + dispatch(setupHomeDefaultShop(json.shops[0].shopsId, json.shops[0].shopName));
234 Actions.Drawer(); 243 Actions.Drawer();
235 }); 244 });
236 }) 245 })
@@ -246,14 +255,6 @@ export function login(account, password) { @@ -246,14 +255,6 @@ export function login(account, password) {
246 255
247 } 256 }
248 257
249 -  
250 -export function modifySubmitDone() {  
251 - Actions.pop();  
252 - return {  
253 - type: PWD_MODIFY_SUBMIT  
254 - };  
255 -}  
256 -  
257 export function getStoredUserInfo() { 258 export function getStoredUserInfo() {
258 259
259 return dispatch => { 260 return dispatch => {
@@ -28,7 +28,9 @@ const { @@ -28,7 +28,9 @@ const {
28 PWD_MODIFY_OLD, 28 PWD_MODIFY_OLD,
29 PWD_MODIFY_NEW, 29 PWD_MODIFY_NEW,
30 PWD_MODIFY_REPEAT, 30 PWD_MODIFY_REPEAT,
31 - PWD_MODIFY_SUBMIT, 31 + PWD_MODIFY_REQUEST,
  32 + PWD_MODIFY_SUCCESS,
  33 + PWD_MODIFY_FAILURE,
32 34
33 LOGIN_REQUEST, 35 LOGIN_REQUEST,
34 LOGIN_SUCCESS, 36 LOGIN_SUCCESS,
@@ -40,10 +42,6 @@ const { @@ -40,10 +42,6 @@ const {
40 42
41 SET_SESSION_TOKEN, 43 SET_SESSION_TOKEN,
42 44
43 - RESET_PASSWORD_REQUEST,  
44 - RESET_PASSWORD_SUCCESS,  
45 - RESET_PASSWORD_FAILURE,  
46 -  
47 CHECK_UPDATE_SUCCESS, 45 CHECK_UPDATE_SUCCESS,
48 CHECK_UPDATE_FAILURE, 46 CHECK_UPDATE_FAILURE,
49 47
@@ -90,8 +88,10 @@ export default function userReducer(state = initialState, action) { @@ -90,8 +88,10 @@ export default function userReducer(state = initialState, action) {
90 let nextState = state.setIn(['password', 'repeat'], action.payload); 88 let nextState = state.setIn(['password', 'repeat'], action.payload);
91 return nextState; 89 return nextState;
92 } 90 }
93 - case PWD_MODIFY_SUBMIT:{  
94 - let nextState = state.setIn(['password', 'old'], '') 91 + case PWD_MODIFY_SUCCESS:{
  92 + let nextState = state.set('isFetching', false)
  93 + .set('error', null)
  94 + .setIn(['password', 'old'], '')
95 .setIn(['password', 'new'], '') 95 .setIn(['password', 'new'], '')
96 .setIn(['password', 'repeat'], ''); 96 .setIn(['password', 'repeat'], '');
97 return nextState; 97 return nextState;
@@ -106,7 +106,7 @@ export default function userReducer(state = initialState, action) { @@ -106,7 +106,7 @@ export default function userReducer(state = initialState, action) {
106 } 106 }
107 107
108 case LOGIN_REQUEST: 108 case LOGIN_REQUEST:
109 - case RESET_PASSWORD_REQUEST: { 109 + case PWD_MODIFY_REQUEST: {
110 let nextState = state.set('isFetching', true) 110 let nextState = state.set('isFetching', true)
111 .set('error', null); 111 .set('error', null);
112 return nextState; 112 return nextState;
@@ -125,12 +125,12 @@ export default function userReducer(state = initialState, action) { @@ -125,12 +125,12 @@ export default function userReducer(state = initialState, action) {
125 } 125 }
126 126
127 case LOGOUT_SUCCESS: 127 case LOGOUT_SUCCESS:
128 - case RESET_PASSWORD_SUCCESS:  
129 - return state.set('isFetching', false); 128 + return state.set('isFetching', false)
  129 + .set('error', null);
130 130
131 case LOGOUT_FAILURE: 131 case LOGOUT_FAILURE:
132 case LOGIN_FAILURE: 132 case LOGIN_FAILURE:
133 - case RESET_PASSWORD_FAILURE: 133 + case PWD_MODIFY_FAILURE:
134 return state.set('isFetching', false) 134 return state.set('isFetching', false)
135 .set('error', action.payload); 135 .set('error', action.payload);
136 136