Skip to content

Commit

Permalink
Merge pull request #37821 from Expensify/lucien/fix-workflows-submiss…
Browse files Browse the repository at this point in the history
…ion-frequency-toggle

Fix Weekly submission frequency not selected by default
  • Loading branch information
luacmartins authored Mar 8, 2024
2 parents 2857c35 + bf2c6cc commit 369cbe2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[]
return announceRoomMembers;
}

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

const params: SetWorkspaceAutoReportingParams = {policyID, enabled};

API.write(WRITE_COMMANDS.SET_WORKSPACE_AUTO_REPORTING, params, {optimisticData, failureData, successData});
}

Expand Down
9 changes: 7 additions & 2 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
title: translate('workflowsPage.delaySubmissionTitle'),
subtitle: translate('workflowsPage.delaySubmissionDescription'),
onToggle: (isEnabled: boolean) => {
Policy.setWorkspaceAutoReporting(route.params.policyID, isEnabled);
const frequency =
policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT || !policy?.autoReportingFrequency
? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY
: policy.autoReportingFrequency;
Policy.setWorkspaceAutoReporting(route.params.policyID, isEnabled, frequency);
},
subMenuItems: (
<MenuItem
title={translate('workflowsPage.submissionFrequency')}
titleStyle={styles.textLabelSupportingNormal}
descriptionTextStyle={styles.textNormalThemeText}
onPress={onPressAutoReportingFrequency}
// Instant submit is the equivalent of delayed submissions being turned off, so we show the feature as disabled if the frequency is instant
description={
getAutoReportingFrequencyDisplayNames(preferredLocale)[
(policy?.autoReportingFrequency as AutoReportingFrequencyKey) ?? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY
Expand All @@ -78,7 +83,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
hoverAndPressStyle={[styles.mr0, styles.br2]}
/>
),
isActive: policy?.harvesting?.enabled ?? false,
isActive: (policy?.harvesting?.enabled && policy.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT) ?? false,
pendingAction: policy?.pendingFields?.isAutoApprovalEnabled,
},
]
Expand Down

0 comments on commit 369cbe2

Please sign in to comment.