Skip to content

Commit

Permalink
Merge pull request #45983 from nkdengineer/fix/45919
Browse files Browse the repository at this point in the history
fix: Hm it's not here shown when edit the tax code and save
  • Loading branch information
mountiny authored Jul 23, 2024
2 parents 17a8bbd + ebfa9b2 commit 1efdcc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,10 @@ function hasNoPolicyOtherThanPersonalType() {
);
}

function getCurrentTaxID(policy: OnyxEntry<Policy>, taxID: string): string | undefined {
return Object.keys(policy?.taxRates?.taxes ?? {}).find((taxIDKey) => policy?.taxRates?.taxes?.[taxIDKey].previousTaxCode === taxID || taxIDKey === taxID);
}

export {
canEditTaxRate,
extractPolicyIDFromPath,
Expand Down Expand Up @@ -878,6 +882,7 @@ export {
isNetSuiteCustomFieldPropertyEditable,
getCurrentSageIntacctEntityName,
hasNoPolicyOtherThanPersonalType,
getCurrentTaxID,
};

export type {MemberEmailsToAccountIDs};
12 changes: 10 additions & 2 deletions src/pages/workspace/taxes/WorkspaceEditTaxPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useState} from 'react';
import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -35,7 +35,8 @@ function WorkspaceEditTaxPage({
}: WorkspaceEditTaxPageBaseProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const currentTaxRate = PolicyUtils.getTaxByID(policy, taxID);
const currentTaxID = PolicyUtils.getCurrentTaxID(policy, taxID);
const currentTaxRate = currentTaxID && policy?.taxRates?.taxes?.[currentTaxID];
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const canEditTaxRate = policy && PolicyUtils.canEditTaxRate(policy, taxID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
Expand All @@ -50,6 +51,13 @@ function WorkspaceEditTaxPage({
setPolicyTaxesEnabled(policyID, [taxID], !!currentTaxRate.isDisabled);
};

useEffect(() => {
if (currentTaxID === taxID || !currentTaxID) {
return;
}
Navigation.setParams({taxID: currentTaxID});
}, [taxID, currentTaxID]);

const deleteTaxRate = () => {
if (!policyID) {
return;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/taxes/WorkspaceTaxCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ function WorkspaceTaxCodePage({route}: WorkspaceTaxCodePageProps) {
}

setPolicyTaxCode(policyID, currentTaxCode, newTaxCode);
Navigation.dismissModal();
Navigation.navigate(ROUTES.WORKSPACE_TAX_EDIT.getRoute(policyID, newTaxCode));
Navigation.goBack(ROUTES.WORKSPACE_TAX_EDIT.getRoute(policyID, currentTaxCode));
},
[currentTaxCode, policyID],
);
Expand Down

0 comments on commit 1efdcc0

Please sign in to comment.