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
165 changes: 86 additions & 79 deletions src/libs/actions/Policy/Policy.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function ConnectExistingBusinessBankAccountPage({route}: ConnectExistingBusiness
if (bankAccountList && methodID && !bankAccountList[methodID]?.accountData?.policyIDs?.includes(policyID)) {
setWorkspaceReimbursement({
policyID,
currentAchAccount: policy?.achAccount,
currentReimbursementChoice: policy?.reimbursementChoice,
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES,
bankAccountID: methodID ?? CONST.DEFAULT_NUMBER_ID,
reimburserEmail: newReimburserEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM
const remainingEmployeeCount = previousEmployeesCount - 1;
if (remainingEmployeeCount === 1 && policy?.preventSelfApproval) {
// We can't let the "Prevent Self Approvals" enabled if there's only one workspace user
setPolicyPreventSelfApproval(policyID, false);
setPolicyPreventSelfApproval(policyID, false, policy.preventSelfApproval);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/rules/ExpenseReportRulesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
return;
}

setPolicyPreventSelfApproval(policyID, isEnabled);
setPolicyPreventSelfApproval(policyID, isEnabled, policy?.preventSelfApproval);
},
},
{
Expand All @@ -77,7 +77,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
return;
}

enableAutoApprovalOptions(policyID, isEnabled);
enableAutoApprovalOptions(policyID, isEnabled, policy?.shouldShowAutoApprovalOptions, policy?.autoApproval?.limit, policy?.autoApproval?.auditRate);
},
subMenuItems: [
<OfflineWithFeedback
Expand Down Expand Up @@ -123,7 +123,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
return;
}

enablePolicyAutoReimbursementLimit(policyID, isEnabled);
enablePolicyAutoReimbursementLimit(policyID, isEnabled, policy?.shouldShowAutoReimbursementLimitOption, policy?.autoReimbursement?.limit);
},
disabled: autoPayApprovedReportsUnavailable,
showLockIcon: autoPayApprovedReportsUnavailable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function RulesAutoApproveReportsUnderPage({route}: RulesAutoApproveReportsUnderP
style={[styles.flexGrow1, styles.mh5]}
formID={ONYXKEYS.FORMS.RULES_AUTO_APPROVE_REPORTS_UNDER_MODAL_FORM}
onSubmit={({maxExpenseAutoApprovalAmount}) => {
setPolicyAutomaticApprovalLimit(policyID, maxExpenseAutoApprovalAmount);
setPolicyAutomaticApprovalLimit(policyID, maxExpenseAutoApprovalAmount, policy?.autoApproval?.limit);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
submitButtonText={translate('common.save')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function RulesAutoPayReportsUnderPage({route}: RulesAutoPayReportsUnderPageProps
formID={ONYXKEYS.FORMS.RULES_AUTO_PAY_REPORTS_UNDER_MODAL_FORM}
validate={validateLimit}
onSubmit={({maxExpenseAutoPayAmount}) => {
setPolicyAutoReimbursementLimit(policyID, maxExpenseAutoPayAmount);
setPolicyAutoReimbursementLimit(policyID, maxExpenseAutoPayAmount, policy?.autoReimbursement?.limit ?? policy?.autoReimbursementLimit);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
submitButtonText={translate('common.save')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/rules/RulesRandomReportAuditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function RulesRandomReportAuditPage({route}: RulesRandomReportAuditPageProps) {
style={[styles.flexGrow1, styles.mh5]}
formID={ONYXKEYS.FORMS.RULES_RANDOM_REPORT_AUDIT_MODAL_FORM}
onSubmit={({auditRatePercentage}) => {
setPolicyAutomaticApprovalRate(policyID, auditRatePercentage);
setPolicyAutomaticApprovalRate(policyID, auditRatePercentage, policy?.autoApproval?.auditRate);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
submitButtonText={translate('common.save')}
Expand Down
8 changes: 4 additions & 4 deletions src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
}
switch (feature.id) {
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.preventSelfApproval.id:
setPolicyPreventSelfApproval(policyID, true);
setPolicyPreventSelfApproval(policyID, true, policy?.preventSelfApproval);
break;
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.autoApproveCompliantReports.id:
enableAutoApprovalOptions(policyID, true);
enableAutoApprovalOptions(policyID, true, policy?.shouldShowAutoApprovalOptions, policy?.autoApproval?.limit, policy?.autoApproval?.auditRate);
break;
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.autoPayApprovedReports.id:
enablePolicyAutoReimbursementLimit(policyID, true);
enablePolicyAutoReimbursementLimit(policyID, true, policy?.shouldShowAutoReimbursementLimitOption, policy?.autoReimbursement?.limit);
break;
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.reportFields.id:
switch (route.params.featureName) {
Expand Down Expand Up @@ -195,7 +195,7 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
enablePerDiem(policyID, true, perDiemCustomUnit?.customUnitID, false);
break;
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.approvals.id:
setWorkspaceApprovalMode(policyID, defaultApprover, CONST.POLICY.APPROVAL_MODE.ADVANCED);
setWorkspaceApprovalMode(policy, defaultApprover, CONST.POLICY.APPROVAL_MODE.ADVANCED);
break;
default:
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function WorkspaceAutoReportingFrequencyPage({policy, route}: WorkspaceAutoRepor
if (!policy?.id) {
return;
}
setWorkspaceAutoReportingFrequency(policy.id, item.keyForList as AutoReportingFrequencyKey);
setWorkspaceAutoReportingFrequency(policy.id, item.keyForList as AutoReportingFrequencyKey, policy.autoReportingFrequency, policy.harvesting);

if (item.keyForList === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ function WorkspaceAutoReportingMonthlyOffsetPage({policy, route}: WorkspaceAutoR
const filteredDaysOfMonth = daysOfMonth.filter((dayItem) => dayItem.text.toLowerCase().includes(trimmedText));

const onSelectDayOfMonth = (item: WorkspaceAutoReportingMonthlyOffsetPageItem) => {
setWorkspaceAutoReportingMonthlyOffset(policy?.id, item.isNumber ? parseInt(item.keyForList, 10) : (item.keyForList as AutoReportingOffsetKeys));
Navigation.goBack(ROUTES.WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY.getRoute(policy?.id));
if (!policy?.id) {
return;
}
setWorkspaceAutoReportingMonthlyOffset(policy.id, item.isNumber ? parseInt(item.keyForList, 10) : (item.keyForList as AutoReportingOffsetKeys), policy.autoReportingOffset);
Navigation.goBack(ROUTES.WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY.getRoute(policy.id));
};
const textInputOptions = useMemo(
() => ({
Expand Down
8 changes: 5 additions & 3 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
}, []);

const confirmDisableApprovals = useCallback(() => {
setWorkspaceApprovalMode(route.params.policyID, policy?.owner ?? '', CONST.POLICY.APPROVAL_MODE.OPTIONAL, {
setWorkspaceApprovalMode(policy, policy?.owner ?? '', CONST.POLICY.APPROVAL_MODE.OPTIONAL, {
reportNextSteps: allReportNextSteps,
transactionViolations,
betas,
});
}, [allReportNextSteps, betas, policy?.owner, route.params.policyID, transactionViolations]);
}, [allReportNextSteps, betas, policy, transactionViolations]);
Comment thread
bernhardoj marked this conversation as resolved.

// User should be allowed to add new Approval Workflow only if he's upgraded to Control Plan, otherwise redirected to the Upgrade Page
const addApprovalAction = useCallback(() => {
Expand Down Expand Up @@ -311,7 +311,7 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
});
return;
}
setWorkspaceApprovalMode(route.params.policyID, policy?.owner ?? '', isEnabled ? updateApprovalMode : CONST.POLICY.APPROVAL_MODE.OPTIONAL, {
setWorkspaceApprovalMode(policy, policy?.owner ?? '', isEnabled ? updateApprovalMode : CONST.POLICY.APPROVAL_MODE.OPTIONAL, {
reportNextSteps: allReportNextSteps,
transactionViolations,
betas,
Expand Down Expand Up @@ -399,6 +399,8 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
const newReimburserEmail = policy?.achAccount?.reimburser ?? policy?.owner;
setWorkspaceReimbursement({
policyID: route.params.policyID,
currentAchAccount: policy?.achAccount,
currentReimbursementChoice: policy?.reimbursementChoice,
reimbursementChoice: newReimbursementChoice,
reimburserEmail: newReimburserEmail ?? '',
bankAccountID: policy?.achAccount?.bankAccountID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingR
Navigation.closeRHPFlow();
return;
}
setWorkspacePayer(policy?.id, authorizedPayerEmail);
setWorkspacePayer(policy.id, authorizedPayerEmail, policy.achAccount?.reimburser);
Navigation.closeRHPFlow();
};

Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ type PolicyConnectionSyncProgress = {
export default Policy;

export type {
AutoReportingOffset,
PolicyReportField,
PolicyReportFieldType,
Unit,
Expand Down
3 changes: 2 additions & 1 deletion src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import type {PersonalDetailsList, PersonalDetailsMetadata} from './PersonalDetai
import type PersonalDetails from './PersonalDetails';
import type PlaidData from './PlaidData';
import type Policy from './Policy';
import type {PolicyConnectionName, PolicyConnectionSyncProgress, PolicyReportField, TaxRate, TaxRates, TaxRatesWithDefault} from './Policy';
import type {AutoReportingOffset, PolicyConnectionName, PolicyConnectionSyncProgress, PolicyReportField, TaxRate, TaxRates, TaxRatesWithDefault} from './Policy';
import type {PolicyCategories, PolicyCategory} from './PolicyCategory';
import type {PolicyEmployeeList} from './PolicyEmployee';
import type PolicyEmployee from './PolicyEmployee';
Expand Down Expand Up @@ -260,6 +260,7 @@ export type {
PolicyConnectionName,
PolicyConnectionSyncProgress,
PolicyOwnershipChangeChecks,
AutoReportingOffset,
PolicyTag,
PolicyTags,
PolicyTagLists,
Expand Down
29 changes: 18 additions & 11 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9641,7 +9641,7 @@ describe('actions/IOU', () => {
let expenseReport: OnyxEntry<Report>;
let chatReport: OnyxEntry<Report>;
return waitForBatchedUpdates()
.then(() => {
.then(async () => {
const policyID = generatePolicyID();
createWorkspace({
policyOwnerEmail: CARLOS_EMAIL,
Expand All @@ -9655,8 +9655,9 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
// Change the approval mode for the policy since default is Submit and Close
setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
return waitForBatchedUpdates();
})
.then(
Expand Down Expand Up @@ -9787,7 +9788,7 @@ describe('actions/IOU', () => {
let chatReport: OnyxEntry<Report>;

return waitForBatchedUpdates()
.then(() => {
.then(async () => {
const policyID = generatePolicyID();
createWorkspace({
policyOwnerEmail: CARLOS_EMAIL,
Expand All @@ -9801,7 +9802,8 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC, {});
return waitForBatchedUpdates();
})
.then(
Expand Down Expand Up @@ -10368,8 +10370,9 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});
return waitForBatchedUpdates()
.then(() => {
setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL);
.then(async () => {
policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL, {});
return waitForBatchedUpdates();
})
.then(
Expand Down Expand Up @@ -10595,7 +10598,7 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC, {});
await waitForBatchedUpdates();

let chatReport: OnyxEntry<Report>;
Expand Down Expand Up @@ -12787,8 +12790,9 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
// Change the approval mode for the policy since default is Submit and Close
setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC, {});
await waitForBatchedUpdates();
await getOnyxData({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -12961,8 +12965,9 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
// Change the approval mode for the policy since default is Submit and Close
setWorkspaceApprovalMode(policyID, RORY_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
setWorkspaceApprovalMode(policy, RORY_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC, {});
await waitForBatchedUpdates();
await getOnyxData({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -13139,7 +13144,8 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC, {});
await waitForBatchedUpdates();

await getOnyxData({
Expand Down Expand Up @@ -13326,8 +13332,9 @@ describe('actions/IOU', () => {
hasActiveAdminPolicies: false,
});

const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
// Change the approval mode for the policy since default is Submit and Close
setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
setWorkspaceApprovalMode(policy, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC, {});
await waitForBatchedUpdates();

await getOnyxData({
Expand Down
Loading
Loading