@jetthai/cuora 1.1.135 → 1.1.137

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
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.1.137](https://github.com/jetthai/cuora-module/compare/v1.1.136...v1.1.137) (2023-07-14)
6
+
7
+ ### [1.1.136](https://github.com/jetthai/cuora-module/compare/v1.1.135...v1.1.136) (2023-07-14)
8
+
5
9
  ### [1.1.135](https://github.com/jetthai/cuora-module/compare/v1.1.134...v1.1.135) (2023-07-12)
6
10
 
7
11
  ### [1.1.134](https://github.com/jetthai/cuora-module/compare/v1.1.133...v1.1.134) (2023-07-12)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.135",
3
+ "version": "1.1.137",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -1,26 +1,27 @@
1
1
  import { createMachine, assign } from 'xstate'
2
- import api from '../../api/activity.js'
2
+ import activity from '../../api/activity.js'
3
+ import payment from '../../api/payment.js'
3
4
 
4
5
  export default function (request) {
5
6
  const { appSecret } = request.config
6
7
  return createMachine(
7
8
  {
8
9
  id: 'activity',
9
- initial: 'fetchingActivityList',
10
+ initial: 'fetchingList',
10
11
  context: {
11
12
  tick: 2000,
12
13
  activityList: [],
13
- activityMap: {},
14
+ promotionList: [],
14
15
  tournamentList: [],
15
- refs: {},
16
+ uidSite: '',
16
17
  },
17
18
  states: {
18
- fetchingActivityList: {
19
+ fetchingList: {
19
20
  invoke: {
20
- src: 'fetchActivityList',
21
+ src: 'fetchList',
21
22
  onDone: {
22
23
  target: 'pending',
23
- actions: ['setActivityList', 'setTournamentList'],
24
+ actions: ['setActivityList', 'setTournamentList', 'setPromotionList'],
24
25
  },
25
26
  onError: {
26
27
  target: 'pending',
@@ -30,7 +31,7 @@ export default function (request) {
30
31
  pending: {
31
32
  after: {
32
33
  TIMEOUT: {
33
- target: 'fetchingActivityList',
34
+ target: 'fetchingList',
34
35
  },
35
36
  },
36
37
  on: {
@@ -38,7 +39,7 @@ export default function (request) {
38
39
  actions: 'setUnread',
39
40
  },
40
41
  REFRESH: {
41
- target: '#activity.fetchingActivityList',
42
+ target: '#activity.fetchingList',
42
43
  },
43
44
  },
44
45
  },
@@ -47,7 +48,8 @@ export default function (request) {
47
48
  {
48
49
  actions: {
49
50
  setTournamentList: assign((context, event) => {
50
- const tournamentList = event.data.filter((item) => item.tournament === 1)
51
+ const { activityList } = event.data
52
+ const tournamentList = activityList.filter((item) => item.tournament === 1)
51
53
  return {
52
54
  tournamentList,
53
55
  }
@@ -55,7 +57,8 @@ export default function (request) {
55
57
  setActivityList: assign((context, event) => {
56
58
  const noReadActivity = [2, 4, 13, 20, 90, 91, 92]
57
59
  const { uidSite } = context
58
- let list = JSON.parse(JSON.stringify(event.data))
60
+ const { activityList } = event.data
61
+ let list = JSON.parse(JSON.stringify(activityList))
59
62
  list.forEach((activity) => {
60
63
  const storageUnread = localStorage.getItem(`unread_${activity.activityNo}_${uidSite}`)
61
64
  if (noReadActivity.includes(activity.activityType)) {
@@ -70,6 +73,12 @@ export default function (request) {
70
73
  activityList: list,
71
74
  }
72
75
  }),
76
+ setPromotionList: assign((context, event) => {
77
+ const { promotionList } = event.data
78
+ return {
79
+ promotionList,
80
+ }
81
+ }),
73
82
  setUnread: assign((context, event) => {
74
83
  const { uidSite, activityNo, unread } = event.data
75
84
  const list = JSON.parse(JSON.stringify(context.activityList))
@@ -93,9 +102,14 @@ export default function (request) {
93
102
  },
94
103
  },
95
104
  services: {
96
- fetchActivityList: async (context, event) => {
97
- const { data } = await request.send(api.getActivityList({ appSecret }))
98
- return data
105
+ fetchList: async (context, event) => {
106
+ const hasToken = request.getToken()
107
+ const [activityList, promotionList] = await Promise.all([
108
+ request.send(activity.getActivityList({ appSecret })),
109
+ hasToken ? request.send(payment.getPromotionsList()) : [],
110
+ ])
111
+
112
+ return { activityList, promotionList }
99
113
  },
100
114
  },
101
115
  }