@twreporter/redux 7.6.0 → 7.7.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [7.7.0-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.6.1-rc.0...@twreporter/redux@7.7.0-rc.0) (2023-07-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * remove unused code ([8f5f72c](https://github.com/twreporter/twreporter-npm-packages/commit/8f5f72c6e48a478b9cc8bbbf458aab51fa94c7b8))
12
+
13
+
14
+ ### Features
15
+
16
+ * add test for getUserData ([f6e8854](https://github.com/twreporter/twreporter-npm-packages/commit/f6e8854b953d49217b2785c1dd2d7195fb0e1ef8))
17
+ * getUserData from api ([bff225b](https://github.com/twreporter/twreporter-npm-packages/commit/bff225bfeb16460b35851ca47712cd488e059414))
18
+
19
+
20
+
21
+
22
+
23
+ ## [7.6.1-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.6.0...@twreporter/redux@7.6.1-rc.0) (2023-06-28)
24
+
25
+ **Note:** Version bump only for package @twreporter/redux
26
+
27
+
28
+
29
+
30
+
6
31
  # [7.6.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.6.0-rc.2...@twreporter/redux@7.6.0) (2023-06-21)
7
32
 
8
33
  **Note:** Version bump only for package @twreporter/redux
@@ -85,7 +85,6 @@ function buildSuccessActionFromRes(axiosResponse, actionType) {
85
85
  * @param {number} userID - id of user
86
86
  * @return {Function} - function will be executed in Redux Thunk middleware
87
87
  */
88
- // TODO: wait till api ready
89
88
 
90
89
 
91
90
  function getUserData(jwt, userID) {
@@ -94,42 +93,33 @@ function getUserData(jwt, userID) {
94
93
  * @param {Function} getState - Redux store getState function
95
94
  * @return {Promise} resolve with success action or reject with fail action
96
95
  */
97
- // return function(dispatch, getState) {
98
- // const state = getState()
99
- // const apiOrigin = _.get(state, [stateFieldNames.origins, 'api'])
100
- // const url = formURL(
101
- // apiOrigin,
102
- // `/v2/${apiEndpoints.users}/${userID}`,
103
- // )
104
- // dispatch({
105
- // type: types.user.read.request,
106
- // url
107
- // })
108
- // const axiosConfig = {
109
- // timeout: apiTimeout,
110
- // headers: {
111
- // Authorization: `Bearer ${jwt}`,
112
- // },
113
- // }
114
- // return axios
115
- // .get(url, axiosConfig)
116
- // .then(res => {
117
- // const successAction = buildSuccessActionFromRes(
118
- // res,
119
- // types.user.read.success
120
- // )
121
- // dispatch(successAction)
122
- // return successAction
123
- // })
124
- // .catch(error => {
125
- // const failAction = failActionCreators.axios(
126
- // error,
127
- // types.user.read.failure
128
- // )
129
- // dispatch(failAction)
130
- // return Promise.reject(failAction)
131
- // })
132
- // }
96
+ return function (dispatch, getState) {
97
+ var state = getState();
98
+
99
+ var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
100
+
101
+ var url = (0, _url.formURL)(apiOrigin, "/v2/".concat(_apiEndpoints["default"].users, "/").concat(userID));
102
+ dispatch({
103
+ type: _actionTypes["default"].user.read.request,
104
+ url: url
105
+ });
106
+ var axiosConfig = {
107
+ timeout: apiTimeout,
108
+ headers: {
109
+ Authorization: "Bearer ".concat(jwt)
110
+ }
111
+ };
112
+ return _axios["default"].get(url, axiosConfig).then(function (res) {
113
+ var successAction = buildSuccessActionFromRes(res, _actionTypes["default"].user.read.success);
114
+ dispatch(successAction);
115
+ return successAction;
116
+ })["catch"](function (error) {
117
+ var failAction = _errorActionCreators["default"].axios(error, _actionTypes["default"].user.read.failure);
118
+
119
+ dispatch(failAction);
120
+ return Promise.reject(failAction);
121
+ });
122
+ };
133
123
  }
134
124
  /**
135
125
  *
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
 
8
- var _featureFlag = require("@twreporter/core/lib/constants/feature-flag");
9
-
10
8
  var _categorySet = require("@twreporter/core/lib/constants/category-set");
11
9
 
12
10
  var entities = 'entities';
@@ -33,14 +31,7 @@ var photosSection = 'photos_section';
33
31
  var reviewsSection = 'reviews_section';
34
32
  var topicsSection = 'topics_section'; // categories in index_page
35
33
 
36
- var humanRightsAndSociety = 'human_rights_and_society';
37
- var environmentAndEducation = 'environment_and_education';
38
- var politicsAndEconomy = 'politics_and_economy';
39
- var cultureAndArt = 'culture_and_art';
40
- var international = 'international';
41
- var livingAndMedicalCare = 'living_and_medical_care'; // feature toggle
42
-
43
- var categories = _featureFlag.ENABLE_NEW_INFO_ARCH ? {
34
+ var categories = {
44
35
  world: _categorySet.CATEGORY_PATH.world,
45
36
  humanrights: _categorySet.CATEGORY_PATH.humanrights,
46
37
  politicsAndSociety: _categorySet.CATEGORY_PATH.politicsAndSociety,
@@ -49,13 +40,6 @@ var categories = _featureFlag.ENABLE_NEW_INFO_ARCH ? {
49
40
  econ: _categorySet.CATEGORY_PATH.econ,
50
41
  culture: _categorySet.CATEGORY_PATH.culture,
51
42
  education: _categorySet.CATEGORY_PATH.education
52
- } : {
53
- humanRightsAndSociety: humanRightsAndSociety,
54
- environmentAndEducation: environmentAndEducation,
55
- politicsAndEconomy: politicsAndEconomy,
56
- cultureAndArt: cultureAndArt,
57
- international: international,
58
- livingAndMedicalCare: livingAndMedicalCare
59
43
  }; // time stamp for next popup
60
44
 
61
45
  var nextNotifyPopupTS = 'nextNotifyPopupTS';
@@ -27,13 +27,13 @@ var initState = {
27
27
  error: null,
28
28
  isFetching: false,
29
29
  isReady: false,
30
- // TODO: need add other user state after connect to getUser api
31
- // userID: -1,
32
- // firstName: '',
33
- // lastName: '',
34
- // role: MEMBER_ROLE.explorer,
35
- // email: '',
36
- // activated: false,
30
+ userID: -1,
31
+ email: '',
32
+ firstName: '',
33
+ lastName: '',
34
+ roles: [],
35
+ registrationDate: '',
36
+ activated: false,
37
37
  readPreference: [],
38
38
  maillist: []
39
39
  };
@@ -44,6 +44,59 @@ function user() {
44
44
  var payload = action.payload;
45
45
 
46
46
  switch (action.type) {
47
+ case _actionTypes["default"].user.read.request:
48
+ {
49
+ return _.merge({}, state, {
50
+ isFetching: true,
51
+ isReady: false
52
+ });
53
+ }
54
+
55
+ case _actionTypes["default"].user.read.success:
56
+ {
57
+ var userID = _.get(payload, 'data.data.user_id');
58
+
59
+ var email = _.get(payload, 'data.data.email');
60
+
61
+ var firstName = _.get(payload, 'data.data.first_name');
62
+
63
+ var lastName = _.get(payload, 'data.data.last_name');
64
+
65
+ var roles = _.get(payload, 'data.data.roles');
66
+
67
+ var registrationDate = _.get(payload, 'data.data.registration_date');
68
+
69
+ var activated = _.get(payload, 'data.data.activated');
70
+
71
+ var readPreference = _.get(payload, 'data.data.read_preference');
72
+
73
+ var maillist = _.get(payload, 'data.data.maillist');
74
+
75
+ return _objectSpread(_objectSpread({}, state), {}, {
76
+ error: null,
77
+ isFetching: false,
78
+ isReady: true,
79
+ userID: userID,
80
+ email: email,
81
+ firstName: firstName,
82
+ lastName: lastName,
83
+ roles: roles,
84
+ registrationDate: registrationDate,
85
+ activated: activated,
86
+ readPreference: readPreference,
87
+ maillist: maillist
88
+ });
89
+ }
90
+
91
+ case _actionTypes["default"].user.read.failure:
92
+ {
93
+ return _objectSpread(_objectSpread({}, state), {}, {
94
+ error: payload.error,
95
+ isFetching: false,
96
+ isReady: false
97
+ });
98
+ }
99
+
47
100
  case _actionTypes["default"].user.update.request:
48
101
  {
49
102
  return _.merge({}, state, {
@@ -54,18 +107,16 @@ function user() {
54
107
 
55
108
  case _actionTypes["default"].user.update.success:
56
109
  {
57
- var readPreference = _.get(payload, 'data.record.read_preference', []);
110
+ var _readPreference = _.get(payload, 'data.record.read_preference', []);
58
111
 
59
- var maillist = _.get(payload, 'data.record.maillist', []);
112
+ var _maillist = _.get(payload, 'data.record.maillist', []);
60
113
 
61
- state.readPreference = readPreference;
62
- state.maillist = maillist;
63
114
  return _objectSpread(_objectSpread({}, state), {}, {
64
115
  error: null,
65
116
  isFetching: false,
66
117
  isReady: true,
67
- maillist: maillist,
68
- readPreference: readPreference
118
+ maillist: _maillist,
119
+ readPreference: _readPreference
69
120
  });
70
121
  }
71
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twreporter/redux",
3
- "version": "7.6.0",
3
+ "version": "7.7.0-rc.0",
4
4
  "description": "redux actions and reducers for twreporter website",
5
5
  "repository": "https://github.com/twreporter/twreporter-npm-packages.git",
6
6
  "author": "twreporter <developer@twreporter.org>",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "homepage": "https://github.com/twreporter/twreporter-redux/#readme",
27
27
  "dependencies": {
28
- "@twreporter/core": "^1.10.0",
28
+ "@twreporter/core": "^1.11.0-rc.0",
29
29
  "axios": "^0.19.0",
30
30
  "es6-error": "^4.0.2",
31
31
  "humps": "^0.6.0",
@@ -44,5 +44,5 @@
44
44
  "files": [
45
45
  "lib"
46
46
  ],
47
- "gitHead": "8bb552690874aabe203b3c8205f725eef6285282"
47
+ "gitHead": "fb910ec11c88214b24e87ef0e4a011a896554471"
48
48
  }