Skip to content
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
105 changes: 28 additions & 77 deletions src/libs/actions/Policy/Policy.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/pages/workspace/rules/IndividualExpenseRulesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection

const handleAttendeeTrackingToggle = useCallback(
(newValue: boolean) => {
setPolicyAttendeeTrackingEnabled(policyID, newValue);
setPolicyAttendeeTrackingEnabled(policyID, newValue, policy?.isAttendeeTrackingEnabled);
},
[policyID],
[policyID, policy?.isAttendeeTrackingEnabled],
);

const maxExpenseAmountNoReceiptText = useMemo(() => {
Expand Down Expand Up @@ -258,7 +258,7 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection
subtitleStyle={styles.pt1}
isActive={areEReceiptsEnabled}
disabled={policyCurrency !== CONST.CURRENCY.USD}
onToggle={() => setWorkspaceEReceiptsEnabled(policyID, !areEReceiptsEnabled)}
onToggle={() => setWorkspaceEReceiptsEnabled(policyID, !areEReceiptsEnabled, policy?.eReceipts)}
pendingAction={policy?.pendingFields?.eReceipts}
/>
<ToggleSettingOptionRow
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/rules/RulesBillableDefaultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function RulesBillableDefaultPage({
data={billableModes}
ListItem={RadioListItem}
onSelectRow={(item) => {
setPolicyBillableMode(policyID, item.value);
setPolicyBillableMode(policyID, item.value, policy?.defaultBillable, policy?.disabledFields?.defaultBillable);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
shouldSingleExecuteRowSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function RulesItemizedReceiptRequiredAmountPage({
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.RULES_REQUIRED_ITEMIZED_RECEIPT_AMOUNT_FORM}
onSubmit={({maxExpenseAmountNoItemizedReceipt}) => {
setPolicyMaxExpenseAmountNoItemizedReceipt(policyID, maxExpenseAmountNoItemizedReceipt);
setPolicyMaxExpenseAmountNoItemizedReceipt(policyID, maxExpenseAmountNoItemizedReceipt, policy?.maxExpenseAmountNoItemizedReceipt);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
validate={validate}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/rules/RulesMaxExpenseAgePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function RulesMaxExpenseAgePage({
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.RULES_MAX_EXPENSE_AGE_FORM}
onSubmit={({maxExpenseAge}) => {
setPolicyMaxExpenseAge(policyID, maxExpenseAge);
setPolicyMaxExpenseAge(policyID, maxExpenseAge, policy?.maxExpenseAge);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
submitButtonText={translate('workspace.editor.save')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/rules/RulesMaxExpenseAmountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function RulesMaxExpenseAmountPage({
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.RULES_MAX_EXPENSE_AMOUNT_FORM}
onSubmit={({maxExpenseAmount}) => {
setPolicyMaxExpenseAmount(policyID, maxExpenseAmount);
setPolicyMaxExpenseAmount(policyID, maxExpenseAmount, policy?.maxExpenseAmount);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
submitButtonText={translate('workspace.editor.save')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/rules/RulesProhibitedDefaultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function RulesProhibitedDefaultPage({
isOn={policy?.prohibitedExpenses?.[prohibitedExpense] ?? false}
accessibilityLabel={translate(`workspace.rules.individualExpenseRules.${prohibitedExpense}`)}
onToggle={() => {
setPolicyProhibitedExpense(policyID, prohibitedExpense);
setPolicyProhibitedExpense(policyID, prohibitedExpense, policy?.prohibitedExpenses);
}}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function RulesReceiptRequiredAmountPage({
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.RULES_REQUIRED_RECEIPT_AMOUNT_FORM}
onSubmit={({maxExpenseAmountNoReceipt}) => {
setPolicyMaxExpenseAmountNoReceipt(policyID, maxExpenseAmountNoReceipt);
setPolicyMaxExpenseAmountNoReceipt(policyID, maxExpenseAmountNoReceipt, policy?.maxExpenseAmountNoReceipt);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
validate={validate}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function billableExpensesPending(policy: OnyxEntry<Policy>) {

function toggleBillableExpenses(policy: OnyxEntry<Policy>) {
if (policy?.disabledFields?.defaultBillable) {
setPolicyBillableMode(policy.id, false);
setPolicyBillableMode(policy.id, false, policy?.defaultBillable, true);
} else if (policy) {
disableWorkspaceBillableExpenses(policy.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function WorkspaceTaxesSettingsCustomTaxName({
);

const submit = ({name}: WorkspaceTaxCustomName) => {
setPolicyCustomTaxName(policyID, name);
setPolicyCustomTaxName(policyID, name, policy?.taxRates?.name);
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import type * as TaxOptionsListUtils from '@libs/TaxOptionsListUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import type {TaxRatesOption} from '@libs/TaxOptionsListUtils';
import {getWorkspaceTaxesSettingsName} from '@libs/TransactionUtils';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading';
import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading';
Expand All @@ -31,10 +31,10 @@ function WorkspaceTaxesSettingsForeignCurrency({

const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault ?? '';

const selectedTaxRate = TransactionUtils.getWorkspaceTaxesSettingsName(policy, foreignTaxDefault);
const selectedTaxRate = getWorkspaceTaxesSettingsName(policy, foreignTaxDefault);

const submit = (taxes: TaxOptionsListUtils.TaxRatesOption) => {
setForeignCurrencyDefault(policyID, taxes.code ?? '');
const submit = (taxes: TaxRatesOption) => {
setForeignCurrencyDefault(policyID, taxes.code ?? '', foreignTaxDefault);
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import type * as TaxOptionsListUtils from '@libs/TaxOptionsListUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import type {TaxRatesOption} from '@libs/TaxOptionsListUtils';
import {getWorkspaceTaxesSettingsName} from '@libs/TransactionUtils';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading';
import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading';
Expand All @@ -30,11 +30,11 @@ function WorkspaceTaxesSettingsWorkspaceCurrency({
const {translate} = useLocalize();
const styles = useThemeStyles();

const defaultExternalID = policy?.taxRates?.defaultExternalID ?? '';
const selectedTaxRate = policy?.taxRates && TransactionUtils.getWorkspaceTaxesSettingsName(policy, defaultExternalID);
const defaultExternalID = policy?.taxRates?.defaultExternalID;
const selectedTaxRate = defaultExternalID && getWorkspaceTaxesSettingsName(policy, defaultExternalID);

const submit = (taxes: TaxOptionsListUtils.TaxRatesOption) => {
setWorkspaceCurrencyDefault(policyID, taxes.code ?? '');
const submit = (taxes: TaxRatesOption) => {
setWorkspaceCurrencyDefault(policyID, taxes.code ?? '', defaultExternalID);
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

Expand Down
12 changes: 6 additions & 6 deletions tests/actions/PolicyTaxTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('actions/PolicyTax', () => {
it('Set policy`s custom tax name', () => {
const customTaxName = 'Custom tag name';
mockFetch?.pause?.();
Policy.setPolicyCustomTaxName(fakePolicy.id, customTaxName);
Policy.setPolicyCustomTaxName(fakePolicy.id, customTaxName, undefined);
return waitForBatchedUpdates()
.then(
() =>
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('actions/PolicyTax', () => {
const originalCustomTaxName = fakePolicy?.taxRates?.name;

mockFetch?.pause?.();
Policy.setPolicyCustomTaxName(fakePolicy.id, customTaxName);
Policy.setPolicyCustomTaxName(fakePolicy.id, customTaxName, originalCustomTaxName);
return waitForBatchedUpdates()
.then(
() =>
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('actions/PolicyTax', () => {
const taxCode = 'id_TAX_RATE_1';

mockFetch?.pause?.();
Policy.setWorkspaceCurrencyDefault(fakePolicy.id, taxCode);
Policy.setWorkspaceCurrencyDefault(fakePolicy.id, taxCode, undefined);
return waitForBatchedUpdates()
.then(
() =>
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('actions/PolicyTax', () => {
const originalDefaultExternalID = fakePolicy?.taxRates?.defaultExternalID;

mockFetch?.pause?.();
Policy.setWorkspaceCurrencyDefault(fakePolicy.id, taxCode);
Policy.setWorkspaceCurrencyDefault(fakePolicy.id, taxCode, originalDefaultExternalID);
return waitForBatchedUpdates()
.then(
() =>
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('actions/PolicyTax', () => {
const taxCode = 'id_TAX_RATE_1';

mockFetch?.pause?.();
Policy.setForeignCurrencyDefault(fakePolicy.id, taxCode);
Policy.setForeignCurrencyDefault(fakePolicy.id, taxCode, undefined);
return waitForBatchedUpdates()
.then(
() =>
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('actions/PolicyTax', () => {
const originalDefaultForeignCurrencyID = fakePolicy?.taxRates?.foreignTaxDefault;

mockFetch?.pause?.();
Policy.setForeignCurrencyDefault(fakePolicy.id, taxCode);
Policy.setForeignCurrencyDefault(fakePolicy.id, taxCode, originalDefaultForeignCurrencyID);
return waitForBatchedUpdates()
.then(
() =>
Expand Down
Loading
Loading