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/38198: "Delayed Submissions" toggle does not toggle off unless backed out for Collect Policy #38215

Merged
merged 5 commits into from
Mar 14, 2024
Merged
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
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,
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
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
Loading