Skip to content

Commit

Permalink
deselect on bulk action
Browse files Browse the repository at this point in the history
  • Loading branch information
cretadn22 committed Sep 27, 2024
1 parent 18fac73 commit c9b63a8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/components/PromotedActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type PromotedActionsType = Record<BasePromotedActions, (report: OnyxReport) => P
isDelegateAccessRestricted: boolean;
setIsNoDelegateAccessMenuVisible: (isVisible: boolean) => void;
currentSearchHash?: number;
onComplete?: () => void;
}) => PromotedAction;
};

Expand Down Expand Up @@ -79,7 +80,7 @@ const PromotedActions = {
}
},
}),
hold: ({isTextHold, reportAction, reportID, isDelegateAccessRestricted, setIsNoDelegateAccessMenuVisible, currentSearchHash}) => ({
hold: ({isTextHold, reportAction, reportID, isDelegateAccessRestricted, setIsNoDelegateAccessMenuVisible, currentSearchHash, onComplete}) => ({
key: CONST.PROMOTED_ACTIONS.HOLD,
icon: Expensicons.Stopwatch,
text: Localize.translateLocal(`iou.${isTextHold ? 'hold' : 'unhold'}`),
Expand All @@ -100,7 +101,7 @@ const PromotedActions = {
return;
}

ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute(targetedReportID), currentSearchHash);
ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute(targetedReportID), currentSearchHash, onComplete);
},
}),
} satisfies PromotedActionsType;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search/SearchPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function SearchPageHeader({queryJSON, hash, onSelectDeleteOption, setOfflineModa
const {isOffline} = useNetwork();
const {activeWorkspaceID} = useActiveWorkspace();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {selectedTransactions} = useSearchContext();
const {selectedTransactions, clearSelectedTransactions} = useSearchContext();
const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE);
const personalDetails = usePersonalDetails();
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
Expand Down Expand Up @@ -220,7 +220,7 @@ function SearchPageHeader({queryJSON, hash, onSelectDeleteOption, setOfflineModa
setOfflineModalOpen?.();
return;
}

clearSelectedTransactions();
SearchActions.unholdMoneyRequestOnSearch(hash, selectedTransactionsKeys);
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3137,7 +3137,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
return {canHoldRequest, canUnholdRequest};
}

const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, backTo?: string, searchHash?: number): void => {
const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, backTo?: string, searchHash?: number, onComplete?: () => void): void => {
if (!ReportActionsUtils.isMoneyRequestAction(reportAction)) {
return;
}
Expand All @@ -3154,6 +3154,7 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, bac
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null;

if (isOnHold) {
onComplete?.();
IOU.unholdRequest(transactionID, reportAction.childReportID ?? '', searchHash);
} else {
const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams());
Expand Down
5 changes: 4 additions & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function ReportDetailsPage({policies, report, route}: ReportDetailsPageProps) {
const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.parentReportID || '-1'}`);
const {reportActions} = usePaginatedReportActions(report.reportID || '-1');
/* eslint-enable @typescript-eslint/prefer-nullish-coalescing */
const {currentSearchHash} = useSearchContext();
const {currentSearchHash, clearSelectedTransactions} = useSearchContext();

const transactionThreadReportID = useMemo(
() => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], isOffline),
Expand Down Expand Up @@ -575,6 +575,9 @@ function ReportDetailsPage({policies, report, route}: ReportDetailsPageProps) {
isDelegateAccessRestricted,
setIsNoDelegateAccessMenuVisible,
currentSearchHash,
onComplete: () => {
clearSelectedTransactions();
},
}),
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Search/SearchHoldReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ type SearchHoldReasonPageProps = {
function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) {
const {translate} = useLocalize();

const {currentSearchHash, selectedTransactions} = useSearchContext();
const {currentSearchHash, selectedTransactions, clearSelectedTransactions} = useSearchContext();
const {backTo = ''} = route.params ?? {};

const selectedTransactionIDs = Object.keys(selectedTransactions);
const onSubmit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM>) => {
clearSelectedTransactions();
SearchActions.holdMoneyRequestOnSearch(currentSearchHash, selectedTransactionIDs, values.comment);
Navigation.goBack();
};
Expand Down
3 changes: 3 additions & 0 deletions src/pages/iou/HoldReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {RouteProp} from '@react-navigation/native';
import React, {useCallback, useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import {useSearchContext} from '@components/Search/SearchContext';
import useLocalize from '@hooks/useLocalize';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -38,6 +39,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) {

const {transactionID, reportID, backTo, searchHash} = route.params;

const {clearSelectedTransactions} = useSearchContext();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`);

// We first check if the report is part of a policy - if not, then it's a personal request (1:1 request)
Expand All @@ -53,6 +55,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
return;
}

clearSelectedTransactions();
IOU.putOnHold(transactionID, values.comment, reportID, searchHash);
Navigation.navigate(backTo);
};
Expand Down

0 comments on commit c9b63a8

Please sign in to comment.