Skip to content

Commit

Permalink
Merge pull request Expensify#45730 from allroundexperts/fix-45689
Browse files Browse the repository at this point in the history
fix: redirect to proper place after upgrade
  • Loading branch information
madmax330 authored and allroundexperts committed Jul 31, 2024
1 parent 899b8c7 commit fd56509
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 18 deletions.
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 @@ -141,7 +141,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 @@ -155,7 +161,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();
}
};

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 @@ -2735,15 +2735,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

0 comments on commit fd56509

Please sign in to comment.