Skip to content

Commit

Permalink
Merge pull request #26710 from Prince-Mendiratta/prince/fix-24291-man…
Browse files Browse the repository at this point in the history
…datory-fallback

[Navigation] Make fallback route necessary for Navigation.goBack method
  • Loading branch information
neil-marcellini authored Sep 20, 2023
2 parents b773455 + c07a584 commit 52dc94d
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 64 deletions.
3 changes: 2 additions & 1 deletion src/components/BlockingViews/FullPageNotFoundView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Navigation from '../../libs/Navigation/Navigation';
import variables from '../../styles/variables';
import styles from '../../styles/styles';
import useLocalize from '../../hooks/useLocalize';
import ROUTES from '../../ROUTES';

const propTypes = {
/** Child elements */
Expand Down Expand Up @@ -44,7 +45,7 @@ const defaultProps = {
titleKey: 'notFound.notHere',
subtitleKey: 'notFound.pageNotFound',
linkKey: 'notFound.goBackHome',
onBackButtonPress: Navigation.goBack,
onBackButtonPress: () => Navigation.goBack(ROUTES.HOME),
shouldShowLink: true,
shouldShowBackButton: true,
onLinkPress: () => Navigation.dismissModal(),
Expand Down
2 changes: 1 addition & 1 deletion src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken,
useEffect(updateGradientVisibility, [scrollContainerHeight, scrollContentHeight]);

const navigateBack = () => {
Navigation.goBack(isEditing ? ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID) : null);
Navigation.goBack(isEditing ? ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID) : ROUTES.HOME);
};

const navigateToNextPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/HeaderWithBackButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import useKeyboardState from '../../hooks/useKeyboardState';
function HeaderWithBackButton({
iconFill = undefined,
guidesCallTaskID = '',
onBackButtonPress = () => Navigation.goBack(),
onBackButtonPress = () => Navigation.goBack(ROUTES.HOME),
onCloseButtonPress = () => Navigation.dismissModal(),
onDownloadButtonPress = () => {},
onThreeDotsButtonPress = () => {},
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function navigate(route = ROUTES.HOME, type) {
* @param {Bool} shouldEnforceFallback - Enforces navigation to fallback route
* @param {Bool} shouldPopToTop - Should we navigate to LHN on back press
*/
function goBack(fallbackRoute = ROUTES.HOME, shouldEnforceFallback = false, shouldPopToTop = false) {
function goBack(fallbackRoute, shouldEnforceFallback = false, shouldPopToTop = false) {
if (!canNavigate('goBack')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function subscribeToReportCommentPushNotifications() {
try {
// If a chat is visible other than the one we are trying to navigate to, then we need to navigate back
if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) {
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
}

Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID, reportActionID});
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = fal
.then(() => {
if (transitionFromOldDot) {
// We must call goBack() to remove the /transition route from history
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
}

if (shouldNavigateToAdminChat) {
Expand Down Expand Up @@ -383,7 +383,7 @@ function setUpPoliciesAndNavigate(session, shouldNavigateToAdminChat) {
Navigation.isNavigationReady()
.then(() => {
// We must call goBack() to remove the /transition route from history
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
Navigation.navigate(exitTo);
})
.then(endSignOnTransition);
Expand All @@ -399,7 +399,7 @@ function redirectThirdPartyDesktopSignIn() {

if (url.pathname === `/${ROUTES.GOOGLE_SIGN_IN}` || url.pathname === `/${ROUTES.APPLE_SIGN_IN}`) {
Navigation.isNavigationReady().then(() => {
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
Navigation.navigate(ROUTES.DESKTOP_SIGN_IN_REDIRECT);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,14 +1393,14 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView
// STEP 7: Navigate the user depending on which page they are on and which resources were deleted
if (isSingleTransactionView && shouldDeleteTransactionThread && !shouldDeleteIOUReport) {
// Pop the deleted report screen before navigating. This prevents navigating to the Concierge chat due to the missing report.
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
Navigation.navigate(ROUTES.getReportRoute(iouReport.reportID));
return;
}

if (shouldDeleteIOUReport) {
// Pop the deleted report screen before navigating. This prevents navigating to the Concierge chat due to the missing report.
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
Navigation.navigate(ROUTES.getReportRoute(iouReport.chatReportID));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/PaymentMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const kycWallRef = createRef();
*/
function continueSetup() {
if (!kycWallRef.current || !kycWallRef.current.continue) {
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
return;
}

// Close the screen (Add Debit Card, Add Bank Account, or Enable Payments) on success and continue with setup
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
kycWallRef.current.continue();
}

Expand Down
8 changes: 4 additions & 4 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ function updateNotificationPreferenceAndNavigate(reportID, previousValue, newVal
function updateWelcomeMessage(reportID, previousValue, newValue) {
// No change needed, navigate back
if (previousValue === newValue) {
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
return;
}

Expand All @@ -1261,7 +1261,7 @@ function updateWelcomeMessage(reportID, previousValue, newValue) {
},
];
API.write('UpdateWelcomeMessage', {reportID, welcomeMessage: parsedWelcomeMessage}, {optimisticData, failureData});
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
}

/**
Expand Down Expand Up @@ -1438,7 +1438,7 @@ function deleteReport(reportID) {
*/
function navigateToConciergeChatAndDeleteReport(reportID) {
// Dismiss the current report screen and replace it with Concierge Chat
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
navigateToConciergeChat();
deleteReport(reportID);
}
Expand Down Expand Up @@ -1820,7 +1820,7 @@ function leaveRoom(reportID) {
);
Navigation.dismissModal();
if (Navigation.getTopmostReportId() === reportID) {
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
}
navigateToConciergeChat();
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/AddPersonalBankAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AddPersonalBankAccountPage extends React.Component {
this.setState({selectedPlaidAccountID});
}}
plaidData={this.props.plaidData}
onExitPlaid={Navigation.goBack}
onExitPlaid={() => Navigation.goBack(ROUTES.HOME)}
receivedRedirectURI={getPlaidOAuthReceivedRedirectURI()}
selectedPlaidAccountID={this.state.selectedPlaidAccountID}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/ConciergePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ONYXKEYS from '../ONYXKEYS';
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
import Navigation from '../libs/Navigation/Navigation';
import * as Report from '../libs/actions/Report';
import ROUTES from '../ROUTES';

const propTypes = {
/** Session info for the currently logged in user. */
Expand All @@ -31,7 +32,7 @@ function ConciergePage(props) {
useFocusEffect(() => {
if (_.has(props.session, 'authToken')) {
// Pop the concierge loading page before opening the concierge report.
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
Report.navigateToConciergeChat();
} else {
Navigation.navigate();
Expand Down
7 changes: 1 addition & 6 deletions src/pages/DetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import * as Report from '../libs/actions/Report';
import OfflineWithFeedback from '../components/OfflineWithFeedback';
import AutoUpdateTime from '../components/AutoUpdateTime';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import * as UserUtils from '../libs/UserUtils';

const matchType = PropTypes.shape({
Expand Down Expand Up @@ -130,10 +128,7 @@ function DetailsPage(props) {
return (
<ScreenWrapper>
<FullPageNotFoundView shouldShow={_.isEmpty(login)}>
<HeaderWithBackButton
title={props.translate('common.details')}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME)}
/>
<HeaderWithBackButton title={props.translate('common.details')} />
<View
pointerEvents="box-none"
style={[styles.containerWithSpaceBetween]}
Expand Down
5 changes: 1 addition & 4 deletions src/pages/EditRequestAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit, report
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
>
<HeaderWithBackButton
title={translate('iou.amount')}
onBackButtonPress={Navigation.goBack}
/>
<HeaderWithBackButton title={translate('iou.amount')} />
<MoneyRequestAmountForm
isEditing
currency={defaultCurrency}
Expand Down
6 changes: 1 addition & 5 deletions src/pages/EditRequestCreatedPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import HeaderWithBackButton from '../components/HeaderWithBackButton';
import Form from '../components/Form';
import ONYXKEYS from '../ONYXKEYS';
import styles from '../styles/styles';
import Navigation from '../libs/Navigation/Navigation';
import useLocalize from '../hooks/useLocalize';
import NewDatePicker from '../components/NewDatePicker';

Expand All @@ -25,10 +24,7 @@ function EditRequestCreatedPage({defaultCreated, onSubmit}) {
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
>
<HeaderWithBackButton
title={translate('common.date')}
onBackButtonPress={Navigation.goBack}
/>
<HeaderWithBackButton title={translate('common.date')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_DATE_FORM}
Expand Down
6 changes: 1 addition & 5 deletions src/pages/EditRequestDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import HeaderWithBackButton from '../components/HeaderWithBackButton';
import Form from '../components/Form';
import ONYXKEYS from '../ONYXKEYS';
import styles from '../styles/styles';
import Navigation from '../libs/Navigation/Navigation';
import CONST from '../CONST';
import useLocalize from '../hooks/useLocalize';
import * as Browser from '../libs/Browser';
Expand All @@ -29,10 +28,7 @@ function EditRequestDescriptionPage({defaultDescription, onSubmit}) {
shouldEnableMaxHeight
onEntryTransitionEnd={() => descriptionInputRef.current && descriptionInputRef.current.focus()}
>
<HeaderWithBackButton
title={translate('common.description')}
onBackButtonPress={() => Navigation.goBack()}
/>
<HeaderWithBackButton title={translate('common.description')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_DESCRIPTION_FORM}
Expand Down
6 changes: 1 addition & 5 deletions src/pages/EditRequestMerchantPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import HeaderWithBackButton from '../components/HeaderWithBackButton';
import Form from '../components/Form';
import ONYXKEYS from '../ONYXKEYS';
import styles from '../styles/styles';
import Navigation from '../libs/Navigation/Navigation';
import CONST from '../CONST';
import useLocalize from '../hooks/useLocalize';

Expand Down Expand Up @@ -40,10 +39,7 @@ function EditRequestMerchantPage({defaultMerchant, onSubmit}) {
shouldEnableMaxHeight
onEntryTransitionEnd={() => merchantInputRef.current && merchantInputRef.current.focus()}
>
<HeaderWithBackButton
title={translate('common.merchant')}
onBackButtonPress={Navigation.goBack}
/>
<HeaderWithBackButton title={translate('common.merchant')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_MERCHANT_FORM}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/EnablePayments/OnfidoStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Growl from '../../libs/Growl';
import OnfidoPrivacy from './OnfidoPrivacy';
import walletOnfidoDataPropTypes from './walletOnfidoDataPropTypes';
import FullPageOfflineBlockingView from '../../components/BlockingViews/FullPageOfflineBlockingView';
import ROUTES from '../../ROUTES';

const propTypes = {
/** Stores various information used to build the UI and call any APIs */
Expand Down Expand Up @@ -51,7 +52,7 @@ class OnfidoStep extends React.Component {
Growl.error(this.props.translate('onfidoStep.genericError'), 10000);
}}
onUserExit={() => {
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
}}
onSuccess={(data) => {
BankAccounts.verifyIdentity({
Expand Down
5 changes: 2 additions & 3 deletions src/pages/PrivateNotes/PrivateNotesEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Report from '../../libs/actions/Report';
import useLocalize from '../../hooks/useLocalize';
import OfflineWithFeedback from '../../components/OfflineWithFeedback';
import focusAndUpdateMultilineInputRange from '../../libs/focusAndUpdateMultilineInputRange';
import ROUTES from '../../ROUTES';

const propTypes = {
/** All of the personal details for everyone */
Expand Down Expand Up @@ -72,7 +73,7 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) {
Keyboard.dismiss();

// Take user back to the PrivateNotesView page
Navigation.goBack();
Navigation.goBack(ROUTES.HOME);
};

return (
Expand All @@ -83,14 +84,12 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) {
<FullPageNotFoundView
shouldShow={_.isEmpty(report) || _.isEmpty(report.privateNotes) || !_.has(report, ['privateNotes', route.params.accountID, 'note']) || !isCurrentUserNote}
subtitleKey="privateNotes.notesUnavailable"
onBackButtonPress={() => Navigation.goBack()}
>
<HeaderWithBackButton
title={translate('privateNotes.title')}
subtitle={translate('privateNotes.myNote')}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
onBackButtonPress={() => Navigation.goBack()}
/>
<View style={[styles.flexGrow1, styles.ph5]}>
<View style={[styles.mb5]}>
Expand Down
6 changes: 1 addition & 5 deletions src/pages/PrivateNotes/PrivateNotesListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,11 @@ function PrivateNotesListPage({report, personalDetailsList, network, session}) {

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
<FullPageNotFoundView
shouldShow={_.isEmpty(report.reportID) || (!report.isLoadingPrivateNotes && network.isOffline && _.isEmpty(lodashGet(report, 'privateNotes', {})))}
onBackButtonPress={() => Navigation.goBack()}
>
<FullPageNotFoundView shouldShow={_.isEmpty(report.reportID) || (!report.isLoadingPrivateNotes && network.isOffline && _.isEmpty(lodashGet(report, 'privateNotes', {})))}>
<HeaderWithBackButton
title={translate('privateNotes.title')}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
onBackButtonPress={() => Navigation.goBack()}
/>
{report.isLoadingPrivateNotes && _.isEmpty(lodashGet(report, 'privateNotes', {})) ? (
<FullScreenLoadingIndicator />
Expand Down
2 changes: 0 additions & 2 deletions src/pages/PrivateNotes/PrivateNotesViewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ function PrivateNotesViewPage({route, personalDetailsList, session, report}) {
<FullPageNotFoundView
shouldShow={_.isEmpty(report) || _.isEmpty(report.privateNotes) || !_.has(report, ['privateNotes', route.params.accountID, 'note'])}
subtitleKey="privateNotes.notesUnavailable"
onBackButtonPress={() => Navigation.goBack()}
>
<HeaderWithBackButton
title={translate('privateNotes.title')}
subtitle={isCurrentUserNote ? translate('privateNotes.myNote') : `${lodashGet(personalDetailsList, [route.params.accountID, 'login'], '')} note`}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
onBackButtonPress={() => Navigation.goBack()}
/>
<ScrollView style={[styles.flexGrow1]}>
<OfflineWithFeedback pendingAction={lodashGet(report, ['privateNotes', route.params.accountID, 'pendingAction'], null)}>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function ProfilePage(props) {
const hasStatus = !!statusEmojiCode && Permissions.canUseCustomStatus(props.betas);
const statusContent = `${statusEmojiCode} ${statusText}`;

const navigateBackTo = lodashGet(props.route, 'params.backTo', '');
const navigateBackTo = lodashGet(props.route, 'params.backTo', ROUTES.HOME);

const chatReportWithCurrentUser = !isCurrentUser && !Session.isAnonymousUser() ? ReportUtils.getChatByParticipants([accountID]) : 0;

Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class ReimbursementAccountPage extends React.Component {
const currentStep = achData.currentStep || CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT;
const subStep = achData.subStep;
const shouldShowOnfido = this.props.onfidoToken && !achData.isOnfidoSetupComplete;
const backTo = lodashGet(this.props.route.params, 'backTo');
const backTo = lodashGet(this.props.route.params, 'backTo', ROUTES.HOME);
switch (currentStep) {
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
if (this.hasInProgressVBBA()) {
Expand Down Expand Up @@ -405,7 +405,7 @@ class ReimbursementAccountPage extends React.Component {
continue={this.continue}
policyName={policyName}
onBackButtonPress={() => {
Navigation.goBack(lodashGet(this.props.route.params, 'backTo'));
Navigation.goBack(lodashGet(this.props.route.params, 'backTo', ROUTES.HOME));
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TeachersUnite/SaveTheWorldPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function SaveTheWorldPage(props) {
<IllustratedHeaderPageLayout
shouldShowBackButton
title={translate('sidebarScreen.saveTheWorld')}
onBackButtonPress={Navigation.goBack}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME)}
backgroundColor={themeColors.PAGE_BACKGROUND_COLORS[ROUTES.I_KNOW_A_TEACHER]}
illustration={LottieAnimations.SaveTheWorld}
>
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ function ReportScreen({
subtitleKey="notFound.noAccess"
shouldShowCloseButton={false}
shouldShowBackButton={isSmallScreenWidth}
onBackButtonPress={Navigation.goBack}
shouldShowLink={false}
>
<OfflineWithFeedback
Expand Down
Loading

0 comments on commit 52dc94d

Please sign in to comment.