-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
FloatingActionButtonAndPopover.tsx
576 lines (541 loc) · 27.6 KB
/
FloatingActionButtonAndPopover.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
import {useIsFocused as useIsFocusedOriginal, useNavigationState} from '@react-navigation/native';
import type {ImageContentFit} from 'expo-image';
import type {ForwardedRef} from 'react';
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {SvgProps} from 'react-native-svg';
import FloatingActionButton from '@components/FloatingActionButton';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import PopoverMenu from '@components/PopoverMenu';
import Text from '@components/Text';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import getIconForAction from '@libs/getIconForAction';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
import Navigation from '@libs/Navigation/Navigation';
import type {CentralPaneName, NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types';
import {hasSeenTourSelector} from '@libs/onboardingSelectors';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
import {getNavatticURL} from '@libs/TourUtils';
import variables from '@styles/variables';
import * as App from '@userActions/App';
import * as IOU from '@userActions/IOU';
import * as Link from '@userActions/Link';
import * as Policy from '@userActions/Policy/Policy';
import * as Report from '@userActions/Report';
import * as Task from '@userActions/Task';
import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {QuickActionName} from '@src/types/onyx/QuickAction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems';
// On small screen we hide the search page from central pane to show the search bottom tab page with bottom tab bar.
// We need to take this in consideration when checking if the screen is focused.
const useIsFocused = () => {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const isFocused = useIsFocusedOriginal();
const topmostCentralPane = useNavigationState<RootStackParamList, NavigationPartialRoute<CentralPaneName> | undefined>(getTopmostCentralPaneRoute);
return isFocused || (topmostCentralPane?.name === SCREENS.SEARCH.CENTRAL_PANE && shouldUseNarrowLayout);
};
type PolicySelector = Pick<OnyxTypes.Policy, 'type' | 'role' | 'isPolicyExpenseChatEnabled' | 'pendingAction' | 'avatarURL' | 'name' | 'id' | 'areInvoicesEnabled'>;
type FloatingActionButtonAndPopoverProps = {
/* Callback function when the menu is shown */
onShowCreateMenu?: () => void;
/* Callback function before the menu is hidden */
onHideCreateMenu?: () => void;
};
type FloatingActionButtonAndPopoverRef = {
hideCreateMenu: () => void;
};
const policySelector = (policy: OnyxEntry<OnyxTypes.Policy>): PolicySelector =>
(policy && {
type: policy.type,
role: policy.role,
id: policy.id,
isPolicyExpenseChatEnabled: policy.isPolicyExpenseChatEnabled,
pendingAction: policy.pendingAction,
avatarURL: policy.avatarURL,
name: policy.name,
areInvoicesEnabled: policy.areInvoicesEnabled,
}) as PolicySelector;
const getQuickActionIcon = (action: QuickActionName): React.FC<SvgProps> => {
switch (action) {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
return getIconForAction(CONST.IOU.TYPE.REQUEST);
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
return Expensicons.ReceiptScan;
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
return Expensicons.Car;
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
return getIconForAction(CONST.IOU.TYPE.SPLIT);
case CONST.QUICK_ACTIONS.SEND_MONEY:
return getIconForAction(CONST.IOU.TYPE.SEND);
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
return Expensicons.Task;
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
return Expensicons.Car;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
return getIconForAction(CONST.IOU.TYPE.TRACK);
case CONST.QUICK_ACTIONS.TRACK_SCAN:
return Expensicons.ReceiptScan;
default:
return Expensicons.MoneyCircle;
}
};
const getQuickActionTitle = (action: QuickActionName): TranslationPaths => {
switch (action) {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
return 'quickAction.requestMoney';
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
return 'quickAction.scanReceipt';
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
return 'quickAction.recordDistance';
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
return 'quickAction.splitBill';
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
return 'quickAction.splitScan';
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
return 'quickAction.splitDistance';
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
return 'quickAction.trackManual';
case CONST.QUICK_ACTIONS.TRACK_SCAN:
return 'quickAction.trackScan';
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
return 'quickAction.trackDistance';
case CONST.QUICK_ACTIONS.SEND_MONEY:
return 'quickAction.paySomeone';
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
return 'quickAction.assignTask';
default:
return '' as TranslationPaths;
}
};
/**
* Responsible for rendering the {@link PopoverMenu}, and the accompanying
* FAB that can open or close the menu.
*/
function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: FloatingActionButtonAndPopoverProps, ref: ForwardedRef<FloatingActionButtonAndPopoverRef>) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const [isLoading = false] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [quickActionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${quickAction?.chatReportID}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${quickActionReport?.reportID ?? -1}`);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
const policyChatForActivePolicy = useMemo(() => {
if (isEmptyObject(activePolicy) || !activePolicy?.isPolicyExpenseChatEnabled) {
return {} as OnyxTypes.Report;
}
const policyChatsForActivePolicy = ReportUtils.getWorkspaceChats(activePolicyID ?? '-1', [session?.accountID ?? -1], allReports);
return policyChatsForActivePolicy.length > 0 ? policyChatsForActivePolicy.at(0) : ({} as OnyxTypes.Report);
}, [activePolicy, activePolicyID, session?.accountID, allReports]);
const [quickActionPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${quickActionReport?.policyID}`);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector)});
const [hasSeenTrackTraining] = useOnyx(ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING);
const [isCreateMenuActive, setIsCreateMenuActive] = useState(false);
const fabRef = useRef<HTMLDivElement>(null);
const {windowHeight} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const isFocused = useIsFocused();
const prevIsFocused = usePrevious(isFocused);
const {isOffline} = useNetwork();
const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions();
const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);
const {environment} = useEnvironment();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const navatticURL = getNavatticURL(environment, introSelected?.choice);
const [hasSeenTour = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: hasSeenTourSelector,
});
const quickActionAvatars = useMemo(() => {
if (quickActionReport) {
const avatars = ReportUtils.getIcons(quickActionReport, personalDetails);
return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID);
}
if (!isEmptyObject(policyChatForActivePolicy)) {
return ReportUtils.getIcons(policyChatForActivePolicy, personalDetails);
}
return [];
// Policy is needed as a dependency in order to update the shortcut details when the workspace changes
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [personalDetails, session?.accountID, quickActionReport, quickActionPolicy, policyChatForActivePolicy]);
const renderQuickActionTooltip = useCallback(
() => (
<Text>
<Text style={styles.quickActionTooltipTitle}>{translate('quickAction.tooltip.title')}</Text>
<Text style={styles.quickActionTooltipSubtitle}>{translate('quickAction.tooltip.subtitle')}</Text>
</Text>
),
[styles.quickActionTooltipTitle, styles.quickActionTooltipSubtitle, translate],
);
const quickActionTitle = useMemo(() => {
if (isEmptyObject(quickActionReport)) {
return '';
}
if (quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && quickActionAvatars.length > 0) {
const name: string = ReportUtils.getDisplayNameForParticipant(+(quickActionAvatars.at(0)?.id ?? -1), true) ?? '';
return translate('quickAction.paySomeone', {name});
}
const titleKey = getQuickActionTitle(quickAction?.action ?? ('' as QuickActionName));
return titleKey ? translate(titleKey) : '';
}, [quickAction, translate, quickActionAvatars, quickActionReport]);
const hideQABSubtitle = useMemo(() => {
if (isEmptyObject(quickActionReport)) {
return true;
}
if (quickActionAvatars.length === 0) {
return false;
}
const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? '';
return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0;
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);
const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
if (shouldRestrictAction && quickActionReport?.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(quickActionReport.policyID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(quickActionReport.policyID));
return;
}
onSelected();
},
[quickActionReport?.policyID],
);
const navigateToQuickAction = useCallback(() => {
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();
switch (quickAction?.action) {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.MANUAL, true), true);
return;
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.SCAN, true), true);
return;
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.DISTANCE, true), true);
return;
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SPLIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.MANUAL, true), true);
return;
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SPLIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.SCAN, true), true);
return;
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SPLIT, quickActionReportID, CONST.IOU.REQUEST_TYPE.DISTANCE, false), true);
return;
case CONST.QUICK_ACTIONS.SEND_MONEY:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.PAY, quickActionReportID, CONST.IOU.REQUEST_TYPE.MANUAL, true), false);
return;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
selectOption(() => Task.startOutCreateTaskQuickAction(isValidReport ? quickActionReportID : '', quickAction.targetAccountID ?? -1), false);
break;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickActionReportID, CONST.IOU.REQUEST_TYPE.MANUAL, true), false);
break;
case CONST.QUICK_ACTIONS.TRACK_SCAN:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickActionReportID, CONST.IOU.REQUEST_TYPE.SCAN, true), false);
break;
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickActionReportID, CONST.IOU.REQUEST_TYPE.DISTANCE, true), false);
break;
default:
}
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);
/**
* Check if LHN status changed from active to inactive.
* Used to close already opened FAB menu when open any other pages (i.e. Press Command + K on web).
*/
const didScreenBecomeInactive = useCallback(
(): boolean =>
// When any other page is opened over LHN
!isFocused && prevIsFocused,
[isFocused, prevIsFocused],
);
/**
* Method called when we click the floating action button
*/
const showCreateMenu = useCallback(
() => {
if (!isFocused && shouldUseNarrowLayout) {
return;
}
setIsCreateMenuActive(true);
onShowCreateMenu?.();
},
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[isFocused, shouldUseNarrowLayout],
);
/**
* Method called either when:
* - Pressing the floating action button to open the CreateMenu modal
* - Selecting an item on CreateMenu or closing it by clicking outside of the modal component
*/
const hideCreateMenu = useCallback(
() => {
if (!isCreateMenuActive) {
return;
}
setIsCreateMenuActive(false);
onHideCreateMenu?.();
},
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[isCreateMenuActive],
);
useEffect(() => {
if (!didScreenBecomeInactive()) {
return;
}
// Hide menu manually when other pages are opened using shortcut key
hideCreateMenu();
}, [didScreenBecomeInactive, hideCreateMenu]);
useImperativeHandle(ref, () => ({
hideCreateMenu() {
hideCreateMenu();
},
}));
const toggleCreateMenu = () => {
if (isCreateMenuActive) {
hideCreateMenu();
} else {
showCreateMenu();
}
};
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
const selfDMReportID = useMemo(() => ReportUtils.findSelfDMReportID(), [isLoading, isCreateMenuActive]);
const expenseMenuItems = useMemo((): PopoverMenuItem[] => {
if (canUseCombinedTrackSubmit) {
return [
{
icon: getIconForAction(CONST.IOU.TYPE.CREATE),
text: translate('iou.createExpense'),
onSelected: () =>
interceptAnonymousUser(() =>
IOU.startMoneyRequest(
CONST.IOU.TYPE.CREATE,
// When starting to create an expense from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used
// for all of the routes in the creation flow.
ReportUtils.generateReportID(),
),
),
},
];
}
return [
...(selfDMReportID
? [
{
icon: getIconForAction(CONST.IOU.TYPE.TRACK),
text: translate('iou.trackExpense'),
onSelected: () => {
interceptAnonymousUser(() =>
IOU.startMoneyRequest(
CONST.IOU.TYPE.TRACK,
// When starting to create a track expense from the global FAB, we need to retrieve selfDM reportID.
// If it doesn't exist, we generate a random optimistic reportID and use it for all of the routes in the creation flow.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
ReportUtils.findSelfDMReportID() || ReportUtils.generateReportID(),
),
);
if (!hasSeenTrackTraining && !isOffline) {
setTimeout(() => {
Navigation.navigate(ROUTES.TRACK_TRAINING_MODAL);
}, CONST.ANIMATED_TRANSITION);
}
},
},
]
: []),
{
icon: getIconForAction(CONST.IOU.TYPE.REQUEST),
text: translate('iou.submitExpense'),
onSelected: () =>
interceptAnonymousUser(() =>
IOU.startMoneyRequest(
CONST.IOU.TYPE.SUBMIT,
// When starting to create an expense from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used
// for all of the routes in the creation flow.
ReportUtils.generateReportID(),
),
),
},
];
}, [canUseCombinedTrackSubmit, translate, selfDMReportID, hasSeenTrackTraining, isOffline]);
const quickActionMenuItems = useMemo(() => {
// Define common properties in baseQuickAction
const baseQuickAction = {
label: translate('quickAction.header'),
isLabelHoverable: false,
floatRightAvatars: quickActionAvatars,
floatRightAvatarSize: CONST.AVATAR_SIZE.SMALL,
numberOfLinesDescription: 1,
tooltipAnchorAlignment: {
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
},
tooltipShiftHorizontal: styles.popoverMenuItem.paddingHorizontal,
tooltipShiftVertical: styles.popoverMenuItem.paddingVertical / 2,
renderTooltipContent: renderQuickActionTooltip,
tooltipWrapperStyle: styles.quickActionTooltipWrapper,
};
if (quickAction?.action) {
return [
{
...baseQuickAction,
icon: getQuickActionIcon(quickAction?.action),
text: quickActionTitle,
description: !hideQABSubtitle ? ReportUtils.getReportName(quickActionReport) ?? translate('quickAction.updateDestination') : '',
onSelected: () => interceptAnonymousUser(() => navigateToQuickAction()),
shouldShowSubscriptRightAvatar: ReportUtils.isPolicyExpenseChat(quickActionReport),
shouldRenderTooltip: quickAction.isFirstQuickAction,
},
];
}
if (!isEmptyObject(policyChatForActivePolicy)) {
return [
{
...baseQuickAction,
icon: Expensicons.ReceiptScan,
text: translate('quickAction.scanReceipt'),
description: ReportUtils.getReportName(policyChatForActivePolicy),
onSelected: () =>
interceptAnonymousUser(() => {
selectOption(() => {
const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs));
const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID();
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true);
}, true);
}),
shouldShowSubscriptRightAvatar: true,
shouldRenderTooltip: false,
},
];
}
return [];
}, [
translate,
quickActionAvatars,
styles.popoverMenuItem.paddingHorizontal,
styles.popoverMenuItem.paddingVertical,
styles.quickActionTooltipWrapper,
renderQuickActionTooltip,
quickAction?.action,
quickAction?.isFirstQuickAction,
policyChatForActivePolicy,
quickActionTitle,
hideQABSubtitle,
quickActionReport,
navigateToQuickAction,
selectOption,
reportNameValuePairs,
]);
return (
<View style={styles.flexGrow1}>
<PopoverMenu
onClose={hideCreateMenu}
isVisible={isCreateMenuActive && (!shouldUseNarrowLayout || isFocused)}
anchorPosition={styles.createMenuPositionSidebar(windowHeight)}
onItemSelected={hideCreateMenu}
fromSidebarMediumScreen={!shouldUseNarrowLayout}
menuItems={[
{
icon: Expensicons.ChatBubble,
text: translate('sidebarScreen.fabNewChat'),
onSelected: () => interceptAnonymousUser(Report.startNewChat),
},
...expenseMenuItems,
...(canSendInvoice
? [
{
icon: Expensicons.InvoiceGeneric,
text: translate('workspace.invoices.sendInvoice'),
onSelected: () =>
interceptAnonymousUser(() =>
IOU.startMoneyRequest(
CONST.IOU.TYPE.INVOICE,
// When starting to create an invoice from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used
// for all of the routes in the creation flow.
ReportUtils.generateReportID(),
),
),
},
]
: []),
...(canUseSpotnanaTravel
? [
{
icon: Expensicons.Suitcase,
text: translate('travel.bookTravel'),
onSelected: () => interceptAnonymousUser(() => Navigation.navigate(ROUTES.TRAVEL_MY_TRIPS)),
},
]
: []),
...(!hasSeenTour
? [
{
icon: Expensicons.Binoculars,
iconStyles: styles.popoverIconCircle,
iconFill: theme.icon,
text: translate('tour.takeATwoMinuteTour'),
description: translate('tour.exploreExpensify'),
onSelected: () => {
Welcome.setSelfTourViewed();
Link.openExternalLink(navatticURL);
},
},
]
: []),
...(!isLoading && !Policy.hasActiveChatEnabledPolicies(allPolicies)
? [
{
displayInDefaultIconColor: true,
contentFit: 'contain' as ImageContentFit,
icon: Expensicons.NewWorkspace,
iconWidth: variables.w46,
iconHeight: variables.h40,
text: translate('workspace.new.newWorkspace'),
description: translate('workspace.new.getTheExpensifyCardAndMore'),
onSelected: () => interceptAnonymousUser(() => App.createWorkspaceWithPolicyDraftAndNavigateToIt()),
},
]
: []),
...quickActionMenuItems,
]}
withoutOverlay
anchorRef={fabRef}
/>
<FloatingActionButton
accessibilityLabel={translate('sidebarScreen.fabNewChatExplained')}
role={CONST.ROLE.BUTTON}
isActive={isCreateMenuActive}
ref={fabRef}
onPress={toggleCreateMenu}
/>
</View>
);
}
FloatingActionButtonAndPopover.displayName = 'FloatingActionButtonAndPopover';
export default forwardRef(FloatingActionButtonAndPopover);
export type {PolicySelector};