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: add default rates data #38375

Merged
merged 29 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
060df3d
fix add default rates data
nkdengineer Mar 15, 2024
4ca4290
fix optimistic data
nkdengineer Mar 15, 2024
385893f
fix remove pending field
nkdengineer Mar 15, 2024
5e03c10
fix remove tax rates pending
nkdengineer Mar 15, 2024
f0a87ff
fix add taxRates data if failed
nkdengineer Mar 15, 2024
578d2d9
fix grey out row once offline
nkdengineer Mar 15, 2024
23e9eff
fix use default tax const
nkdengineer Mar 16, 2024
8ca415f
fix add taxes data to param
nkdengineer Mar 19, 2024
1948ce0
Merge branch 'main' into fix/38234
nkdengineer Mar 19, 2024
47a2dc7
fix lint
nkdengineer Mar 19, 2024
b4e2493
fix import type
nkdengineer Mar 19, 2024
f49fd7e
fix offline mode issue
nkdengineer Mar 20, 2024
bd33bd3
fix failure data
nkdengineer Mar 20, 2024
b7e8947
fix lint
nkdengineer Mar 20, 2024
2437b2c
fix refactor the default taxes data const
nkdengineer Mar 20, 2024
713782d
fix typo
nkdengineer Mar 20, 2024
95af3e3
fix lint
nkdengineer Mar 20, 2024
016e4f1
fix use array reduce
nkdengineer Mar 20, 2024
c915f96
fix remove reduce
nkdengineer Mar 20, 2024
d26c90d
fix use taxFields as string
nkdengineer Mar 21, 2024
469be4c
fix revert change
nkdengineer Mar 21, 2024
2d751ea
fix use taxFields as string
nkdengineer Mar 21, 2024
ec240ac
fix merge main
nkdengineer Mar 21, 2024
0cd290e
fix refactor optimistic data
nkdengineer Mar 21, 2024
0b1005e
fix lint
nkdengineer Mar 21, 2024
dc5dfda
fix combine two data in optimistic data
nkdengineer Mar 22, 2024
3472f14
fix lint
nkdengineer Mar 22, 2024
c923ed6
fix rename taxt rate 1
nkdengineer Mar 22, 2024
250baa9
fix do not import type in CONST
nkdengineer Mar 22, 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
15 changes: 15 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,21 @@ const CONST = {

TOOLTIP_MAX_LINES: 3,

TAXES: {
DEFAULT: {
EXTERNAL_ID: 'id_TAX_EXEMPT',
FOREIGN_ID: 'id_TAX_EXEMPT',
VALUE: '0%',
EXEMPT_ID: 'id_TAX_EXEMPT',
NAME: 'Tax',
EXEMPT_NAME: 'Tax exempt',
EXEMPT_VALUE: '0%',
TAX_RATE_1_ID: 'id_TAX_RATE_1',
TAX_RATE_1_NAME: 'Tax Rate 1',
TAX_RATE_1_VALUE: '5%',
},
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These data are obtained when I try turning on the tax feature in OD

Copy link
Contributor

Choose a reason for hiding this comment

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

@luacmartins @kosmydel @filip-solecki
Please confirm if the following default tax rates as per @nkdengineer proposal would match the BE defaults.
Also, is localization required for name i.e. "Tax", "Tax exempt", "Tax option 1"?

{
        "defaultExternalID": "id_TAX_EXEMPT",
        "defaultValue": "0%",
        "foreignTaxDefault": "id_TAX_EXEMPT",
        "name": "Tax",
        "taxes": {
            "id_TAX_EXEMPT": {
                "name": "Tax exempt",
                "value": "0%"
            },
            "id_TAX_OPTION_1": {
                "name": "Tax option 1",
                "value": "5%"
            }
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

{ "defaultExternalID": "id_TAX_EXEMPT", "defaultValue": "0%", "foreignTaxDefault": "id_TAX_EXEMPT", "name": "Tax", "taxes": { "id_TAX_EXEMPT": { "name": "Tax exempt", "value": "0%" }, "id_TAX_RATE_1": { "name": "Tax rate 1", "value": "5%" } } }

Copy link
Contributor

Choose a reason for hiding this comment

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

I left a comment above, I think the only difference is id_TAX_OPTION_1 should be id_TAX_RATE_1 and same for the name Tax option 1 -> Tax rate 1

Copy link
Contributor

Choose a reason for hiding this comment

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

I left a comment above, I think the only difference is id_TAX_OPTION_1 should be id_TAX_RATE_1 and same for the name Tax option 1 -> Tax rate 1

I think the code has incorporated most of these already. Only one minor change is pending: Tax Rate 1 -> Tax rate 1

LOGIN_TYPE: {
PHONE: 'phone',
EMAIL: 'email',
Expand Down
32 changes: 32 additions & 0 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3415,6 +3415,36 @@ function enablePolicyTags(policyID: string, enabled: boolean) {
}

function enablePolicyTaxes(policyID: string, enabled: boolean) {
const taxRatesData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
defaultExternalID: CONST.TAXES.DEFAULT.EXTERNAL_ID,
defaultValue: CONST.TAXES.DEFAULT.VALUE,
foreignTaxDefault: CONST.TAXES.DEFAULT.FOREIGN_ID,
name: CONST.TAXES.DEFAULT.NAME,
taxes: {
[CONST.TAXES.DEFAULT.EXEMPT_ID]: {
name: CONST.TAXES.DEFAULT.EXEMPT_NAME,
value: CONST.TAXES.DEFAULT.EXEMPT_VALUE,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
[CONST.TAXES.DEFAULT.TAX_RATE_1_ID]: {
name: CONST.TAXES.DEFAULT.TAX_RATE_1_NAME,
value: CONST.TAXES.DEFAULT.TAX_RATE_1_VALUE,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a const with these defaults

Copy link
Contributor

Choose a reason for hiding this comment

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

@luacmartins Apologies as it looks like I introduced some confusion here. I was unaware of your earlier review comments about using individual values in CONST to generate taxRates object. But I am ok with that too.
So, I need a clarification here.
Did you mean creating a const object for taxRates in the code itself and set it to value or did you mean creating the entire taxRates object in CONST?
The reason why I ask is that @nkdengineer has reverted the code in the latest commit to create the entire taxRates object in CONST

},
},
},
},
],
};
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
const policy = ReportUtils.getPolicy(policyID);
const shouldAddDefaultTaxRatesData = isEmptyObject(policy.taxRates) && enabled;
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const onyxData: OnyxData = {
optimisticData: [
{
Expand All @@ -3429,6 +3459,7 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) {
},
},
},
...(shouldAddDefaultTaxRatesData ? taxRatesData.optimisticData ?? [] : []),
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
],
successData: [
{
Expand All @@ -3449,6 +3480,7 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) {
tax: {
trackingEnabled: !enabled,
},
taxRates: undefined,
pendingFields: {
tax: null,
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/taxes/WorkspaceTaxesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function WorkspaceTaxesPage({policy, route}: WorkspaceTaxesPageProps) {
text: value.name,
alternateText: textForDefault(key),
keyForList: key,
pendingAction: value.pendingAction,
isSelected: !!selectedTaxesIDs.includes(key),
isDisabledCheckbox: key === defaultExternalID,
rightElement: (
Expand Down
4 changes: 2 additions & 2 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type DisabledFields = {
reimbursable?: boolean;
};

type TaxRate = {
type TaxRate = OnyxCommon.OnyxValueWithOfflineFeedback<{
/** Name of the a tax rate. */
name: string;

Expand All @@ -47,7 +47,7 @@ type TaxRate = {

/** Indicates if the tax rate is disabled. */
isDisabled?: boolean;
};
}>;

type TaxRates = Record<string, TaxRate>;

Expand Down
Loading