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

[GL] Tax - Add tax code #43156

Merged
merged 39 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5d711c4
add glcode route
rushatgabhane Jun 6, 2024
f66b22b
add glcode screen const
rushatgabhane Jun 6, 2024
9b1b630
add lang
rushatgabhane Jun 6, 2024
8703337
rename to taxcode
rushatgabhane Jun 6, 2024
235158b
add api params
rushatgabhane Jun 6, 2024
6e9009b
add api params
rushatgabhane Jun 6, 2024
02e0428
add api types for tax code
rushatgabhane Jun 6, 2024
093711b
add tax code to rhp
rushatgabhane Jun 6, 2024
d3f86b7
add tax code type for navigation
rushatgabhane Jun 6, 2024
1eca1e1
add access variant for control policy
rushatgabhane Jul 9, 2024
da57f9e
fix merge
rushatgabhane Jul 9, 2024
d046fe0
fix api params for taxcode
rushatgabhane Jul 9, 2024
ed414d7
fix lang
rushatgabhane Jul 9, 2024
451548c
add tax code
rushatgabhane Jul 9, 2024
a69ff83
add menu item for taxcode
rushatgabhane Jul 9, 2024
1131d5d
add tax type to onyx forms
rushatgabhane Jul 9, 2024
f782d3f
fix form id
rushatgabhane Jul 9, 2024
bee9d44
add setpolicy tax code onyx method
rushatgabhane Jul 9, 2024
6dedec2
add prev tax code
rushatgabhane Jul 9, 2024
69ddb27
fix types
rushatgabhane Jul 9, 2024
2c17a1f
add tax code validation and make form working
rushatgabhane Jul 9, 2024
78a4aeb
handle tax code navigation
rushatgabhane Jul 9, 2024
5d00b9f
go back
rushatgabhane Jul 9, 2024
7336fa1
fix navigation
rushatgabhane Jul 9, 2024
f49b915
fix merge
rushatgabhane Jul 9, 2024
9f95f89
fix merge
rushatgabhane Jul 9, 2024
2f8b223
Merge branch 'Expensify:main' into gl-code-taxes
rushatgabhane Jul 9, 2024
5bd6329
Merge branch 'main' of github.com:rushatgabhane/exfy into gl-code-taxes
rushatgabhane Jul 12, 2024
b167d5c
fix validation
rushatgabhane Jul 12, 2024
702e1d2
disable taxcode edit for non control policy
rushatgabhane Jul 12, 2024
36e8d9c
add onyx draft key
rushatgabhane Jul 12, 2024
08e7fbd
Merge branch 'Expensify:main' into gl-code-taxes
rushatgabhane Jul 12, 2024
9ca398b
fix disabled
rushatgabhane Jul 12, 2024
828d62f
Merge branch 'gl-code-taxes' of github.com:rushatgabhane/exfy into gl…
rushatgabhane Jul 15, 2024
62f5256
fix translation
rushatgabhane Jul 15, 2024
07067a6
add taxid to param
rushatgabhane Jul 15, 2024
04f31e0
Merge branch 'main' of github.com:rushatgabhane/exfy into gl-code-taxes
rushatgabhane Jul 16, 2024
81bc5b0
correct logic for existing tax code
rushatgabhane Jul 16, 2024
a78d2b5
Merge branch 'main' of github.com:rushatgabhane/exfy into gl-code-taxes
rushatgabhane Jul 16, 2024
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
3 changes: 3 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ const ONYXKEYS = {
WORKSPACE_NEW_TAX_FORM: 'workspaceNewTaxForm',
WORKSPACE_NEW_TAX_FORM_DRAFT: 'workspaceNewTaxFormDraft',
WORKSPACE_TAX_NAME_FORM: 'workspaceTaxNameForm',
WORKSPACE_TAX_CODE_FORM: 'workspaceTaxCodeForm',
WORKSPACE_TAX_CODE_FORM_DRAFT: 'workspaceTaxCodeFormDraft',
WORKSPACE_TAX_NAME_FORM_DRAFT: 'workspaceTaxNameFormDraft',
WORKSPACE_TAX_VALUE_FORM: 'workspaceTaxValueForm',
WORKSPACE_TAX_VALUE_FORM_DRAFT: 'workspaceTaxValueFormDraft',
Expand Down Expand Up @@ -633,6 +635,7 @@ type OnyxFormValuesMapping = {
[ONYXKEYS.FORMS.POLICY_DISTANCE_RATE_EDIT_FORM]: FormTypes.PolicyDistanceRateEditForm;
[ONYXKEYS.FORMS.POLICY_DISTANCE_RATE_TAX_RECLAIMABLE_ON_EDIT_FORM]: FormTypes.PolicyDistanceRateTaxReclaimableOnEditForm;
[ONYXKEYS.FORMS.WORKSPACE_TAX_NAME_FORM]: FormTypes.WorkspaceTaxNameForm;
[ONYXKEYS.FORMS.WORKSPACE_TAX_CODE_FORM]: FormTypes.WorkspaceTaxCodeForm;
[ONYXKEYS.FORMS.WORKSPACE_TAX_VALUE_FORM]: FormTypes.WorkspaceTaxValueForm;
[ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM]: FormTypes.NewChatNameForm;
[ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM]: FormTypes.SubscriptionSizeForm;
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/tax/:taxID/value',
getRoute: (policyID: string, taxID: string) => `settings/workspaces/${policyID}/tax/${encodeURIComponent(taxID)}/value` as const,
},
WORKSPACE_TAX_CODE: {
route: 'settings/workspaces/:policyID/tax/:taxID/tax-code',
getRoute: (policyID: string, taxID: string) => `settings/workspaces/${policyID}/tax/${encodeURIComponent(taxID)}/tax-code` as const,
},
WORKSPACE_REPORT_FIELDS: {
route: 'settings/workspaces/:policyID/reportFields',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/reportFields` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ const SCREENS = {
TAX_EDIT: 'Workspace_Tax_Edit',
TAX_NAME: 'Workspace_Tax_Name',
TAX_VALUE: 'Workspace_Tax_Value',
TAX_CODE: 'Workspace_Tax_Code',
TAXES_SETTINGS: 'Workspace_Taxes_Settings',
TAXES_SETTINGS_CUSTOM_TAX_NAME: 'Workspace_Taxes_Settings_CustomTaxName',
TAXES_SETTINGS_WORKSPACE_CURRENCY_DEFAULT: 'Workspace_Taxes_Settings_WorkspaceCurrency',
Expand Down
3 changes: 3 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2841,6 +2841,7 @@ export default {
taxRate: 'Tax rate',
error: {
taxRateAlreadyExists: 'This tax name is already in use.',
taxCodeAlreadyExists: 'This tax code is already in use.',
valuePercentageRange: 'Please enter a valid percentage between 0 and 100.',
customNameRequired: 'Custom tax name is required.',
deleteFailureMessage: 'An error occurred while deleting the tax rate. Please try again or ask Concierge for help.',
Expand All @@ -2859,6 +2860,8 @@ export default {
enableMultiple: 'Enable rates',
},
importedFromAccountingSoftware: 'The taxes below are imported from your',
taxCode: 'Tax code',
updateTaxCodeFailureMessage: 'An error occurred while updating the tax code, please try again.',
},
emptyWorkspace: {
title: 'Create a workspace',
Expand Down
3 changes: 3 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2890,6 +2890,7 @@ export default {
taxReclaimableOn: 'Impuesto recuperable en',
error: {
taxRateAlreadyExists: 'Ya existe un impuesto con este nombre.',
taxCodeAlreadyExists: 'Ya existe un código de impuesto con este nombre.',
customNameRequired: 'El nombre del impuesto es obligatorio.',
valuePercentageRange: 'Por favor, introduce un porcentaje entre 0 y 100.',
deleteFailureMessage: 'Se ha producido un error al intentar eliminar la tasa de impuesto. Por favor, inténtalo más tarde.',
Expand All @@ -2908,6 +2909,8 @@ export default {
enableMultiple: 'Activar tasas',
},
importedFromAccountingSoftware: 'Impuestos importadas desde',
taxCode: 'Código de impuesto',
updateTaxCodeFailureMessage: 'Se produjo un error al actualizar el código tributario, inténtelo nuevamente.',
},
emptyWorkspace: {
title: 'Crea un espacio de trabajo',
Expand Down
8 changes: 8 additions & 0 deletions src/libs/API/parameters/UpdatePolicyTaxCodeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type UpdatePolicyTaxCodeParams = {
policyID: string;
oldTaxCode: string;
newTaxCode: string;
taxID: string;
};

export default UpdatePolicyTaxCodeParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export type {default as UpdatePolicyConnectionConfigParams} from './UpdatePolicy
export type {default as UpdateManyPolicyConnectionConfigurationsParams} from './UpdateManyPolicyConnectionConfigurationsParams';
export type {default as RemovePolicyConnectionParams} from './RemovePolicyConnectionParams';
export type {default as RenamePolicyTaxParams} from './RenamePolicyTaxParams';
export type {default as UpdatePolicyTaxCodeParams} from './UpdatePolicyTaxCodeParams';
export type {default as CompleteGuidedSetupParams} from './CompleteGuidedSetupParams';
export type {default as DismissTrackExpenseActionableWhisperParams} from './DismissTrackExpenseActionableWhisperParams';
export type {default as ConvertTrackedExpenseToRequestParams} from './ConvertTrackedExpenseToRequestParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const WRITE_COMMANDS = {
DELETE_POLICY_TAXES: 'DeletePolicyTaxes',
UPDATE_POLICY_TAX_VALUE: 'UpdatePolicyTaxValue',
RENAME_POLICY_TAX: 'RenamePolicyTax',
UPDATE_POLICY_TAX_CODE: 'UpdatePolicyTaxCode',
CREATE_POLICY_DISTANCE_RATE: 'CreatePolicyDistanceRate',
REQUEST_WORKSPACE_OWNER_CHANGE: 'RequestWorkspaceOwnerChange',
ADD_BILLING_CARD_AND_REQUEST_WORKSPACE_OWNER_CHANGE: 'AddBillingCardAndRequestPolicyOwnerChange',
Expand Down Expand Up @@ -515,6 +516,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.REQUEST_WORKSPACE_OWNER_CHANGE]: Parameters.RequestWorkspaceOwnerChangeParams;
[WRITE_COMMANDS.ADD_BILLING_CARD_AND_REQUEST_WORKSPACE_OWNER_CHANGE]: Parameters.AddBillingCardAndRequestWorkspaceOwnerChangeParams;
[WRITE_COMMANDS.RENAME_POLICY_TAX]: Parameters.RenamePolicyTaxParams;
[WRITE_COMMANDS.UPDATE_POLICY_TAX_CODE]: Parameters.UpdatePolicyTaxCodeParams;
[WRITE_COMMANDS.SET_POLICY_DISTANCE_RATES_UNIT]: Parameters.SetPolicyDistanceRatesUnitParams;
[WRITE_COMMANDS.SET_POLICY_DISTANCE_RATES_DEFAULT_CATEGORY]: Parameters.SetPolicyDistanceRatesDefaultCategoryParams;
[WRITE_COMMANDS.ENABLE_DISTANCE_REQUEST_TAX]: Parameters.SetPolicyDistanceRatesDefaultCategoryParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.WORKSPACE.TAX_NAME]: () => require<ReactComponentModule>('../../../../pages/workspace/taxes/NamePage').default,
[SCREENS.WORKSPACE.TAX_VALUE]: () => require<ReactComponentModule>('../../../../pages/workspace/taxes/ValuePage').default,
[SCREENS.WORKSPACE.TAX_CREATE]: () => require<ReactComponentModule>('../../../../pages/workspace/taxes/WorkspaceCreateTaxPage').default,
[SCREENS.WORKSPACE.TAX_CODE]: () => require<ReactComponentModule>('../../../../pages/workspace/taxes/WorkspaceTaxCodePage').default,
[SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW]: () => require<ReactComponentModule>('../../../../pages/workspace/card/issueNew/IssueNewCardPage').default,
[SCREENS.WORKSPACE.EXPENSIFY_CARD_BANK_ACCOUNT]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts').default,
[SCREENS.WORKSPACE.EXPENSIFY_CARD_DETAILS]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage').default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial<Record<FullScreenName, string[]>> = {
SCREENS.WORKSPACE.TAX_EDIT,
SCREENS.WORKSPACE.TAX_NAME,
SCREENS.WORKSPACE.TAX_VALUE,
SCREENS.WORKSPACE.TAX_CODE,
],
[SCREENS.WORKSPACE.TAGS]: [
SCREENS.WORKSPACE.TAGS_SETTINGS,
Expand Down
6 changes: 6 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
taxID: (taxID: string) => decodeURIComponent(taxID),
},
},
[SCREENS.WORKSPACE.TAX_CODE]: {
path: ROUTES.WORKSPACE_TAX_CODE.route,
parse: {
taxID: (taxID: string) => decodeURIComponent(taxID),
},
},
[SCREENS.WORKSPACE.TAX_NAME]: {
path: ROUTES.WORKSPACE_TAX_NAME.route,
parse: {
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ type SettingsNavigatorParamList = {
policyID: string;
taxID: string;
};
[SCREENS.WORKSPACE.TAX_CODE]: {
policyID: string;
taxID: string;
};
[SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW]: {
policyID: string;
};
Expand Down
6 changes: 6 additions & 0 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ function isExistingTaxName(taxName: string, taxRates: TaxRates): boolean {
return !!Object.values(taxRates).find((taxRate) => taxRate.name === trimmedTaxName);
}

function isExistingTaxCode(taxCode: string, taxRates: TaxRates): boolean {
const trimmedTaxCode = taxCode.trim();
return !!Object.keys(taxRates).find((taxID) => taxID === trimmedTaxCode);
}

/**
* Validates the given value if it is correct subscription size.
*/
Expand Down Expand Up @@ -528,4 +533,5 @@ export {
isValidReportName,
isExistingTaxName,
isValidSubscriptionSize,
isExistingTaxCode,
};
100 changes: 99 additions & 1 deletion src/libs/actions/TaxRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {FormOnyxValues} from '@components/Form/types';
import * as API from '@libs/API';
import type {CreatePolicyTaxParams, DeletePolicyTaxesParams, RenamePolicyTaxParams, SetPolicyTaxesEnabledParams, UpdatePolicyTaxValueParams} from '@libs/API/parameters';
import type {
CreatePolicyTaxParams,
DeletePolicyTaxesParams,
RenamePolicyTaxParams,
SetPolicyTaxesEnabledParams,
UpdatePolicyTaxCodeParams,
UpdatePolicyTaxValueParams,
} from '@libs/API/parameters';
import {WRITE_COMMANDS} from '@libs/API/types';
import {translateLocal} from '@libs/Localize';
import * as ValidationUtils from '@libs/ValidationUtils';
import CONST from '@src/CONST';
import * as ErrorUtils from '@src/libs/ErrorUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/WorkspaceNewTaxForm';
// eslint-disable-next-line import/no-named-default
import {default as INPUT_IDS_TAX_CODE} from '@src/types/form/WorkspaceTaxCodeForm';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we use import INPUT_IDS_TAX_CODE from '@src/types/form/WorkspaceTaxCodeForm'; here?

Copy link
Member Author

Choose a reason for hiding this comment

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

because it'll conflict with import INPUT_IDS from '@src/types/form/WorkspaceNewTaxForm .

The default import name is INPUT_IDS for forms

import type {Policy, TaxRate, TaxRates} from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {OnyxData} from '@src/types/onyx/Request';
Expand Down Expand Up @@ -46,6 +55,17 @@ const validateTaxName = (policy: Policy, values: FormOnyxValues<typeof ONYXKEYS.
return errors;
};

const validateTaxCode = (policy: Policy, values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_TAX_CODE_FORM>) => {
const errors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS_TAX_CODE.TAX_CODE]);

const taxCode = values[INPUT_IDS_TAX_CODE.TAX_CODE];
if (policy?.taxRates?.taxes && ValidationUtils.isExistingTaxCode(taxCode, policy.taxRates.taxes)) {
errors[INPUT_IDS_TAX_CODE.TAX_CODE] = translateLocal('workspace.taxes.error.taxCodeAlreadyExists');
}

return errors;
};

/**
* Function to validate tax value
*/
Expand Down Expand Up @@ -463,6 +483,82 @@ function renamePolicyTax(policyID: string, taxID: string, newName: string) {
API.write(WRITE_COMMANDS.RENAME_POLICY_TAX, parameters, onyxData);
}

function setPolicyTaxCode(policyID: string, oldTaxCode: string, newTaxCode: string) {
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
const originalTaxRate = {...policy?.taxRates?.taxes[oldTaxCode]};
const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
taxes: {
[oldTaxCode]: null,
[newTaxCode]: {
...originalTaxRate,
pendingFields: {code: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
errorFields: {code: null},
previousTaxCode: oldTaxCode,
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB - are we using this anywhere? not sure we need it

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, if the action fails then we need to reset the taxCode. The previousTaxCode will be used for it

},
},
},
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
taxes: {
[oldTaxCode]: null,
[newTaxCode]: {
...originalTaxRate,
code: newTaxCode,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - do we need this?

Copy link
Member Author

@rushatgabhane rushatgabhane Jul 16, 2024

Choose a reason for hiding this comment

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

im using it for pending fields and showing errors. we need a key inside the object for which an error or pending action can be associated

https://github.com/Expensify/App/pull/43156/files/81bc5b0bc03d1cbf731a4ab2de1e1968e0aef781#diff-008bfc3488a59780cc0f301b91072fc1e18513a7bca89cb81b883772a76275a5R128

Copy link
Contributor

Choose a reason for hiding this comment

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

ah right, thanks!

pendingFields: {code: null},
pendingAction: null,
errorFields: {code: null},
},
},
},
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
taxes: {
[newTaxCode]: null,
[oldTaxCode]: {
...originalTaxRate,
code: originalTaxRate.code,
pendingFields: {code: null},
pendingAction: null,
errorFields: {code: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.taxes.error.updateFailureMessage')},
},
},
},
},
},
],
};

const parameters: UpdatePolicyTaxCodeParams = {
policyID,
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to pass the taxID (the name) here. We only really use it if the newTaxCode is clear, but you might s well pass it always, for simplicity

Copy link
Member Author

@rushatgabhane rushatgabhane Jul 13, 2024

Choose a reason for hiding this comment

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

taxCode is same as taxID right.

do you mean that the api expects ?
taxID: newTaxCode

Copy link
Member Author

Choose a reason for hiding this comment

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

i.e. just a different variable name

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, not quite. It expects the name, which is often similar (as we get the default code based on the name, which is why we need it when empty), but not the same as the taxCode.

This one:
Screenshot 2024-07-15 at 8 51 39 AM

oldTaxCode,
newTaxCode,
taxID: originalTaxRate.name ?? '',
};

API.write(WRITE_COMMANDS.UPDATE_POLICY_TAX_CODE, parameters, onyxData);
}

export {
createPolicyTax,
getNextTaxCode,
Expand All @@ -471,8 +567,10 @@ export {
getTaxValueWithPercentage,
setPolicyTaxesEnabled,
validateTaxName,
validateTaxCode,
validateTaxValue,
deletePolicyTaxes,
updatePolicyTaxValue,
renamePolicyTax,
setPolicyTaxCode,
};
23 changes: 20 additions & 3 deletions src/pages/workspace/taxes/WorkspaceEditTaxPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ function WorkspaceEditTaxPage({
const {translate} = useLocalize();
const currentTaxRate = PolicyUtils.getTaxByID(policy, taxID);
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const canEdit = policy && PolicyUtils.canEditTaxRate(policy, taxID);
const canEditTaxRate = policy && PolicyUtils.canEditTaxRate(policy, taxID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
const canEditTaxCode = !PolicyUtils.isControlPolicy(policy);

const shouldShowDeleteMenuItem = canEdit && !hasAccountingConnections;
const shouldShowDeleteMenuItem = canEditTaxRate && !hasAccountingConnections;

const toggleTaxRate = () => {
if (!currentTaxRate) {
Expand Down Expand Up @@ -87,7 +88,7 @@ function WorkspaceEditTaxPage({
isOn={!currentTaxRate?.isDisabled}
accessibilityLabel={translate('workspace.taxes.actions.enable')}
onToggle={toggleTaxRate}
disabled={!canEdit}
disabled={!canEditTaxRate}
/>
</View>
</View>
Expand Down Expand Up @@ -122,6 +123,22 @@ function WorkspaceEditTaxPage({
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_TAX_VALUE.getRoute(`${policyID}`, taxID))}
/>
</OfflineWithFeedback>
<OfflineWithFeedback
errors={ErrorUtils.getLatestErrorField(currentTaxRate, 'code')}
pendingAction={currentTaxRate?.pendingFields?.code}
errorRowStyles={styles.mh5}
onClose={() => clearTaxRateFieldError(policyID, taxID, 'code')}
>
<MenuItemWithTopDescription
shouldShowRightIcon
title={taxID}
description={translate('workspace.taxes.taxCode')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
disabled={canEditTaxCode}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_TAX_CODE.getRoute(`${policyID}`, taxID))}
/>
</OfflineWithFeedback>
{shouldShowDeleteMenuItem && (
<MenuItem
icon={Expensicons.Trashcan}
Expand Down
Loading
Loading