diff --git a/src/components/ButtonWithDropdownMenu/types.ts b/src/components/ButtonWithDropdownMenu/types.ts index 720a599f73919..19a8e3f322666 100644 --- a/src/components/ButtonWithDropdownMenu/types.ts +++ b/src/components/ButtonWithDropdownMenu/types.ts @@ -35,7 +35,6 @@ type DropdownOption = { titleStyle?: ViewStyle; shouldCloseModalOnSelect?: boolean; displayInDefaultIconColor?: boolean; - shouldPreserveSelectionAfterHideModal?: boolean; subMenuItems?: PopoverMenuItem[]; }; diff --git a/src/pages/Search/SearchHoldReasonPage.tsx b/src/pages/Search/SearchHoldReasonPage.tsx index 229f7d7e69945..3bcd3a84de912 100644 --- a/src/pages/Search/SearchHoldReasonPage.tsx +++ b/src/pages/Search/SearchHoldReasonPage.tsx @@ -2,12 +2,12 @@ import React, {useCallback, useEffect} from 'react'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import {useSearchContext} from '@components/Search/SearchContext'; import useLocalize from '@hooks/useLocalize'; +import {clearErrorFields, clearErrors} from '@libs/actions/FormActions'; +import {holdMoneyRequestOnSearch} from '@libs/actions/Search'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; -import * as ValidationUtils from '@libs/ValidationUtils'; +import {getFieldRequiredErrors} from '@libs/ValidationUtils'; import HoldReasonFormView from '@pages/iou/HoldReasonFormView'; -import * as FormActions from '@userActions/FormActions'; -import * as SearchActions from '@src/libs/actions/Search'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import INPUT_IDS from '@src/types/form/MoneyRequestHoldReasonForm'; @@ -25,18 +25,19 @@ 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) => { - SearchActions.holdMoneyRequestOnSearch(currentSearchHash, selectedTransactionIDs, values.comment); + holdMoneyRequestOnSearch(currentSearchHash, selectedTransactionIDs, values.comment); + clearSelectedTransactions(); Navigation.goBack(); }; const validate = useCallback( (values: FormOnyxValues) => { - const errors: FormInputErrors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]); + const errors: FormInputErrors = getFieldRequiredErrors(values, [INPUT_IDS.COMMENT]); if (!values.comment) { errors.comment = translate('common.error.fieldRequired'); @@ -48,8 +49,8 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) { ); useEffect(() => { - FormActions.clearErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); - FormActions.clearErrorFields(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); + clearErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); + clearErrorFields(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM); }, []); return ( diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index 81c5a775bbc1b..111d072d6a0f5 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -128,6 +128,7 @@ function SearchPage({route}: SearchPageProps) { setIsDownloadErrorModalVisible(true); }, ); + clearSelectedTransactions(); }, }; @@ -159,6 +160,9 @@ function SearchPage({route}: SearchPageProps) { ? Object.values(selectedTransactions).map((transaction) => transaction.reportID) : selectedReports?.filter((report) => !!report).map((report) => report.reportID) ?? []; approveMoneyRequestOnSearch(hash, reportIDList, transactionIDList); + InteractionManager.runAfterInteractions(() => { + clearSelectedTransactions(); + }); }, }); } @@ -223,6 +227,9 @@ function SearchPage({route}: SearchPageProps) { ) as PaymentData[]; payMoneyRequestOnSearch(hash, paymentData, transactionIDList); + InteractionManager.runAfterInteractions(() => { + clearSelectedTransactions(); + }); }, }); } @@ -263,6 +270,9 @@ function SearchPage({route}: SearchPageProps) { } unholdMoneyRequestOnSearch(hash, selectedTransactionsKeys); + InteractionManager.runAfterInteractions(() => { + clearSelectedTransactions(); + }); }, }); } @@ -275,7 +285,6 @@ function SearchPage({route}: SearchPageProps) { text: translate('search.bulkActions.delete'), value: CONST.SEARCH.BULK_ACTION_TYPES.DELETE, shouldCloseModalOnSelect: true, - shouldPreserveSelectionAfterHideModal: true, onSelected: () => { if (isOffline) { setIsOfflineModalVisible(true); @@ -316,6 +325,7 @@ function SearchPage({route}: SearchPageProps) { selectedReports, queryJSON, activeWorkspaceID, + clearSelectedTransactions, lastPaymentMethods, theme.icon, styles.colorMuted, diff --git a/src/pages/Search/SearchSelectedNarrow.tsx b/src/pages/Search/SearchSelectedNarrow.tsx index dbd30abaa71dc..ec40dd420b580 100644 --- a/src/pages/Search/SearchSelectedNarrow.tsx +++ b/src/pages/Search/SearchSelectedNarrow.tsx @@ -4,7 +4,6 @@ import Button from '@components/Button'; import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; import MenuItem from '@components/MenuItem'; import Modal from '@components/Modal'; -import {useSearchContext} from '@components/Search/SearchContext'; import type {SearchHeaderOptionValue} from '@components/Search/SearchPageHeader/SearchPageHeader'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -24,18 +23,12 @@ function SearchSelectedNarrow({options, itemsLength}: SearchSelectedNarrowProps) const openMenu = () => setIsModalVisible(true); const closeMenu = () => setIsModalVisible(false); - const {clearSelectedTransactions} = useSearchContext(); - const handleOnModalHide = () => { if (selectedOptionIndexRef.current === -1) { return; } options[selectedOptionIndexRef.current]?.onSelected?.(); - if (options[selectedOptionIndexRef.current]?.shouldPreserveSelectionAfterHideModal) { - return; - } - clearSelectedTransactions(); }; const handleOnMenuItemPress = (option: DropdownOption, index: number) => { @@ -45,7 +38,6 @@ function SearchSelectedNarrow({options, itemsLength}: SearchSelectedNarrowProps) return; } option?.onSelected?.(); - clearSelectedTransactions(); }; const handleOnCloseMenu = () => {