Skip to content
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
10 changes: 10 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTagList, PolicyTags} from '@src/types/onyx';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import Navigation from './Navigation/Navigation';

type MemberEmailsToAccountIDs = Record<string, number>;
type UnitRate = {rate: number};
Expand Down Expand Up @@ -250,6 +252,13 @@ function getPolicyMembersByIdWithoutCurrentUser(policyMembers: OnyxCollection<Po
: [];
}

function goBackFromInvalidPolicy() {
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);

// Needed when workspace with given policyID does not exist
Navigation.navigateWithSwitchPolicyID({route: ROUTES.ALL_SETTINGS});
}

export {
getActivePolicies,
hasPolicyMemberError,
Expand Down Expand Up @@ -279,6 +288,7 @@ export {
extractPolicyIDFromPath,
getPathWithoutPolicyID,
getPolicyMembersByIdWithoutCurrentUser,
goBackFromInvalidPolicy,
};

export type {MemberEmailsToAccountIDs};
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ function ReimbursementAccountPage({reimbursementAccount, route, onfidoToken, pol
<ScreenWrapper testID={ReimbursementAccountPage.displayName}>
<FullPageNotFoundView
shouldShow
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
subtitleKey={_.isEmpty(policy) ? undefined : 'workspace.common.notAuthorized'}
/>
</ScreenWrapper>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type WorkspaceInitialPageOnyxProps = {
type WorkspaceInitialPageProps = WithPolicyAndFullscreenLoadingProps & WorkspaceInitialPageOnyxProps & StackScreenProps<BottomTabNavigatorParamList, typeof SCREENS.WORKSPACE.INITIAL>;

function dismissError(policyID: string) {
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);
PolicyUtils.goBackFromInvalidPolicy();
Policy.removeWorkspace(policyID);
}

Expand Down Expand Up @@ -188,7 +188,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
style={[styles.pb0]}
>
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
shouldShow={shouldShowNotFoundPage}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ function WorkspaceInviteMessagePage({workspaceInviteMessageDraft, invitedEmailsT
<FullPageNotFoundView
shouldShow={isEmptyObject(policy) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
>
<HeaderWithBackButton
title={translate('workspace.inviteMessage.inviteMessageTitle')}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ function WorkspaceInvitePage({
<FullPageNotFoundView
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
>
<HeaderWithBackButton
title={translate('workspace.invite.invitePeople')}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
<FullPageNotFoundView
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
>
<HeaderWithBackButton
title={translate('workspace.common.members')}
Expand Down
11 changes: 2 additions & 9 deletions src/pages/workspace/WorkspacePageWithSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ function WorkspacePageWithSections({
const {isSmallScreenWidth} = useWindowDimensions();
const firstRender = useRef(true);

const goBack = () => {
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);

// Needed when workspace with given policyID does not exist
Navigation.navigateWithSwitchPolicyID({route: ROUTES.ALL_SETTINGS});
};

useEffect(() => {
// Because isLoading is false before merging in Onyx, we need firstRender ref to display loading page as well before isLoading is change to true
firstRender.current = false;
Expand Down Expand Up @@ -153,8 +146,8 @@ function WorkspacePageWithSections({
shouldShowOfflineIndicatorInWideScreen={shouldShowOfflineIndicatorInWideScreen && !shouldShow}
>
<FullPageNotFoundView
onBackButtonPress={goBack}
onLinkPress={goBack}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
shouldShow={shouldShow}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
shouldForceFullScreen
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceProfileCurrencyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as Policy from '@userActions/Policy';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {CurrencyList} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading';
Expand Down Expand Up @@ -77,7 +76,8 @@ function WorkspaceProfileCurrencyPage({currencyList = {}, policy, isLoadingRepor
testID={WorkspaceProfileCurrencyPage.displayName}
>
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
>
Expand Down