@jetthai/cuora 1.0.118 → 1.0.120
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 +4 -0
- package/package.json +1 -1
- package/src/machine/auth.js +5 -5
- package/src/machine/reward_fc.js +97 -0
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.0.120](https://github.com/jetthai/cuora-module/compare/v1.0.119...v1.0.120) (2022-05-23)
|
|
6
|
+
|
|
7
|
+
### [1.0.119](https://github.com/jetthai/cuora-module/compare/v1.0.118...v1.0.119) (2022-05-22)
|
|
8
|
+
|
|
5
9
|
### [1.0.118](https://github.com/jetthai/cuora-module/compare/v1.0.117...v1.0.118) (2022-05-22)
|
|
6
10
|
|
|
7
11
|
### [1.0.117](https://github.com/jetthai/cuora-module/compare/v1.0.116...v1.0.117) (2022-05-18)
|
package/package.json
CHANGED
package/src/machine/auth.js
CHANGED
|
@@ -10,8 +10,8 @@ export default function (request) {
|
|
|
10
10
|
const { clientId, fpToken, sentry } = request.config
|
|
11
11
|
const tokenKey = `cuora_${clientId}`
|
|
12
12
|
const userKey = `cuora_tempuser`
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const accountPhoneKey = 'account_phone'
|
|
14
|
+
const accountEmailKey = 'account_email'
|
|
15
15
|
const cookies = new Cookies()
|
|
16
16
|
|
|
17
17
|
return createMachine(
|
|
@@ -60,7 +60,7 @@ export default function (request) {
|
|
|
60
60
|
src: 'authenticate',
|
|
61
61
|
onDone: {
|
|
62
62
|
target: 'authenticated',
|
|
63
|
-
actions: 'setToken',
|
|
63
|
+
actions: ['setToken', 'setAccount'],
|
|
64
64
|
},
|
|
65
65
|
onError: {
|
|
66
66
|
target: 'idle',
|
|
@@ -251,12 +251,12 @@ export default function (request) {
|
|
|
251
251
|
}),
|
|
252
252
|
setAccount: assign((context, event) => {
|
|
253
253
|
if (context.loginData.phone) {
|
|
254
|
-
cookies.set(
|
|
254
|
+
cookies.set(accountPhoneKey, context.loginData.phone, {
|
|
255
255
|
path: '/',
|
|
256
256
|
maxAge: 60 * 60 * 24,
|
|
257
257
|
})
|
|
258
258
|
} else if (context.loginData.email) {
|
|
259
|
-
cookies.set(
|
|
259
|
+
cookies.set(accountEmailKey, context.loginData.email, {
|
|
260
260
|
path: '/',
|
|
261
261
|
maxAge: 60 * 60 * 24,
|
|
262
262
|
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createMachine, assign, send } from 'xstate'
|
|
2
|
+
import activity from '../api/activity'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'reward',
|
|
9
|
+
type: 'parallel',
|
|
10
|
+
context: {
|
|
11
|
+
rewardList: [],
|
|
12
|
+
callback: () => { },
|
|
13
|
+
},
|
|
14
|
+
states: {
|
|
15
|
+
timer: {
|
|
16
|
+
initial: 'loading',
|
|
17
|
+
states: {
|
|
18
|
+
loading: {
|
|
19
|
+
invoke: {
|
|
20
|
+
src: 'fetchRewardList',
|
|
21
|
+
onDone: {
|
|
22
|
+
target: 'pending',
|
|
23
|
+
actions: 'setRewardList',
|
|
24
|
+
},
|
|
25
|
+
onError: {
|
|
26
|
+
target: 'pending',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
pending: {
|
|
31
|
+
after: {
|
|
32
|
+
20000: { target: 'loading' },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
on: {
|
|
37
|
+
REFRESH: {
|
|
38
|
+
target: '.loading',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
reward: {
|
|
43
|
+
initial: 'idle',
|
|
44
|
+
states: {
|
|
45
|
+
idle: {
|
|
46
|
+
on: {
|
|
47
|
+
RECEIVE_REWARD: {
|
|
48
|
+
target: 'receiving',
|
|
49
|
+
actions: 'setCallback',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
receiving: {
|
|
54
|
+
invoke: {
|
|
55
|
+
src: 'receiveReward',
|
|
56
|
+
onDone: {
|
|
57
|
+
target: 'idle',
|
|
58
|
+
actions: [send({ type: 'REFRESH' }), 'doCallback'],
|
|
59
|
+
},
|
|
60
|
+
onError: {
|
|
61
|
+
target: 'idle',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
actions: {
|
|
71
|
+
setRewardList: assign((context, event) => {
|
|
72
|
+
return {
|
|
73
|
+
rewardList: event.data || [],
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
setCallback: assign((context, event) => {
|
|
77
|
+
return {
|
|
78
|
+
callback: event.data?.callback || (() => { }),
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
doCallback: (context, event) => {
|
|
82
|
+
context.callback()
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
services: {
|
|
86
|
+
fetchRewardList: async (context, event) => {
|
|
87
|
+
const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
|
|
88
|
+
return data
|
|
89
|
+
},
|
|
90
|
+
receiveReward: async (context, event) => {
|
|
91
|
+
const { activityNo, receiveNo, attended } = event.data
|
|
92
|
+
return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}
|