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: inconsistent Navigation After Creating Workspace #46939

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ const ROUTES = {
WORKSPACE_NEW_ROOM: 'workspace/new-room',
WORKSPACE_INITIAL: {
route: 'settings/workspaces/:policyID',
getRoute: (policyID: string) => `settings/workspaces/${policyID}` as const,
getRoute: (policyID: string, backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const,
},
WORKSPACE_INVITE: {
route: 'settings/workspaces/:policyID/invite',
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ type TravelNavigatorParamList = {
type FullScreenNavigatorParamList = {
[SCREENS.WORKSPACE.INITIAL]: {
policyID: string;
backTo?: string;
};
[SCREENS.WORKSPACE.PROFILE]: {
policyID: string;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ function endSignOnTransition() {
* @param [policyName] Optional, custom policy name we will use for created workspace
* @param [transitionFromOldDot] Optional, if the user is transitioning from old dot
* @param [makeMeAdmin] Optional, leave the calling account as an admin on the policy
* @param [backTo] An optional return path. If provided, it will be URL-encoded and appended to the resulting URL.
*/
function createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail = '', policyName = '', transitionFromOldDot = false, makeMeAdmin = false) {
function createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail = '', policyName = '', transitionFromOldDot = false, makeMeAdmin = false, backTo = '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll be nice to add param comment for backTo to explain how it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eh2077 i updated

const policyID = Policy.generatePolicyID();
Policy.createDraftInitialWorkspace(policyOwnerEmail, policyName, policyID, makeMeAdmin);

Expand All @@ -361,7 +362,7 @@ function createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail = '', po
// We must call goBack() to remove the /transition route from history
Navigation.goBack();
}
Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID));
Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID, backTo));
})
.then(endSignOnTransition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import Navigation from '@libs/Navigation/Navigation';
import * as App from '@userActions/App';
import CONST from '@src/CONST';

Expand All @@ -32,7 +33,8 @@ function WorkspacesSectionHeader() {
accessible={false}
role={CONST.ROLE.BUTTON}
onPress={() => {
interceptAnonymousUser(() => App.createWorkspaceWithPolicyDraftAndNavigateToIt());
const activeRoute = Navigation.getActiveRouteWithoutParams();
interceptAnonymousUser(() => App.createWorkspaceWithPolicyDraftAndNavigateToIt('', '', false, false, activeRoute));
}}
>
{({hovered}) => (
Expand Down
10 changes: 9 additions & 1 deletion src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as ReimbursementAccount from '@userActions/ReimbursementAccount';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
Expand Down Expand Up @@ -393,7 +394,14 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc
>
<HeaderWithBackButton
title={policyName}
onBackButtonPress={Navigation.dismissModal}
onBackButtonPress={() => {
if (route.params?.backTo) {
Navigation.resetToHome();
Navigation.isNavigationReady().then(() => Navigation.navigate(route.params?.backTo as Route));
} else {
Navigation.dismissModal();
}
}}
policyAvatar={policyAvatar}
style={styles.headerBarDesktopHeight}
/>
Expand Down
Loading