1
1
import type { ReactElement } from 'react' ;
2
- import React , { useCallback , useState } from 'react' ;
2
+ import React , { useCallback , useEffect , useRef , useState } from 'react' ;
3
3
4
4
import classNames from 'classnames' ;
5
5
import { useMutation , useQuery } from '@tanstack/react-query' ;
@@ -38,15 +38,22 @@ import { labels } from '../../../lib';
38
38
import type { ApiErrorResult } from '../../../graphql/common' ;
39
39
import { generateQueryKey , RequestKey } from '../../../lib/query' ;
40
40
import { useAuthContext } from '../../../contexts/AuthContext' ;
41
+ import { Origin } from '../../../lib/log' ;
42
+ import type { Post } from '../../../graphql/posts' ;
41
43
42
44
const AwardItem = ( { item } : { item : Product } ) => {
43
- const { setActiveStep } = useGiveAwardModalContext ( ) ;
45
+ const { setActiveStep, logAwardEvent } = useGiveAwardModalContext ( ) ;
46
+
47
+ const onClick = useCallback ( ( ) => {
48
+ logAwardEvent ( { awardEvent : 'PICK' , extra : { award : item . value } } ) ;
49
+ setActiveStep ( { screen : 'COMMENT' , product : item } ) ;
50
+ } , [ item , logAwardEvent , setActiveStep ] ) ;
44
51
45
52
return (
46
53
< Button
47
54
variant = { ButtonVariant . Float }
48
55
className = "flex !h-auto flex-col items-center justify-center gap-2 rounded-14 bg-surface-float !p-1"
49
- onClick = { ( ) => setActiveStep ( { screen : 'COMMENT' , product : item } ) }
56
+ onClick = { onClick }
50
57
>
51
58
< Image src = { item . image } alt = { item . name } className = "size-20" />
52
59
< div className = "flex items-center justify-center" >
@@ -133,8 +140,14 @@ const IntroScreen = () => {
133
140
134
141
const CommentScreen = ( ) => {
135
142
const { updateUser, user } = useAuthContext ( ) ;
136
- const { setActiveStep, type, entity, product, onRequestClose } =
137
- useGiveAwardModalContext ( ) ;
143
+ const {
144
+ setActiveStep,
145
+ type,
146
+ entity,
147
+ product,
148
+ onRequestClose,
149
+ logAwardEvent,
150
+ } = useGiveAwardModalContext ( ) ;
138
151
const isMobile = useViewSize ( ViewSize . MobileL ) ;
139
152
const { displayToast } = useToastNotification ( ) ;
140
153
const [ note , setNote ] = useState ( '' ) ;
@@ -163,6 +176,24 @@ const CommentScreen = () => {
163
176
} ,
164
177
} ) ;
165
178
179
+ const onAwardClick = useCallback ( ( ) => {
180
+ logAwardEvent ( { awardEvent : 'AWARD' , extra : { award : product . value } } ) ;
181
+ awardMutation ( {
182
+ productId : product . id ,
183
+ type,
184
+ entityId : entity . id ,
185
+ note,
186
+ } ) ;
187
+ } , [
188
+ awardMutation ,
189
+ entity . id ,
190
+ logAwardEvent ,
191
+ note ,
192
+ product . id ,
193
+ product . value ,
194
+ type ,
195
+ ] ) ;
196
+
166
197
return (
167
198
< >
168
199
< Modal . Header title = "Give an Award" showCloseButton = { ! isMobile } >
@@ -223,14 +254,7 @@ const CommentScreen = () => {
223
254
loading = { isPending }
224
255
className = "w-full"
225
256
variant = { ButtonVariant . Primary }
226
- onClick = { ( ) => {
227
- awardMutation ( {
228
- productId : product . id ,
229
- type,
230
- entityId : entity . id ,
231
- note,
232
- } ) ;
233
- } }
257
+ onClick = { onAwardClick }
234
258
>
235
259
Send Award for < CoinIcon /> { ' ' }
236
260
{ product . value === 0 ? 'Free' : product . value }
@@ -269,7 +293,15 @@ const ModalBody = () => {
269
293
270
294
const ModalRender = ( { ...props } : ModalProps ) => {
271
295
const isMobile = useViewSize ( ViewSize . MobileL ) ;
272
- const { activeModal, setActiveModal } = useGiveAwardModalContext ( ) ;
296
+ const { activeModal, setActiveModal, logAwardEvent } =
297
+ useGiveAwardModalContext ( ) ;
298
+ const trackingRef = useRef ( false ) ;
299
+ useEffect ( ( ) => {
300
+ if ( ! trackingRef . current ) {
301
+ trackingRef . current = true ;
302
+ logAwardEvent ( { awardEvent : 'START' } ) ;
303
+ }
304
+ } , [ logAwardEvent ] ) ;
273
305
274
306
const onCompletion = useCallback ( ( ) => {
275
307
setActiveModal ( 'AWARD' ) ;
@@ -288,7 +320,11 @@ const ModalRender = ({ ...props }: ModalProps) => {
288
320
</ Modal >
289
321
) : null }
290
322
{ activeModal === 'BUY_CORES' ? (
291
- < BuyCoresModal { ...props } onCompletion = { onCompletion } />
323
+ < BuyCoresModal
324
+ { ...props }
325
+ onCompletion = { onCompletion }
326
+ origin = { Origin . Award }
327
+ />
292
328
) : null }
293
329
</ >
294
330
) ;
@@ -297,6 +333,7 @@ const ModalRender = ({ ...props }: ModalProps) => {
297
333
type GiveAwardModalProps = ModalProps & {
298
334
type : AwardTypes ;
299
335
entity : AwardEntity ;
336
+ post ?: Post ;
300
337
} ;
301
338
const GiveAwardModal = ( props : GiveAwardModalProps ) : ReactElement => {
302
339
return (
0 commit comments