Skip to content

Commit

Permalink
[SignIn Page] New user flow (#145)
Browse files Browse the repository at this point in the history
Co-authored-by: war-in <war-in@users.noreply.github.com>
  • Loading branch information
war-in and war-in authored Nov 28, 2024
1 parent ecb93e2 commit 6f926fe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/libs/HybridApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry<HybridApp>, tryN
}

Log.info('[HybridApp] Closing NewDot as sign-in to OldDot succeeded');
NativeModules.HybridAppModule.closeReactNativeApp(false, false);
NativeModules.HybridAppModule.closeReactNativeApp(false, true);
}

if (
Expand Down
14 changes: 11 additions & 3 deletions src/libs/actions/HybridApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,27 @@ function startOldDotSignIn(autoGeneratedLogin: string, autoGeneratedPassword: st
oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.STARTED,
});

NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword);
NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, false, '', '', '', '');
}

/*
* Retries sign-in on OldDot side
*/
function retryOldDotSignInAfterFailure(autoGeneratedLogin: string, autoGeneratedPassword: string) {
function retryOldDotSignInAfterFailure(
autoGeneratedLogin: string,
autoGeneratedPassword: string,
isNewUser: boolean,
authToken: string,
encryptedAuthToken: string,
email: string,
policyID: string,
) {
Onyx.merge(ONYXKEYS.HYBRID_APP, {
oldDotSignInError: null,
oldDotSignInState: CONST.HYBRID_APP_SIGN_IN_STATE.RETRYING_AFTER_FAILURE,
});

NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword);
NativeModules.HybridAppModule.signInToOldDot(autoGeneratedLogin, autoGeneratedPassword, isNewUser, authToken, encryptedAuthToken, email, policyID);
}

/*
Expand Down
35 changes: 27 additions & 8 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import useWaitForNavigation from '@hooks/useWaitForNavigation';
import {resetExitSurveyForm} from '@libs/actions/ExitSurvey';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getCurrentUserEmail} from '@libs/Network/NetworkStore';
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
import * as UserUtils from '@libs/UserUtils';
import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils';
Expand All @@ -42,7 +43,6 @@ import * as HybridAppActions from '@userActions/HybridApp';
import * as Link from '@userActions/Link';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as Session from '@userActions/Session';
import {signOutAndRedirectToSignIn} from '@userActions/Session';
import * as Wallet from '@userActions/Wallet';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -91,6 +91,8 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP);
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS);
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);

const network = useNetwork();
const theme = useTheme();
Expand Down Expand Up @@ -262,12 +264,15 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
return;
}

if (credentials?.autoGeneratedLogin && credentials?.autoGeneratedPassword) {
HybridAppActions.retryOldDotSignInAfterFailure(credentials.autoGeneratedLogin, credentials.autoGeneratedPassword);
} else {
signOutAndRedirectToSignIn(false, false, false);
HybridAppActions.resetStateAfterSignOut();
}
HybridAppActions.retryOldDotSignInAfterFailure(
credentials?.autoGeneratedLogin ?? '',
credentials?.autoGeneratedPassword ?? '',
!credentials?.autoGeneratedLogin,
session?.authToken ?? '',
session?.encryptedAuthToken ?? '',
getCurrentUserEmail() ?? '',
activePolicyID ?? '',
);
},
}
: {
Expand Down Expand Up @@ -307,7 +312,21 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
},
],
};
}, [styles.pt4, styles.popoverMenuIcon, hybridApp, theme.spinner, credentials?.autoGeneratedLogin, credentials?.autoGeneratedPassword, setInitialURL, signOut, shouldOpenBookACall]);
}, [
styles.pt4,
styles.popoverMenuIcon,
hybridApp?.oldDotSignInState,
hybridApp?.oldDotSignInError,
theme.spinner,
credentials?.autoGeneratedLogin,
credentials?.autoGeneratedPassword,
session?.authToken,
session?.encryptedAuthToken,
activePolicyID,
setInitialURL,
shouldOpenBookACall,
signOut,
]);

/**
* Retuns JSX.Element with menu items
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 @@ -9,7 +9,7 @@ type HybridAppModule = {
closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void;
completeOnboarding: (status: boolean) => void;
switchAccount: (newDotCurrentAccount: string) => void;
signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string) => void;
signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, isNewUser: boolean, authToken: string, encryptedAuthToken: string, email: string, policyID: string) => void;
signOutFromOldDot: () => void;
exitApp: () => void;
};
Expand Down

0 comments on commit 6f926fe

Please sign in to comment.