From a27b365ec21320343fd4a9921e17ebcf543f9d29 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 2 Oct 2023 09:52:48 +0700 Subject: [PATCH 1/7] fix clicking back button bring back the workspace --- src/libs/actions/App.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index b8be35aa19196..a493dd9b74d9e 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -325,9 +325,11 @@ function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = fal } if (shouldNavigateToAdminChat) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)); + Navigation.dismissModal(adminsChatReportID); } - + }) + .then(() => Navigation.isNavigationReady()) + .then(() => { Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); }) .then(endSignOnTransition); From a803a71b9ecd22bb274020655a72bde5a76012d2 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 2 Oct 2023 18:55:58 +0700 Subject: [PATCH 2/7] fix refactor logic then --- src/libs/actions/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index a493dd9b74d9e..5c9a0c2a86284 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -327,8 +327,8 @@ function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = fal if (shouldNavigateToAdminChat) { Navigation.dismissModal(adminsChatReportID); } + return Navigation.isNavigationReady(); }) - .then(() => Navigation.isNavigationReady()) .then(() => { Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); }) From 4fe4ff020c80b21bcca6b00131fd2e553fb55075 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 3 Oct 2023 00:17:04 +0700 Subject: [PATCH 3/7] fix handle case create workspace without openning modal --- src/libs/actions/App.js | 17 +++++++++++++++-- .../FloatingActionButtonAndPopover.js | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 5c9a0c2a86284..fbea58b17efec 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -313,8 +313,17 @@ function endSignOnTransition() { * @param {String} [policyName] Optional, custom policy name we will use for created workspace * @param {Boolean} [transitionFromOldDot] Optional, if the user is transitioning from old dot * @param {Boolean} [shouldNavigateToAdminChat] Optional, navigate to the #admin room after creation + * @param {Boolean} [isThereModalToDismiss] Optional, if there is a modal to dismiss + */ -function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false, shouldNavigateToAdminChat = true) { +function createWorkspaceAndNavigateToIt( + policyOwnerEmail = '', + makeMeAdmin = false, + policyName = '', + transitionFromOldDot = false, + shouldNavigateToAdminChat = true, + isThereModalToDismiss = true, +) { const policyID = Policy.generatePolicyID(); const adminsChatReportID = Policy.createWorkspace(policyOwnerEmail, makeMeAdmin, policyName, policyID); Navigation.isNavigationReady() @@ -325,7 +334,11 @@ function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = fal } if (shouldNavigateToAdminChat) { - Navigation.dismissModal(adminsChatReportID); + if (isThereModalToDismiss) { + Navigation.dismissModal(adminsChatReportID); + } else { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)); + } } return Navigation.isNavigationReady(); }) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index e9ede2c9a89ab..bf703715848f7 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -216,7 +216,7 @@ function FloatingActionButtonAndPopover(props) { iconHeight: 40, text: props.translate('workspace.new.newWorkspace'), description: props.translate('workspace.new.getTheExpensifyCardAndMore'), - onSelected: () => interceptAnonymousUser(() => App.createWorkspaceAndNavigateToIt('', false, '', false, !props.isSmallScreenWidth)), + onSelected: () => interceptAnonymousUser(() => App.createWorkspaceAndNavigateToIt('', false, '', false, !props.isSmallScreenWidth, false)), }, ] : []), From 392e320554727161916e4547eb24afd7567a5641 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 6 Oct 2023 22:32:14 +0700 Subject: [PATCH 4/7] fix wait for browser history load url after navigate --- src/libs/actions/App.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index fbea58b17efec..753e73947c4e9 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -336,14 +336,24 @@ function createWorkspaceAndNavigateToIt( if (shouldNavigateToAdminChat) { if (isThereModalToDismiss) { Navigation.dismissModal(adminsChatReportID); + setTimeout(() => { + Navigation.navigate(ROUTES.SETTINGS); + setTimeout(() => { + Navigation.navigate(ROUTES.SETTINGS_WORKSPACES); + setTimeout(() => { + Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); + }, 50); + }, 50); + }, 50); } else { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)); + setTimeout(() => { + Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); + }, 50); } + } else { + Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); } - return Navigation.isNavigationReady(); - }) - .then(() => { - Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); }) .then(endSignOnTransition); } From a88dabc930281aed291622932b25c364d942f5d4 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 23 Oct 2023 10:15:02 +0700 Subject: [PATCH 5/7] fix update the latest change in staging --- src/libs/actions/App.js | 31 +++---------------- .../FloatingActionButtonAndPopover.js | 2 +- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 42efa0353fd58..d4837a0b17a4d 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -333,14 +333,7 @@ function endSignOnTransition() { * @param {Boolean} [isThereModalToDismiss] Optional, if there is a modal to dismiss */ -function createWorkspaceAndNavigateToIt( - policyOwnerEmail = '', - makeMeAdmin = false, - policyName = '', - transitionFromOldDot = false, - shouldNavigateToAdminChat = true, - isThereModalToDismiss = true, -) { +function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false, shouldNavigateToAdminChat = true) { const policyID = Policy.generatePolicyID(); const adminsChatReportID = Policy.createWorkspace(policyOwnerEmail, makeMeAdmin, policyName, policyID); Navigation.isNavigationReady() @@ -351,26 +344,10 @@ function createWorkspaceAndNavigateToIt( } if (shouldNavigateToAdminChat) { - if (isThereModalToDismiss) { - Navigation.dismissModal(adminsChatReportID); - setTimeout(() => { - Navigation.navigate(ROUTES.SETTINGS); - setTimeout(() => { - Navigation.navigate(ROUTES.SETTINGS_WORKSPACES); - setTimeout(() => { - Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); - }, 50); - }, 50); - }, 50); - } else { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)); - setTimeout(() => { - Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); - }, 50); - } - } else { - Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)); } + + Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); }) .then(endSignOnTransition); } diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 5932049cd32c6..02f1856c7bf59 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -228,7 +228,7 @@ function FloatingActionButtonAndPopover(props) { iconHeight: 40, text: props.translate('workspace.new.newWorkspace'), description: props.translate('workspace.new.getTheExpensifyCardAndMore'), - onSelected: () => interceptAnonymousUser(() => App.createWorkspaceAndNavigateToIt('', false, '', false, !props.isSmallScreenWidth, false)), + onSelected: () => interceptAnonymousUser(() => App.createWorkspaceAndNavigateToIt('', false, '', false, !props.isSmallScreenWidth)), }, ] : []), From 54a01bb3a1153a629d70c78b2a4f4ac5e7e91add Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 23 Oct 2023 10:52:30 +0700 Subject: [PATCH 6/7] fix on press create new workspace --- src/libs/actions/App.js | 2 -- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index d4837a0b17a4d..75520d483f986 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -330,8 +330,6 @@ function endSignOnTransition() { * @param {String} [policyName] Optional, custom policy name we will use for created workspace * @param {Boolean} [transitionFromOldDot] Optional, if the user is transitioning from old dot * @param {Boolean} [shouldNavigateToAdminChat] Optional, navigate to the #admin room after creation - * @param {Boolean} [isThereModalToDismiss] Optional, if there is a modal to dismiss - */ function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false, shouldNavigateToAdminChat = true) { const policyID = Policy.generatePolicyID(); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 02f1856c7bf59..1bbb64d99c2b5 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -228,7 +228,7 @@ function FloatingActionButtonAndPopover(props) { iconHeight: 40, text: props.translate('workspace.new.newWorkspace'), description: props.translate('workspace.new.getTheExpensifyCardAndMore'), - onSelected: () => interceptAnonymousUser(() => App.createWorkspaceAndNavigateToIt('', false, '', false, !props.isSmallScreenWidth)), + onSelected: () => interceptAnonymousUser(() => App.createWorkspaceWithPolicyDraftAndNavigateToIt()), }, ] : []), From cd3261a101db98b1f86966d82d21b940dc45ec4c Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 23 Oct 2023 22:03:31 +0700 Subject: [PATCH 7/7] fix remove createWorkspaceAndNavigateToIt --- .../Navigation/AppNavigator/AuthScreens.js | 2 +- src/libs/actions/App.js | 39 +++---------------- src/libs/actions/Policy.js | 4 +- src/pages/workspace/WorkspaceInitialPage.js | 2 +- src/pages/workspace/WorkspaceNewRoomPage.js | 2 +- 5 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index dd7175dbc6f6b..8b07034400a3b 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -184,7 +184,7 @@ class AuthScreens extends React.Component { App.reconnectApp(this.props.lastUpdateIDAppliedToClient); } - App.setUpPoliciesAndNavigate(this.props.session, !this.props.isSmallScreenWidth); + App.setUpPoliciesAndNavigate(this.props.session); App.redirectThirdPartyDesktopSignIn(); // Check if we should be running any demos immediately after signing in. diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 75520d483f986..678b5f9f45942 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -322,44 +322,17 @@ function endSignOnTransition() { return resolveSignOnTransitionToFinishPromise(); } -/** - * Create a new workspace and navigate to it - * - * @param {String} [policyOwnerEmail] Optional, the email of the account to make the owner of the policy - * @param {Boolean} [makeMeAdmin] Optional, leave the calling account as an admin on the policy - * @param {String} [policyName] Optional, custom policy name we will use for created workspace - * @param {Boolean} [transitionFromOldDot] Optional, if the user is transitioning from old dot - * @param {Boolean} [shouldNavigateToAdminChat] Optional, navigate to the #admin room after creation - */ -function createWorkspaceAndNavigateToIt(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false, shouldNavigateToAdminChat = true) { - const policyID = Policy.generatePolicyID(); - const adminsChatReportID = Policy.createWorkspace(policyOwnerEmail, makeMeAdmin, policyName, policyID); - Navigation.isNavigationReady() - .then(() => { - if (transitionFromOldDot) { - // We must call goBack() to remove the /transition route from history - Navigation.goBack(ROUTES.HOME); - } - - if (shouldNavigateToAdminChat) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)); - } - - Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); - }) - .then(endSignOnTransition); -} - /** * Create a new draft workspace and navigate to it * * @param {String} [policyOwnerEmail] Optional, the email of the account to make the owner of the policy * @param {String} [policyName] Optional, custom policy name we will use for created workspace * @param {Boolean} [transitionFromOldDot] Optional, if the user is transitioning from old dot + * @param {Boolean} [makeMeAdmin] Optional, leave the calling account as an admin on the policy */ -function createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail = '', policyName = '', transitionFromOldDot = false) { +function createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail = '', policyName = '', transitionFromOldDot = false, makeMeAdmin = false) { const policyID = Policy.generatePolicyID(); - Policy.createDraftInitialWorkspace(policyOwnerEmail, policyName, policyID); + Policy.createDraftInitialWorkspace(policyOwnerEmail, policyName, policyID, makeMeAdmin); Navigation.isNavigationReady() .then(() => { @@ -403,9 +376,8 @@ function savePolicyDraftByNewWorkspace(policyID, policyName, policyOwnerEmail = * pass it in as a parameter. withOnyx guarantees that the value has been read * from Onyx because it will not render the AuthScreens until that point. * @param {Object} session - * @param {Boolean} shouldNavigateToAdminChat Should we navigate to admin chat after creating workspace */ -function setUpPoliciesAndNavigate(session, shouldNavigateToAdminChat) { +function setUpPoliciesAndNavigate(session) { const currentUrl = getCurrentUrl(); if (!session || !currentUrl || !currentUrl.includes('exitTo')) { return; @@ -426,7 +398,7 @@ function setUpPoliciesAndNavigate(session, shouldNavigateToAdminChat) { const shouldCreateFreePolicy = !isLoggingInAsNewUser && isTransitioning && exitTo === ROUTES.WORKSPACE_NEW; if (shouldCreateFreePolicy) { - createWorkspaceAndNavigateToIt(policyOwnerEmail, makeMeAdmin, policyName, true, shouldNavigateToAdminChat); + createWorkspaceWithPolicyDraftAndNavigateToIt(policyOwnerEmail, policyName, true, makeMeAdmin); return; } if (!isLoggingInAsNewUser && exitTo) { @@ -555,7 +527,6 @@ export { handleRestrictedEvent, beginDeepLinkRedirect, beginDeepLinkRedirectAfterTransition, - createWorkspaceAndNavigateToIt, getMissingOnyxUpdates, finalReconnectAppAfterActivatingReliableUpdates, savePolicyDraftByNewWorkspace, diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 89324dd354859..a239ca691de33 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -922,8 +922,9 @@ function buildOptimisticCustomUnits() { * @param {String} [policyOwnerEmail] Optional, the email of the account to make the owner of the policy * @param {String} [policyName] Optional, custom policy name we will use for created workspace * @param {String} [policyID] Optional, custom policy id we will use for created workspace + * @param {Boolean} [makeMeAdmin] Optional, leave the calling account as an admin on the policy */ -function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', policyID = generatePolicyID()) { +function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', policyID = generatePolicyID(), makeMeAdmin = false) { const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail); const {customUnits} = buildOptimisticCustomUnits(); @@ -941,6 +942,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol outputCurrency: lodashGet(allPersonalDetails, [sessionAccountID, 'localCurrencyCode'], CONST.CURRENCY.USD), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, customUnits, + makeMeAdmin, }, }, { diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index d275b7f0dd10a..edaa1b29bffde 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -88,7 +88,7 @@ function WorkspaceInitialPage(props) { return; } - App.savePolicyDraftByNewWorkspace(props.policyDraft.id, props.policyDraft.name, '', false); + App.savePolicyDraftByNewWorkspace(props.policyDraft.id, props.policyDraft.name, '', props.policyDraft.makeMeAdmin); // We only care when the component renders the first time // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index da0bf845cc818..8a62a3b876eaf 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -165,7 +165,7 @@ function WorkspaceNewRoomPage(props) { shouldShow={!Permissions.canUsePolicyRooms(props.betas) || !workspaceOptions.length} shouldShowBackButton={false} linkKey="workspace.emptyWorkspace.title" - onLinkPress={() => App.createWorkspaceAndNavigateToIt('', false, '', false, false)} + onLinkPress={() => App.createWorkspaceWithPolicyDraftAndNavigateToIt()} >