Skip to content

Commit

Permalink
Merge pull request #35432 from Expensify/vit-addHarvestingEnabledKey
Browse files Browse the repository at this point in the history
Add harvesting key structure so it follows backend data structure
  • Loading branch information
johnmlee101 authored Jan 31, 2024
2 parents 53c2ccc + 90583bc commit 6bdf20f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt

// The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on
const isWaitingForSubmissionFromCurrentUser = useMemo(
() => chatReport?.isOwnPolicyExpenseChat && !policy.isHarvestingEnabled,
[chatReport?.isOwnPolicyExpenseChat, policy.isHarvestingEnabled],
() => chatReport?.isOwnPolicyExpenseChat && !(policy.harvesting?.enabled ?? policy.isHarvestingEnabled),
[chatReport?.isOwnPolicyExpenseChat, policy.harvesting?.enabled, policy.isHarvestingEnabled],
);

const threeDotsMenuItems = [HeaderUtils.getPinMenuItem(moneyRequestReport)];
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ function ReportPreview({

// The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on
const isWaitingForSubmissionFromCurrentUser = useMemo(
() => chatReport?.isOwnPolicyExpenseChat && !policy?.isHarvestingEnabled,
[chatReport?.isOwnPolicyExpenseChat, policy?.isHarvestingEnabled],
() => chatReport?.isOwnPolicyExpenseChat && !(policy?.harvesting?.enabled ?? policy?.isHarvestingEnabled),
[chatReport?.isOwnPolicyExpenseChat, policy?.harvesting?.enabled, policy?.isHarvestingEnabled],
);

const getDisplayAmount = (): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ function getMoneyRequestInformation(
isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy);

// If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN
needsToBeManuallySubmitted = isFromPaidPolicy && !(policy.isHarvestingEnabled || false);
needsToBeManuallySubmitted = isFromPaidPolicy && !(lodashGet(policy, 'harvesting.enabled', policy.isHarvestingEnabled) || false);

// If the linked expense report on paid policy is not draft, we need to create a new draft expense report
if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport)) {
Expand Down
7 changes: 6 additions & 1 deletion src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ type Policy = {
/** The scheduled submit frequency set up on this policy */
autoReportingFrequency?: ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES>;

/** Whether the scheduled submit is enabled */
/** @deprecated Whether the scheduled submit is enabled */
isHarvestingEnabled?: boolean;

/** Whether the scheduled submit is enabled */
harvesting?: {
enabled: boolean;
};

/** Whether the self approval or submitting is enabled */
isPreventSelfApprovalEnabled?: boolean;

/** When the monthly scheduled submit should happen */
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/LHNTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ function getFakePolicy(id = 1, name = 'Workspace-Test-001') {
lastModified: 1697323926777105,
autoReporting: true,
autoReportingFrequency: 'immediate',
isHarvestingEnabled: true,
harvesting: {
enabled: true,
},
autoReportingOffset: 1,
isPreventSelfApprovalEnabled: true,
submitsTo: 123456,
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/collections/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default function createRandomPolicy(index: number): Policy {
autoReporting: randBoolean(),
isPolicyExpenseChatEnabled: randBoolean(),
autoReportingFrequency: rand(Object.values(CONST.POLICY.AUTO_REPORTING_FREQUENCIES)),
isHarvestingEnabled: randBoolean(),
harvesting: {
enabled: randBoolean(),
},
autoReportingOffset: 1,
isPreventSelfApprovalEnabled: randBoolean(),
submitsTo: index,
Expand Down

0 comments on commit 6bdf20f

Please sign in to comment.