diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index b75fb713a6b8..d31da53304f6 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -91,6 +91,7 @@ const WRITE_COMMANDS = { REQUEST_NEW_VALIDATE_CODE: 'RequestNewValidateCode', SIGN_IN_WITH_APPLE: 'SignInWithApple', SIGN_IN_WITH_GOOGLE: 'SignInWithGoogle', + SIGN_IN_USER: 'SigninUser', SIGN_IN_USER_WITH_LINK: 'SigninUserWithLink', SEARCH: 'Search', REQUEST_UNLINK_VALIDATION_LINK: 'RequestUnlinkValidationLink', @@ -516,6 +517,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.REQUEST_NEW_VALIDATE_CODE]: Parameters.RequestNewValidateCodeParams; [WRITE_COMMANDS.SIGN_IN_WITH_APPLE]: Parameters.BeginAppleSignInParams; [WRITE_COMMANDS.SIGN_IN_WITH_GOOGLE]: Parameters.BeginGoogleSignInParams; + [WRITE_COMMANDS.SIGN_IN_USER]: SignInUserParams; [WRITE_COMMANDS.SIGN_IN_USER_WITH_LINK]: Parameters.SignInUserWithLinkParams; [WRITE_COMMANDS.REQUEST_UNLINK_VALIDATION_LINK]: Parameters.RequestUnlinkValidationLinkParams; [WRITE_COMMANDS.UNLINK_LOGIN]: Parameters.UnlinkLoginParams; @@ -1027,7 +1029,6 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate', COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding', CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop', - SIGN_IN_USER: 'SigninUser', } as const; type SideEffectRequestCommand = ValueOf; @@ -1048,7 +1049,6 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.DISCONNECT_AS_DELEGATE]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject; [SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams; - [SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER]: SignInUserParams; }; type ApiRequestCommandParameters = WriteCommandParameters & ReadCommandParameters & SideEffectRequestCommandParameters; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 9cc89a8d896b..4d12d0773365 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -423,6 +423,16 @@ function signInAttemptState(): OnyxData { */ function beginSignIn(email: string) { const {optimisticData, successData, failureData} = signInAttemptState(); + // this data is mocked and should be removed before the merge + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.NVP_TRYNEWDOT, + value: { + classicRedirect: { + dismissed: true, + }, + }, + }); const params: BeginSignInParams = {email}; @@ -618,17 +628,7 @@ function signIn(validateCode: string, twoFactorAuthCode?: string) { params.validateCode = validateCode || credentials.validateCode; } - // eslint-disable-next-line rulesdir/no-api-side-effects-method - API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER, params, { - optimisticData, - successData, - failureData, - }).then((response) => { - if (!response) { - return; - } - Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, {classicRedirect: {dismissed: !response.tryNewDot}}); - }); + API.write(WRITE_COMMANDS.SIGN_IN_USER, params, {optimisticData, successData, failureData}); }); } diff --git a/src/pages/signin/ChooseSSOOrMagicCode.tsx b/src/pages/signin/ChooseSSOOrMagicCode.tsx index 2551fe34a21b..7ebe90d2eafa 100644 --- a/src/pages/signin/ChooseSSOOrMagicCode.tsx +++ b/src/pages/signin/ChooseSSOOrMagicCode.tsx @@ -1,5 +1,5 @@ import React, {useEffect} from 'react'; -import {Keyboard, View} from 'react-native'; +import {Keyboard, NativeModules, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import Button from '@components/Button'; @@ -12,6 +12,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as HybridAppActions from '@userActions/HybridApp'; import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -61,6 +62,7 @@ function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: Choos text={translate('samlSignIn.useSingleSignOn')} isLoading={account?.isLoading} onPress={() => { + HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED); Navigation.navigate(ROUTES.SAML_SIGN_IN); }} /> @@ -83,7 +85,14 @@ function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: Choos }} /> {!!account && !isEmptyObject(account.errors) && } - Session.clearSignInData()} /> + { + if (NativeModules.HybridAppModule) { + HybridAppActions.resetSignInFlow(); + } + Session.clearSignInData(); + }} + /> diff --git a/src/pages/signin/SAMLSignInPage/index.native.tsx b/src/pages/signin/SAMLSignInPage/index.native.tsx index 3b9bc456a680..d183c936cd2e 100644 --- a/src/pages/signin/SAMLSignInPage/index.native.tsx +++ b/src/pages/signin/SAMLSignInPage/index.native.tsx @@ -1,4 +1,5 @@ import React, {useCallback, useState} from 'react'; +import {NativeModules} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import WebView from 'react-native-webview'; import type {WebViewNativeEvent} from 'react-native-webview/lib/WebViewTypes'; @@ -9,6 +10,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import getPlatform from '@libs/getPlatform'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; +import * as HybridAppActions from '@userActions/HybridApp'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -58,6 +60,9 @@ function SAMLSignInPage() { { + if (NativeModules.HybridAppModule) { + HybridAppActions.resetSignInFlow(); + } Session.clearSignInData(); Navigation.isNavigationReady().then(() => { Navigation.goBack();