diff --git a/src/libs/API/parameters/OpenWorkspaceViewParams.ts b/src/libs/API/parameters/OpenWorkspaceViewParams.ts index 3dc9da6e1947..4e5579e4a1e0 100644 --- a/src/libs/API/parameters/OpenWorkspaceViewParams.ts +++ b/src/libs/API/parameters/OpenWorkspaceViewParams.ts @@ -1,5 +1,5 @@ type OpenWorkspaceViewParams = { - policyID: string; + policyID: string | undefined; }; export default OpenWorkspaceViewParams; diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index a6e01969d506..7fd0c82e3ac0 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -644,7 +644,7 @@ function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoD API.write(WRITE_COMMANDS.VERIFY_IDENTITY_FOR_BANK_ACCOUNT, parameters, getVBBADataForOnyx()); } -function openWorkspaceView(policyID: string) { +function openWorkspaceView(policyID: string | undefined) { API.read( READ_COMMANDS.OPEN_WORKSPACE_VIEW, { diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 642ab02f24f4..99325ce45242 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -37,6 +37,7 @@ import usePrevious from '@hooks/usePrevious'; import useSingleExecution from '@hooks/useSingleExecution'; import useThemeStyles from '@hooks/useThemeStyles'; import useWaitForNavigation from '@hooks/useWaitForNavigation'; +import {confirmReadyToOpenApp} from '@libs/actions/App'; import {isConnectionInProgress} from '@libs/actions/connections'; import {clearErrors, openPolicyInitialPage, removeWorkspace, updateGeneralSettings} from '@libs/actions/Policy/Policy'; import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount'; @@ -60,7 +61,6 @@ import { } from '@libs/PolicyUtils'; import {getDefaultWorkspaceAvatar, getIcons, getPolicyExpenseChat, getReportName, getReportOfflinePendingActionAndErrors} from '@libs/ReportUtils'; import type {FullScreenNavigatorParamList} from '@navigation/types'; -import {confirmReadyToOpenApp} from '@userActions/App'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -400,17 +400,18 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac const prevPolicy = usePrevious(policy); const shouldShowPolicy = useMemo(() => checkIfShouldShowPolicy(policy, isOffline, currentUserLogin), [policy, isOffline, currentUserLogin]); - const prevShouldShowPolicy = useMemo(() => checkIfShouldShowPolicy(prevPolicy, isOffline, currentUserLogin), [prevPolicy, isOffline, currentUserLogin]); - // We check shouldShowPolicy and prevShouldShowPolicy to prevent the NotFound view from showing right after we delete the workspace + const isPendingDelete = isPendingDeletePolicy(policy); + const prevIsPendingDelete = isPendingDeletePolicy(prevPolicy); + // We check isPendingDelete and prevIsPendingDelete to prevent the NotFound view from showing right after we delete the workspace // eslint-disable-next-line rulesdir/no-negated-variables - const shouldShowNotFoundPage = isEmptyObject(policy) || (!shouldShowPolicy && !prevShouldShowPolicy); + const shouldShowNotFoundPage = !shouldShowPolicy && (!isPendingDelete || prevIsPendingDelete); useEffect(() => { - if (isEmptyObject(prevPolicy) || isPendingDeletePolicy(prevPolicy) || !isPendingDeletePolicy(policy)) { + if (isEmptyObject(prevPolicy) || prevIsPendingDelete || !isPendingDelete) { return; } goBackFromInvalidPolicy(); - }, [policy, prevPolicy]); + }, [isPendingDelete, policy, prevIsPendingDelete, prevPolicy]); // We are checking if the user can access the route. // If user can't access the route, we are dismissing any modals that are open when the NotFound view is shown diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx index 8867e32fa8ef..c30ac3c57381 100644 --- a/src/pages/workspace/WorkspacePageWithSections.tsx +++ b/src/pages/workspace/WorkspacePageWithSections.tsx @@ -10,13 +10,14 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import type HeaderWithBackButtonProps from '@components/HeaderWithBackButton/types'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollViewWithContext from '@components/ScrollViewWithContext'; +import useNetwork from '@hooks/useNetwork'; import usePrevious from '@hooks/usePrevious'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import {openWorkspaceView} from '@libs/actions/BankAccounts'; import BankAccount from '@libs/models/BankAccount'; import Navigation from '@libs/Navigation/Navigation'; -import {isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils'; +import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -34,7 +35,7 @@ type WorkspacePageWithSectionsProps = WithPolicyAndFullscreenLoadingProps & headerText: string; /** Main content of the page */ - children: ((hasVBA: boolean, policyID: string, isUsingECard: boolean) => ReactNode) | ReactNode; + children: ((hasVBA: boolean, policyID: string | undefined, isUsingECard: boolean) => ReactNode) | ReactNode; /** Content to be added as fixed footer */ footer?: ReactNode; @@ -86,7 +87,7 @@ type WorkspacePageWithSectionsProps = WithPolicyAndFullscreenLoadingProps & isLoading?: boolean; }; -function fetchData(policyID: string, skipVBBACal?: boolean) { +function fetchData(policyID: string | undefined, skipVBBACal?: boolean) { if (skipVBBACal) { return; } @@ -122,7 +123,8 @@ function WorkspacePageWithSections({ threeDotsAnchorPosition, }: WorkspacePageWithSectionsProps) { const styles = useThemeStyles(); - const policyID = route.params?.policyID ?? `${CONST.DEFAULT_NUMBER_ID}`; + const policyID = route.params?.policyID; + const {isOffline} = useNetwork({onReconnect: () => fetchData(policyID, shouldSkipVBBACall)}); const [user] = useOnyx(ONYXKEYS.USER); const [reimbursementAccount = CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT); @@ -149,18 +151,19 @@ function WorkspacePageWithSections({ }, [policyID, shouldSkipVBBACall]), ); - const shouldShowPolicy = useMemo(() => shouldShowPolicyUtil(policy, false, currentUserLogin), [policy, currentUserLogin]); - const prevShouldShowPolicy = useMemo(() => shouldShowPolicyUtil(prevPolicy, false, currentUserLogin), [prevPolicy, currentUserLogin]); + const shouldShowPolicy = useMemo(() => shouldShowPolicyUtil(policy, isOffline, currentUserLogin), [policy, isOffline, currentUserLogin]); + const isPendingDelete = isPendingDeletePolicy(policy); + const prevIsPendingDelete = isPendingDeletePolicy(prevPolicy); const shouldShow = useMemo(() => { // If the policy object doesn't exist or contains only error data, we shouldn't display it. if (((isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors))) && isEmptyObject(policyDraft)) || shouldShowNotFoundPage) { return true; } - // We check shouldShowPolicy and prevShouldShowPolicy to prevent the NotFound view from showing right after we delete the workspace - return (!isEmptyObject(policy) && !isPolicyAdmin(policy) && !shouldShowNonAdmin) || (!shouldShowPolicy && !prevShouldShowPolicy); + // We check isPendingDelete and prevIsPendingDelete to prevent the NotFound view from showing right after we delete the workspace + return (!isEmptyObject(policy) && !isPolicyAdmin(policy) && !shouldShowNonAdmin) || (!shouldShowPolicy && (!isPendingDelete || prevIsPendingDelete)); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [policy, shouldShowNonAdmin, shouldShowPolicy, prevShouldShowPolicy]); + }, [policy, shouldShowNonAdmin, shouldShowPolicy]); return (