Skip to content

Commit

Permalink
Merge pull request #35410 from Expensify/dsilva_addSupportalNavigation
Browse files Browse the repository at this point in the history
Add supportal navigation
  • Loading branch information
roryabraham authored Mar 4, 2024
2 parents 780e2ac + 205cb7f commit 2a89743
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 126 deletions.
9 changes: 5 additions & 4 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const CONST = {
FAILED: 'failed',
},

AUTH_TOKEN_TYPES: {
ANONYMOUS: 'anonymousAccount',
SUPPORT: 'support',
},

AVATAR_MAX_ATTACHMENT_SIZE: 6291456,

AVATAR_ALLOWED_EXTENSIONS: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg'],
Expand Down Expand Up @@ -3341,10 +3346,6 @@ const CONST = {
SESSION_STORAGE_KEYS: {
INITIAL_URL: 'INITIAL_URL',
},

AUTH_TOKEN_TYPE: {
ANONYMOUS: 'anonymousAccount',
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const ONYXKEYS = {

/** Credentials to authenticate the user */
CREDENTIALS: 'credentials',
STASHED_CREDENTIALS: 'stashedCredentials',

// Contains loading data for the IOU feature (MoneyRequestModal, IOUDetail, & MoneyRequestPreview Components)
IOU: 'iou',
Expand Down Expand Up @@ -102,6 +103,7 @@ const ONYXKEYS = {

/** Information about the current session (authToken, accountID, email, loading, error) */
SESSION: 'session',
STASHED_SESSION: 'stashedSession',
BETAS: 'betas',

/** NVP keys
Expand Down Expand Up @@ -491,6 +493,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.PERSISTED_REQUESTS]: OnyxTypes.Request[];
[ONYXKEYS.CURRENT_DATE]: string;
[ONYXKEYS.CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.STASHED_CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.IOU]: OnyxTypes.IOU;
[ONYXKEYS.MODAL]: OnyxTypes.Modal;
[ONYXKEYS.NETWORK]: OnyxTypes.Network;
Expand All @@ -509,6 +512,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.USER_LOCATION]: OnyxTypes.UserLocation;
[ONYXKEYS.LOGIN_LIST]: OnyxTypes.LoginList;
[ONYXKEYS.SESSION]: OnyxTypes.Session;
[ONYXKEYS.STASHED_SESSION]: OnyxTypes.Session;
[ONYXKEYS.BETAS]: OnyxTypes.Beta[];
[ONYXKEYS.NVP_PRIORITY_MODE]: ValueOf<typeof CONST.PRIORITY_MODE>;
[ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE]: OnyxTypes.BlockedFromConcierge;
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ export default {
},
security: 'Security',
signOut: 'Sign out',
restoreStashed: 'Restore stashed login',
signOutConfirmationText: "You'll lose any offline changes if you sign-out.",
versionLetter: 'v',
readTheTermsAndPrivacy: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ export default {
logSizeTooLarge: ({size}: LogSizeParams) => `El tamaño del registro excede el límite de ${size} MB. Utilice "Guardar registro" para descargar el archivo de registro.`,
},
security: 'Seguridad',
restoreStashed: 'Restablecer login guardado',
signOut: 'Desconectar',
signOutConfirmationText: 'Si cierras sesión perderás los cambios hechos mientras estabas desconectado',
versionLetter: 'v',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/API/parameters/SignInWithSupportAuthTokenParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type SignInWithSupportAuthTokenParams = {
authToken: string;
};

export default SignInWithSupportAuthTokenParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type {default as SendPerformanceTimingParams} from './SendPerformanceTimi
export type {default as SetContactMethodAsDefaultParams} from './SetContactMethodAsDefaultParams';
export type {default as SignInUserWithLinkParams} from './SignInUserWithLinkParams';
export type {default as SignInWithShortLivedAuthTokenParams} from './SignInWithShortLivedAuthTokenParams';
export type {default as SignInWithSupportAuthTokenParams} from './SignInWithSupportAuthTokenParams';
export type {default as UnlinkLoginParams} from './UnlinkLoginParams';
export type {default as UpdateAutomaticTimezoneParams} from './UpdateAutomaticTimezoneParams';
export type {default as UpdateChatPriorityModeParams} from './UpdateChatPriorityModeParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ const READ_COMMANDS = {
OPEN_ENABLE_PAYMENTS_PAGE: 'OpenEnablePaymentsPage',
BEGIN_SIGNIN: 'BeginSignIn',
SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN: 'SignInWithShortLivedAuthToken',
SIGN_IN_WITH_SUPPORT_AUTH_TOKEN: 'SignInWithSupportAuthToken',
OPEN_WORKSPACE_REIMBURSE_VIEW: 'OpenWorkspaceReimburseView',
OPEN_WORKSPACE: 'OpenWorkspace',
OPEN_WORKSPACE_MEMBERS_PAGE: 'OpenWorkspaceMembersPage',
Expand Down Expand Up @@ -369,6 +370,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_ENABLE_PAYMENTS_PAGE]: EmptyObject;
[READ_COMMANDS.BEGIN_SIGNIN]: Parameters.BeginSignInParams;
[READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN]: Parameters.SignInWithShortLivedAuthTokenParams;
[READ_COMMANDS.SIGN_IN_WITH_SUPPORT_AUTH_TOKEN]: Parameters.SignInWithSupportAuthTokenParams;
[READ_COMMANDS.OPEN_WORKSPACE_REIMBURSE_VIEW]: Parameters.OpenWorkspaceReimburseViewParams;
[READ_COMMANDS.OPEN_WORKSPACE]: Parameters.OpenWorkspaceParams;
[READ_COMMANDS.OPEN_WORKSPACE_MEMBERS_PAGE]: Parameters.OpenWorkspaceMembersPageParams;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ function AuthScreens({session, lastOpenedPublicRoomID, isUsingMemoryOnlyKeys = f
const shouldGetAllData = !!isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession();
// Sign out the current user if we're transitioning with a different user
const isTransitioning = currentUrl.includes(ROUTES.TRANSITION_BETWEEN_APPS);
const isSupportalTransition = currentUrl.includes('authTokenType=support');
if (isLoggingInAsNewUser && isTransitioning) {
Session.signOutAndRedirectToSignIn();
Session.signOutAndRedirectToSignIn(false, isSupportalTransition);
return;
}

Expand Down
21 changes: 8 additions & 13 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,27 @@ type BottomTabNavigatorParamList = {
[SCREENS.WORKSPACE.INITIAL]: undefined;
};

type PublicScreensParamList = {
type SharedScreensParamList = {
[NAVIGATORS.BOTTOM_TAB_NAVIGATOR]: NavigatorScreenParams<BottomTabNavigatorParamList>;
[SCREENS.TRANSITION_BETWEEN_APPS]: {
email?: string;
accountID?: number;
error?: string;
shortLivedAuthToken?: string;
shortLivedToken?: string;
authTokenType?: ValueOf<typeof CONST.AUTH_TOKEN_TYPES>;
exitTo?: Routes | HybridAppRoute;
shouldForceLogin: string;
domain?: Routes;
};
[SCREENS.VALIDATE_LOGIN]: {
accountID: string;
validateCode: string;
exitTo?: Routes | HybridAppRoute;
};
};

type PublicScreensParamList = SharedScreensParamList & {
[SCREENS.UNLINK_LOGIN]: {
accountID?: string;
validateCode?: string;
Expand All @@ -543,19 +549,8 @@ type PublicScreensParamList = {
[SCREENS.SAML_SIGN_IN]: undefined;
};

type AuthScreensParamList = {
[NAVIGATORS.BOTTOM_TAB_NAVIGATOR]: NavigatorScreenParams<BottomTabNavigatorParamList>;
type AuthScreensParamList = SharedScreensParamList & {
[NAVIGATORS.CENTRAL_PANE_NAVIGATOR]: NavigatorScreenParams<CentralPaneNavigatorParamList>;
[SCREENS.VALIDATE_LOGIN]: {
accountID: string;
validateCode: string;
};
[SCREENS.TRANSITION_BETWEEN_APPS]: {
shouldForceLogin: string;
email: string;
shortLivedAuthToken: string;
exitTo: string;
};
[SCREENS.CONCIERGE]: undefined;
[SCREENS.REPORT_ATTACHMENTS]: {
reportID: string;
Expand Down
17 changes: 7 additions & 10 deletions src/libs/Network/NetworkStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type Credentials from '@src/types/onyx/Credentials';

let credentials: Credentials | null = null;
let authToken: string | null = null;
let supportAuthToken: string | null = null;
let authTokenType: ValueOf<typeof CONST.AUTH_TOKEN_TYPES> | null;
let currentUserEmail: string | null = null;
let offline = false;
let authenticating = false;
Expand Down Expand Up @@ -51,7 +53,7 @@ Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
authToken = val?.authToken ?? null;
supportAuthToken = val?.supportAuthToken ?? null;
authTokenType = val?.authTokenType ?? null;
currentUserEmail = val?.email ?? null;
checkRequiredData();
},
Expand Down Expand Up @@ -99,12 +101,8 @@ function isSupportRequest(command: string): boolean {
return [WRITE_COMMANDS.OPEN_APP, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT].some((cmd) => cmd === command);
}

function getSupportAuthToken(): string | null {
return supportAuthToken;
}

function setSupportAuthToken(newSupportAuthToken: string) {
supportAuthToken = newSupportAuthToken;
function isSupportAuthToken(): boolean {
return authTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT;
}

function setAuthToken(newAuthToken: string | null) {
Expand Down Expand Up @@ -139,7 +137,6 @@ export {
setIsAuthenticating,
getCredentials,
checkRequiredData,
getSupportAuthToken,
setSupportAuthToken,
isSupportAuthToken,
isSupportRequest,
};
8 changes: 2 additions & 6 deletions src/libs/Network/enhanceParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ function isAuthTokenRequired(command: string): boolean {
export default function enhanceParameters(command: string, parameters: Record<string, unknown>): Record<string, unknown> {
const finalParameters = {...parameters};

if (isAuthTokenRequired(command)) {
if (NetworkStore.getSupportAuthToken() && NetworkStore.isSupportRequest(command)) {
finalParameters.authToken = NetworkStore.getSupportAuthToken();
} else if (!parameters.authToken) {
finalParameters.authToken = NetworkStore.getAuthToken();
}
if (isAuthTokenRequired(command) && !parameters.authToken) {
finalParameters.authToken = NetworkStore.getAuthToken();
}

finalParameters.referer = CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ Onyx.connect({

currentUserEmail = value.email;
currentUserAccountID = value.accountID;
isAnonymousUser = value.authTokenType === CONST.AUTH_TOKEN_TYPE.ANONYMOUS;
isAnonymousUser = value.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
currentUserPrivateDomain = isEmailPublicDomain(currentUserEmail ?? '') ? '' : Str.extractEmailDomain(currentUserEmail ?? '');
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function makeXHR(request: Request): Promise<Response | void> {
return NetworkStore.hasReadRequiredDataFromStorage().then((): Promise<Response | void> => {
// If we're using the Supportal token and this is not a Supportal request
// let's just return a promise that will resolve itself.
if (NetworkStore.getSupportAuthToken() && !NetworkStore.isSupportRequest(request.command)) {
if (NetworkStore.isSupportAuthToken() && !NetworkStore.isSupportRequest(request.command)) {
return new Promise<void>((resolve) => {
resolve();
});
Expand Down
Loading

0 comments on commit 2a89743

Please sign in to comment.