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
14 changes: 12 additions & 2 deletions src/components/Modal/Global/HoldMenuModalWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import DecisionModal from '@components/DecisionModal';
import useHoldMenuSubmit from '@hooks/useHoldMenuSubmit';
import type {ActionHandledType} from '@hooks/useHoldMenuSubmit';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type {ModalProps} from './ModalContext';

Expand All @@ -20,6 +22,10 @@ type HoldMenuModalWrapperProps = ModalProps & {
hasNonHeldExpenses?: boolean;
transactionCount: number;
onConfirm?: (full: boolean) => void;
// Optional overrides for callers that source reports from a place other
// than the main report collection (e.g. Search rows render from a snapshot).
moneyRequestReport?: OnyxEntry<Report>;
chatReport?: OnyxEntry<Report>;
};

function HoldMenuModalWrapper({
Expand All @@ -34,15 +40,19 @@ function HoldMenuModalWrapper({
hasNonHeldExpenses,
transactionCount,
onConfirm,
moneyRequestReport: moneyRequestReportOverride,
chatReport: chatReportOverride,
}: HoldMenuModalWrapperProps) {
const [isVisible, setIsVisible] = useState(true);
const {translate} = useLocalize();
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to apply the correct modal type
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();

const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
const [moneyRequestReportFromOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [chatReportFromOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
const moneyRequestReport = moneyRequestReportOverride ?? moneyRequestReportFromOnyx;
const chatReport = chatReportOverride ?? chatReportFromOnyx;
Comment on lines +52 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Anything we can do so we don't have to subscribe to those reportIDs if we have the override?


const {onSubmit, isApprove} = useHoldMenuSubmit({
moneyRequestReport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {ListItem} from '@components/SelectionList/types';
import Text from '@components/Text';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useHoldMenuModal from '@hooks/useHoldMenuModal';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -24,8 +25,8 @@ import {handleActionButtonPress} from '@libs/actions/Search';
import {syncMissingAttendeesViolation} from '@libs/AttendeeUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {isAttendeeTrackingEnabled} from '@libs/PolicyUtils';
import {isInvoiceReport, isOpenExpenseReport, isProcessingReport, isReportPendingDelete} from '@libs/ReportUtils';
import {isViolationDismissed, shouldShowViolation} from '@libs/TransactionUtils';
import {getNonHeldAndFullAmount, isInvoiceReport, isOpenExpenseReport, isProcessingReport, isReportPendingDelete} from '@libs/ReportUtils';
import {isOnHold, isViolationDismissed, shouldShowViolation} from '@libs/TransactionUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -49,7 +50,6 @@ function ExpenseReportListItem<TItem extends ListItem>({
onFocus,
onLongPressRow,
shouldSyncFocus,
onHoldMenuOpen,
onSelectionButtonPress,
lastPaymentMethod,
personalPolicyID,
Expand All @@ -72,6 +72,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
// Fetch live policy categories from Onyx to sync violations at render time
const [parentPolicy] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(reportItem.policyID)}`);
const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportItem.reportID)}`);
const [parentChatReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportItem.parentReportID)}`);
const [policyCategories] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getNonEmptyStringOnyxID(reportItem.policyID)}`);

const searchData = currentSearchResults?.data;
Expand All @@ -80,6 +81,10 @@ function ExpenseReportListItem<TItem extends ListItem>({
return (searchData?.[`${ONYXKEYS.COLLECTION.REPORT}${reportItem.reportID}`] ?? {}) as Report;
}, [searchData, reportItem.reportID]);

const snapshotChatReport = useMemo(() => {
return searchData?.[`${ONYXKEYS.COLLECTION.REPORT}${reportItem.parentReportID}`];
}, [searchData, reportItem.parentReportID]);

const snapshotPolicy = useMemo(() => {
return (searchData?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem.policyID}`] ?? {}) as Policy;
}, [searchData, reportItem.policyID]);
Expand Down Expand Up @@ -136,6 +141,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const {showHoldMenu} = useHoldMenuModal();

const handleOnButtonPress = useCallback(() => {
handleActionButtonPress({
Expand All @@ -151,7 +157,26 @@ function ExpenseReportListItem<TItem extends ListItem>({
isDelegateAccessRestricted,
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
onHoldMenuOpen,
onHoldMenuOpen: (holdItem, requestType, paymentType) => {
// Search rows render from a snapshot; the report may not exist in the main
// collection yet. Fall back to the snapshot so the modal can submit.
const moneyRequestReport = parentReport ?? snapshotReport;
const chatReport = parentChatReport ?? snapshotChatReport;
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, holdItem.allActions?.includes(CONST.SEARCH.ACTION_TYPES.PAY) ?? false);
const hasNonHeldExpenses = holdItem.transactions.some((t) => !isOnHold(t));
showHoldMenu({
reportID: holdItem.reportID,
chatReportID: holdItem.parentReportID,
Comment thread
TMisiukiewicz marked this conversation as resolved.
Resolved
moneyRequestReport,
chatReport,
requestType,
paymentType,
nonHeldAmount: hasNonHeldExpenses && hasValidNonHeldAmount ? nonHeldAmount : undefined,
fullAmount,
hasNonHeldExpenses,
transactionCount: holdItem.transactionCount ?? 0,
});
},
ownerBillingGracePeriodEnd,
amountOwed,
});
Expand All @@ -160,15 +185,18 @@ function ExpenseReportListItem<TItem extends ListItem>({
reportItem,
onSelectRow,
snapshotReport,
snapshotChatReport,
snapshotPolicy,
parentPolicy,
parentReport,
parentChatReport,
lastPaymentMethod,
userBillingGracePeriodEnds,
personalPolicyID,
currentSearchKey,
isDelegateAccessRestricted,
showDelegateNoAccessModal,
onHoldMenuOpen,
showHoldMenu,
ownerBillingGracePeriodEnd,
amountOwed,
]);
Expand Down
7 changes: 0 additions & 7 deletions src/components/Search/SearchList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type {TransactionPreviewData} from '@userActions/Search';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {CardList, Policy, Transaction} from '@src/types/onyx';
import type {HoldMenuCallback} from '..';
import BaseSearchList from './BaseSearchList';
import type ChatListItem from './ListItem/ChatListItem';
import type ExpenseReportListItem from './ListItem/ExpenseReportListItem';
Expand Down Expand Up @@ -118,9 +117,6 @@ type SearchListProps = Pick<FlashListProps<SearchListItem>, 'onScroll' | 'conten

newTransactions?: Transaction[];

/** Callback to fire when hold menu should be opened */
onHoldMenuOpen?: HoldMenuCallback;

/** Selected transactions for determining isSelected state */
selectedTransactions: SelectedTransactions;

Expand Down Expand Up @@ -214,7 +210,6 @@ function SearchList({
shouldAnimate,
isMobileSelectionModeEnabled,
newTransactions = [],
onHoldMenuOpen,
nonPersonalAndWorkspaceCards,
selectedTransactions,
hasLoadedAllTransactions,
Expand Down Expand Up @@ -454,7 +449,6 @@ function SearchList({
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
onFocus={onFocus}
newTransactionID={newTransactionID}
onHoldMenuOpen={onHoldMenuOpen}
onUndelete={handleUndelete}
keyForList={item.keyForList}
isFirstItem={index === firstVisibleIndex}
Expand Down Expand Up @@ -482,7 +476,6 @@ function SearchList({
isOffline,
lastPaymentMethod,
personalPolicyID,
onHoldMenuOpen,
userBillingGracePeriodEnds,
ownerBillingGracePeriodEnd,
nonPersonalAndWorkspaceCards,
Expand Down
54 changes: 3 additions & 51 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import type {OnyxEntry} from 'react-native-onyx';
import Animated, {useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import FullPageErrorView from '@components/BlockingViews/FullPageErrorView';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import type {ActionHandledType} from '@components/ProcessMoneyReportHoldMenu';
import ProcessMoneyReportHoldMenu from '@components/ProcessMoneyReportHoldMenu';
import type {SelectionListHandle} from '@components/SelectionList/types';
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import {useWideRHPActions} from '@components/WideRHPContextProvider';
import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs';
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import type {ActionHandledType} from '@hooks/useHoldMenuSubmit';
import useLocalize from '@hooks/useLocalize';
import useMultipleSnapshots from '@hooks/useMultipleSnapshots';
import useNetwork from '@hooks/useNetwork';
Expand All @@ -39,7 +38,7 @@ import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNa
import TransitionTracker from '@libs/Navigation/TransitionTracker';
import {isCreatedTaskReportAction} from '@libs/ReportActionsUtils';
import {isSplitAction} from '@libs/ReportSecondaryActionUtils';
import {canEditFieldOfMoneyRequest, canHoldUnholdReportAction, canRejectReportAction, getNonHeldAndFullAmount, isOneTransactionReport, selectFilteredReportActions} from '@libs/ReportUtils';
import {canEditFieldOfMoneyRequest, canHoldUnholdReportAction, canRejectReportAction, isOneTransactionReport, selectFilteredReportActions} from '@libs/ReportUtils';
import {buildCannedSearchQuery, buildSearchQueryString, isDefaultExpensesQuery} from '@libs/SearchQueryUtils';
import {
createAndOpenSearchTransactionThread,
Expand Down Expand Up @@ -75,7 +74,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import {columnsSelector} from '@src/selectors/AdvancedSearchFiltersForm';
import type {OutstandingReportsByPolicyIDDerivedValue, Report, SaveSearch, Transaction} from '@src/types/onyx';
import type {OutstandingReportsByPolicyIDDerivedValue, SaveSearch, Transaction} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type SearchResults from '@src/types/onyx/SearchResults';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -307,18 +306,6 @@ function Search({
const styles = useThemeStyles();
const navigation = useNavigation<PlatformStackNavigationProp<SearchFullscreenNavigatorParamList>>();
const isFocused = useIsFocused();
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
const [holdMenuParams, setHoldMenuParams] = useState<{
chatReport: OnyxEntry<Report>;
fullAmount: string;
moneyRequestReport: OnyxEntry<Report>;
transactionCount: number;
nonHeldAmount: string;
requestType: ActionHandledType;
paymentType?: PaymentMethodType;
hasValidNonHeldAmount: boolean;
hasNoneHeldExpenses: boolean;
} | null>(null);

const {markReportIDAsExpense, markReportIDAsMultiTransactionExpense, unmarkReportIDAsMultiTransactionExpense} = useWideRHPActions();
const {
Expand Down Expand Up @@ -379,26 +366,6 @@ function Search({
selector: savedSearchSelector,
});

const handleHoldMenuOpen = useCallback(
(item: TransactionReportGroupListItemType, requestType: ActionHandledType, paymentType?: PaymentMethodType) => {
const chatReport = searchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${item.parentReportID}`];
const moneyRequestReport = searchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`];
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, item.allActions?.includes(CONST.SEARCH.ACTION_TYPES.PAY) ?? false);
setHoldMenuParams({
chatReport,
moneyRequestReport,
transactionCount: item.transactionCount ?? 0,
fullAmount,
requestType,
paymentType,
nonHeldAmount,
hasValidNonHeldAmount,
hasNoneHeldExpenses: item.transactions.some((t) => !isOnHold(t)),
});
setIsHoldMenuVisible(true);
},
[searchResults?.data],
);
const {convertToDisplayString} = useCurrencyListActions();

const validGroupBy = getValidGroupBy(groupBy);
Expand Down Expand Up @@ -1858,25 +1825,10 @@ function Search({
shouldAnimate={type === CONST.SEARCH.DATA_TYPES.EXPENSE}
newTransactions={newTransactions}
hasLoadedAllTransactions={hasLoadedAllTransactions}
onHoldMenuOpen={handleHoldMenuOpen}
policyForMovingExpenses={policyForMovingExpenses}
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
isActionColumnWide={isTask || hasDeletedTransaction}
/>
{isHoldMenuVisible && !!holdMenuParams && (
<ProcessMoneyReportHoldMenu
isVisible={isHoldMenuVisible}
onClose={() => setIsHoldMenuVisible(false)}
chatReport={holdMenuParams.chatReport}
fullAmount={holdMenuParams.fullAmount}
moneyRequestReport={holdMenuParams.moneyRequestReport}
transactionCount={holdMenuParams.transactionCount}
hasNonHeldExpenses={holdMenuParams?.hasNoneHeldExpenses}
nonHeldAmount={holdMenuParams.hasNoneHeldExpenses && holdMenuParams.hasValidNonHeldAmount ? holdMenuParams.nonHeldAmount : undefined}
requestType={holdMenuParams.requestType}
paymentType={holdMenuParams.paymentType}
/>
)}
</Animated.View>
</SearchScopeProvider>
);
Expand Down
Loading