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
22 changes: 14 additions & 8 deletions src/components/AnonymousReportFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import useIsInSidePanel from '@hooks/useIsInSidePanel';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import variables from '@styles/variables';
import {signOutAndRedirectToSignIn} from '@userActions/Session';
import type {Report} from '@src/types/onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import AvatarWithDisplayName from './AvatarWithDisplayName';
import Button from './Button';
import ExpensifyWordmark from './ExpensifyWordmark';
import Text from './Text';

type AnonymousReportFooterProps = {
/** The report currently being looked at */
report: OnyxEntry<Report>;

/** Whether the small screen size layout should be used */
isSmallSizeLayout?: boolean;
/** The reportID of the report currently being looked at */
reportID: string | undefined;
};

function AnonymousReportFooter({isSmallSizeLayout = false, report}: AnonymousReportFooterProps) {
function AnonymousReportFooter({reportID}: AnonymousReportFooterProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const isInSidePanel = useIsInSidePanel();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {windowWidth} = useWindowDimensions();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const isSmallSizeLayout = windowWidth - (shouldUseNarrowLayout ? 0 : variables.sideBarWithLHBWidth) < variables.anonymousReportFooterBreakpoint || isInSidePanel;

return (
<View style={[styles.anonymousRoomFooter, styles.anonymousRoomFooterFlexDirection(isSmallSizeLayout)]}>
Expand Down
15 changes: 8 additions & 7 deletions src/components/ArchivedReportFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {getLastClosedReportAction} from '@selectors/ReportAction';
import lodashEscape from 'lodash/escape';
import React from 'react';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -9,23 +10,23 @@ import {getOriginalMessage, isClosedAction} from '@libs/ReportActionsUtils';
import {getPolicyName} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Report} from '@src/types/onyx';
import type {PersonalDetailsList} from '@src/types/onyx';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
import Banner from './Banner';

type ArchivedReportFooterProps = {
/** The archived report */
report: Report;
/** Current user's account id */
currentUserAccountID: number;
/** The reportID of the archived report */
reportID: string;
};

function ArchivedReportFooter({report, currentUserAccountID}: ArchivedReportFooterProps) {
function ArchivedReportFooter({reportID}: ArchivedReportFooterProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);

const [personalDetails = getEmptyObject<PersonalDetailsList>()] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [reportClosedAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false, selector: getLastClosedReportAction});
const [reportClosedAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {canEvict: false, selector: getLastClosedReportAction});
const originalMessage = isClosedAction(reportClosedAction) ? getOriginalMessage(reportClosedAction) : null;
const archiveReason = originalMessage?.reason ?? CONST.REPORT.ARCHIVE_REASON.DEFAULT;
const actorPersonalDetails = personalDetails?.[reportClosedAction?.actorAccountID ?? CONST.DEFAULT_NUMBER_ID];
Expand Down
48 changes: 21 additions & 27 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import truncate from 'lodash/truncate';
import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {InteractionManager, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useActiveAdminPolicies from '@hooks/useActiveAdminPolicies';
import useConfirmModal from '@hooks/useConfirmModal';
Expand All @@ -23,13 +22,15 @@ import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePaginatedReportActions from '@hooks/usePaginatedReportActions';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePaymentOptions from '@hooks/usePaymentOptions';
import usePermissions from '@hooks/usePermissions';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useReportTransactionsCollection from '@hooks/useReportTransactionsCollection';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useResponsiveLayoutOnWideRHP from '@hooks/useResponsiveLayoutOnWideRHP';
import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals';
Expand All @@ -53,7 +54,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import getPlatform from '@libs/getPlatform';
import {getExistingTransactionID} from '@libs/IOUUtils';
import Log from '@libs/Log';
import {getThreadReportIDsForTransactions, getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import {getAllNonDeletedTransactions, getThreadReportIDsForTransactions, getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportsSplitNavigatorParamList, RightModalNavigatorParamList} from '@libs/Navigation/types';
Expand All @@ -68,8 +69,10 @@ import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
import {handleUnvalidatedAccount, selectPaymentType} from '@libs/PaymentUtils';
import {getConnectedIntegration, getValidConnectedIntegration, hasDynamicExternalWorkflow, sortPoliciesByName} from '@libs/PolicyUtils';
import {
getFilteredReportActionsForReportView,
getIOUActionForReportID,
getIOUActionForTransactionID,
getOneTransactionThreadReportID,
getOriginalMessage,
getReportAction,
hasPendingDEWApprove,
Expand Down Expand Up @@ -195,21 +198,8 @@ import type {PaymentActionParams} from './SettlementButton/types';
import Text from './Text';

type MoneyReportHeaderProps = {
/** The report currently being looked at */
report: OnyxEntry<OnyxTypes.Report>;

/** The policy tied to the expense report */
policy: OnyxEntry<OnyxTypes.Policy>;

/** Array of report actions for the report */
reportActions: OnyxTypes.ReportAction[];

/** The reportID of the transaction thread report associated with this current report, if any */
// eslint-disable-next-line react/no-unused-prop-types
transactionThreadReportID: string | undefined;

/** whether we are loading report data in openReport command */
isLoadingInitialReportActions?: boolean;
/** The reportID of the report currently being looked at */
reportID: string | undefined;

/** Whether back button should be displayed in header */
shouldDisplayBackButton?: boolean;
Expand All @@ -218,15 +208,14 @@ type MoneyReportHeaderProps = {
onBackButtonPress: () => void;
};

function MoneyReportHeader({
policy,
report: moneyRequestReport,
transactionThreadReportID,
reportActions,
isLoadingInitialReportActions,
shouldDisplayBackButton = false,
onBackButtonPress,
}: MoneyReportHeaderProps) {
function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = false, onBackButtonPress}: MoneyReportHeaderProps) {
const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDProp}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(moneyRequestReport?.policyID)}`);
const [reportMetadataInternal] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDProp}`);
const isLoadingInitialReportActions = reportMetadataInternal?.isLoadingInitialReportActions;
const {reportActions: unfilteredReportActions} = usePaginatedReportActions(moneyRequestReport?.reportID);
const reportActions = getFilteredReportActionsForReportView(unfilteredReportActions);

// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to use a correct layout for the hold expense modal https://github.com/Expensify/App/pull/47990#issuecomment-2362382026
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth, isMediumScreenWidth} = useResponsiveLayout();
Expand All @@ -245,6 +234,12 @@ function MoneyReportHeader({
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`);
const {isOffline} = useNetwork();
const allReportTransactions = useReportTransactionsCollection(reportIDProp);
const nonDeletedTransactions = getAllNonDeletedTransactions(allReportTransactions, reportActions, isOffline, true);
const visibleTransactionsForThreadID = nonDeletedTransactions?.filter((t) => isOffline || t.pendingAction !== 'delete');
const reportTransactionIDs = visibleTransactionsForThreadID?.map((t) => t.transactionID);
const transactionThreadReportID = getOneTransactionThreadReportID(moneyRequestReport, chatReport, reportActions ?? [], isOffline, reportTransactionIDs);
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`);
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {
selector: isUserValidatedSelector,
Expand Down Expand Up @@ -407,7 +402,6 @@ function MoneyReportHeader({
usePaymentAnimations();
const styles = useThemeStyles();
const theme = useTheme();
const {isOffline} = useNetwork();
const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction);
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION);
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
Expand Down
20 changes: 9 additions & 11 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
import type {ReactNode} from 'react';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useConfirmModal from '@hooks/useConfirmModal';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
Expand All @@ -16,6 +15,7 @@ import useGetIOUReportFromReportAction from '@hooks/useGetIOUReportFromReportAct
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useParentReportAction from '@hooks/useParentReportAction';
import usePermissions from '@hooks/usePermissions';
import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
import useReportIsArchived from '@hooks/useReportIsArchived';
Expand Down Expand Up @@ -74,7 +74,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {Policy, Report, ReportAction, Transaction} from '@src/types/onyx';
import type {Transaction} from '@src/types/onyx';
import type IconAsset from '@src/types/utils/IconAsset';
import BrokenConnectionDescription from './BrokenConnectionDescription';
import Button from './Button';
Expand All @@ -96,20 +96,18 @@ import {useSearchActionsContext, useSearchStateContext} from './Search/SearchCon
import {useWideRHPState} from './WideRHPContextProvider';

type MoneyRequestHeaderProps = {
/** The report currently being looked at */
report: OnyxEntry<Report>;

/** The policy which the report is tied to */
policy: OnyxEntry<Policy>;

/** The report action the transaction is tied to from the parent report */
parentReportAction: OnyxEntry<ReportAction>;
/** The reportID of the report currently being looked at */
reportID: string | undefined;

/** Method to trigger when pressing close button of the header */
onBackButtonPress: (prioritizeBackTo?: boolean) => void;
};

function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPress}: MoneyRequestHeaderProps) {
function MoneyRequestHeader({reportID: reportIDProp, onBackButtonPress}: MoneyRequestHeaderProps) {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDProp}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(report?.policyID)}`);
const parentReportAction = useParentReportAction(report);

// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to use a correct layout for the hold expense modal https://github.com/Expensify/App/pull/47990#issuecomment-2362382026
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth, isInNarrowPaneModal} = useResponsiveLayout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
() =>
isTransactionThreadView ? (
<MoneyRequestHeader
report={report}
policy={policy}
parentReportAction={parentReportAction}
reportID={report?.reportID}
onBackButtonPress={() => {
if (!backToRoute) {
goBackFromSearchMoneyRequest();
Expand All @@ -193,11 +191,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
/>
) : (
<MoneyReportHeader
report={report}
policy={policy}
reportActions={reportActions}
transactionThreadReportID={transactionThreadReportID}
isLoadingInitialReportActions={isLoadingInitialReportActions}
reportID={report?.reportID}
shouldDisplayBackButton
onBackButtonPress={() => {
if (!backToRoute) {
Expand All @@ -208,7 +202,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
}}
/>
),
[backToRoute, isLoadingInitialReportActions, isTransactionThreadView, parentReportAction, policy, report, reportActions, transactionThreadReportID],
[backToRoute, isTransactionThreadView, report?.reportID],
);

// We need to cancel telemetry span when user leaves the screen before full report data is loaded
Expand Down
15 changes: 1 addition & 14 deletions src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
}
Navigation.dismissModal();
}
}, [report]);

Check warning on line 109 in src/pages/Search/SearchMoneyRequestReportPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useEffect has missing dependencies: 'isFocused' and 'prevReport'. Either include them or remove the dependency array

useEffect(() => {
// Update last visit time when the expense super wide RHP report is focused
Expand All @@ -133,19 +133,6 @@
});
}, [isFocused, deleteTransactionNavigateBackUrl]);

const snapshotReport = useMemo(() => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return (snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`] ?? {}) as typeof report;
}, [snapshot, reportIDFromRoute]);

// Use snapshot report currency if main collection doesn't have it (for offline mode)
const reportToUse = useMemo(() => {
if (!report) {
return report;
}
return {...report, currency: report.currency ?? snapshotReport?.currency};
}, [report, snapshotReport?.currency]);

const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`);
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
Expand Down Expand Up @@ -428,7 +415,7 @@
>
<DragAndDropProvider isDisabled={isEditingDisabled}>
<MoneyRequestReportView
report={reportToUse}
report={report}
reportMetadata={reportMetadata}
policy={policy}
shouldDisplayReportFooter={isCurrentReportLoadedFromOnyx}
Expand Down
18 changes: 5 additions & 13 deletions src/pages/inbox/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {pendingChatMembersSelector} from '@selectors/ReportMetaData';
import {isPast} from 'date-fns';
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';
Expand Down Expand Up @@ -83,30 +82,23 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import SCREENS from '@src/SCREENS';
import reportsSelector from '@src/selectors/Attributes';
import type {Report, ReportAction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type HeaderViewProps = {
/** Toggles the navigationMenu open and closed */
onNavigationMenuButtonClicked: () => void;

/** The report currently being looked at */
report: OnyxEntry<Report>;

/** The report action the transaction is tied to from the parent report */
parentReportAction: OnyxEntry<ReportAction> | null;

/** The reportID of the current report */
reportID: string | undefined;

/** Whether we should display the header as in narrow layout */
shouldUseNarrowLayout?: boolean;
};

function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, shouldUseNarrowLayout = false}: HeaderViewProps) {
function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps) {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const parentReportAction = useParentReportAction(report);

const icons = useMemoizedLazyExpensifyIcons(['BackArrow', 'Close', 'DotIndicator'] as const);
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
const {isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const isInSidePanel = useIsInSidePanel();
const route = useRoute();
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID) ?? getNonEmptyStringOnyxID(report?.reportID)}`);
Expand Down
Loading
Loading