Skip to content

Commit

Permalink
Merge pull request #47856 from software-mansion-labs/war-in/proceed-w…
Browse files Browse the repository at this point in the history
…ith-closing-ND-after-timeout

[HybridApp] Disable ExitSurvey in HybridApp
  • Loading branch information
AndrewGable authored Aug 30, 2024
2 parents fa8fa1a + 75c9258 commit eb57e57
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 41 deletions.
4 changes: 0 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ const ONYXKEYS = {
/** Is report data loading? */
IS_LOADING_APP: 'isLoadingApp',

/** Is the user in the process of switching to OldDot? */
IS_SWITCHING_TO_OLD_DOT: 'isSwitchingToOldDot',

/** Is the test tools modal open? */
IS_TEST_TOOLS_MODAL_OPEN: 'isTestToolsModalOpen',

Expand Down Expand Up @@ -862,7 +859,6 @@ type OnyxValuesMapping = {
[ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean;
[ONYXKEYS.APP_PROFILING_IN_PROGRESS]: boolean;
[ONYXKEYS.IS_LOADING_APP]: boolean;
[ONYXKEYS.IS_SWITCHING_TO_OLD_DOT]: boolean;
[ONYXKEYS.WALLET_TRANSFER]: OnyxTypes.WalletTransfer;
[ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID]: string;
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: boolean;
Expand Down
1 change: 0 additions & 1 deletion src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ const SIDE_EFFECT_REQUEST_COMMANDS = {
RECONNECT_APP: 'ReconnectApp',
ADD_PAYMENT_CARD_GBP: 'AddPaymentCardGBP',
REVEAL_EXPENSIFY_CARD_DETAILS: 'RevealExpensifyCardDetails',
SWITCH_TO_OLD_DOT: 'SwitchToOldDot',
TWO_FACTOR_AUTH_VALIDATE: 'TwoFactorAuth_Validate',
CONNECT_AS_DELEGATE: 'ConnectAsDelegate',
DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate',
Expand Down
21 changes: 4 additions & 17 deletions src/libs/actions/ExitSurvey.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import {WRITE_COMMANDS} from '@libs/API/types';
import ONYXKEYS from '@src/ONYXKEYS';
import REASON_INPUT_IDS from '@src/types/form/ExitSurveyReasonForm';
import type {ExitReason} from '@src/types/form/ExitSurveyReasonForm';
Expand Down Expand Up @@ -31,19 +31,6 @@ function saveResponse(response: string) {
*/
function switchToOldDot() {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.IS_SWITCHING_TO_OLD_DOT,
value: true,
},
];

const finallyData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.IS_SWITCHING_TO_OLD_DOT,
value: false,
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.FORMS.EXIT_SURVEY_REASON_FORM,
Expand All @@ -67,13 +54,13 @@ function switchToOldDot() {
];

// eslint-disable-next-line rulesdir/no-api-side-effects-method
return API.makeRequestWithSideEffects(
SIDE_EFFECT_REQUEST_COMMANDS.SWITCH_TO_OLD_DOT,
API.write(
WRITE_COMMANDS.SWITCH_TO_OLD_DOT,
{
reason: exitReason,
surveyResponse: exitSurveyResponse,
},
{optimisticData, finallyData},
{optimisticData},
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess
if (!isAnonymousUser()) {
// In the HybridApp, we want the Old Dot to handle the sign out process
if (NativeModules.HybridAppModule && killHybridApp) {
NativeModules.HybridAppModule.closeReactNativeApp(true);
NativeModules.HybridAppModule.closeReactNativeApp(true, false);
return;
}
// We'll only call signOut if we're not stashing the session and this is not a supportal session,
Expand Down
18 changes: 3 additions & 15 deletions src/pages/settings/ExitSurvey/ExitSurveyConfirmPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useEffect} from 'react';
import {NativeModules, View} from 'react-native';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Icon from '@components//Icon';
Expand Down Expand Up @@ -28,12 +28,11 @@ import ExitSurveyOffline from './ExitSurveyOffline';

type ExitSurveyConfirmPageOnyxProps = {
exitReason?: ExitReason | null;
isLoading: OnyxEntry<boolean>;
};

type ExitSurveyConfirmPageProps = ExitSurveyConfirmPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.EXIT_SURVEY.CONFIRM>;

function ExitSurveyConfirmPage({exitReason, isLoading, route, navigation}: ExitSurveyConfirmPageProps) {
function ExitSurveyConfirmPage({exitReason, route, navigation}: ExitSurveyConfirmPageProps) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const styles = useThemeStyles();
Expand Down Expand Up @@ -84,18 +83,10 @@ function ExitSurveyConfirmPage({exitReason, isLoading, route, navigation}: ExitS
large
text={translate('exitSurvey.goToExpensifyClassic')}
onPress={() => {
const promise = ExitSurvey.switchToOldDot();
if (NativeModules.HybridAppModule) {
promise.then(() => {
Navigation.resetToHome();
NativeModules.HybridAppModule.closeReactNativeApp(false);
});
return;
}
ExitSurvey.switchToOldDot();
Navigation.dismissModal();
Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX);
}}
isLoading={isLoading ?? false}
isDisabled={isOffline}
/>
</FixedFooter>
Expand All @@ -110,7 +101,4 @@ export default withOnyx<ExitSurveyConfirmPageProps, ExitSurveyConfirmPageOnyxPro
key: ONYXKEYS.FORMS.EXIT_SURVEY_REASON_FORM,
selector: (value: OnyxEntry<ExitSurveyReasonForm>) => value?.[EXIT_SURVEY_REASON_INPUT_IDS.REASON] ?? null,
},
isLoading: {
key: ONYXKEYS.IS_SWITCHING_TO_OLD_DOT,
},
})(ExitSurveyConfirmPage);
12 changes: 10 additions & 2 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useRoute} from '@react-navigation/native';
import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent, ScrollView as RNScrollView, ScrollViewProps, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import {NativeModules, View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -144,7 +144,15 @@ function InitialSettingsPage({userWallet, bankAccountList, fundList, walletTerms
{
translationKey: 'exitSurvey.goToExpensifyClassic',
icon: Expensicons.ExpensifyLogoNew,
routeName: ROUTES.SETTINGS_EXIT_SURVEY_REASON,
...(NativeModules.HybridAppModule
? {
action: () => {
NativeModules.HybridAppModule.closeReactNativeApp(false, true);
},
}
: {
routeName: ROUTES.SETTINGS_EXIT_SURVEY_REASON,
}),
},
{
translationKey: 'common.profile',
Expand Down
2 changes: 1 addition & 1 deletion src/types/modules/react-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {EnvironmentCheckerModule} from '@libs/Environment/betaChecker/types
import type StartupTimer from '@libs/StartupTimer/types';

type HybridAppModule = {
closeReactNativeApp: (shouldSignOut: boolean) => void;
closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void;
completeOnboarding: (status: boolean) => void;
exitApp: () => void;
};
Expand Down

0 comments on commit eb57e57

Please sign in to comment.