Skip to content
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

fix: redirect to proper place after upgrade #45730

Merged
merged 4 commits into from
Jul 26, 2024
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
4 changes: 3 additions & 1 deletion src/components/ConnectToNetSuiteButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function ConnectToNetSuiteButton({policyID, shouldDisconnectIntegrationBeforeCon
<Button
onPress={() => {
if (!isControlPolicy(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias));
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias, ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID)),
);
return;
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/ConnectToSageIntacctButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ function ConnectToSageIntacctButton({policyID, shouldDisconnectIntegrationBefore
<Button
onPress={() => {
if (!isControlPolicy(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias));
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(
policyID,
CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias,
ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID),
),
);
return;
}

Expand Down
16 changes: 14 additions & 2 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet
description={translate(`workspace.categories.glCode`)}
onPress={() => {
if (!isControlPolicy(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(route.params.policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias));
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(
route.params.policyID,
CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias,
ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(route.params.policyID, policyCategory.name),
),
);
return;
}
Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(route.params.policyID, policyCategory.name));
Expand All @@ -156,7 +162,13 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet
description={translate(`workspace.categories.payrollCode`)}
onPress={() => {
if (!isControlPolicy(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(route.params.policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias));
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(
route.params.policyID,
CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias,
ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(route.params.policyID, policyCategory.name),
),
);
return;
}
Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(route.params.policyID, policyCategory.name));
Expand Down
8 changes: 7 additions & 1 deletion src/pages/workspace/tags/TagSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ function TagSettingsPage({route, policyTags, navigation}: TagSettingsPageProps)

const navigateToEditGlCode = () => {
if (!PolicyUtils.isControlPolicy(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(route.params.policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias));
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(
route.params.policyID,
CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias,
ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policy?.id ?? '', route.params.orderWeight, route.params.tagName),
),
);
return;
}
Navigation.navigate(ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(route.params.policyID, route.params.orderWeight, currentPolicyTag.name));
Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/upgrade/UpgradeConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import ROUTES from '@src/ROUTES';

type Props = {
policyName: string;
policyID: string;
onConfirmUpgrade: () => void;
};

function UpgradeConfirmation({policyName, policyID}: Props) {
function UpgradeConfirmation({policyName, onConfirmUpgrade}: Props) {
const {translate} = useLocalize();
const styles = useThemeStyles();

Expand All @@ -31,7 +31,7 @@ function UpgradeConfirmation({policyName, policyID}: Props) {
</>
}
shouldShowButton
onButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_PROFILE.getRoute(policyID))}
onButtonPress={onConfirmUpgrade}
buttonText={translate('workspace.upgrade.completed.gotIt')}
/>
);
Expand Down
19 changes: 15 additions & 4 deletions src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import {isControlPolicy} from '@libs/PolicyUtils';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import CONST from '@src/CONST';
import * as Policy from '@src/libs/actions/Policy/Policy';
Expand All @@ -26,15 +27,25 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
const [policy] = useOnyx(`policy_${policyID}`);
const {isOffline} = useNetwork();

const isUpgraded = React.useMemo(() => isControlPolicy(policy), [policy]);

if (!feature || !policy) {
return <NotFoundPage />;
}

const upgradeToCorporate = () => {
Policy.upgradeToCorporate(policy.id, feature.id);
Policy.upgradeToCorporate(policy.id, feature.name);
};

const isUpgraded = policy.type === CONST.POLICY.TYPE.CORPORATE;
const confirmUpgrade = () => {
switch (feature.id) {
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.reportFields.id:
Policy.enablePolicyReportFields(policyID, true);
return Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID), CONST.NAVIGATION.TYPE.UP);
default:
return route.params.backTo ? Navigation.navigate(route.params.backTo, CONST.NAVIGATION.TYPE.UP) : Navigation.goBack();
Comment on lines +41 to +46
Copy link
Contributor

@aldo-expensify aldo-expensify Jul 29, 2024

Choose a reason for hiding this comment

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

Why is this not simply Navigation.goBack()? Seems to work fine and fix #46450, but maybe I'm missing something 🤷

}
};

return (
<ScreenWrapper
Expand All @@ -44,11 +55,11 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
>
<HeaderWithBackButton
title={translate('common.upgrade')}
onBackButtonPress={() => Navigation.goBack(route.params.backTo ?? ROUTES.WORKSPACE_PROFILE.getRoute(policyID))}
onBackButtonPress={() => Navigation.goBack()}
/>
{isUpgraded && (
<UpgradeConfirmation
policyID={policy.id}
onConfirmUpgrade={confirmUpgrade}
policyName={policy.name}
/>
)}
Expand Down
7 changes: 1 addition & 6 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2748,15 +2748,10 @@ const styles = (theme: ThemeColors) =>
width: 110,
},

workspaceUpgradeIntroBox: ({isExtraSmallScreenWidth, isSmallScreenWidth}: WorkspaceUpgradeIntroBoxParams): ViewStyle => {
workspaceUpgradeIntroBox: ({isExtraSmallScreenWidth}: WorkspaceUpgradeIntroBoxParams): ViewStyle => {
let paddingHorizontal = spacing.ph5;
let paddingVertical = spacing.pv5;

if (isSmallScreenWidth) {
paddingHorizontal = spacing.ph4;
paddingVertical = spacing.pv4;
}

if (isExtraSmallScreenWidth) {
paddingHorizontal = spacing.ph2;
paddingVertical = spacing.pv2;
Expand Down
Loading