diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 60fca9fac87b..31c2af8f4e58 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -258,11 +258,6 @@ const ROUTES = { getRoute: (reportID: string, reportActionID: string, field: ValueOf, tagIndex?: number) => `r/${reportID}/split/${reportActionID}/edit/${field}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const, }, - EDIT_SPLIT_BILL_CURRENCY: { - route: 'r/:reportID/split/:reportActionID/edit/currency', - getRoute: (reportID: string, reportActionID: string, currency: string, backTo: string) => - `r/${reportID}/split/${reportActionID}/edit/currency?currency=${currency}&backTo=${backTo}` as const, - }, TASK_TITLE: { route: 'r/:reportID/title', getRoute: (reportID: string) => `r/${reportID}/title` as const, @@ -295,10 +290,6 @@ const ROUTES = { route: ':iouType/new/participants/:reportID?', getRoute: (iouType: string, reportID = '') => `${iouType}/new/participants/${reportID}` as const, }, - MONEY_REQUEST_CURRENCY: { - route: ':iouType/new/currency/:reportID?', - getRoute: (iouType: string, reportID: string, currency: string, backTo: string) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}` as const, - }, MONEY_REQUEST_HOLD_REASON: { route: ':iouType/edit/reason/:transactionID?', getRoute: (iouType: string, transactionID: string, reportID: string, backTo: string) => `${iouType}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const, diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index b4c97ed40556..c251f8143631 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -87,7 +87,6 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator require('../../../../pages/iou/request/step/IOURequestStepTag').default as React.ComponentType, [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: () => require('../../../../pages/iou/request/step/IOURequestStepWaypoint').default as React.ComponentType, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: () => require('../../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default as React.ComponentType, - [SCREENS.MONEY_REQUEST.CURRENCY]: () => require('../../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, [SCREENS.MONEY_REQUEST.HOLD]: () => require('../../../../pages/iou/HoldReasonPage').default as React.ComponentType, [SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: () => require('../../../../pages/AddPersonalBankAccountPage').default as React.ComponentType, [SCREENS.IOU_SEND.ADD_DEBIT_CARD]: () => require('../../../../pages/settings/Wallet/AddDebitCardPage').default as React.ComponentType, @@ -100,7 +99,6 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator({ [SCREENS.SPLIT_DETAILS.ROOT]: () => require('../../../../pages/iou/SplitBillDetailsPage').default as React.ComponentType, [SCREENS.SPLIT_DETAILS.EDIT_REQUEST]: () => require('../../../../pages/EditSplitBillPage').default as React.ComponentType, - [SCREENS.SPLIT_DETAILS.EDIT_CURRENCY]: () => require('../../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, }); const DetailsModalStackNavigator = createModalStackNavigator({ @@ -298,7 +296,6 @@ const FlagCommentStackNavigator = createModalStackNavigator({ [SCREENS.EDIT_REQUEST.ROOT]: () => require('../../../../pages/EditRequestPage').default as React.ComponentType, - [SCREENS.EDIT_REQUEST.CURRENCY]: () => require('../../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, [SCREENS.EDIT_REQUEST.REPORT_FIELD]: () => require('../../../../pages/EditReportFieldPage').default as React.ComponentType, }); diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index f7cdc54335ab..95294b7711b5 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -567,7 +567,6 @@ const config: LinkingOptions['config'] = { [SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.route, [SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: ROUTES.MONEY_REQUEST_STEP_TAX_RATE.route, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: ROUTES.MONEY_REQUEST_PARTICIPANTS.route, - [SCREENS.MONEY_REQUEST.CURRENCY]: ROUTES.MONEY_REQUEST_CURRENCY.route, [SCREENS.MONEY_REQUEST.RECEIPT]: ROUTES.MONEY_REQUEST_RECEIPT.route, [SCREENS.MONEY_REQUEST.STATE_SELECTOR]: {path: ROUTES.MONEY_REQUEST_STATE_SELECTOR.route, exact: true}, [SCREENS.IOU_SEND.ENABLE_PAYMENTS]: ROUTES.IOU_SEND_ENABLE_PAYMENTS, @@ -579,7 +578,6 @@ const config: LinkingOptions['config'] = { screens: { [SCREENS.SPLIT_DETAILS.ROOT]: ROUTES.SPLIT_BILL_DETAILS.route, [SCREENS.SPLIT_DETAILS.EDIT_REQUEST]: ROUTES.EDIT_SPLIT_BILL.route, - [SCREENS.SPLIT_DETAILS.EDIT_CURRENCY]: ROUTES.EDIT_SPLIT_BILL_CURRENCY.route, }, }, [SCREENS.RIGHT_MODAL.TASK_DETAILS]: { @@ -611,7 +609,6 @@ const config: LinkingOptions['config'] = { [SCREENS.RIGHT_MODAL.EDIT_REQUEST]: { screens: { [SCREENS.EDIT_REQUEST.ROOT]: ROUTES.EDIT_REQUEST.route, - [SCREENS.EDIT_REQUEST.CURRENCY]: ROUTES.EDIT_CURRENCY_REQUEST.route, [SCREENS.EDIT_REQUEST.REPORT_FIELD]: ROUTES.EDIT_REPORT_FIELD_REQUEST.route, }, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index ed34b8ee3856..1f1e7ec9a459 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -360,12 +360,6 @@ type MoneyRequestNavigatorParamList = { iouType: string; reportID: string; }; - [SCREENS.MONEY_REQUEST.CURRENCY]: { - iouType: string; - reportID: string; - currency: string; - backTo: Routes; - }; [SCREENS.MONEY_REQUEST.STEP_DATE]: { action: ValueOf; iouType: ValueOf; @@ -500,7 +494,6 @@ type SplitDetailsNavigatorParamList = { currency: string; tagIndex: string; }; - [SCREENS.SPLIT_DETAILS.EDIT_CURRENCY]: undefined; }; type AddPersonalBankAccountNavigatorParamList = { @@ -534,7 +527,6 @@ type EditRequestNavigatorParamList = { field: string; threadReportID: string; }; - [SCREENS.EDIT_REQUEST.CURRENCY]: undefined; }; type SignInNavigatorParamList = { diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js deleted file mode 100644 index dd0510d09958..000000000000 --- a/src/pages/iou/IOUCurrencySelection.js +++ /dev/null @@ -1,196 +0,0 @@ -import Str from 'expensify-common/lib/str'; -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; -import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; -import {Keyboard} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import {withNetwork} from '@components/OnyxProvider'; -import ScreenWrapper from '@components/ScreenWrapper'; -import SelectionList from '@components/SelectionList'; -import RadioListItem from '@components/SelectionList/RadioListItem'; -import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; -import compose from '@libs/compose'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; -import Navigation from '@libs/Navigation/Navigation'; -import * as ReportActionsUtils from '@libs/ReportActionsUtils'; -import * as ReportUtils from '@libs/ReportUtils'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import {iouDefaultProps, iouPropTypes} from './propTypes'; - -/** - * IOU Currency selection for selecting currency - */ -const propTypes = { - /** Route from navigation */ - route: PropTypes.shape({ - /** Params from the route */ - params: PropTypes.shape({ - /** The type of IOU report, i.e. bill, request, send */ - iouType: PropTypes.string, - - /** The report ID of the IOU */ - reportID: PropTypes.string, - - /** Currently selected currency */ - currency: PropTypes.string, - - /** Route to navigate back after selecting a currency */ - backTo: PropTypes.string, - }), - }).isRequired, - - // The currency list constant object from Onyx - currencyList: PropTypes.objectOf( - PropTypes.shape({ - // Symbol for the currency - symbol: PropTypes.string, - - // Name of the currency - name: PropTypes.string, - - // ISO4217 Code for the currency - ISO4217: PropTypes.string, - }), - ), - - /** Holds data related to Money Request view state, rather than the underlying Money Request data. */ - iou: iouPropTypes, - - ...withLocalizePropTypes, -}; - -const defaultProps = { - currencyList: {}, - iou: iouDefaultProps, -}; - -function IOUCurrencySelection(props) { - const [searchValue, setSearchValue] = useState(''); - const optionsSelectorRef = useRef(); - const selectedCurrencyCode = (lodashGet(props.route, 'params.currency', props.iou.currency) || CONST.CURRENCY.USD).toUpperCase(); - const threadReportID = lodashGet(props.route, 'params.threadReportID', ''); - const backTo = lodashGet(props.route, 'params.backTo', ''); - - // Decides whether to allow or disallow editing a money request - useEffect(() => { - // Do not dismiss the modal, when it is not the edit flow. - if (!threadReportID) { - return; - } - - const report = ReportUtils.getReport(threadReportID); - const parentReportAction = report ? ReportActionsUtils.getReportAction(report.parentReportID, report.parentReportActionID) : null; - - // Do not dismiss the modal, when a current user can edit this currency of this money request. - if (ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.CURRENCY)) { - return; - } - - // Dismiss the modal when a current user cannot edit a money request. - Navigation.isNavigationReady().then(() => { - Navigation.dismissModal(); - }); - }, [threadReportID]); - - const confirmCurrencySelection = useCallback( - (option) => { - Keyboard.dismiss(); - - // When we refresh the web, the money request route gets cleared from the navigation stack. - // Navigating to "backTo" will result in forward navigation instead, causing disruption to the currency selection. - // To prevent any negative experience, we have made the decision to simply close the currency selection page. - if (_.isEmpty(backTo) || props.navigation.getState().routes.length === 1) { - Navigation.goBack(); - } else { - Navigation.navigate(`${props.route.params.backTo}?currency=${option.currencyCode}`); - } - }, - [props.route, props.navigation, backTo], - ); - - const {translate, currencyList} = props; - const {sections, headerMessage, initiallyFocusedOptionKey} = useMemo(() => { - const currencyOptions = _.map(currencyList, (currencyInfo, currencyCode) => { - const isSelectedCurrency = currencyCode === selectedCurrencyCode; - return { - currencyName: currencyInfo.name, - text: `${currencyCode} - ${CurrencyUtils.getLocalizedCurrencySymbol(currencyCode)}`, - currencyCode, - keyForList: currencyCode, - isSelected: isSelectedCurrency, - }; - }); - - const searchRegex = new RegExp(Str.escapeForRegExp(searchValue.trim().replace(CONST.REGEX.ANY_SPACE, ' ')), 'i'); - const filteredCurrencies = _.filter( - currencyOptions, - (currencyOption) => - searchRegex.test(currencyOption.text.replace(CONST.REGEX.ANY_SPACE, ' ')) || searchRegex.test(currencyOption.currencyName.replace(CONST.REGEX.ANY_SPACE, ' ')), - ); - const isEmpty = searchValue.trim() && !filteredCurrencies.length; - - return { - initiallyFocusedOptionKey: _.get( - _.find(filteredCurrencies, (currency) => currency.currencyCode === selectedCurrencyCode), - 'keyForList', - ), - sections: isEmpty - ? [] - : [ - { - data: filteredCurrencies, - }, - ], - headerMessage: isEmpty ? translate('common.noResultsFound') : '', - }; - }, [currencyList, searchValue, selectedCurrencyCode, translate]); - - return ( - optionsSelectorRef.current && optionsSelectorRef.current.focus()} - testID={IOUCurrencySelection.displayName} - > - {({didScreenTransitionEnd}) => ( - <> - Navigation.goBack(backTo)} - /> - { - if (!didScreenTransitionEnd) { - return; - } - confirmCurrencySelection(option); - }} - headerMessage={headerMessage} - initiallyFocusedOptionKey={initiallyFocusedOptionKey} - showScrollIndicator - /> - - )} - - ); -} - -IOUCurrencySelection.displayName = 'IOUCurrencySelection'; -IOUCurrencySelection.propTypes = propTypes; -IOUCurrencySelection.defaultProps = defaultProps; - -export default compose( - withLocalize, - withOnyx({ - currencyList: {key: ONYXKEYS.CURRENCY_LIST}, - iou: {key: ONYXKEYS.IOU}, - }), - withNetwork(), -)(IOUCurrencySelection);