Skip to content

fix: correct back button in workspace list page #57237

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

Merged
merged 7 commits into from
Mar 5, 2025
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 @@ -151,7 +151,7 @@ const ROUTES = {
SETTINGS_PRIORITY_MODE: 'settings/preferences/priority-mode',
SETTINGS_LANGUAGE: 'settings/preferences/language',
SETTINGS_THEME: 'settings/preferences/theme',
SETTINGS_WORKSPACES: 'settings/workspaces',
SETTINGS_WORKSPACES: {route: 'settings/workspaces', getRoute: (backTo?: string) => getUrlWithBackToParam('settings/workspaces', backTo)},
SETTINGS_SECURITY: 'settings/security',
SETTINGS_CLOSE: 'settings/security/closeAccount',
SETTINGS_ADD_DELEGATE: 'settings/security/delegate',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation/BottomTabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps

// If there is settings workspace screen in the settings navigator, then we should open the settings workspaces as it should be "remembered".
if (state?.routes?.at(-1)?.name === SCREENS.SETTINGS.WORKSPACES) {
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
screens: {
[SCREENS.SETTINGS.ROOT]: ROUTES.SETTINGS,
[SCREENS.SETTINGS.WORKSPACES]: {
path: ROUTES.SETTINGS_WORKSPACES,
path: ROUTES.SETTINGS_WORKSPACES.route,
exact: true,
},
[SCREENS.SETTINGS.PROFILE.ROOT]: {
Expand Down
5 changes: 4 additions & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.DOWNGRADE]: {
policyID?: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORIES_SETTINGS]: {
policyID: string;
Expand Down Expand Up @@ -1599,7 +1600,9 @@ type ReportsSplitNavigatorParamList = {

type SettingsSplitNavigatorParamList = {
[SCREENS.SETTINGS.ROOT]: undefined;
[SCREENS.SETTINGS.WORKSPACES]: undefined;
[SCREENS.SETTINGS.WORKSPACES]: {
backTo?: Routes;
};
[SCREENS.SETTINGS.PREFERENCES.ROOT]: undefined;
[SCREENS.SETTINGS.SECURITY]: undefined;
[SCREENS.SETTINGS.PROFILE.ROOT]: undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ function getPolicyEmployeeListByIdWithoutCurrentUser(policies: OnyxCollection<Pi
}

function goBackFromInvalidPolicy() {
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route);
}

/** Get a tax with given ID from policy */
Expand Down
2 changes: 1 addition & 1 deletion src/libs/navigateAfterJoinRequest/index.desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const navigateAfterJoinRequest = () => {
if (getIsSmallScreenWidth()) {
Navigation.navigate(ROUTES.SETTINGS);
}
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route);
};
export default navigateAfterJoinRequest;
2 changes: 1 addition & 1 deletion src/libs/navigateAfterJoinRequest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import ROUTES from '@src/ROUTES';
const navigateAfterJoinRequest = () => {
Navigation.goBack(undefined, {shouldPopToTop: true});
Navigation.navigate(ROUTES.SETTINGS);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route);
};
export default navigateAfterJoinRequest;
2 changes: 1 addition & 1 deletion src/libs/navigateAfterJoinRequest/index.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const navigateAfterJoinRequest = () => {
if (getIsSmallScreenWidth()) {
Navigation.navigate(ROUTES.SETTINGS);
}
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route);
};
export default navigateAfterJoinRequest;
12 changes: 6 additions & 6 deletions src/pages/home/sidebar/AllSettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWaitForNavigation from '@hooks/useWaitForNavigation';
import {buildOldDotURL, openOldDotLink} from '@libs/actions/Link';
import Navigation from '@libs/Navigation/Navigation';
import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -39,7 +39,7 @@ function AllSettingsScreen() {
icon: Expensicons.Building,
action: () => {
waitForNavigate(() => {
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route);
})();
},
focused: !shouldUseNarrowLayout,
Expand All @@ -51,23 +51,23 @@ function AllSettingsScreen() {
translationKey: 'allSettingsScreen.subscription',
icon: Expensicons.MoneyBag,
action: () => {
Link.openOldDotLink(CONST.OLDDOT_URLS.ADMIN_POLICIES_URL);
openOldDotLink(CONST.OLDDOT_URLS.ADMIN_POLICIES_URL);
},
shouldShowRightIcon: true,
iconRight: Expensicons.NewWindow,
link: () => Link.buildOldDotURL(CONST.OLDDOT_URLS.ADMIN_POLICIES_URL),
link: () => buildOldDotURL(CONST.OLDDOT_URLS.ADMIN_POLICIES_URL),
},
]
: []),
{
translationKey: 'allSettingsScreen.domains',
icon: Expensicons.Globe,
action: () => {
Link.openOldDotLink(CONST.OLDDOT_URLS.ADMIN_DOMAINS_URL);
openOldDotLink(CONST.OLDDOT_URLS.ADMIN_DOMAINS_URL);
},
shouldShowRightIcon: true,
iconRight: Expensicons.NewWindow,
link: () => Link.buildOldDotURL(CONST.OLDDOT_URLS.ADMIN_DOMAINS_URL),
link: () => buildOldDotURL(CONST.OLDDOT_URLS.ADMIN_DOMAINS_URL),
},
];
return baseMenuItems.map((item) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
icon: Expensicons.Buildings,
screenName: SCREENS.SETTINGS.WORKSPACES,
brickRoadIndicator: hasGlobalWorkspaceSettingsRBR(policies, allConnectionSyncProgresses) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
action: () => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES),
action: () => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route),
},
{
translationKey: 'allSettingsScreen.domains',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import TextLink from '@components/TextLink';
import useCancellationType from '@hooks/useCancellationType';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {navigateToConciergeChat} from '@libs/actions/Report';
import {cancelBillingSubscription} from '@libs/actions/Subscription';
import Navigation from '@libs/Navigation/Navigation';
import * as Report from '@userActions/Report';
import * as Subscription from '@userActions/Subscription';
import type {CancellationType, FeedbackSurveyOptionID} from '@src/CONST';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -31,7 +31,7 @@ function RequestEarlyCancellationPage() {

const handleSubmit = (cancellationReason: FeedbackSurveyOptionID, cancellationNote = '') => {
setIsLoading(true);
Subscription.cancelBillingSubscription(cancellationReason, cancellationNote);
cancelBillingSubscription(cancellationReason, cancellationNote);
};

const acknowledgementText = useMemo(
Expand All @@ -52,7 +52,7 @@ function RequestEarlyCancellationPage() {
<Text style={styles.textHeadline}>{translate('subscription.requestEarlyCancellation.requestSubmitted.title')}</Text>
<Text style={[styles.mt1, styles.textNormalThemeText]}>
{translate('subscription.requestEarlyCancellation.requestSubmitted.subtitle.part1')}
<TextLink onPress={() => Report.navigateToConciergeChat()}>{translate('subscription.requestEarlyCancellation.requestSubmitted.subtitle.link')}</TextLink>
<TextLink onPress={() => navigateToConciergeChat()}>{translate('subscription.requestEarlyCancellation.requestSubmitted.subtitle.link')}</TextLink>
{translate('subscription.requestEarlyCancellation.requestSubmitted.subtitle.part2')}
</Text>
</View>
Expand All @@ -78,7 +78,7 @@ function RequestEarlyCancellationPage() {
<Text style={[styles.mv4, styles.textNormalThemeText]}>{translate('subscription.requestEarlyCancellation.subscriptionCanceled.info')}</Text>
<Text>
{translate('subscription.requestEarlyCancellation.subscriptionCanceled.preventFutureActivity.part1')}
<TextLink onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES)}>
<TextLink onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route)}>
{translate('subscription.requestEarlyCancellation.subscriptionCanceled.preventFutureActivity.link')}
</TextLink>
{translate('subscription.requestEarlyCancellation.subscriptionCanceled.preventFutureActivity.part2')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function PageNotFoundFallback({policyID, fullPageNotFoundViewProps, isFeatureEna
shouldShowOfflineIndicator={false}
onBackButtonPress={() => {
if (isPolicyNotAccessible) {
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES.route);
return;
}
Navigation.goBack(policyID && !isMoneyRequest ? ROUTES.WORKSPACE_OVERVIEW.getRoute(policyID) : undefined);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
>
<HeaderWithBackButton
title={policyName}
onBackButtonPress={() => Navigation.goBack(route.params?.backTo ?? ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={() => Navigation.goBack(route.params?.backTo ?? ROUTES.SETTINGS_WORKSPACES.route)}
policyAvatar={policyAvatar}
style={styles.headerBarDesktopHeight}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function WorkspaceNewRoomPage() {
success
large
text={translate('footer.learnMore')}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES)}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route)}
Copy link
Member

Choose a reason for hiding this comment

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

We are using navigate without backTo here causing #59686

style={[styles.mh5, styles.mb5]}
/>
{isSmallScreenWidth && (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspacePageWithSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function WorkspacePageWithSections({
shouldShowOfflineIndicatorInWideScreen={shouldShowOfflineIndicatorInWideScreen && !shouldShow}
>
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES.route)}
onLinkPress={Navigation.goBackToHome}
shouldShow={shouldShow}
subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined}
Expand Down
17 changes: 15 additions & 2 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRoute} from '@react-navigation/native';
import React, {useCallback, useMemo, useState} from 'react';
import {FlatList, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -35,12 +36,16 @@ import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import localeCompare from '@libs/LocaleCompare';
import resetPolicyIDInNavigationState from '@libs/Navigation/helpers/resetPolicyIDInNavigationState';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsSplitNavigatorParamList} from '@libs/Navigation/types';
import {getPolicy, getPolicyBrickRoadIndicatorStatus, getWorkspaceAccountID, isPolicyAdmin, shouldShowPolicy} from '@libs/PolicyUtils';
import {getDefaultWorkspaceAvatar} from '@libs/ReportUtils';
import type {AvatarSource} from '@libs/UserUtils';
import useHandleBackButton from '@pages/Search/useHandleBackButton';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Policy as PolicyType} from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {PolicyDetailsForNonMembers} from '@src/types/onyx/Policy';
Expand Down Expand Up @@ -120,6 +125,7 @@ function WorkspacesListPage() {
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const shouldShowLoadingIndicator = isLoadingApp && !isOffline;
const route = useRoute<PlatformStackRouteProp<SettingsSplitNavigatorParamList, typeof SCREENS.SETTINGS.WORKSPACES>>();

const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [policyIDToDelete, setPolicyIDToDelete] = useState<string>();
Expand Down Expand Up @@ -429,6 +435,13 @@ function WorkspacesListPage() {
/>
);

const onBackButtonPress = () => {
Navigation.goBack(route.params?.backTo ?? ROUTES.SETTINGS);
return true;
};

useHandleBackButton(onBackButtonPress);

if (isEmptyObject(workspaces)) {
return (
<ScreenWrapper
Expand All @@ -442,7 +455,7 @@ function WorkspacesListPage() {
title={translate('common.workspaces')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
onBackButtonPress={onBackButtonPress}
icon={Illustrations.Buildings}
shouldUseHeadlineHeader
/>
Expand Down Expand Up @@ -482,7 +495,7 @@ function WorkspacesListPage() {
title={translate('common.workspaces')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
onBackButtonPress={onBackButtonPress}
icon={Illustrations.Buildings}
shouldUseHeadlineHeader
>
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/downgrade/DowngradeIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import {openLink} from '@libs/actions/Link';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';

type Props = {
buttonDisabled?: boolean;
loading?: boolean;
onDowngrade: () => void;
policyID?: string;
backTo?: Route;
};

function DowngradeIntro({onDowngrade, buttonDisabled, loading, policyID}: Props) {
function DowngradeIntro({onDowngrade, buttonDisabled, loading, policyID, backTo}: Props) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {environmentURL} = useEnvironment();
Expand Down Expand Up @@ -93,7 +95,7 @@ function DowngradeIntro({onDowngrade, buttonDisabled, loading, policyID}: Props)
<Button
text={translate('workspace.common.goToWorkspaces')}
success
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES, {forceReplace: true})}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.getRoute(backTo ?? Navigation.getActiveRoute()), {forceReplace: true})}
large
/>
)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/downgrade/WorkspaceDowngradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function WorkspaceDowngradePage({route}: WorkspaceDowngradePageProps) {
onDowngrade={onDowngradeToTeam}
buttonDisabled={isOffline}
loading={policy?.isPendingDowngrade}
backTo={route.params.backTo}
/>
)}
</ScrollView>
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/upgrade/GenericFeaturesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';

type GenericFeaturesViewProps = {
buttonDisabled?: boolean;
loading?: boolean;
onUpgrade: () => void;
formattedPrice: string;
policyID?: string;
backTo?: Route;
};

function GenericFeaturesView({onUpgrade, buttonDisabled, loading, formattedPrice, policyID}: GenericFeaturesViewProps) {
function GenericFeaturesView({onUpgrade, buttonDisabled, loading, formattedPrice, backTo, policyID}: GenericFeaturesViewProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isExtraSmallScreenWidth} = useResponsiveLayout();
Expand Down Expand Up @@ -86,7 +88,7 @@ function GenericFeaturesView({onUpgrade, buttonDisabled, loading, formattedPrice
<Button
text={translate('workspace.common.goToWorkspaces')}
success
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES, {forceReplace: true})}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.getRoute(backTo ?? Navigation.getActiveRoute()), {forceReplace: true})}
large
/>
)}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/workspace/upgrade/UpgradeIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {convertToShortDisplayString} from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import GenericFeaturesView from './GenericFeaturesView';

type Props = {
Expand All @@ -29,9 +30,10 @@ type Props = {
onUpgrade: () => void;
isCategorizing?: boolean;
policyID?: string;
backTo?: Route;
};

function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading, isCategorizing, policyID}: Props) {
function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading, isCategorizing, policyID, backTo}: Props) {
const styles = useThemeStyles();
const {isExtraSmallScreenWidth} = useResponsiveLayout();
const {translate} = useLocalize();
Expand Down Expand Up @@ -62,6 +64,7 @@ function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading, isCategorizi
formattedPrice={formattedPrice}
loading={loading}
policyID={policyID}
backTo={backTo}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
onUpgrade={onUpgradeToCorporate}
buttonDisabled={isOffline}
loading={policy?.isPendingUpgrade}
backTo={route.params.backTo}
/>
)}
</ScrollView>
Expand Down