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

[Simplified Collect][Taxes] Tax editing and bulk actions #38208

Merged
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dff681d
add edit tax modal
kosmydel Mar 13, 2024
ff731cb
add enabling/disabling taxes
kosmydel Mar 13, 2024
ea97afb
add deleting tax rates
kosmydel Mar 13, 2024
f512cf0
update enable tax api call
kosmydel Mar 14, 2024
2a3f4c3
add NamePage and ValuePage
kosmydel Mar 14, 2024
f40c5b5
Merge branch 'wave8/CreatingNewTaxes' into wave8/WorkspaceEditPage
kosmydel Mar 14, 2024
a25926f
renaming tax names
kosmydel Mar 14, 2024
ac59d75
update backend queries
kosmydel Mar 14, 2024
76d56f8
refactor
kosmydel Mar 14, 2024
75c48ba
update to new backend
kosmydel Mar 14, 2024
3b590c6
add bulk actions
kosmydel Mar 14, 2024
ed94efe
add wrappers
kosmydel Mar 14, 2024
b8eb432
pending actions draft
kosmydel Mar 14, 2024
27ecd7e
Merge branch 'wave8/CreatingNewTaxes' into wave8/WorkspaceEditPage
kosmydel Mar 15, 2024
2cee1ee
fix error handling and offline feedback
kosmydel Mar 15, 2024
75f7f03
Merge branch 'main' into wave8/WorkspaceEditPage
kosmydel Mar 19, 2024
f7a6213
improvements
kosmydel Mar 19, 2024
27ddedf
improve validation
kosmydel Mar 19, 2024
f8992bd
use policyID from route
kosmydel Mar 19, 2024
561c651
address review
kosmydel Mar 19, 2024
472d983
new spanish translations
kosmydel Mar 19, 2024
3f55637
new translations
kosmydel Mar 19, 2024
ddee558
add param, address review
kosmydel Mar 19, 2024
1bac4db
extract policyID
kosmydel Mar 19, 2024
2fc8fee
lint & ts
kosmydel Mar 19, 2024
110f743
address review
kosmydel Mar 19, 2024
89f474c
improve types
kosmydel Mar 19, 2024
d0164a4
fix routes
kosmydel Mar 19, 2024
70f726e
fix icons,
kosmydel Mar 19, 2024
94a3111
fix dropdown button
kosmydel Mar 19, 2024
b9dce2f
fix android
kosmydel Mar 19, 2024
5876e11
fix Spanish translations
kosmydel Mar 20, 2024
52688aa
fix copies
kosmydel Mar 20, 2024
8cadf35
address review
kosmydel Mar 20, 2024
089661e
Merge branch 'main' into wave8/WorkspaceEditPage
kosmydel Mar 20, 2024
e6335cd
rename
kosmydel Mar 20, 2024
ef278f1
rename taxes to tax
kosmydel Mar 20, 2024
0c68d88
move canEditTaxRate to PolicyUtils
kosmydel Mar 20, 2024
acd8d58
Merge branch 'main' into wave8/WorkspaceEditPage
kosmydel Mar 20, 2024
d97bcd3
add FeatureEnabledAccessOrNotFoundWrapper
kosmydel Mar 20, 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
5 changes: 5 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,11 @@ const CONST = {
DISABLE: 'disable',
ENABLE: 'enable',
},
TAX_RATES_BULK_ACTION_TYPES: {
DELETE: 'delete',
DISABLE: 'disable',
ENABLE: 'enable',
},
},

CUSTOM_UNITS: {
Expand Down
6 changes: 6 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ const ONYXKEYS = {
POLICY_TAG_NAME_FORM_DRAFT: 'policyTagNameFormDraft',
WORKSPACE_NEW_TAX_FORM: 'workspaceNewTaxForm',
WORKSPACE_NEW_TAX_FORM_DRAFT: 'workspaceNewTaxFormDraft',
WORKSPACE_TAX_NAME_FORM: 'workspaceTaxNameForm',
kosmydel marked this conversation as resolved.
Show resolved Hide resolved
WORKSPACE_TAX_NAME_FORM_DRAFT: 'workspaceTaxNameFormDraft',
WORKSPACE_TAX_VALUE_FORM: 'workspaceTaxValueForm',
WORKSPACE_TAX_VALUE_FORM_DRAFT: 'workspaceTaxValueFormDraft',
},
} as const;

Expand Down Expand Up @@ -465,6 +469,8 @@ type OnyxFormValuesMapping = {
[ONYXKEYS.FORMS.POLICY_TAG_NAME_FORM]: FormTypes.PolicyTagNameForm;
[ONYXKEYS.FORMS.WORKSPACE_NEW_TAX_FORM]: FormTypes.WorkspaceNewTaxForm;
[ONYXKEYS.FORMS.POLICY_CREATE_DISTANCE_RATE_FORM]: FormTypes.PolicyCreateDistanceRateForm;
[ONYXKEYS.FORMS.WORKSPACE_TAX_NAME_FORM]: FormTypes.WorkspaceTaxNameForm;
[ONYXKEYS.FORMS.WORKSPACE_TAX_VALUE_FORM]: FormTypes.WorkspaceTaxValueForm;
};

type OnyxFormDraftValuesMapping = {
Expand Down
12 changes: 12 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,18 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/taxes/new',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/taxes/new` as const,
},
WORKSPACE_TAXES_EDIT: {
route: 'settings/workspaces/:policyID/tax/:taxID',
getRoute: (policyID: string, taxID: string) => `settings/workspaces/${policyID}/tax/${encodeURI(taxID)}` as const,
},
WORKSPACE_TAXES_NAME: {
route: 'settings/workspaces/:policyID/tax/:taxID/name',
getRoute: (policyID: string, taxID: string) => `settings/workspaces/${policyID}/tax/${encodeURI(taxID)}/name` as const,
},
WORKSPACE_TAXES_VALUE: {
route: 'settings/workspaces/:policyID/tax/:taxID/value',
getRoute: (policyID: string, taxID: string) => `settings/workspaces/${policyID}/tax/${encodeURI(taxID)}/value` as const,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB the url changes when navigating from Edit to Name/Value pages. We can address this as a follow up though

Screen.Recording.2024-03-19.at.10.04.53.AM.mov

WORKSPACE_DISTANCE_RATES: {
route: 'settings/workspaces/:policyID/distance-rates',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/distance-rates` as const,
Expand Down
3 changes: 3 additions & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ const SCREENS = {
TAGS_SETTINGS: 'Tags_Settings',
TAGS_EDIT: 'Tags_Edit',
TAXES: 'Workspace_Taxes',
TAXES_EDIT: 'Workspace_Taxes_Edit',
kosmydel marked this conversation as resolved.
Show resolved Hide resolved
TAXES_NAME: 'Workspace_Taxes_Name',
kosmydel marked this conversation as resolved.
Show resolved Hide resolved
TAXES_VALUE: 'Workspace_Taxes_Value',
kosmydel marked this conversation as resolved.
Show resolved Hide resolved
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: 2 additions & 1 deletion src/components/AmountPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function AmountPicker({value, description, title, errorText = '', onInputChange,

const updateInput = (updatedValue: string) => {
if (updatedValue !== value) {
onInputChange?.(updatedValue);
// We cast the updatedValue to a number and then back to a string to remove any leading zeros and separating commas
onInputChange?.(String(Number(updatedValue)));
}
hidePickerModal();
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/ButtonWithDropdownMenu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type WorkspaceMemberBulkActionType = DeepValueOf<typeof CONST.POLICY.MEMBERS_BUL

type WorkspaceDistanceRatesBulkActionType = DeepValueOf<typeof CONST.POLICY.DISTANCE_RATES_BULK_ACTION_TYPES>;

type WorkspaceTaxRatesBulkActionType = DeepValueOf<typeof CONST.POLICY.TAX_RATES_BULK_ACTION_TYPES>;

type DropdownOption<TValueType> = {
value: TValueType;
text: string;
Expand Down Expand Up @@ -73,4 +75,4 @@ type ButtonWithDropdownMenuProps<TValueType> = {
wrapperStyle?: StyleProp<ViewStyle>;
};

export type {PaymentType, WorkspaceMemberBulkActionType, WorkspaceDistanceRatesBulkActionType, DropdownOption, ButtonWithDropdownMenuProps};
export type {PaymentType, WorkspaceMemberBulkActionType, WorkspaceDistanceRatesBulkActionType, DropdownOption, ButtonWithDropdownMenuProps, WorkspaceTaxRatesBulkActionType};
14 changes: 13 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,19 @@ export default {
errors: {
taxRateAlreadyExists: 'This tax name is already in use.',
valuePercentageRange: 'Please enter a valid percentage between 0 and 100.',
genericFailureMessage: 'An error occurred while updating the tax rate, please try again.',
deleteFailureMessage: 'An error occurred while deleting the tax rate, please try again.',
updateFailureMessage: 'An error occurred while updating the tax rate, please try again.',
createFailureMessage: 'An error occurred while creating the tax rate, please try again.',
},
deleteTaxConfirmation: 'Are you sure you want to delete this tax?',
Copy link
Contributor

Choose a reason for hiding this comment

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

missing es translations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Asked for translations here.

deleteMultipleTaxConfirmation: ({taxAmount}) => `Are you sure you want to delete ${taxAmount} taxes?`,
actions: {
delete: 'Delete rate',
deleteMultiple: 'Delete rates',
disable: 'Disable rate',
disableMultiple: 'Disable rates',
enable: 'Enable rate',
enableMultiple: 'Enable rates',
Copy link
Contributor

Choose a reason for hiding this comment

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

@Expensify/marketing could you please review this copy?

Copy link
Contributor

Choose a reason for hiding this comment

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

To confirm, these are just generic error messages where we don't really know exactly what happened? Or is there any more info we have where we can get more specific? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, these are just generic for when we don't know what happened. Otherwise the server sends specific error messages for the cases we do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if needed we can be a bit more specific for updateFailureMessage. We can split it:

  • toggling the tax rate,
  • changing name,
  • changing value.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would guess, though, that we'd show the error message right after you take the action that triggered it, so it would be fairly easy to understand what went wrong. Maybe we can stick with the generics here:

  • deleteFailureMessage: An error occurred while deleting the tax rate. Please try again or ask Concierge for help.
  • updateFailureMessage: An error occurred while updating the tax rate. Please try again or ask Concierge for help.
  • createFailureMessage: An error occurred while creating the tax rate. Please try again or ask Concierge for help.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, agreed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the PR.

},
},
emptyWorkspace: {
Expand Down
16 changes: 14 additions & 2 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1892,8 +1892,20 @@ export default {
value: 'Valor',
errors: {
taxRateAlreadyExists: 'Ya existe un impuesto con este nombre',
valuePercentageRange: 'Introduzca un porcentaje válido entre 0 y 100',
genericFailureMessage: 'Se produjo un error al actualizar el tipo impositivo, inténtelo nuevamente.',
valuePercentageRange: 'Por favor, introduce un porcentaje entre 0 y 100',
Copy link
Contributor

Choose a reason for hiding this comment

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

valuePercentageRange isn't confirmed in the Slack.

deleteFailureMessage: 'Se ha producido un error al intentar eliminar el tipo impositivo. Por favor, inténtalo más tarde.',
updateFailureMessage: 'Se ha producido un error al intentar eliminar el tipo impositivo. Por favor, inténtalo más tarde.',
createFailureMessage: 'Se ha producido un error al intentar crear el tipo impositivo. Por favor, inténtalo más tarde.',
},
deleteTaxConfirmation: '¿Estás seguro de que quieres eliminar este impuesto?',
deleteMultipleTaxConfirmation: ({taxAmount}) => `¿Está seguro de que desea eliminar ${taxAmount} impuestos?`,
actions: {
delete: 'Eliminar impositivo',
deleteMultiple: 'Eliminar impuestos',
disable: 'Desactivar impositivo',
disableMultiple: 'Desactivar impuestos',
enable: 'Activar impositivo',
enableMultiple: 'Activar impuestos',
},
},
emptyWorkspace: {
Expand Down
11 changes: 11 additions & 0 deletions src/libs/API/parameters/DeletePolicyTaxesParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type DeletePolicyTaxesParams = {
policyID: string;
/**
* Stringified JSON object with type of following structure:
* Array<string>
* Each element is a tax name
*/
taxNames: string;
};

export default DeletePolicyTaxesParams;
7 changes: 7 additions & 0 deletions src/libs/API/parameters/RenamePolicyTaxParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type SetPolicyCurrencyDefaultParams = {
policyID: string;
taxCode: string;
newName: string;
};

export default SetPolicyCurrencyDefaultParams;
10 changes: 10 additions & 0 deletions src/libs/API/parameters/SetPolicyTaxesEnabledParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type SetPolicyTaxesEnabledParams = {
policyID: string;
/**
* Stringified JSON object with type of following structure:
* Array<{taxCode: string, enabled: bool}>
*/
taxFieldsArray: string;
};

export default SetPolicyTaxesEnabledParams;
7 changes: 7 additions & 0 deletions src/libs/API/parameters/UpdatePolicyTaxValueParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type UpdatePolicyTaxValueParams = {
policyID: string;
taxCode: string;
taxAmount: number;
};

export default UpdatePolicyTaxValueParams;
4 changes: 4 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ export type {default as EnablePolicyTaxesParams} from './EnablePolicyTaxesParams
export type {default as OpenPolicyMoreFeaturesPageParams} from './OpenPolicyMoreFeaturesPageParams';
export type {default as CreatePolicyDistanceRateParams} from './CreatePolicyDistanceRateParams';
export type {default as CreatePolicyTagsParams} from './CreatePolicyTagsParams';
export type {default as SetPolicyTaxesEnabledParams} from './SetPolicyTaxesEnabledParams';
export type {default as DeletePolicyTaxesParams} from './DeletePolicyTaxesParams';
export type {default as UpdatePolicyTaxValueParams} from './UpdatePolicyTaxValueParams';
export type {default as DeletePolicyTagsParams} from './DeletePolicyTagsParams';
export type {default as SetPolicyCustomTaxNameParams} from './SetPolicyCustomTaxNameParams';
export type {default as SetPolicyForeignCurrencyDefaultParams} from './SetPolicyForeignCurrencyDefaultParams';
export type {default as SetPolicyCurrencyDefaultParams} from './SetPolicyCurrencyDefaultParams';
export type {default as RenamePolicyTaxParams} from './RenamePolicyTaxParams';
8 changes: 8 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ const WRITE_COMMANDS = {
ACCEPT_JOIN_REQUEST: 'AcceptJoinRequest',
DECLINE_JOIN_REQUEST: 'DeclineJoinRequest',
CREATE_POLICY_TAX: 'CreatePolicyTax',
SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled',
DELETE_POLICY_TAXES: 'DeletePolicyTaxes',
UPDATE_POLICY_TAX_VALUE: 'UpdatePolicyTaxValue',
RENAME_POLICY_TAX: 'RenamePolicyTax',
CREATE_POLICY_DISTANCE_RATE: 'CreatePolicyDistanceRate',
} as const;

Expand Down Expand Up @@ -361,7 +365,11 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.SET_POLICY_CUSTOM_TAX_NAME]: Parameters.SetPolicyCustomTaxNameParams;
[WRITE_COMMANDS.SET_POLICY_TAXES_FOREIGN_CURRENCY_DEFAULT]: Parameters.SetPolicyForeignCurrencyDefaultParams;
[WRITE_COMMANDS.CREATE_POLICY_TAX]: Parameters.CreatePolicyTaxParams;
[WRITE_COMMANDS.SET_POLICY_TAXES_ENABLED]: Parameters.SetPolicyTaxesEnabledParams;
[WRITE_COMMANDS.DELETE_POLICY_TAXES]: Parameters.DeletePolicyTaxesParams;
[WRITE_COMMANDS.UPDATE_POLICY_TAX_VALUE]: Parameters.UpdatePolicyTaxValueParams;
[WRITE_COMMANDS.CREATE_POLICY_DISTANCE_RATE]: Parameters.CreatePolicyDistanceRateParams;
[WRITE_COMMANDS.RENAME_POLICY_TAX]: Parameters.RenamePolicyTaxParams;
};

const READ_COMMANDS = {
Expand Down
16 changes: 16 additions & 0 deletions src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxDa
return {[key]: getErrorMessageWithTranslationData(errorsForField[key])};
}

/**
* Method used to get the latest error field for any field
*/
function getLatestErrorFieldForAnyField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData): Errors {
const errorFields = onyxData.errorFields ?? {};

if (Object.keys(errorFields).length === 0) {
return {};
}

const fieldNames = Object.keys(errorFields);
const latestErrorFields = fieldNames.map((fieldName) => getLatestErrorField(onyxData, fieldName));
return latestErrorFields.reduce((acc, error) => ({...acc, ...error}), {});
}

/**
* Method used to attach already translated message with isTranslated property
* @param errors - An object containing current errors in the form
Expand Down Expand Up @@ -176,6 +191,7 @@ export {
getLatestErrorField,
getLatestErrorMessage,
getLatestErrorMessageField,
getLatestErrorFieldForAnyField,
getMicroSecondOnyxError,
getMicroSecondOnyxErrorObject,
isReceiptError,
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.SETTINGS.EXIT_SURVEY.CONFIRM]: () => require('../../../pages/settings/ExitSurvey/ExitSurveyConfirmPage').default as React.ComponentType,
[SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY]: () => require('../../../pages/workspace/workflows/WorkspaceAutoReportingFrequencyPage').default as React.ComponentType,
[SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET]: () => require('../../../pages/workspace/workflows/WorkspaceAutoReportingMonthlyOffsetPage').default as React.ComponentType,
[SCREENS.WORKSPACE.TAXES_EDIT]: () => require('../../../pages/workspace/taxes/WorkspaceEditTaxPage').default as React.ComponentType,
[SCREENS.WORKSPACE.TAXES_NAME]: () => require('../../../pages/workspace/taxes/NamePage').default as React.ComponentType,
[SCREENS.WORKSPACE.TAXES_VALUE]: () => require('../../../pages/workspace/taxes/ValuePage').default as React.ComponentType,
[SCREENS.WORKSPACE.TAX_CREATE]: () => require('../../../pages/workspace/taxes/WorkspaceCreateTaxPage').default as React.ComponentType,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial<Record<FullScreenName, string[]>> = {
SCREENS.WORKSPACE.TAXES_SETTINGS_CUSTOM_TAX_NAME,
SCREENS.WORKSPACE.TAXES_SETTINGS_FOREIGN_CURRENCY_DEFAULT,
SCREENS.WORKSPACE.TAXES_SETTINGS_WORKSPACE_CURRENCY_DEFAULT,
SCREENS.WORKSPACE.TAX_CREATE,
SCREENS.WORKSPACE.TAXES_EDIT,
SCREENS.WORKSPACE.TAXES_NAME,
SCREENS.WORKSPACE.TAXES_VALUE,
],
[SCREENS.WORKSPACE.TAGS]: [SCREENS.WORKSPACE.TAGS_SETTINGS, SCREENS.WORKSPACE.TAGS_EDIT, SCREENS.WORKSPACE.TAG_CREATE, SCREENS.WORKSPACE.TAG_SETTINGS, SCREENS.WORKSPACE.TAX_CREATE],
[SCREENS.WORKSPACE.CATEGORIES]: [SCREENS.WORKSPACE.CATEGORY_CREATE, SCREENS.WORKSPACE.CATEGORY_SETTINGS, SCREENS.WORKSPACE.CATEGORIES_SETTINGS, SCREENS.WORKSPACE.CATEGORY_EDIT],
Expand Down
9 changes: 9 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.WORKSPACE.TAX_CREATE]: {
path: ROUTES.WORKSPACE_TAX_CREATE.route,
},
[SCREENS.WORKSPACE.TAXES_EDIT]: {
path: ROUTES.WORKSPACE_TAXES_EDIT.route,
},
[SCREENS.WORKSPACE.TAXES_NAME]: {
path: ROUTES.WORKSPACE_TAXES_NAME.route,
},
[SCREENS.WORKSPACE.TAXES_VALUE]: {
path: ROUTES.WORKSPACE_TAXES_VALUE.route,
},
},
},
[SCREENS.RIGHT_MODAL.PRIVATE_NOTES]: {
Expand Down
12 changes: 12 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ type SettingsNavigatorParamList = {
[SCREENS.WORKSPACE.TAX_CREATE]: {
policyID: string;
};
[SCREENS.WORKSPACE.TAXES_EDIT]: {
policyID: string;
taxID: string;
};
[SCREENS.WORKSPACE.TAXES_NAME]: {
policyID: string;
taxID: string;
};
[SCREENS.WORKSPACE.TAXES_VALUE]: {
policyID: string;
taxID: string;
};
} & ReimbursementAccountNavigatorParamList;

type NewChatNavigatorParamList = {
Expand Down
10 changes: 8 additions & 2 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PersonalDetailsList, Policy, PolicyCategories, PolicyMembers, PolicyTagList, PolicyTags} from '@src/types/onyx';
import type {PersonalDetailsList, Policy, PolicyCategories, PolicyMembers, PolicyTagList, PolicyTags, TaxRate} from '@src/types/onyx';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import Navigation from './Navigation/Navigation';
Expand Down Expand Up @@ -34,7 +34,7 @@ function hasPolicyMemberError(policyMembers: OnyxEntry<PolicyMembers>): boolean
* Check if the policy has any tax rate errors.
*/
function hasTaxRateError(policy: OnyxEntry<Policy>): boolean {
return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0);
return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0 || Object.values(taxRate?.errorFields ?? {}).some(Boolean));
}

/**
Expand Down Expand Up @@ -276,6 +276,11 @@ function goBackFromInvalidPolicy() {
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
}

/** Get a tax with given ID from policy */
function getTaxByID(policy: OnyxEntry<Policy>, taxID: string): TaxRate | undefined {
return policy?.taxRates?.taxes?.[taxID];
}

export {
getActivePolicies,
hasAccountingConnections,
Expand Down Expand Up @@ -307,6 +312,7 @@ export {
getPolicyMembersByIdWithoutCurrentUser,
goBackFromInvalidPolicy,
hasTaxRateError,
getTaxByID,
hasPolicyCategoriesError,
};

Expand Down
3 changes: 2 additions & 1 deletion src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ function isValidPercentage(value: string): boolean {
* Validates the given value if it is correct tax name.
*/
function isExistingTaxName(value: string, taxRates: TaxRates): boolean {
kosmydel marked this conversation as resolved.
Show resolved Hide resolved
return !!Object.values(taxRates).find((taxRate) => taxRate.name === value);
const toCheck = value.trim();
kosmydel marked this conversation as resolved.
Show resolved Hide resolved
return !!Object.values(taxRates).find((taxRate) => taxRate.name === toCheck);
}

export {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/WorkspacesSettingsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection<Policy>, policyM

function hasWorkspaceSettingsRBR(policy: Policy) {
const policyMemberError = allPolicyMembers ? hasPolicyMemberError(allPolicyMembers[`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policy.id}`]) : false;
const taxRateError = hasTaxRateError(policy);

return Object.keys(reimbursementAccount?.errors ?? {}).length > 0 || hasPolicyError(policy) || hasCustomUnitsError(policy) || policyMemberError;
return Object.keys(reimbursementAccount?.errors ?? {}).length > 0 || hasPolicyError(policy) || hasCustomUnitsError(policy) || policyMemberError || taxRateError;
}

function getChatTabBrickRoad(policyID?: string): BrickRoad | undefined {
Expand Down
Loading
Loading