Skip to content
Merged
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
120 changes: 2 additions & 118 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import DropZoneUI from '@components/DropZone/DropZoneUI';
import HoldOrRejectEducationalModal from '@components/HoldOrRejectEducationalModal';
import HoldSubmitterEducationalModal from '@components/HoldSubmitterEducationalModal';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PaymentMethodType} from '@components/KYCWall/types';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider';
Expand All @@ -33,8 +32,7 @@
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {confirmReadyToOpenApp} from '@libs/actions/App';
import {openWorkspace} from '@libs/actions/Policy/Policy';
import {moveIOUReportToPolicy, moveIOUReportToPolicyAndInviteSubmitter, openReport, searchInServer} from '@libs/actions/Report';
import {moveIOUReportToPolicy, moveIOUReportToPolicyAndInviteSubmitter, searchInServer} from '@libs/actions/Report';
import {
approveMoneyRequestOnSearch,
deleteMoneyRequestOnSearch,
Expand Down Expand Up @@ -62,8 +60,6 @@
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
import {getActiveAdminWorkspaces, hasDynamicExternalWorkflow, hasVBBA, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {
canRejectReportAction,
checkBulkRejectHydration,
generateReportID,
getPolicyExpenseChat,
getReportOrDraftReport,
Expand All @@ -75,7 +71,6 @@
} from '@libs/ReportUtils';
import {buildSearchQueryJSON} from '@libs/SearchQueryUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {getTransactionViolationsOfTransaction} from '@libs/TransactionUtils';
import type {ReceiptFile} from '@pages/iou/request/step/IOURequestStepScan/types';
import variables from '@styles/variables';
import {dismissRejectUseExplanation, initMoneyRequest, setMoneyRequestParticipantsFromReport, setMoneyRequestReceipt} from '@userActions/IOU';
Expand Down Expand Up @@ -190,58 +185,6 @@
}
}, [lastSearchType, queryJSON, setLastSearchType, currentSearchResults]);

// Check hydration status and prefetch missing data for bulk reject
const bulkRejectHydrationStatus = useMemo(() => {
if (Object.keys(selectedTransactions).length === 0) {
return {areHydrated: true, missingReportIDs: [], missingPolicyIDs: []};
}
return checkBulkRejectHydration(selectedTransactions, policies);
}, [selectedTransactions, policies]);

// Prefetch missing report and policy data when items are selected
const lastPrefetchKeyRef = useRef('');
useEffect(() => {
const {areHydrated, missingReportIDs, missingPolicyIDs} = bulkRejectHydrationStatus;

// If hydrated or nothing selected, clear and exit
if (areHydrated) {
lastPrefetchKeyRef.current = '';
return;
}
if (isOffline) {
return;
}

const key = `${[...missingReportIDs].sort().join(',')}|${[...missingPolicyIDs].sort().join(',')}`;
if (key === lastPrefetchKeyRef.current) {
return;
}

// Prefetch once per unique set of missing IDs
for (const id of missingReportIDs) {
if (id) {
openReport(id);
}
}

for (const id of missingPolicyIDs) {
if (id) {
openWorkspace(id, []);
}
}

lastPrefetchKeyRef.current = key;
}, [bulkRejectHydrationStatus, isOffline]);

// Allow retry on reconnect
const prevIsOffline = usePrevious(isOffline);
useEffect(() => {
if (isOffline || !prevIsOffline) {
return;
}
lastPrefetchKeyRef.current = '';
}, [isOffline, prevIsOffline]);

const {status, hash} = queryJSON ?? {};
const selectedTransactionsKeys = Object.keys(selectedTransactions ?? {});

Expand Down Expand Up @@ -537,63 +480,6 @@
});
}

// Check if any items are explicitly not rejectable (only when data is hydrated)
// If data is not hydrated, we don't treat it as "not rejectable" - instead we'll disable the button
const login = currentUserPersonalDetails?.login ?? '';
const areAllExplicitlyRejectable =
selectedTransactionReportIDs.length > 0 &&
selectedTransactionReportIDs.every((id) => {
const report = getReportOrDraftReport(id);
if (!report) {
return false;
}
const policyForReport = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
if (!policyForReport) {
return false;
}
return canRejectReportAction(login, report, policyForReport);
});

const hasNoRejectedTransaction = selectedTransactionsKeys.every((id) => {
const transactionViolations = getTransactionViolationsOfTransaction(id) ?? [];
return !transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE);
});

// Check if all selected items have hydrated Onyx data for rejection
const {areHydrated: areItemsHydratedForReject} = bulkRejectHydrationStatus;

// Show the Reject option unless we know for sure it's not allowed
const shouldShowRejectOption = !isOffline && areAllExplicitlyRejectable && hasNoRejectedTransaction;

// Disabled if not hydrated
const isRejectDisabled = !areItemsHydratedForReject;

if (shouldShowRejectOption) {
options.push({
icon: Expensicons.ThumbsDown,
text: translate('search.bulkActions.reject'),
value: CONST.SEARCH.BULK_ACTION_TYPES.REJECT,
shouldCloseModalOnSelect: true,
disabled: isRejectDisabled,
onSelected: () => {
if (isOffline) {
setIsOfflineModalVisible(true);
return;
}

if (!areItemsHydratedForReject) {
return;
}

if (dismissedRejectUseExplanation) {
Navigation.navigate(ROUTES.SEARCH_REJECT_REASON_RHP);
} else {
setRejectModalAction(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT);
}
},
});
}

const shouldShowSubmitOption =
!isOffline &&
areSelectedTransactionsIncludedInReports &&
Expand Down Expand Up @@ -767,7 +653,7 @@
}

return options;
}, [

Check warning on line 656 in src/pages/Search/SearchPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has an unnecessary dependency: 'currentUserPersonalDetails.login'. Either exclude it or remove the dependency array
selectedTransactionsKeys,
status,
hash,
Expand Down Expand Up @@ -796,7 +682,6 @@
dismissedHoldUseExplanation,
dismissedRejectUseExplanation,
areAllTransactionsFromSubmitter,
bulkRejectHydrationStatus,
currentUserPersonalDetails?.login,
]);

Expand Down Expand Up @@ -1033,8 +918,7 @@
Navigation.navigate(ROUTES.TRANSACTION_HOLD_REASON_RHP);
}
} else {
dismissRejectUseExplanation();
Navigation.navigate(ROUTES.SEARCH_REJECT_REASON_RHP);
// TODO: Add reject
}
setRejectModalAction(null);
}, [rejectModalAction, hash, selectedTransactionsKeys.length]);
Expand Down
Loading