From b068258b3f0ca69df9d0df8a7db0abcdf3eed4b9 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 23 Oct 2023 09:49:20 +0700 Subject: [PATCH 1/7] fix: 30100 --- src/pages/workspace/WorkspaceInitialPage.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index d275b7f0dd10..67fcfdec6328 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -32,6 +32,7 @@ import * as ReimbursementAccountProps from '../ReimbursementAccount/reimbursemen import * as ReportUtils from '../../libs/ReportUtils'; import withWindowDimensions from '../../components/withWindowDimensions'; import PressableWithoutFeedback from '../../components/Pressable/PressableWithoutFeedback'; +import usePrevious from '../../hooks/usePrevious'; const propTypes = { ...policyPropTypes, @@ -78,8 +79,6 @@ function WorkspaceInitialPage(props) { const policyReports = _.filter(props.reports, (report) => report && report.policyID === policy.id); Policy.deleteWorkspace(policy.id, policyReports, policy.name); setIsDeleteModalOpen(false); - // Pop the deleted workspace page before opening workspace settings. - Navigation.goBack(ROUTES.SETTINGS_WORKSPACES); }, [props.reports, policy]); useEffect(() => { @@ -193,6 +192,14 @@ function WorkspaceInitialPage(props) { }, ]; + const prevPolicy = usePrevious(policy); + + useEffect(() => { + if (PolicyUtils.isPendingDeletePolicy(policy) && !PolicyUtils.isPendingDeletePolicy(prevPolicy)) { + Navigation.goBack(ROUTES.SETTINGS_WORKSPACES); + } + }, [policy, prevPolicy]); + return ( ( Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)} - shouldShow={_.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)} + shouldShow={_.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy))} subtitleKey={_.isEmpty(policy) ? undefined : 'workspace.common.notAuthorized'} > Date: Mon, 13 Nov 2023 10:22:32 +0700 Subject: [PATCH 2/7] fix lint --- src/pages/workspace/WorkspaceInitialPage.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index 48483d68e80b..1a568babaff0 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -16,6 +16,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import Text from '@components/Text'; import Tooltip from '@components/Tooltip'; import useLocalize from '@hooks/useLocalize'; +import usePrevious from '@hooks/usePrevious'; import useSingleExecution from '@hooks/useSingleExecution'; import useWaitForNavigation from '@hooks/useWaitForNavigation'; import useWindowDimensions from '@hooks/useWindowDimensions'; @@ -223,12 +224,6 @@ function WorkspaceInitialPage(props) { const prevPolicy = usePrevious(policy); - useEffect(() => { - if (PolicyUtils.isPendingDeletePolicy(policy) && !PolicyUtils.isPendingDeletePolicy(prevPolicy)) { - Navigation.goBack(ROUTES.SETTINGS_WORKSPACES); - } - }, [policy, prevPolicy]); - return ( Date: Tue, 14 Nov 2023 12:00:53 +0700 Subject: [PATCH 3/7] add variable --- src/pages/workspace/WorkspaceInitialPage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index 1a568babaff0..81afb148bfbc 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -224,6 +224,9 @@ function WorkspaceInitialPage(props) { const prevPolicy = usePrevious(policy); + // We should check both policy and prevPolicy to prevent not found page appearing after we delete the workspace and navigate + const shouldShowNotFound = _.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); + return ( ( Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)} - shouldShow={_.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy))} + shouldShow={shouldShowNotFound} subtitleKey={_.isEmpty(policy) ? undefined : 'workspace.common.notAuthorized'} > Date: Tue, 14 Nov 2023 12:17:20 +0700 Subject: [PATCH 4/7] fix lint --- src/pages/workspace/WorkspaceInitialPage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index 81afb148bfbc..c6f76e63e221 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -225,7 +225,8 @@ function WorkspaceInitialPage(props) { const prevPolicy = usePrevious(policy); // We should check both policy and prevPolicy to prevent not found page appearing after we delete the workspace and navigate - const shouldShowNotFound = _.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); + // eslint-disable-next-line rulesdir/no-negated-variables + const shouldShowNotFoundPage = _.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); return ( ( Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)} - shouldShow={shouldShowNotFound} + shouldShow={shouldShowNotFoundPage} subtitleKey={_.isEmpty(policy) ? undefined : 'workspace.common.notAuthorized'} > Date: Tue, 14 Nov 2023 17:04:54 +0700 Subject: [PATCH 5/7] edit comment --- src/pages/workspace/WorkspaceInitialPage.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index c6f76e63e221..a2082396f196 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -224,9 +224,14 @@ function WorkspaceInitialPage(props) { const prevPolicy = usePrevious(policy); - // We should check both policy and prevPolicy to prevent not found page appearing after we delete the workspace and navigate // eslint-disable-next-line rulesdir/no-negated-variables - const shouldShowNotFoundPage = _.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); + const shouldShowNotFoundPage = + _.isEmpty(policy) || + !PolicyUtils.isPolicyAdmin(policy) || + // Somtimes, when we delete the workspace, the data is updated into Onyx faster than navigation time. + // That makes delete condition return true and not found page appears briefly before navigating. + // We check delete condition for both policy and prevPolicy to prevent the not found page showing if we are deleting the workspace + (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); return ( Date: Tue, 14 Nov 2023 17:05:33 +0700 Subject: [PATCH 6/7] edit comment --- src/pages/workspace/WorkspaceInitialPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index a2082396f196..913a28e6e698 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -228,7 +228,7 @@ function WorkspaceInitialPage(props) { const shouldShowNotFoundPage = _.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || - // Somtimes, when we delete the workspace, the data is updated into Onyx faster than navigation time. + // Somtimes, when we delete the workspace, the data is updated into Onyx faster than navigation trasaction time. // That makes delete condition return true and not found page appears briefly before navigating. // We check delete condition for both policy and prevPolicy to prevent the not found page showing if we are deleting the workspace (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); From c57dc10fec5795d6109499e1763b4bd1f8bdad1c Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:49:07 +0700 Subject: [PATCH 7/7] Update src/pages/workspace/WorkspaceInitialPage.js Co-authored-by: Vinh Hoang --- src/pages/workspace/WorkspaceInitialPage.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.js b/src/pages/workspace/WorkspaceInitialPage.js index 913a28e6e698..50aa87041c21 100644 --- a/src/pages/workspace/WorkspaceInitialPage.js +++ b/src/pages/workspace/WorkspaceInitialPage.js @@ -228,9 +228,7 @@ function WorkspaceInitialPage(props) { const shouldShowNotFoundPage = _.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy) || - // Somtimes, when we delete the workspace, the data is updated into Onyx faster than navigation trasaction time. - // That makes delete condition return true and not found page appears briefly before navigating. - // We check delete condition for both policy and prevPolicy to prevent the not found page showing if we are deleting the workspace + // We check isPendingDelete for both policy and prevPolicy to prevent the NotFound view from showing right after we delete the workspace (PolicyUtils.isPendingDeletePolicy(policy) && PolicyUtils.isPendingDeletePolicy(prevPolicy)); return (