Skip to content

Commit

Permalink
Merge pull request #38215 from DylanDylann/fix/38198
Browse files Browse the repository at this point in the history
Fix/38198: "Delayed Submissions" toggle does not toggle off unless backed out for Collect Policy
  • Loading branch information
mountiny authored Mar 14, 2024
2 parents 2faffcd + 1fa0d91 commit 6917151
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,15 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[]
}

function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency: ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES>) {
const policy = ReportUtils.getPolicy(policyID);
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReporting: enabled,
harvesting: {
enabled: true,
enabled,
},
autoReportingFrequency: frequency,
pendingFields: {isAutoApprovalEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
Expand All @@ -456,7 +457,11 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReporting: !enabled,
autoReporting: policy.autoReporting ?? null,
harvesting: {
enabled: policy.harvesting?.enabled ?? null,
},
autoReportingFrequency: policy.autoReportingFrequency ?? null,
pendingFields: {isAutoApprovalEnabled: null, harvesting: null},
},
},
Expand All @@ -478,6 +483,8 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
}

function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES>) {
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -494,6 +501,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReportingFrequency: policy.autoReportingFrequency ?? null,
pendingFields: {autoReportingFrequency: null},
},
},
Expand All @@ -515,6 +523,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf

function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingOffset: number | ValueOf<typeof CONST.POLICY.AUTO_REPORTING_OFFSET>) {
const value = JSON.stringify({autoReportingOffset: autoReportingOffset.toString()});
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
{
Expand All @@ -532,6 +541,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReportingOffset: policy.autoReportingOffset ?? null,
pendingFields: {autoReportingOffset: null},
},
},
Expand All @@ -553,6 +563,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO

function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMode: ValueOf<typeof CONST.POLICY.APPROVAL_MODE>) {
const isAutoApprovalEnabled = approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC;
const policy = ReportUtils.getPolicy(policyID);

const value = {
approver,
Expand All @@ -576,6 +587,9 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
approver: policy.approver ?? null,
approvalMode: policy.approvalMode ?? null,
isAutoApprovalEnabled: policy.isAutoApprovalEnabled ?? null,
pendingFields: {approvalMode: null},
},
},
Expand Down Expand Up @@ -627,8 +641,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimburserEmail: policy.reimburserEmail,
reimburserAccountID: policy.reimburserAccountID,
reimburserEmail: policy.reimburserEmail ?? null,
reimburserAccountID: policy.reimburserAccountID ?? null,
errorFields: {reimburserEmail: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')},
pendingFields: {reimburserEmail: null},
},
Expand Down Expand Up @@ -677,9 +691,9 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimbursementChoice: policy.reimbursementChoice,
reimburserAccountID: policy.reimburserAccountID,
reimburserEmail: policy.reimburserEmail,
reimbursementChoice: policy.reimbursementChoice ?? null,
reimburserAccountID: policy.reimburserAccountID ?? null,
reimburserEmail: policy.reimburserEmail ?? null,
errorFields: {reimbursementChoice: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')},
pendingFields: {reimbursementChoice: null},
},
Expand Down

0 comments on commit 6917151

Please sign in to comment.