userActions.js
3.19 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* # guideActions.js
*
* App user guide
*
*/
'use strict';
import {Actions} from 'react-native-router-flux';
import AppAuthToken from '../../services/AppAuthToken';
import UserService from '../../services/UserService';
import {Linking} from 'react-native';
const {
DELETE_TOKEN_REQUEST,
DELETE_TOKEN_SUCCESS,
ACCOUNT_CHANGE,
ACCOUNT_CLEAN,
PWD_CHANGE,
PWD_DISPLAY,
PWD_MODIFY,
PWD_MODIFY_OLD,
PWD_MODIFY_NEW,
PWD_MODIFY_REPEAT,
PWD_MODIFY_SUBMIT,
LOGIN_REQUEST,
LOGIN_SUCCESS,
LOGIN_FAILURE,
LOGOUT_REQUEST,
LOGOUT_SUCCESS,
LOGOUT_FAILURE,
SET_SESSION_TOKEN,
RESET_PASSWORD_REQUEST,
RESET_PASSWORD_SUCCESS,
RESET_PASSWORD_FAILURE,
PHONE_CALL,
ABOUT_US,
USER_ITEMS_PRESSED,
CHECK_UPDATE,
UPDATE_VERSION,
} = require('../../constants/actionTypes').default;
export function userItemsPressed(item) {
switch (item.index) {
case 0:
Linking.openURL('tel:025-87781000');
return {
type: PHONE_CALL,
};
case 1:
Actions.AboutUs();
return {
type: ABOUT_US,
};
}
}
export function checkUpdate(currentVersion) {
// todo
return {
type: CHECK_UPDATE,
isShowUpdate: true,
};
}
export function updateVersion() {
// todo
return {
type: UPDATE_VERSION,
}
}
export function loginRequest() {
return {
type: LOGIN_REQUEST
};
}
export function loginSuccess(json) {
return {
type: LOGIN_SUCCESS,
payload: json
};
}
export function loginFailure(error) {
return {
type: LOGIN_FAILURE,
payload: error
};
}
export function accountChange(account) {
return {
type: ACCOUNT_CHANGE,
payload: account
};
}
export function accountClean() {
return {
type: ACCOUNT_CLEAN,
};
}
export function pwdChange(pwd) {
return {
type: PWD_CHANGE,
payload: pwd
};
}
export function pwdDisplay(ishow) {
return {
type: PWD_DISPLAY,
payload: ishow
};
}
export function logout() {
new AppAuthToken().deleteSessionToken();
Actions.pop();
Actions.Login();
return {
type: LOGOUT_REQUEST
};
}
export function pwdModify() {
Actions.Modify();
return {
type: PWD_MODIFY
};
}
export function pwdModifyOld(pwd) {
return {
type: PWD_MODIFY_OLD,
payload: pwd
};
}
export function pwdModifyNew(pwd) {
return {
type: PWD_MODIFY_NEW,
payload: pwd
};
}
export function pwdModifyRepeat(pwd) {
return {
type: PWD_MODIFY_REPEAT,
payload: pwd
};
}
export function pwdModifySubmit() {
return {
type: PWD_MODIFY_SUBMIT
};
}
export function login(account, password) {
return dispatch => {
dispatch(loginRequest());
return new UserService().login(account,password)
.then(function (json) {
console.log(json);
return saveSessionToken(json)
.then(function () {
dispatch(loginSuccess(json));
Actions.Drawer();
});
})
.catch((error) => {
Actions.Drawer();
console.error(error);
dispatch(loginFailure(error));
});
};
}
export function saveSessionToken(json) {
return new AppAuthToken().storeSessionToken(json);
}