Skip to content

Commit

Permalink
improve nav flow
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkiy37 committed Mar 11, 2024
1 parent c4e8292 commit 1ec0295
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type {
InvitedEmailsToAccountIDs,
Expand Down Expand Up @@ -2652,6 +2653,18 @@ function clearCategoryErrors(policyID: string, categoryName: string) {
});
}

function navigateWhenEnableFeature(policyID: string, featureRoute: Route) {
const isNarrowLayout = getIsNarrowLayout();

if (isNarrowLayout) {
Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID), CONST.NAVIGATION.TYPE.FORCED_UP);

return;
}

Navigation.navigate(featureRoute);
}

function enablePolicyCategories(policyID: string, enabled: boolean) {
const onyxData: OnyxData = {
optimisticData: [
Expand Down Expand Up @@ -2696,8 +2709,7 @@ function enablePolicyCategories(policyID: string, enabled: boolean) {
API.write(WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES, parameters, onyxData);

if (enabled) {
const navigationAction = getIsNarrowLayout() ? Navigation.goBack : () => Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID));
navigationAction();
navigateWhenEnableFeature(policyID, ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID));
}
}

Expand Down Expand Up @@ -2789,8 +2801,7 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) {
API.write(WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, parameters, onyxData);

if (enabled) {
const navigationAction = getIsNarrowLayout() ? Navigation.goBack : () => Navigation.navigate(ROUTES.WORKSPACE_DISTANCE_RATES.getRoute(policyID));
navigationAction();
navigateWhenEnableFeature(policyID, ROUTES.WORKSPACE_DISTANCE_RATES.getRoute(policyID));
}
}

Expand Down Expand Up @@ -2882,8 +2893,7 @@ function enablePolicyTags(policyID: string, enabled: boolean) {
API.write(WRITE_COMMANDS.ENABLE_POLICY_TAGS, parameters, onyxData);

if (enabled) {
const navigationAction = getIsNarrowLayout() ? Navigation.goBack : () => Navigation.navigate(ROUTES.WORKSPACE_TAGS.getRoute(policyID));
navigationAction();
navigateWhenEnableFeature(policyID, ROUTES.WORKSPACE_TAGS.getRoute(policyID));
}
}

Expand Down Expand Up @@ -2979,8 +2989,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
API.write(WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS, parameters, onyxData);

if (enabled) {
const navigationAction = getIsNarrowLayout() ? Navigation.goBack : () => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID));
navigationAction();
navigateWhenEnableFeature(policyID, ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID));
}
}

Expand Down

0 comments on commit 1ec0295

Please sign in to comment.