Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/components/HeaderLoadingBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import LoadingBar from './LoadingBar';

function HeaderLoadingBar() {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const shouldShowLoadingBar = useLoadingBarVisibility();

return <LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />;
}

export default HeaderLoadingBar;
11 changes: 5 additions & 6 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useRoute} from '@react-navigation/native';
import {isUserValidatedSelector} from '@selectors/Account';
import {shouldFailAllRequestsSelector} from '@selectors/Network';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {getArchiveReason} from '@selectors/Report';
import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
Expand All @@ -14,7 +15,6 @@
import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations';
import useGetIOUReportFromReportAction from '@hooks/useGetIOUReportFromReportAction';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -146,13 +146,13 @@
import DecisionModal from './DecisionModal';
import {useDelegateNoAccessActions, useDelegateNoAccessState} from './DelegateNoAccessModalProvider';
import Header from './Header';
import HeaderLoadingBar from './HeaderLoadingBar';
import HeaderWithBackButton from './HeaderWithBackButton';
import HoldOrRejectEducationalModal from './HoldOrRejectEducationalModal';
import HoldSubmitterEducationalModal from './HoldSubmitterEducationalModal';
import Icon from './Icon';
import {KYCWallContext} from './KYCWall/KYCWallContext';
import type {PaymentMethod} from './KYCWall/types';
import LoadingBar from './LoadingBar';
import Modal from './Modal';
import {ModalActions} from './Modal/Global/ModalContext';
import MoneyReportHeaderKYCDropdown from './MoneyReportHeaderKYCDropdown';
Expand Down Expand Up @@ -440,7 +440,7 @@
const {removeTransaction, clearSelectedTransactions} = useSearchActionsContext();
const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, currentSearchQueryJSON?.hash, true);

const [network] = useOnyx(ONYXKEYS.NETWORK);
const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector});

const {isWideRHPDisplayedOnWideLayout, isSuperWideRHPDisplayedOnWideLayout} = useResponsiveLayoutOnWideRHP();

Expand Down Expand Up @@ -569,7 +569,6 @@
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const shouldShowLoadingBar = useLoadingBarVisibility();
const kycWallRef = useContext(KYCWallContext);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const isReportInRHP = route.name !== SCREENS.REPORT;
Expand Down Expand Up @@ -843,7 +842,7 @@

const dismissModalAndUpdateUseHold = () => {
setIsHoldEducationalModalVisible(false);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !network?.shouldFailAllRequests);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !shouldFailAllRequests);
if (requestParentReportAction) {
changeMoneyRequestHoldStatus(requestParentReportAction);
}
Expand Down Expand Up @@ -1777,7 +1776,7 @@
}
return option;
});
}, [originalSelectedTransactionsOptions, showDeleteModal, dismissedRejectUseExplanation]);

Check warning on line 1779 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has missing dependencies: 'isDelegateAccessRestricted' and 'showDelegateNoAccessModal'. Either include them or remove the dependency array

Check warning on line 1779 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has missing dependencies: 'isDelegateAccessRestricted' and 'showDelegateNoAccessModal'. Either include them or remove the dependency array

const shouldShowSelectedTransactionsButton = !!selectedTransactionsOptions.length && !transactionThreadReportID;

Expand Down Expand Up @@ -1912,7 +1911,7 @@
</View>
)}

<LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />
<HeaderLoadingBar />
{isHoldMenuVisible && requestType !== undefined && (
<ProcessMoneyReportHoldMenu
nonHeldAmount={!hasOnlyHeldExpenses && hasValidNonHeldAmount ? nonHeldAmount : undefined}
Expand Down
11 changes: 5 additions & 6 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useRoute} from '@react-navigation/native';
import {shouldFailAllRequestsSelector} from '@selectors/Network';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
import type {ReactNode} from 'react';
Expand All @@ -13,7 +14,6 @@ import useDeleteTransactions from '@hooks/useDeleteTransactions';
import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations';
import useGetIOUReportFromReportAction from '@hooks/useGetIOUReportFromReportAction';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
Expand Down Expand Up @@ -77,11 +77,11 @@ import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
import type {DropdownOption} from './ButtonWithDropdownMenu/types';
import DecisionModal from './DecisionModal';
import {useDelegateNoAccessActions, useDelegateNoAccessState} from './DelegateNoAccessModalProvider';
import HeaderLoadingBar from './HeaderLoadingBar';
import HeaderWithBackButton from './HeaderWithBackButton';
import HoldOrRejectEducationalModal from './HoldOrRejectEducationalModal';
import HoldSubmitterEducationalModal from './HoldSubmitterEducationalModal';
import Icon from './Icon';
import LoadingBar from './LoadingBar';
import {ModalActions} from './Modal/Global/ModalContext';
import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusBar';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
Expand Down Expand Up @@ -148,7 +148,6 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
const [isDuplicateActive, temporarilyDisableDuplicateAction] = useThrottledButtonState();
const [dismissedRejectUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_REJECT_USE_EXPLANATION);
const [dismissedHoldUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION);
const shouldShowLoadingBar = useLoadingBarVisibility();
const personalDetails = usePersonalDetails();
const styles = useThemeStyles();
const theme = useTheme();
Expand Down Expand Up @@ -194,7 +193,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
const shouldOpenParentReportInCurrentTab = !isSelfDM(parentReport);

const {wideRHPRouteKeys} = useWideRHPState();
const [network] = useOnyx(ONYXKEYS.NETWORK);
const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [betas] = useOnyx(ONYXKEYS.BETAS);
Expand Down Expand Up @@ -399,7 +398,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre

const dismissModalAndUpdateUseHold = () => {
setIsHoldEducationalModalVisible(false);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !network?.shouldFailAllRequests);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !shouldFailAllRequests);
if (parentReportAction) {
changeMoneyRequestHoldStatus(parentReportAction);
}
Expand Down Expand Up @@ -671,7 +670,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
/>
</View>
)}
<LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />
<HeaderLoadingBar />
<DecisionModal
title={translate('common.downloadFailedTitle')}
prompt={translate('common.downloadFailedDescription')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe

const reportID = report?.reportID;
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`);
const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`);

Expand Down Expand Up @@ -233,10 +232,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
{shouldDisplayReportFooter ? (
<ReportFooter
report={report}
reportMetadata={reportMetadata}
policy={policy}
pendingAction={reportPendingAction}
isComposerFullSize={!!isComposerFullSize}
lastReportAction={lastReportAction}
// If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction)
transactionThreadReportID={isSentMoneyReport ? undefined : transactionThreadReportID}
Expand Down Expand Up @@ -306,10 +301,6 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
<>
<ReportFooter
report={report}
reportMetadata={reportMetadata}
policy={policy}
pendingAction={reportPendingAction}
isComposerFullSize={!!isComposerFullSize}
lastReportAction={lastReportAction}
reportTransactions={transactions}
// If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction)
Expand Down
15 changes: 9 additions & 6 deletions src/hooks/useLoadingBarVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import type {OnyxEntry} from 'react-native-onyx';
import {WRITE_COMMANDS} from '@libs/API/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {AnyRequest} from '@src/types/onyx';
import useNetwork from './useNetwork';
import useOnyx from './useOnyx';

// Commands that should trigger the LoadingBar to show
const RELEVANT_COMMANDS = new Set<string>([WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT, WRITE_COMMANDS.READ_NEWEST_ACTION]);

const persistedRequestsSelector = (requests: OnyxEntry<AnyRequest[]>) => !!requests?.some((r) => RELEVANT_COMMANDS.has(r.command) && !r.initiatedOffline);

const ongoingRequestSelector = (request: OnyxEntry<AnyRequest>) => !!request && RELEVANT_COMMANDS.has(request.command);

/**
* Hook that determines whether LoadingBar should be visible based on active queue requests
* Shows LoadingBar when any of the RELEVANT_COMMANDS are being processed
*/
export default function useLoadingBarVisibility(): boolean {
const [persistedRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS);
const [ongoingRequests] = useOnyx(ONYXKEYS.PERSISTED_ONGOING_REQUESTS);
const [hasRelevantPersistedRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {selector: persistedRequestsSelector});
const [hasRelevantOngoingRequest] = useOnyx(ONYXKEYS.PERSISTED_ONGOING_REQUESTS, {selector: ongoingRequestSelector});
const {isOffline} = useNetwork();

// Don't show loading bar if currently offline
if (isOffline) {
return false;
}

const hasPersistedRequests = !!persistedRequests?.some((request) => RELEVANT_COMMANDS.has(request.command) && !request.initiatedOffline);
const hasOngoingRequests = !!ongoingRequests && RELEVANT_COMMANDS.has(ongoingRequests?.command);

return hasPersistedRequests || hasOngoingRequests;
return !!hasRelevantPersistedRequests || !!hasRelevantOngoingRequest;
}
8 changes: 6 additions & 2 deletions src/hooks/useParentReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ function useParentReportAction(report: OnyxEntry<Report>) {
[report?.parentReportActionID],
);

const parentReportID = getNonEmptyStringOnyxID(report?.parentReportID);

const [parentReportAction] = useOnyx(
`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(report?.parentReportID)}`,
`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
{
canEvict: false,
// Only set canEvict when we have a valid parentReportID — reportActions_<id> is an evictable key,
// but reportActions_undefined is not and will throw if canEvict is specified.
canEvict: parentReportID ? false : undefined,

selector: getParentReportAction,
},
Expand Down
27 changes: 14 additions & 13 deletions src/pages/inbox/HeaderView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {useRoute} from '@react-navigation/native';
import {accountGuideDetailsSelector} from '@selectors/Account';
import {pendingChatMembersSelector} from '@selectors/ReportMetaData';
import {isPast} from 'date-fns';
import React, {memo, useMemo} from 'react';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
import CaretWrapper from '@components/CaretWrapper';
import DisplayNames from '@components/DisplayNames';
import HeaderLoadingBar from '@components/HeaderLoadingBar';
import Icon from '@components/Icon';
import LoadingBar from '@components/LoadingBar';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import OnboardingHelpDropdownButton from '@components/OnboardingHelpDropdownButton';
import ParentNavigationSubtitle from '@components/ParentNavigationSubtitle';
Expand All @@ -22,9 +24,9 @@ import Tooltip from '@components/Tooltip';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useHasTeam2025Pricing from '@hooks/useHasTeam2025Pricing';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useParentReportAction from '@hooks/useParentReportAction';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -109,16 +111,15 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
const route = useRoute();
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID) ?? getNonEmptyStringOnyxID(report?.reportID)}`);
const [grandParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`);
const [grandParentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`);
const grandParentReportAction = useParentReportAction(parentReport);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID);
const shouldShowLoadingBar = useLoadingBarVisibility();
const [firstDayFreeTrial] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL);
const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL);
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [accountGuideDetails] = useOnyx(ONYXKEYS.ACCOUNT, {selector: accountGuideDetailsSelector});
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`, {selector: pendingChatMembersSelector});
const isReportArchived = isArchivedReport(reportNameValuePairs);
const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: reportsSelector});

Expand All @@ -145,7 +146,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
// This is used to check if the report is a chat thread and has a parent invoice report.
const isParentInvoiceAndIsChatThread = isChatThread && !!parentReport && isInvoiceReport(parentReport);
const reportHeaderData = (!isTaskReport && !isChatThread && report?.parentReportID) || isParentInvoiceAndIsChatThread ? parentReport : report;
const isParentOneTransactionThread = isOneTransactionThread(parentReport, grandParentReport, grandParentReportActions?.[`${parentReport?.parentReportActionID}`]);
const isParentOneTransactionThread = isOneTransactionThread(parentReport, grandParentReport, grandParentReportAction);
const parentNavigationReport = isParentOneTransactionThread ? parentReport : reportHeaderData;
const isReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.reportID);
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
Expand Down Expand Up @@ -185,9 +186,9 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
};

const shouldShowGuideBooking =
!!account &&
account?.guideDetails?.email !== CONST.EMAIL.CONCIERGE &&
!!account?.guideDetails?.calendarLink &&
!!accountGuideDetails &&
accountGuideDetails?.email !== CONST.EMAIL.CONCIERGE &&
!!accountGuideDetails?.calendarLink &&
isAdminRoom(report) &&
!!canUserPerformWriteAction(report, isReportArchived) &&
!isChatThread &&
Expand Down Expand Up @@ -429,7 +430,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
</View>
</View>
)}
<LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />
<HeaderLoadingBar />
</View>
{shouldShowEarlyDiscountBanner && (
<EarlyDiscountBanner
Expand All @@ -442,4 +443,4 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
);
}

export default memo(HeaderView);
export default HeaderView;
Comment thread
adhorodyski marked this conversation as resolved.
Resolved
Loading
Loading