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
2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ const CONST = {
AUTO_REIMBURSEMENT_MAX_LIMIT_CENTS: 2000000,
AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS: 10000,
AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS: 10000,
RANDOM_AUDIT_DEFAULT_PERCENTAGE: 5,
RANDOM_AUDIT_DEFAULT_PERCENTAGE: 0.05,

AUTO_REPORTING_FREQUENCIES: {
INSTANT: 'instant',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type SetPolicyAutoReimbursementLimitParams = {
policyID: string;
autoReimbursement: {limit: number};
limit: number;
};

export default SetPolicyAutoReimbursementLimitParams;
37 changes: 11 additions & 26 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4292,9 +4292,10 @@ function setPolicyAutomaticApprovalLimit(policyID: string, limit: string) {
function setPolicyAutomaticApprovalRate(policyID: string, auditRate: string) {
const policy = getPolicy(policyID);
const fallbackAuditRate = auditRate === '' ? '0' : auditRate;
const parsedAuditRate = parseInt(fallbackAuditRate, 10);
const parsedAuditRate = parseInt(fallbackAuditRate, 10) / 100;

if (parsedAuditRate === policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE) {
// The auditRate arrives as an int to this method so we will convert it to a float before sending it to the API.
if (parsedAuditRate === (policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE)) {
return;
}

Expand Down Expand Up @@ -4370,17 +4371,8 @@ function enableAutoApprovalOptions(policyID: string, enabled: boolean) {
return;
}

const autoApprovalCleanupValues = !enabled
? {
pendingFields: {
limit: null,
auditRate: null,
},
}
: {};
const autoApprovalValues = !enabled ? {auditRate: CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE, limit: CONST.POLICY.AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS} : {};
const autoApprovalFailureValues = !enabled ? {autoApproval: {limit: policy?.autoApproval?.limit, auditRate: policy?.autoApproval?.auditRate, ...autoApprovalCleanupValues}} : {};

const autoApprovalValues = {auditRate: CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE, limit: CONST.POLICY.AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS};
const autoApprovalFailureValues = {autoApproval: {limit: policy?.autoApproval?.limit, auditRate: policy?.autoApproval?.auditRate, pendingFields: null}};
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -4406,7 +4398,7 @@ function enableAutoApprovalOptions(policyID: string, enabled: boolean) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoApproval: {...autoApprovalCleanupValues},
autoApproval: {pendingFields: null},
pendingFields: {
shouldShowAutoApprovalOptions: null,
},
Expand Down Expand Up @@ -4499,7 +4491,7 @@ function setPolicyAutoReimbursementLimit(policyID: string, limit: string) {
];

const parameters: SetPolicyAutoReimbursementLimitParams = {
autoReimbursement: {limit: parsedLimit},
limit: parsedLimit,
policyID,
};

Expand All @@ -4512,6 +4504,7 @@ function setPolicyAutoReimbursementLimit(policyID: string, limit: string) {

/**
* Call the API to enable auto-payment for the reports in the given policy
*
* @param policyID - id of the policy to apply the limit to
* @param enabled - whether auto-payment for the reports is enabled in the given policy
*/
Expand All @@ -4522,16 +4515,8 @@ function enablePolicyAutoReimbursementLimit(policyID: string, enabled: boolean)
return;
}

const autoReimbursementCleanupValues = !enabled
? {
pendingFields: {
limit: null,
},
}
: {};
const autoReimbursementFailureValues = !enabled ? {autoReimbursement: {limit: policy?.autoReimbursement?.limit, ...autoReimbursementCleanupValues}} : {};
const autoReimbursementValues = !enabled ? {limit: CONST.POLICY.AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS} : {};

const autoReimbursementFailureValues = {autoReimbursement: {limit: policy?.autoReimbursement?.limit, pendingFields: null}};
const autoReimbursementValues = {limit: CONST.POLICY.AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS};
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -4556,7 +4541,7 @@ function enablePolicyAutoReimbursementLimit(policyID: string, enabled: boolean)
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReimbursement: {...autoReimbursementCleanupValues},
autoReimbursement: {pendingFields: null},
pendingFields: {
shouldShowAutoReimbursementLimitOption: null,
},
Expand Down
15 changes: 4 additions & 11 deletions src/pages/workspace/rules/ExpenseReportRulesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
);
};

const reportTitlePendingFields = policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.pendingFields ?? {};
const optionItems = [
{
title: translate('workspace.rules.expenseReportRules.customReportNamesTitle'),
Expand All @@ -62,11 +63,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
onToggle: (isEnabled: boolean) => PolicyActions.enablePolicyDefaultReportTitle(policyID, isEnabled),
subMenuItems: [
<OfflineWithFeedback
pendingAction={
!policy?.pendingFields?.shouldShowCustomReportTitleOption && policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE].pendingFields?.defaultValue
? policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE].pendingFields?.defaultValue
: null
}
pendingAction={!policy?.pendingFields?.shouldShowCustomReportTitleOption && reportTitlePendingFields.defaultValue ? reportTitlePendingFields.defaultValue : null}
key="customName"
>
<MenuItemWithTopDescription
Expand All @@ -78,11 +75,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
/>
</OfflineWithFeedback>,
<ToggleSettingOptionRow
pendingAction={
!policy?.pendingFields?.shouldShowCustomReportTitleOption && policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE].pendingFields?.deletable
? policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE].pendingFields?.deletable
: null
}
pendingAction={!policy?.pendingFields?.shouldShowCustomReportTitleOption && reportTitlePendingFields.deletable ? reportTitlePendingFields.deletable : null}
key="preventMembersFromChangingCustomNames"
title={translate('workspace.rules.expenseReportRules.preventMembersFromChangingCustomNamesTitle')}
switchAccessibilityLabel={translate('workspace.rules.expenseReportRules.preventMembersFromChangingCustomNamesTitle')}
Expand Down Expand Up @@ -142,7 +135,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) {
>
<MenuItemWithTopDescription
description={translate('workspace.rules.expenseReportRules.randomReportAuditTitle')}
title={`${policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE}%`}
title={`${Math.round((policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE) * 100)}%`}
shouldShowRightIcon
style={[styles.sectionMenuItemTopDescription, styles.mt6, styles.mbn3]}
onPress={() => Navigation.navigate(ROUTES.RULES_RANDOM_REPORT_AUDIT.getRoute(policyID))}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/rules/RulesRandomReportAuditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function RulesRandomReportAuditPage({route}: RulesRandomReportAuditPageProps) {
const styles = useThemeStyles();

const workflowApprovalsUnavailable = PolicyUtils.getWorkflowApprovalsUnavailable(policy);
const defaultValue = policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE;

const defaultValue = Math.round((policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE) * 100);
return (
<AccessOrNotFoundWrapper
policyID={policyID}
Expand Down