@jetthai/cuora 1.0.59 → 1.0.60
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,8 @@
|
|
|
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.0.60](https://github.com/jetthai/cuora-module/compare/v1.0.59...v1.0.60) (2021-12-20)
|
|
6
|
+
|
|
5
7
|
### [1.0.59](https://github.com/jetthai/cuora-module/compare/v1.0.58...v1.0.59) (2021-12-17)
|
|
6
8
|
|
|
7
9
|
### [1.0.58](https://github.com/jetthai/cuora-module/compare/v1.0.57...v1.0.58) (2021-12-17)
|
package/package.json
CHANGED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate'
|
|
2
|
+
import api from '../../api/activity'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'diamond_shop_activity',
|
|
9
|
+
context: {
|
|
10
|
+
activityNo: null,
|
|
11
|
+
activityDetail: null,
|
|
12
|
+
awards: [],
|
|
13
|
+
exchangeList: [],
|
|
14
|
+
exchangeAward: 0,
|
|
15
|
+
exchangePoint: 0,
|
|
16
|
+
},
|
|
17
|
+
initial: 'idle',
|
|
18
|
+
states: {
|
|
19
|
+
idle: {
|
|
20
|
+
on: {
|
|
21
|
+
SET_ACTIVITY_NO: {
|
|
22
|
+
target: 'loading',
|
|
23
|
+
actions: 'setActivityNo',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
loading: {
|
|
28
|
+
invoke: {
|
|
29
|
+
src: 'fetchActivityDetail',
|
|
30
|
+
onDone: {
|
|
31
|
+
target: 'loaded',
|
|
32
|
+
actions: ['setActivityDetail', 'setAwardList'],
|
|
33
|
+
},
|
|
34
|
+
onError: {
|
|
35
|
+
target: 'idle',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
loaded: {
|
|
40
|
+
on: {
|
|
41
|
+
EXCHANGE: {
|
|
42
|
+
target: 'exchanging',
|
|
43
|
+
cond: 'isExchangeable',
|
|
44
|
+
},
|
|
45
|
+
ADD_TO_CART: {
|
|
46
|
+
actions: ['addProduct', 'count'],
|
|
47
|
+
},
|
|
48
|
+
CLEAR_CART: {
|
|
49
|
+
actions: ['clearCart', 'count'],
|
|
50
|
+
},
|
|
51
|
+
COLLECT: {
|
|
52
|
+
target: 'collecting',
|
|
53
|
+
cond: 'hasUnclaimedReward',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
exchanging: {
|
|
58
|
+
invoke: {
|
|
59
|
+
src: 'exchange',
|
|
60
|
+
onDone: {
|
|
61
|
+
target: 'collecting',
|
|
62
|
+
actions: ['clearCart', 'count'],
|
|
63
|
+
},
|
|
64
|
+
onError: {
|
|
65
|
+
target: 'loaded',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
collecting: {
|
|
70
|
+
invoke: {
|
|
71
|
+
src: 'collect',
|
|
72
|
+
onDone: {
|
|
73
|
+
target: 'collected',
|
|
74
|
+
},
|
|
75
|
+
onError: {
|
|
76
|
+
target: 'collected',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
collected: {
|
|
81
|
+
after: {
|
|
82
|
+
0: {
|
|
83
|
+
target: 'loaded',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
actions: {
|
|
91
|
+
setActivityNo: assign((context, event) => {
|
|
92
|
+
return {
|
|
93
|
+
activityNo: event.data,
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
setActivityDetail: assign((context, event) => {
|
|
97
|
+
return {
|
|
98
|
+
activityDetail: event.data,
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
setAwardList: assign((context, event) => {
|
|
102
|
+
return {
|
|
103
|
+
awardList: event.data?.awards || [],
|
|
104
|
+
}
|
|
105
|
+
}),
|
|
106
|
+
addProduct: assign((context, event) => {
|
|
107
|
+
return {
|
|
108
|
+
exchangeList: [...context.exchangeList, event.data],
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
clearCart: assign((context, event) => {
|
|
112
|
+
return {
|
|
113
|
+
exchangeList: [],
|
|
114
|
+
}
|
|
115
|
+
}),
|
|
116
|
+
count: assign((context, event) => {
|
|
117
|
+
const { exchangeList } = context
|
|
118
|
+
const { exchangeAward, exchangePoint } = exchangeList.reduce(
|
|
119
|
+
({ exchangeAward, exchangePoint }, item) => {
|
|
120
|
+
return {
|
|
121
|
+
exchangeAward: exchangeAward + item.award,
|
|
122
|
+
exchangePoint: exchangePoint + item.points,
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{ exchangeAward: 0, exchangePoint: 0 }
|
|
126
|
+
)
|
|
127
|
+
return {
|
|
128
|
+
exchangeAward,
|
|
129
|
+
exchangePoint,
|
|
130
|
+
}
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
guards: {
|
|
134
|
+
hasUnclaimedReward: (context, event) => {
|
|
135
|
+
return context.activityDetail?.unclaimedReward?.length > 0
|
|
136
|
+
},
|
|
137
|
+
isExchangeable: (context, event) => {
|
|
138
|
+
const { exchangeList } = context
|
|
139
|
+
return exchangeList.length > 0
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
services: {
|
|
143
|
+
fetchActivityDetail: async (context, event) => {
|
|
144
|
+
const { activityNo } = context
|
|
145
|
+
const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
|
|
146
|
+
return data
|
|
147
|
+
},
|
|
148
|
+
exchange: async (context, event) => {
|
|
149
|
+
const { activityNo, exchangeList } = context
|
|
150
|
+
return await Promise.all(
|
|
151
|
+
exchangeList.map((item) =>
|
|
152
|
+
request.send(
|
|
153
|
+
api.exchange({
|
|
154
|
+
exchangeType: 1,
|
|
155
|
+
activityNo,
|
|
156
|
+
exchangeAward: item.award,
|
|
157
|
+
})
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
},
|
|
162
|
+
collect: async (context, event) => {
|
|
163
|
+
return await request.send(api.collect({ appSecret }))
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
}
|
|
@@ -7,12 +7,25 @@ export default function (request) {
|
|
|
7
7
|
{
|
|
8
8
|
id: 'ranking_activity',
|
|
9
9
|
context: {
|
|
10
|
+
rankActivities: null,
|
|
10
11
|
activityNo: null,
|
|
11
12
|
activityDetail: null,
|
|
12
13
|
activityMap: {},
|
|
13
14
|
},
|
|
14
|
-
initial: '
|
|
15
|
+
initial: 'fetching',
|
|
15
16
|
states: {
|
|
17
|
+
fetching: {
|
|
18
|
+
invoke: {
|
|
19
|
+
src: 'fetchActivityList',
|
|
20
|
+
onDone: {
|
|
21
|
+
target: 'checking',
|
|
22
|
+
actions: 'setRankActivities',
|
|
23
|
+
},
|
|
24
|
+
onError: {
|
|
25
|
+
target: 'idle',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
16
29
|
idle: {
|
|
17
30
|
on: {
|
|
18
31
|
SET_ACTIVITY_NO: {
|
|
@@ -40,6 +53,15 @@ export default function (request) {
|
|
|
40
53
|
},
|
|
41
54
|
{
|
|
42
55
|
actions: {
|
|
56
|
+
setRankActivities: assign((context, event) => {
|
|
57
|
+
const rankActivities = event.data.filter((item) => item.activityType === 2 || item.activityType === 200)
|
|
58
|
+
// 2: ranking_activity
|
|
59
|
+
// 200: cl_activity
|
|
60
|
+
return {
|
|
61
|
+
rankActivities,
|
|
62
|
+
activityNo: rankActivities?.[0]?.activityNo,
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
43
65
|
setActivityNo: assign((context, event) => {
|
|
44
66
|
return {
|
|
45
67
|
activityNo: event.data,
|
|
@@ -65,6 +87,10 @@ export default function (request) {
|
|
|
65
87
|
},
|
|
66
88
|
},
|
|
67
89
|
services: {
|
|
90
|
+
fetchActivityList: async (context, event) => {
|
|
91
|
+
const { data } = await request.send(api.getActivityList({ appSecret, include: 'cl' }))
|
|
92
|
+
return data
|
|
93
|
+
},
|
|
68
94
|
fetchActivityDetail: async (context, event) => {
|
|
69
95
|
const { activityNo } = context
|
|
70
96
|
const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
|