-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathWorkspaceInitialPage.tsx
523 lines (477 loc) · 26 KB
/
WorkspaceInitialPage.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
import {findFocusedRoute, useFocusEffect, useNavigationState} from '@react-navigation/native';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import HighlightableMenuItem from '@components/HighlightableMenuItem';
import {
Building,
CalendarSolid,
Car,
Coins,
CreditCard,
ExpensifyAppIcon,
ExpensifyCard,
Feed,
Folder,
Gear,
InvoiceGeneric,
Pencil,
Sync,
Tag,
Users,
Workflows,
} from '@components/Icon/Expensicons';
import MenuItem from '@components/MenuItem';
import BottomTabBar from '@components/Navigation/BottomTabBar';
import BOTTOM_TABS from '@components/Navigation/BottomTabBar/BOTTOM_TABS';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useSingleExecution from '@hooks/useSingleExecution';
import useThemeStyles from '@hooks/useThemeStyles';
import useWaitForNavigation from '@hooks/useWaitForNavigation';
import {confirmReadyToOpenApp} from '@libs/actions/App';
import {isConnectionInProgress} from '@libs/actions/connections';
import {clearErrors, openPolicyInitialPage, removeWorkspace, updateGeneralSettings} from '@libs/actions/Policy/Policy';
import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount';
import {checkIfFeedConnectionIsBroken, flatAllCardsList} from '@libs/CardUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {
shouldShowPolicy as checkIfShouldShowPolicy,
getWorkspaceAccountID,
goBackFromInvalidPolicy,
hasPolicyCategoriesError,
isPaidGroupPolicy,
isPendingDeletePolicy,
isPolicyAdmin,
isPolicyFeatureEnabled,
shouldShowEmployeeListError,
shouldShowSyncError,
shouldShowTaxRateError,
} from '@libs/PolicyUtils';
import {getDefaultWorkspaceAvatar, getIcons, getPolicyExpenseChat, getReportName, getReportOfflinePendingActionAndErrors} from '@libs/ReportUtils';
import type WORKSPACE_TO_RHP from '@navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP';
import type {WorkspaceSplitNavigatorParamList} from '@navigation/types';
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 {PendingAction} from '@src/types/onyx/OnyxCommon';
import type {PolicyFeatureName} from '@src/types/onyx/Policy';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';
type WorkspaceTopLevelScreens = keyof typeof WORKSPACE_TO_RHP;
type WorkspaceMenuItem = {
translationKey: TranslationPaths;
icon: IconAsset;
action: () => void;
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>;
screenName: WorkspaceTopLevelScreens;
badgeText?: string;
highlighted?: boolean;
};
type WorkspaceInitialPageProps = WithPolicyAndFullscreenLoadingProps & PlatformStackScreenProps<WorkspaceSplitNavigatorParamList, typeof SCREENS.WORKSPACE.INITIAL>;
type PolicyFeatureStates = Record<PolicyFeatureName, boolean>;
function dismissError(policyID: string | undefined, pendingAction: PendingAction | undefined) {
if (!policyID || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
goBackFromInvalidPolicy();
if (policyID) {
removeWorkspace(policyID);
}
} else {
clearErrors(policyID);
}
}
function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: WorkspaceInitialPageProps) {
const styles = useThemeStyles();
const policy = policyDraft?.id ? policyDraft : policyProp;
const workspaceAccountID = getWorkspaceAccountID(policy?.id);
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false);
const hasPolicyCreationError = policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && !isEmptyObject(policy.errors);
const [allFeedsCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`);
const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`);
const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email});
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID}`);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const {login, accountID} = useCurrentUserPersonalDetails();
const hasSyncError = shouldShowSyncError(policy, isConnectionInProgress(connectionSyncProgress, policy));
const waitForNavigate = useWaitForNavigation();
const {singleExecution, isExecuting} = useSingleExecution();
const activeRoute = useNavigationState((state) => findFocusedRoute(state)?.name);
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const wasRendered = useRef(false);
const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id)?.reportID;
const [currentUserPolicyExpenseChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentUserPolicyExpenseChatReportID}`);
const {reportPendingAction} = getReportOfflinePendingActionAndErrors(currentUserPolicyExpenseChat);
const isPolicyExpenseChatEnabled = !!policy?.isPolicyExpenseChatEnabled;
const prevPendingFields = usePrevious(policy?.pendingFields);
const policyFeatureStates = useMemo(
() => ({
[CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED]: policy?.areDistanceRatesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED]: policy?.areWorkflowsEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED]: policy?.areCategoriesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED]: policy?.areTagsEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED]: policy?.tax?.trackingEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED]: policy?.areCompanyCardsEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED]: !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections),
[CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED]: policy?.areExpensifyCardsEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_REPORT_FIELDS_ENABLED]: policy?.areReportFieldsEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED]: policy?.areRulesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED]: policy?.areInvoicesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED]: policy?.arePerDiemRatesEnabled,
}),
[policy],
) as PolicyFeatureStates;
const fetchPolicyData = useCallback(() => {
if (policyDraft?.id) {
return;
}
openPolicyInitialPage(route.params.policyID);
}, [policyDraft?.id, route.params.policyID]);
useNetwork({onReconnect: fetchPolicyData});
useFocusEffect(
useCallback(() => {
fetchPolicyData();
}, [fetchPolicyData]),
);
const policyID = policy?.id;
const policyName = policy?.name ?? '';
useEffect(() => {
if (!isCurrencyModalOpen || policy?.outputCurrency !== CONST.CURRENCY.USD) {
return;
}
setIsCurrencyModalOpen(false);
}, [policy?.outputCurrency, isCurrencyModalOpen]);
/** Call update workspace currency and hide the modal */
const confirmCurrencyChangeAndHideModal = useCallback(() => {
updateGeneralSettings(policyID, policyName, CONST.CURRENCY.USD);
setIsCurrencyModalOpen(false);
navigateToBankAccountRoute(policyID);
}, [policyID, policyName]);
const hasMembersError = shouldShowEmployeeListError(policy);
const hasPolicyCategoryError = hasPolicyCategoriesError(policyCategories);
const hasGeneralSettingsError =
!isEmptyObject(policy?.errorFields?.name ?? {}) ||
!isEmptyObject(policy?.errorFields?.avatarURL ?? {}) ||
!isEmptyObject(policy?.errorFields?.ouputCurrency ?? {}) ||
!isEmptyObject(policy?.errorFields?.address ?? {});
const shouldShowProtectedItems = isPolicyAdmin(policy, login);
const [featureStates, setFeatureStates] = useState(policyFeatureStates);
const [highlightedFeature, setHighlightedFeature] = useState<string | undefined>(undefined);
const workspaceMenuItems: WorkspaceMenuItem[] = useMemo(() => {
const protectedMenuItems: WorkspaceMenuItem[] = [];
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.distanceRates',
icon: Car,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_DISTANCE_RATES.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.DISTANCE_RATES,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.expensifyCard',
icon: ExpensifyCard,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.EXPENSIFY_CARD,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED]) {
const hasBrokenFeedConnection = checkIfFeedConnectionIsBroken(flatAllCardsList(allFeedsCards, workspaceAccountID));
protectedMenuItems.push({
translationKey: 'workspace.common.companyCards',
icon: CreditCard,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.COMPANY_CARDS,
brickRoadIndicator: hasBrokenFeedConnection ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED]) {
protectedMenuItems.push({
translationKey: 'common.perDiem',
icon: CalendarSolid,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_PER_DIEM.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.PER_DIEM,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.workflows',
icon: Workflows,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.WORKFLOWS,
brickRoadIndicator: !isEmptyObject(policy?.errorFields?.reimburser ?? {}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.rules',
icon: Feed,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_RULES.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.RULES,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED]) {
const currencyCode = policy?.outputCurrency ?? CONST.CURRENCY.USD;
protectedMenuItems.push({
translationKey: 'workspace.common.invoices',
icon: InvoiceGeneric,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_INVOICES.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.INVOICES,
badgeText: convertToDisplayString(policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0, currencyCode),
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.categories',
icon: Folder,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID)))),
brickRoadIndicator: hasPolicyCategoryError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
screenName: SCREENS.WORKSPACE.CATEGORIES,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.tags',
icon: Tag,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_TAGS.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.TAGS,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.taxes',
icon: Coins,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_TAXES.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.TAXES,
brickRoadIndicator: shouldShowTaxRateError(policy) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_REPORT_FIELDS_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.reportFields',
icon: Pencil,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_REPORT_FIELDS.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.REPORT_FIELDS,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_REPORT_FIELDS_ENABLED,
});
}
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED]) {
protectedMenuItems.push({
translationKey: 'workspace.common.accounting',
icon: Sync,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)))),
brickRoadIndicator: hasSyncError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
screenName: SCREENS.WORKSPACE.ACCOUNTING.ROOT,
highlighted: highlightedFeature === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED,
});
}
protectedMenuItems.push({
translationKey: 'workspace.common.moreFeatures',
icon: Gear,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID)))),
screenName: SCREENS.WORKSPACE.MORE_FEATURES,
});
const menuItems: WorkspaceMenuItem[] = [
{
translationKey: 'workspace.common.profile',
icon: Building,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_PROFILE.getRoute(policyID)))),
brickRoadIndicator: hasGeneralSettingsError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
screenName: SCREENS.WORKSPACE.PROFILE,
},
{
translationKey: 'workspace.common.members',
icon: Users,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)))),
brickRoadIndicator: hasMembersError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
screenName: SCREENS.WORKSPACE.MEMBERS,
},
...(isPaidGroupPolicy(policy) && shouldShowProtectedItems ? protectedMenuItems : []),
];
return menuItems;
}, [
featureStates,
hasGeneralSettingsError,
hasMembersError,
hasPolicyCategoryError,
hasSyncError,
highlightedFeature,
policy,
policyID,
shouldShowProtectedItems,
singleExecution,
waitForNavigate,
allFeedsCards,
workspaceAccountID,
]);
// We only update feature states if they aren't pending.
// These changes are made to synchronously change feature states along with AccessOrNotFoundWrapperComponent.
useEffect(() => {
setFeatureStates((currentFeatureStates) => {
const newFeatureStates = {} as PolicyFeatureStates;
(Object.keys(policy?.pendingFields ?? {}) as PolicyFeatureName[]).forEach((key) => {
const isFeatureEnabled = isPolicyFeatureEnabled(policy, key);
newFeatureStates[key] =
prevPendingFields?.[key] !== policy?.pendingFields?.[key] || isOffline || !policy?.pendingFields?.[key] ? isFeatureEnabled : currentFeatureStates[key];
});
setHighlightedFeature(Object.keys(newFeatureStates).at(0));
return {
...policyFeatureStates,
...newFeatureStates,
};
});
}, [policy, isOffline, policyFeatureStates, prevPendingFields]);
useEffect(() => {
confirmReadyToOpenApp();
}, []);
const prevPolicy = usePrevious(policy);
const shouldShowPolicy = useMemo(() => checkIfShouldShowPolicy(policy, isOffline, currentUserLogin), [policy, isOffline, currentUserLogin]);
const isPendingDelete = isPendingDeletePolicy(policy);
const prevIsPendingDelete = isPendingDeletePolicy(prevPolicy);
// We check isPendingDelete and prevIsPendingDelete to prevent the NotFound view from showing right after we delete the workspace
// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = !shouldShowPolicy && (!isPendingDelete || prevIsPendingDelete);
useEffect(() => {
if (isEmptyObject(prevPolicy) || prevIsPendingDelete || !isPendingDelete) {
return;
}
goBackFromInvalidPolicy();
}, [isPendingDelete, policy, prevIsPendingDelete, prevPolicy]);
// We are checking if the user can access the route.
// If user can't access the route, we are dismissing any modals that are open when the NotFound view is shown
const canAccessRoute = activeRoute && (workspaceMenuItems.some((item) => item.screenName === activeRoute) || activeRoute === SCREENS.WORKSPACE.INITIAL);
useEffect(() => {
if (!shouldShowNotFoundPage && canAccessRoute) {
return;
}
if (wasRendered.current) {
return;
}
wasRendered.current = true;
// We are dismissing any modals that are open when the NotFound view is shown
Navigation.isNavigationReady().then(() => {
Navigation.closeRHPFlow();
});
}, [canAccessRoute, shouldShowNotFoundPage]);
const policyAvatar = useMemo(() => {
if (!policy) {
return {source: ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR};
}
const avatar = policy?.avatarURL ? policy.avatarURL : getDefaultWorkspaceAvatar(policy?.name);
return {
source: avatar,
name: policy?.name ?? '',
type: CONST.ICON_TYPE_WORKSPACE,
id: policy.id,
};
}, [policy]);
const shouldShowBottomTab = !shouldShowNotFoundPage;
return (
<ScreenWrapper
testID={WorkspaceInitialPage.displayName}
includeSafeAreaPaddingBottom
bottomContent={shouldShowBottomTab ? <BottomTabBar selectedTab={BOTTOM_TABS.SETTINGS} /> : null}
>
<FullPageNotFoundView
onBackButtonPress={Navigation.dismissModal}
onLinkPress={Navigation.goBackToHome}
shouldShow={shouldShowNotFoundPage}
subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined}
>
<HeaderWithBackButton
title={policyName}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
policyAvatar={policyAvatar}
style={styles.headerBarDesktopHeight}
/>
<ScrollView contentContainerStyle={[styles.flexColumn]}>
<OfflineWithFeedback
pendingAction={policy?.pendingAction}
onClose={() => dismissError(policyID, policy?.pendingAction)}
errors={policy?.errors}
errorRowStyles={[styles.ph5, styles.pv2]}
shouldDisableStrikeThrough={false}
shouldHideOnDelete={false}
>
<View style={[styles.pb4, styles.mh3, styles.mt3]}>
{/*
Ideally we should use MenuList component for MenuItems with singleExecution/Navigation actions.
In this case where user can click on workspace avatar or menu items, we need to have a check for `isExecuting`. So, we are directly mapping menuItems.
*/}
{workspaceMenuItems.map((item) => (
<HighlightableMenuItem
key={item.translationKey}
disabled={hasPolicyCreationError || isExecuting}
interactive={!hasPolicyCreationError}
title={translate(item.translationKey)}
icon={item.icon}
onPress={item.action}
brickRoadIndicator={item.brickRoadIndicator}
wrapperStyle={styles.sectionMenuItem}
highlighted={!!item?.highlighted}
focused={!!(item.screenName && activeRoute?.startsWith(item.screenName))}
badgeText={item.badgeText}
shouldIconUseAutoWidthStyle
/>
))}
</View>
</OfflineWithFeedback>
{isPolicyExpenseChatEnabled && (
<View style={[styles.pb4, styles.mh3, styles.mt3]}>
<Text style={[styles.textSupporting, styles.fontSizeLabel, styles.ph2]}>{translate('workspace.common.submitExpense')}</Text>
<OfflineWithFeedback pendingAction={reportPendingAction}>
<MenuItem
title={getReportName(currentUserPolicyExpenseChat)}
description={translate('workspace.common.workspace')}
icon={getIcons(currentUserPolicyExpenseChat, personalDetails)}
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(currentUserPolicyExpenseChat?.reportID))}
shouldShowRightIcon
wrapperStyle={[styles.br2, styles.pl2, styles.pr0, styles.pv3, styles.mt1, styles.alignItemsCenter]}
shouldShowSubscriptAvatar
/>
</OfflineWithFeedback>
</View>
)}
</ScrollView>
<ConfirmModal
title={translate('workspace.bankAccount.workspaceCurrency')}
isVisible={isCurrencyModalOpen}
onConfirm={confirmCurrencyChangeAndHideModal}
onCancel={() => setIsCurrencyModalOpen(false)}
prompt={translate('workspace.bankAccount.updateCurrencyPrompt')}
confirmText={translate('workspace.bankAccount.updateToUSD')}
cancelText={translate('common.cancel')}
danger
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
WorkspaceInitialPage.displayName = 'WorkspaceInitialPage';
export default withPolicyAndFullscreenLoading(WorkspaceInitialPage);