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: Hm it's not here shown when edit the tax code and save #45983

Merged
merged 1 commit into from
Jul 23, 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
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
Loading