Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inbox from briefly displaying when creating WS from selector and … #52092

Closed
4 changes: 3 additions & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,9 @@ type TransactionDuplicateNavigatorParamList = {
};

type LeftModalNavigatorParamList = {
[SCREENS.LEFT_MODAL.WORKSPACE_SWITCHER]: undefined;
[SCREENS.LEFT_MODAL.WORKSPACE_SWITCHER]: {
isHomeResetRequired?: string;
};
};

type RightModalNavigatorParamList = {
Expand Down
6 changes: 4 additions & 2 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Issue - https://github.com/Expensify/App/issues/26719
import {Str} from 'expensify-common';
import type {AppStateStatus} from 'react-native';
import {AppState} from 'react-native';
import {AppState, InteractionManager} from 'react-native';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -378,7 +378,9 @@ function createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail = '', po
Navigation.goBack();
}
savePolicyDraftByNewWorkspace(policyID, policyName, policyOwnerEmail, makeMeAdmin);
Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID, backTo));
InteractionManager.runAfterInteractions(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the RCA but using runAfterInteractions is not a good idea to me (same as using setTimeout). This bug is also not related to the original one so we can ignore it for now and create another issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID, backTo));
});
})
.then(endSignOnTransition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Illustrations from '@components/Icon/Illustrations';
import Section, {CARD_LAYOUT} from '@components/Section';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as App from '@userActions/App';

function WorkspaceCardCreateAWorkspace() {
Expand All @@ -21,7 +22,8 @@ function WorkspaceCardCreateAWorkspace() {
>
<Button
onPress={() => {
App.createWorkspaceWithPolicyDraftAndNavigateToIt();
const activeRoute = Navigation.getActiveRouteWithoutParams();
App.createWorkspaceWithPolicyDraftAndNavigateToIt('', '', false, false, activeRoute);
}}
text={translate('workspace.emptyWorkspace.createAWorkspaceCTA')}
style={styles.mt5}
Expand Down
26 changes: 22 additions & 4 deletions src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand All @@ -15,13 +16,16 @@ import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {LeftModalNavigatorParamList} from '@libs/Navigation/types';
import * as PolicyUtils from '@libs/PolicyUtils';
import {sortWorkspacesBySelected} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {getWorkspacesBrickRoads, getWorkspacesUnreadStatuses} from '@libs/WorkspacesSettingsUtils';
import type {BrickRoad} from '@libs/WorkspacesSettingsUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import WorkspaceCardCreateAWorkspace from './WorkspaceCardCreateAWorkspace';

Expand All @@ -33,8 +37,9 @@ type WorkspaceListItem = {
} & ListItem;

const WorkspaceCardCreateAWorkspaceInstance = <WorkspaceCardCreateAWorkspace />;
type WorkspaceSwitcherPageProps = StackScreenProps<LeftModalNavigatorParamList, typeof SCREENS.LEFT_MODAL.WORKSPACE_SWITCHER>;

function WorkspaceSwitcherPage() {
function WorkspaceSwitcherPage({route}: WorkspaceSwitcherPageProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {isOffline} = useNetwork();
Expand All @@ -49,6 +54,7 @@ function WorkspaceSwitcherPage() {

const brickRoadsForPolicies = useMemo(() => getWorkspacesBrickRoads(reports, policies, reportActions), [reports, policies, reportActions]);
const unreadStatusesForPolicies = useMemo(() => getWorkspacesUnreadStatuses(reports), [reports]);
const isHomeResetRequired = route?.params?.isHomeResetRequired === 'true';

const getIndicatorTypeForPolicy = useCallback(
(policyId?: string) => {
Expand Down Expand Up @@ -90,12 +96,17 @@ function WorkspaceSwitcherPage() {
const {policyID} = option;

setActiveWorkspaceID(policyID);
Navigation.goBack();
if (isHomeResetRequired) {
Navigation.resetToHome();
Navigation.navigate(ROUTES.HOME);
} else {
Navigation.goBack();
}
if (policyID !== activeWorkspaceID) {
Navigation.navigateWithSwitchPolicyID({policyID});
}
},
[activeWorkspaceID, setActiveWorkspaceID],
[activeWorkspaceID, isHomeResetRequired, setActiveWorkspaceID],
);

const usersWorkspaces = useMemo<WorkspaceListItem[]>(() => {
Expand Down Expand Up @@ -164,7 +175,14 @@ function WorkspaceSwitcherPage() {
<>
<HeaderWithBackButton
title={translate('workspace.switcher.headerTitle')}
onBackButtonPress={Navigation.goBack}
onBackButtonPress={() => {
if (isHomeResetRequired) {
Navigation.resetToHome();
Navigation.navigate(ROUTES.HOME);
} else {
Navigation.goBack();
}
}}
/>
<View style={[styles.ph5, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.mb1]}>
<Text
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
title={policyName}
onBackButtonPress={() => {
if (route.params?.backTo) {
Navigation.resetToHome();
Navigation.isNavigationReady().then(() => Navigation.navigate(route.params?.backTo as Route));
Navigation.isNavigationReady().then(() => Navigation.navigate(`${route.params?.backTo}?isHomeResetRequired=true` as Route));
} else {
Navigation.dismissModal();
}
Expand Down
Loading