Skip to content

Commit

Permalink
better function name and check for isExpenseReport too
Browse files Browse the repository at this point in the history
  • Loading branch information
rojiphil committed Feb 26, 2024
1 parent 292f358 commit fc4297d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) {
// If it's a paid policy expense report, only allow deleting the request if it's in draft state or instantly submitted state or the user is the policy admin
canDeleteRequest =
canDeleteRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || ReportUtils.isInstantSubmittedState(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy));
canDeleteRequest &&
(ReportUtils.isDraftExpenseReport(moneyRequestReport) || ReportUtils.isExpenseReportWithInstantSubmittedState(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy));
}

const changeMoneyRequestStatus = () => {
Expand Down
10 changes: 5 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ function isProcessingReport(report: OnyxEntry<Report> | EmptyObject): boolean {
/**
* Returns true if the policy has `instant` reporting frequency and if the report is still being processed (i.e. submitted state)
*/
function isInstantSubmittedState(report: OnyxEntry<Report> | EmptyObject): boolean {
function isExpenseReportWithInstantSubmittedState(report: OnyxEntry<Report> | EmptyObject): boolean {
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null;
return isProcessingReport(report) && PolicyUtils.isInstantSubmitEnabled(policy);
return isExpenseReport(report) && isProcessingReport(report) && PolicyUtils.isInstantSubmitEnabled(policy);
}

/**
Expand Down Expand Up @@ -1273,7 +1273,7 @@ function canDeleteReportAction(reportAction: OnyxEntry<ReportAction>, reportID:
if (isActionOwner) {
if (!isEmptyObject(report) && isPaidGroupPolicyExpenseReport(report)) {
// If it's a paid policy expense report, only allow deleting the request if it's a draft or is instantly submitted or the user is the policy admin
return isDraftExpenseReport(report) || isInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy);
return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy);
}
return true;
}
Expand Down Expand Up @@ -4264,7 +4264,7 @@ function canRequestMoney(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, o
if (isMoneyRequestReport(report)) {
const isOwnExpenseReport = isExpenseReport(report) && isOwnPolicyExpenseChat;
if (isOwnExpenseReport && PolicyUtils.isPaidGroupPolicy(policy)) {
return isDraftExpenseReport(report) || isInstantSubmittedState(report);
return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report);
}

return (isOwnExpenseReport || isIOUReport(report)) && !isReportApproved(report) && !isSettled(report?.reportID);
Expand Down Expand Up @@ -5066,7 +5066,7 @@ export {
isPublicAnnounceRoom,
isConciergeChatReport,
isProcessingReport,
isInstantSubmittedState,
isExpenseReportWithInstantSubmittedState,
isCurrentUserTheOnlyParticipant,
hasAutomatedExpensifyAccountIDs,
hasExpensifyGuidesEmails,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ function getMoneyRequestInformation(
needsToBeManuallySubmitted = isFromPaidPolicy && !policy?.harvesting?.enabled;

// If the linked expense report on paid policy is not draft and not instantly submitted, we need to create a new draft expense report
if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport) && !ReportUtils.isInstantSubmittedState(iouReport)) {
if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport) && !ReportUtils.isExpenseReportWithInstantSubmittedState(iouReport)) {
iouReport = null;
}
}
Expand Down

0 comments on commit fc4297d

Please sign in to comment.