@@ -9,10 +9,11 @@ import type {OnyxEntry} from 'react-native-onyx';
9
9
import ConfirmModal from '@components/ConfirmModal' ;
10
10
import PopoverWithMeasuredContent from '@components/PopoverWithMeasuredContent' ;
11
11
import useLocalize from '@hooks/useLocalize' ;
12
+ import { deleteMoneyRequest , deleteTrackExpense } from '@libs/actions/IOU' ;
13
+ import { deleteReportComment } from '@libs/actions/Report' ;
12
14
import calculateAnchorPosition from '@libs/calculateAnchorPosition' ;
13
- import * as ReportActionsUtils from '@libs/ReportActionsUtils' ;
14
- import * as IOU from '@userActions/IOU' ;
15
- import * as Report from '@userActions/Report' ;
15
+ import { getOriginalMessage , isMoneyRequestAction , isTrackExpenseAction } from '@libs/ReportActionsUtils' ;
16
+ import CONST from '@src/CONST' ;
16
17
import type { AnchorDimensions } from '@src/styles' ;
17
18
import type { ReportAction } from '@src/types/onyx' ;
18
19
import BaseReportActionContextMenu from './BaseReportActionContextMenu' ;
@@ -33,11 +34,11 @@ function extractPointerEvent(event: GestureResponderEvent | MouseEvent): MouseEv
33
34
34
35
function PopoverReportActionContextMenu ( _props : unknown , ref : ForwardedRef < ReportActionContextMenu > ) {
35
36
const { translate} = useLocalize ( ) ;
36
- const reportIDRef = useRef ( '-1' ) ;
37
+ const reportIDRef = useRef < string | undefined > ( ) ;
37
38
const typeRef = useRef < ContextMenuType > ( ) ;
38
39
const reportActionRef = useRef < NonNullable < OnyxEntry < ReportAction > > | null > ( null ) ;
39
- const reportActionIDRef = useRef ( '-1' ) ;
40
- const originalReportIDRef = useRef ( '-1' ) ;
40
+ const reportActionIDRef = useRef < string | undefined > ( ) ;
41
+ const originalReportIDRef = useRef < string | undefined > ( ) ;
41
42
const selectionRef = useRef ( '' ) ;
42
43
const reportActionDraftMessageRef = useRef < string > ( ) ;
43
44
@@ -77,6 +78,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
77
78
} ) ;
78
79
79
80
const onPopoverShow = useRef ( ( ) => { } ) ;
81
+ const [ isContextMenuOpening , setIsContextMenuOpening ] = useState ( false ) ;
80
82
const onPopoverHide = useRef ( ( ) => { } ) ;
81
83
const onEmojiPickerToggle = useRef < undefined | ( ( state : boolean ) => void ) > ( ) ;
82
84
const onCancelDeleteModal = useRef ( ( ) => { } ) ;
@@ -132,7 +134,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
132
134
! ! actionID && ( reportActionIDRef . current === actionID || reportActionRef . current ?. reportActionID === actionID ) ;
133
135
134
136
const clearActiveReportAction = ( ) => {
135
- reportActionIDRef . current = '-1' ;
137
+ reportActionIDRef . current = undefined ;
136
138
reportActionRef . current = null ;
137
139
} ;
138
140
@@ -175,6 +177,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
175
177
isOverflowMenu = false ,
176
178
isThreadReportParentActionParam = false ,
177
179
) => {
180
+ setIsContextMenuOpening ( true ) ;
178
181
const { pageX = 0 , pageY = 0 } = extractPointerEvent ( event ) ;
179
182
contextMenuAnchorRef . current = contextMenuAnchor ;
180
183
contextMenuTargetNode . current = event . target as HTMLDivElement ;
@@ -211,10 +214,10 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
211
214
} ) . then ( ( ) => {
212
215
setDisabledActions ( disabledOptions ) ;
213
216
typeRef . current = type ;
214
- reportIDRef . current = reportID ?? '-1' ;
215
- reportActionIDRef . current = reportActionID ?? '-1' ;
217
+ reportIDRef . current = reportID ;
218
+ reportActionIDRef . current = reportActionID ;
216
219
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
217
- originalReportIDRef . current = originalReportID || '-1' ;
220
+ originalReportIDRef . current = originalReportID || undefined ;
218
221
selectionRef . current = selection ;
219
222
setIsPopoverVisible ( true ) ;
220
223
reportActionDraftMessageRef . current = draftMessage ;
@@ -234,6 +237,11 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
234
237
235
238
// After we have called the action, reset it.
236
239
onPopoverShow . current = ( ) => { } ;
240
+
241
+ // After the context menu opening animation ends reset isContextMenuOpening.
242
+ setTimeout ( ( ) => {
243
+ setIsContextMenuOpening ( false ) ;
244
+ } , CONST . ANIMATED_TRANSITION ) ;
237
245
} ;
238
246
239
247
/** Run the callback and return a noop function to reset it */
@@ -244,9 +252,9 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
244
252
245
253
/** After Popover hides, call the registered onPopoverHide & onPopoverHideActionCallback callback and reset it */
246
254
const runAndResetOnPopoverHide = ( ) => {
247
- reportIDRef . current = '-1' ;
248
- reportActionIDRef . current = '-1' ;
249
- originalReportIDRef . current = '-1' ;
255
+ reportIDRef . current = undefined ;
256
+ reportActionIDRef . current = undefined ;
257
+ originalReportIDRef . current = undefined ;
250
258
setInstanceID ( '' ) ;
251
259
252
260
onPopoverHide . current = runAndResetCallback ( onPopoverHide . current ) ;
@@ -270,15 +278,15 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
270
278
const confirmDeleteAndHideModal = useCallback ( ( ) => {
271
279
callbackWhenDeleteModalHide . current = runAndResetCallback ( onConfirmDeleteModal . current ) ;
272
280
const reportAction = reportActionRef . current ;
273
- if ( ReportActionsUtils . isMoneyRequestAction ( reportAction ) ) {
274
- const originalMessage = ReportActionsUtils . getOriginalMessage ( reportAction ) ;
275
- if ( ReportActionsUtils . isTrackExpenseAction ( reportAction ) ) {
276
- IOU . deleteTrackExpense ( reportIDRef . current , originalMessage ?. IOUTransactionID ?? '-1' , reportAction ) ;
281
+ if ( isMoneyRequestAction ( reportAction ) ) {
282
+ const originalMessage = getOriginalMessage ( reportAction ) ;
283
+ if ( isTrackExpenseAction ( reportAction ) ) {
284
+ deleteTrackExpense ( reportIDRef . current , originalMessage ?. IOUTransactionID , reportAction ) ;
277
285
} else {
278
- IOU . deleteMoneyRequest ( originalMessage ?. IOUTransactionID ?? '-1' , reportAction ) ;
286
+ deleteMoneyRequest ( originalMessage ?. IOUTransactionID , reportAction ) ;
279
287
}
280
288
} else if ( reportAction ) {
281
- Report . deleteReportComment ( reportIDRef . current , reportAction ) ;
289
+ deleteReportComment ( reportIDRef . current , reportAction ) ;
282
290
}
283
291
284
292
DeviceEventEmitter . emit ( `deletedReportAction_${ reportIDRef . current } ` , reportAction ?. reportActionID ) ;
@@ -317,6 +325,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
317
325
runAndResetOnPopoverHide,
318
326
clearActiveReportAction,
319
327
contentRef,
328
+ isContextMenuOpening,
320
329
} ) ) ;
321
330
322
331
const reportAction = reportActionRef . current ;
0 commit comments