@jetthai/cuora 1.0.34 → 1.0.35

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.35](https://github.com/jetthai/cuora-module/compare/v1.0.34...v1.0.35) (2021-10-28)
6
+
5
7
  ### [1.0.34](https://github.com/jetthai/cuora-module/compare/v1.0.33...v1.0.34) (2021-10-26)
6
8
 
7
9
  ### [1.0.33](https://github.com/jetthai/cuora-module/compare/v1.0.32...v1.0.33) (2021-10-22)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/api/user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  getUserInfo: () => ({ url: 'self', method: 'get' }),
3
- modifyUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
3
+ updateUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
4
4
  changePassword: (data) => ({ url: 'settings/password', method: 'post', params: data }),
5
5
  setPreference: ({ defaultCategory }) => ({ url: 'settings/preference', method: 'post', params: { defaultCategory } }),
6
6
  resetOtp: ({ requestId, number }) => ({ url: 'reset', method: 'post', params: { requestId, number } }),
@@ -104,28 +104,48 @@ export default function (request) {
104
104
  },
105
105
  },
106
106
  user: {
107
+ id: 'user',
107
108
  initial: 'idle',
108
109
  states: {
109
110
  idle: {
110
111
  on: {
111
- MODIFY_USER_INFO: {
112
- target: 'modifyingUserInfo',
112
+ CHECK: {
113
+ target: 'checking',
113
114
  },
114
115
  },
115
116
  },
116
- modifyingUserInfo: {
117
- invoke: {
118
- src: 'modifyUserInfo',
119
- onDone: {
120
- target: 'idle',
121
- actions: send({ type: 'FETCH_USER_INFO' }),
122
- },
123
- onError: {
124
- target: 'idle',
117
+ checking: {
118
+ always: [
119
+ { target: 'inline', cond: 'isInline' },
120
+ {
121
+ target: 'normal',
125
122
  },
126
- },
123
+ ],
127
124
  },
125
+ inline: {},
126
+ normal: {},
128
127
  },
128
+ // states: {
129
+ // idle: {
130
+ // on: {
131
+ // UPDATE_USER_INFO: {
132
+ // target: 'updatingUserInfo',
133
+ // },
134
+ // },
135
+ // },
136
+ // updatingUserInfo: {
137
+ // invoke: {
138
+ // src: 'updateUserInfo',
139
+ // onDone: {
140
+ // target: 'idle',
141
+ // actions: send({ type: 'FETCH_USER_INFO' }),
142
+ // },
143
+ // onError: {
144
+ // target: 'idle',
145
+ // },
146
+ // },
147
+ // },
148
+ // },
129
149
  },
130
150
  },
131
151
  on: {
@@ -164,6 +184,10 @@ export default function (request) {
164
184
  const { bank_account, bank_setting_status } = context.userInfo || {}
165
185
  return !!bank_account || bank_setting_status === 1
166
186
  },
187
+ isInline: (context, event) => {
188
+ console.log(context.userInfo?.rank, context.userInfo?.rank >= 0)
189
+ return context.userInfo?.rank >= 0
190
+ },
167
191
  },
168
192
  actions: {
169
193
  fetchToken: assign((context, event) => {
@@ -236,8 +260,8 @@ export default function (request) {
236
260
  fetchUserInfo: async (context, event) => {
237
261
  return await request.send(user.getUserInfo())
238
262
  },
239
- modifyUserInfo: async (context, event) => {
240
- return await request.send(user.modifyUserInfo(event.data))
263
+ updateUserInfo: async (context, event) => {
264
+ return await request.send(user.updateUserInfo(event.data))
241
265
  },
242
266
  },
243
267
  }
@@ -174,7 +174,7 @@ export default function (request) {
174
174
  },
175
175
  sendPhone: async (context, event) => {
176
176
  const { countryCode, phone } = context
177
- return await request.send(api.modifyUserInfo({ countryCode, phone }))
177
+ return await request.send(api.updateUserInfo({ countryCode, phone }))
178
178
  },
179
179
  resetOtp: async (context, event) => {
180
180
  const { requestId, number } = context
@@ -71,9 +71,9 @@ export default function (request) {
71
71
  return context.userInfo?.rank >= 0
72
72
  },
73
73
  isInquiryIncomplete: (context, event) => {
74
- const { bank_account, bank_setting_status } = context.userInfo || {}
74
+ const { bank_account, bank_setting_status, uid } = context.userInfo || {}
75
75
  const hasBankAccount = bank_account || bank_setting_status === 1
76
- return !hasBankAccount && !cookies.get('welcome')
76
+ return !hasBankAccount && !cookies.get(`welcome_${uid}`)
77
77
  },
78
78
  isInquiryFilled: (context, event) => {
79
79
  const { bonus, gender } = context
@@ -87,7 +87,7 @@ export default function (request) {
87
87
  }
88
88
  }),
89
89
  setInfo: (context, event) => {
90
- cookies.set('welcome', 'done', {
90
+ cookies.set(`welcome_${context.userInfo.uid}`, 'done', {
91
91
  path: '/',
92
92
  maxAge: 60 * 60 * 24 * 365,
93
93
  })
@@ -104,7 +104,7 @@ export default function (request) {
104
104
  const { bonus, gender } = context
105
105
  await Promise.all([
106
106
  request.send(payment.setBonusSetting({ bonus })),
107
- request.send(user.modifyUserInfo({ gender })),
107
+ request.send(user.updateUserInfo({ gender })),
108
108
  ])
109
109
  },
110
110
  },
@@ -15,6 +15,7 @@ import reward from './reward'
15
15
  import setting from './setting'
16
16
  import side from './side'
17
17
  import withdraw from './withdraw'
18
+ import user_info from './user_info'
18
19
 
19
20
  export default {
20
21
  ...activity,
@@ -34,4 +35,5 @@ export default {
34
35
  setting,
35
36
  side,
36
37
  withdraw,
38
+ user_info,
37
39
  }
@@ -0,0 +1,64 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import user from '../api/user'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'user_info',
8
+ initial: 'fetching',
9
+ context: {
10
+ userInfo: {},
11
+ },
12
+ states: {
13
+ fetching: {
14
+ invoke: {
15
+ src: 'fetchUserInfo',
16
+ onDone: {
17
+ target: 'idle',
18
+ actions: 'setUserInfo',
19
+ },
20
+ onError: {
21
+ target: 'idle',
22
+ },
23
+ },
24
+ },
25
+ idle: {
26
+ on: {
27
+ UPDATE_USER_INFO: {
28
+ target: 'updating',
29
+ },
30
+ },
31
+ },
32
+ updating: {
33
+ invoke: {
34
+ src: 'updateUserInfo',
35
+ onDone: {
36
+ target: 'idle',
37
+ // target: 'fetching', // 因為更新 userInfo 後 get self 還是拿到舊資料
38
+ },
39
+ onError: {
40
+ target: 'idle',
41
+ },
42
+ },
43
+ },
44
+ },
45
+ },
46
+ {
47
+ actions: {
48
+ setUserInfo: assign((context, event) => {
49
+ return {
50
+ userInfo: event.data,
51
+ }
52
+ }),
53
+ },
54
+ services: {
55
+ fetchUserInfo: async (context, event) => {
56
+ return await request.send(user.getUserInfo())
57
+ },
58
+ updateUserInfo: async (context, event) => {
59
+ return await request.send(user.updateUserInfo(event.data))
60
+ },
61
+ },
62
+ }
63
+ )
64
+ }