Skip to content

Commit

Permalink
Merge pull request #51155 from Expensify/revert-49602-use-newdot-trav…
Browse files Browse the repository at this point in the history
…el-page-on-olddot

Revert "[HybridApp] Allow classic experience users to use NewDot travel page"

(cherry picked from commit 0083067)

(CP triggered by AndrewGable)
  • Loading branch information
yuwenmemon authored and OSBotify committed Oct 21, 2024
1 parent 7e4d5c0 commit cd9776c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 88 deletions.
4 changes: 0 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,6 @@ const ONYXKEYS = {
/** Stores recently used currencies */
RECENTLY_USED_CURRENCIES: 'nvp_recentlyUsedCurrencies',

/** States whether we transitioned from OldDot to show only certain group of screens. It should be undefined on pure NewDot. */
IS_SINGLE_NEW_DOT_ENTRY: 'isSingleNewDotEntry',

/** Company cards custom names */
NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES: 'nvp_expensify_ccCustomNames',

Expand Down Expand Up @@ -1007,7 +1004,6 @@ type OnyxValuesMapping = {
[ONYXKEYS.APPROVAL_WORKFLOW]: OnyxTypes.ApprovalWorkflowOnyx;
[ONYXKEYS.IMPORTED_SPREADSHEET]: OnyxTypes.ImportedSpreadsheet;
[ONYXKEYS.LAST_ROUTE]: string;
[ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY]: boolean | undefined;
[ONYXKEYS.IS_USING_IMPORTED_STATE]: boolean;
[ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean;
[ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record<string, string>;
Expand Down
7 changes: 3 additions & 4 deletions src/components/InitialURLContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ function InitialURLContextProvider({children, url}: InitialURLContextProviderPro

useEffect(() => {
if (url) {
signInAfterTransitionFromOldDot(url).then((route) => {
setInitialURL(route);
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
});
const route = signInAfterTransitionFromOldDot(url);
setInitialURL(route);
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
return;
}
Linking.getInitialURL().then((initURL) => {
Expand Down
13 changes: 2 additions & 11 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {UNSTABLE_usePreventRemove, useIsFocused, useNavigation, useRoute} from '@react-navigation/native';
import {useIsFocused, useNavigation} from '@react-navigation/native';
import type {StackNavigationProp} from '@react-navigation/stack';
import type {ForwardedRef, ReactNode} from 'react';
import React, {createContext, forwardRef, useEffect, useMemo, useRef, useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {Keyboard, NativeModules, PanResponder, View} from 'react-native';
import {Keyboard, PanResponder, View} from 'react-native';
import {PickerAvoidingView} from 'react-native-picker-select';
import type {EdgeInsets} from 'react-native-safe-area-context';
import useEnvironment from '@hooks/useEnvironment';
Expand Down Expand Up @@ -161,15 +161,6 @@ function ScreenWrapper(

isKeyboardShownRef.current = keyboardState?.isKeyboardShown ?? false;

const route = useRoute();
const shouldReturnToOldDot = useMemo(() => {
return !!route?.params && 'singleNewDotEntry' in route.params && route.params.singleNewDotEntry === 'true';
}, [route]);

UNSTABLE_usePreventRemove(shouldReturnToOldDot, () => {
NativeModules.HybridAppModule?.closeReactNativeApp(false, false);
});

const panResponder = useRef(
PanResponder.create({
onStartShouldSetPanResponderCapture: (_e, gestureState) => gestureState.numberActiveTouches === CONST.TEST_TOOL.NUMBER_OF_TAPS,
Expand Down
8 changes: 3 additions & 5 deletions src/hooks/useOnboardingFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ function useOnboardingFlowRouter() {
selector: hasCompletedHybridAppOnboardingFlowSelector,
});

const [isSingleNewDotEntry, isSingleNewDotEntryMetadata] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY);

useEffect(() => {
if (isLoadingOnyxValue(isOnboardingCompletedMetadata, isHybridAppOnboardingCompletedMetadata, isSingleNewDotEntryMetadata)) {
if (isLoadingOnyxValue(isOnboardingCompletedMetadata, isHybridAppOnboardingCompletedMetadata)) {
return;
}

if (NativeModules.HybridAppModule) {
// When user is transitioning from OldDot to NewDot, we usually show the explanation modal
if (isHybridAppOnboardingCompleted === false && !isSingleNewDotEntry) {
if (isHybridAppOnboardingCompleted === false) {
Navigation.navigate(ROUTES.EXPLANATION_MODAL_ROOT);
}

Expand All @@ -45,7 +43,7 @@ function useOnboardingFlowRouter() {
if (!NativeModules.HybridAppModule && isOnboardingCompleted === false) {
OnboardingFlow.startOnboardingFlow();
}
}, [isOnboardingCompleted, isHybridAppOnboardingCompleted, isOnboardingCompletedMetadata, isHybridAppOnboardingCompletedMetadata, isSingleNewDotEntryMetadata, isSingleNewDotEntry]);
}, [isOnboardingCompleted, isHybridAppOnboardingCompleted, isOnboardingCompletedMetadata, isHybridAppOnboardingCompletedMetadata]);

return {isOnboardingCompleted, isHybridAppOnboardingCompleted};
}
Expand Down
25 changes: 3 additions & 22 deletions src/libs/TripReservationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Str} from 'expensify-common';
import type {Dispatch, SetStateAction} from 'react';
import {NativeModules} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
Expand All @@ -14,7 +13,6 @@ import type Transaction from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import * as Link from './actions/Link';
import Log from './Log';
import Navigation from './Navigation/Navigation';
import * as PolicyUtils from './PolicyUtils';

Expand Down Expand Up @@ -42,14 +40,6 @@ Onyx.connect({
},
});

let isSingleNewDotEntry: boolean | undefined;
Onyx.connect({
key: ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY,
callback: (val) => {
isSingleNewDotEntry = val;
},
});

function getTripReservationIcon(reservationType: ReservationType): IconAsset {
switch (reservationType) {
case CONST.RESERVATION_TYPE.FLIGHT:
Expand Down Expand Up @@ -101,17 +91,8 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag
if (ctaErrorMessage) {
setCtaErrorMessage('');
}
Link.openTravelDotLink(activePolicyID)
?.then(() => {
if (!NativeModules.HybridAppModule || !isSingleNewDotEntry) {
return;
}

Log.info('[HybridApp] Returning to OldDot after opening TravelDot');
NativeModules.HybridAppModule.closeReactNativeApp(false, false);
})
?.catch(() => {
setCtaErrorMessage(translate('travel.errorMessage'));
});
Link.openTravelDotLink(activePolicyID)?.catch(() => {
setCtaErrorMessage(translate('travel.errorMessage'));
});
}
export {getTripReservationIcon, getReservationsFromTripTransactions, getTripEReceiptIcon, bookATrip};
6 changes: 2 additions & 4 deletions src/libs/actions/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function openTravelDotLink(policyID: OnyxEntry<string>, postLoginPath?: string)
policyID,
};

return new Promise((resolve, reject) => {
return new Promise((_, reject) => {
const error = new Error('Failed to generate spotnana token.');

asyncOpenURL(
Expand All @@ -122,9 +122,7 @@ function openTravelDotLink(policyID: OnyxEntry<string>, postLoginPath?: string)
reject(error);
throw error;
}
const travelURL = buildTravelDotURL(response.spotnanaToken, postLoginPath);
resolve(undefined);
return travelURL;
return buildTravelDotURL(response.spotnanaToken, postLoginPath);
})
.catch(() => {
reject(error);
Expand Down
53 changes: 19 additions & 34 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,43 +482,28 @@ function signUpUser() {
function signInAfterTransitionFromOldDot(transitionURL: string) {
const [route, queryParams] = transitionURL.split('?');

const {email, authToken, encryptedAuthToken, accountID, autoGeneratedLogin, autoGeneratedPassword, clearOnyxOnStart, completedHybridAppOnboarding, isSingleNewDotEntry, primaryLogin} =
Object.fromEntries(
queryParams.split('&').map((param) => {
const [key, value] = param.split('=');
return [key, value];
}),
);

const clearOnyxForNewAccount = () => {
if (clearOnyxOnStart !== 'true') {
return Promise.resolve();
}

return Onyx.clear(KEYS_TO_PRESERVE);
const {email, authToken, encryptedAuthToken, accountID, autoGeneratedLogin, autoGeneratedPassword, clearOnyxOnStart, completedHybridAppOnboarding} = Object.fromEntries(
queryParams.split('&').map((param) => {
const [key, value] = param.split('=');
return [key, value];
}),
);

const setSessionDataAndOpenApp = () => {
Onyx.multiSet({
[ONYXKEYS.SESSION]: {email, authToken, encryptedAuthToken: decodeURIComponent(encryptedAuthToken), accountID: Number(accountID)},
[ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword},
[ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {completedHybridAppOnboarding: completedHybridAppOnboarding === 'true'}},
}).then(App.openApp);
};

const setSessionDataAndOpenApp = new Promise<Route>((resolve) => {
clearOnyxForNewAccount()
.then(() =>
Onyx.multiSet({
[ONYXKEYS.SESSION]: {email, authToken, encryptedAuthToken: decodeURIComponent(encryptedAuthToken), accountID: Number(accountID)},
[ONYXKEYS.ACCOUNT]: {primaryLogin},
[ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin, autoGeneratedPassword},
[ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY]: isSingleNewDotEntry === 'true',
[ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {completedHybridAppOnboarding: completedHybridAppOnboarding === 'true'}},
}),
)
.then(App.openApp)
.catch((error) => {
Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error});
})
.finally(() => {
resolve(`${route}?singleNewDotEntry=${isSingleNewDotEntry}` as Route);
});
});
if (clearOnyxOnStart === 'true') {
Onyx.clear(KEYS_TO_PRESERVE).then(setSessionDataAndOpenApp);
} else {
setSessionDataAndOpenApp();
}

return setSessionDataAndOpenApp;
return route as Route;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/perf-test/ReportScreen.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ jest.mock('@react-navigation/native', () => {
useFocusEffect: jest.fn(),
useIsFocused: () => true,
useRoute: () => jest.fn(),
// eslint-disable-next-line @typescript-eslint/naming-convention
UNSTABLE_usePreventRemove: () => jest.fn(),
useNavigation: () => ({
navigate: jest.fn(),
addListener: () => jest.fn(),
Expand Down Expand Up @@ -233,6 +231,7 @@ test('[ReportScreen] should render ReportScreen', async () => {
...reportCollectionDataSet,
...reportActionsCollectionDataSet,
});

await measureRenders(
<ReportScreenWrapper
navigation={navigation}
Expand Down Expand Up @@ -312,6 +311,7 @@ test('[ReportScreen] should render report list', async () => {
...reportCollectionDataSet,
...reportActionsCollectionDataSet,
});

await measureRenders(
<ReportScreenWrapper
navigation={navigation}
Expand Down
2 changes: 0 additions & 2 deletions tests/perf-test/SearchRouter.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ jest.mock('@react-navigation/native', () => {
useFocusEffect: jest.fn(),
useIsFocused: () => true,
useRoute: () => jest.fn(),
// eslint-disable-next-line @typescript-eslint/naming-convention
UNSTABLE_usePreventRemove: () => jest.fn(),
useNavigation: () => ({
navigate: jest.fn(),
addListener: () => jest.fn(),
Expand Down

0 comments on commit cd9776c

Please sign in to comment.