Skip to content
Merged
Show file tree
Hide file tree
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
36 changes: 35 additions & 1 deletion src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ function buildOptimisticNextStepForPreventSelfApprovalsEnabled() {
* @param predictedNextStatus - a next expected status of the report
* @param shouldFixViolations - whether to show `fix the issue` next step
* @param isUnapprove - whether a report is being unapproved
* @param isReopen - whether a report is being reopened
* @returns nextStep
*/
function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>, shouldFixViolations?: boolean, isUnapprove?: boolean): ReportNextStep | null {
function buildNextStep(
report: OnyxEntry<Report>,
predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>,
shouldFixViolations?: boolean,
isUnapprove?: boolean,
isReopen?: boolean,
): ReportNextStep | null {
if (!isExpenseReport(report)) {
return null;
}
Expand Down Expand Up @@ -209,6 +216,33 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
};
break;
}
if (isReopen) {
optimisticNextStep = {
type,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
message: [
{
text: 'Waiting for ',
},
{
text: `${ownerDisplayName}`,
type: 'strong',
clickToCopyText: ownerAccountID === currentUserAccountID ? currentUserEmail : '',
},
{
text: ' to ',
},
{
text: 'submit',
},
{
text: ' %expenses.',
},
],
};
break;
}

// Self review
optimisticNextStep = {
type,
Expand Down
5 changes: 5 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ function isRenamedAction(reportAction: OnyxEntry<ReportAction>): reportAction is
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.RENAMED);
}

function isReopenedAction(reportAction: OnyxEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REOPENED> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REOPENED);
}

function isRoomChangeLogAction(reportAction: OnyxEntry<ReportAction>): reportAction is ReportAction<ValueOf<typeof CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG>> {
return isActionOfType(reportAction, ...Object.values(CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG));
}
Expand Down Expand Up @@ -2581,6 +2585,7 @@ export {
getLeaveRoomMessage,
getRetractedMessage,
getReportActionFromExpensifyCard,
isReopenedAction,
getIntegrationSyncFailedMessage,
};

Expand Down
14 changes: 10 additions & 4 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getParentReport,
hasExportError as hasExportErrorUtil,
hasOnlyHeldExpenses,
hasReportBeenReopened as hasReportBeenReopenedUtils,
isArchivedReport,
isClosedReport as isClosedReportUtils,
isCurrentUserSubmitter,
Expand Down Expand Up @@ -53,7 +54,7 @@ function isAddExpenseAction(report: Report, reportTransactions: Transaction[]) {
return isExpenseReport && canAddTransaction && isReportSubmitter && reportTransactions.length === 0;
}

function isSubmitAction(report: Report, reportTransactions: Transaction[], policy?: Policy, reportNameValuePairs?: ReportNameValuePairs) {
function isSubmitAction(report: Report, reportTransactions: Transaction[], policy?: Policy, reportNameValuePairs?: ReportNameValuePairs, reportActions?: ReportAction[]) {
if (isArchivedReport(reportNameValuePairs)) {
return false;
}
Expand All @@ -63,7 +64,7 @@ function isSubmitAction(report: Report, reportTransactions: Transaction[], polic
const isOpenReport = isOpenReportUtils(report);
const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;
const transactionAreComplete = reportTransactions.every((transaction) => transaction.amount !== 0 || transaction.modifiedAmount !== 0);

const hasReportBeenReopened = hasReportBeenReopenedUtils(reportActions);
const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction));

if (isAnyReceiptBeingScanned) {
Expand All @@ -76,7 +77,12 @@ function isSubmitAction(report: Report, reportTransactions: Transaction[], polic
return false;
}

return isExpenseReport && isReportSubmitter && isOpenReport && isManualSubmitEnabled && reportTransactions.length !== 0 && transactionAreComplete;
const baseIsSubmit = isExpenseReport && isReportSubmitter && isOpenReport && reportTransactions.length !== 0 && transactionAreComplete;
if (hasReportBeenReopened && baseIsSubmit) {
return true;
}
Comment thread
rushatgabhane marked this conversation as resolved.

return isManualSubmitEnabled && baseIsSubmit;
}

function isApproveAction(report: Report, reportTransactions: Transaction[], policy?: Policy) {
Expand Down Expand Up @@ -299,7 +305,7 @@ function getReportPrimaryAction(
return CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD;
}

if (isSubmitAction(report, reportTransactions, policy, reportNameValuePairs)) {
if (isSubmitAction(report, reportTransactions, policy, reportNameValuePairs, reportActions)) {
return CONST.REPORT.PRIMARY_ACTIONS.SUBMIT;
}

Expand Down
10 changes: 8 additions & 2 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
canHoldUnholdReportAction,
getTransactionDetails,
hasOnlyHeldExpenses,
hasReportBeenReopened as hasReportBeenReopenedUtils,
isArchivedReport,
isAwaitingFirstLevelApproval,
isClosedReport as isClosedReportUtils,
Expand Down Expand Up @@ -102,7 +103,7 @@ function isSplitAction(report: Report, reportTransactions: Transaction[], policy
return isSubmitter || isAdmin || isManager;
}

function isSubmitAction(report: Report, reportTransactions: Transaction[], policy?: Policy, reportNameValuePairs?: ReportNameValuePairs): boolean {
function isSubmitAction(report: Report, reportTransactions: Transaction[], policy?: Policy, reportNameValuePairs?: ReportNameValuePairs, reportActions?: ReportAction[]): boolean {
if (isArchivedReport(reportNameValuePairs)) {
return false;
}
Expand Down Expand Up @@ -135,6 +136,11 @@ function isSubmitAction(report: Report, reportTransactions: Transaction[], polic
return false;
}

const hasReportBeenReopened = hasReportBeenReopenedUtils(reportActions);
if (hasReportBeenReopened && isReportSubmitter) {
return false;
}

const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const isManager = report.managerID === getCurrentUserAccountID();
if (isAdmin || isManager) {
Expand Down Expand Up @@ -502,7 +508,7 @@ function getSecondaryReportActions(
options.push(CONST.REPORT.SECONDARY_ACTIONS.ADD_EXPENSE);
}

if (isSubmitAction(report, reportTransactions, policy, reportNameValuePairs)) {
if (isSubmitAction(report, reportTransactions, policy, reportNameValuePairs, reportActions)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT);
}

Expand Down
12 changes: 12 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ import {
isPolicyChangeLogAction,
isReimbursementQueuedAction,
isRenamedAction,
isReopenedAction,
isReportActionAttachment,
isReportPreviewAction,
isReversedTransaction,
Expand Down Expand Up @@ -10810,6 +10811,16 @@ function findReportIDForAction(action?: ReportAction): string | undefined {
})
?.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, '');
}

function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[]): boolean {
if (!reportActions) {
return false;
}

const reportActionList = Array.isArray(reportActions) ? reportActions : Object.values(reportActions);
return reportActionList.some((action) => isReopenedAction(action));
}

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -11185,6 +11196,7 @@ export {
findReportIDForAction,
isWorkspaceEligibleForReportChange,
navigateOnDeleteExpense,
hasReportBeenReopened,
};

export type {
Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9436,7 +9436,7 @@ function reopenReport(expenseReport: OnyxEntry<OnyxTypes.Report>) {
const predictedNextState = CONST.REPORT.STATE_NUM.OPEN;
const predictedNextStatus = CONST.REPORT.STATUS_NUM.OPEN;

const optimisticNextStep = buildNextStep(expenseReport, predictedNextStatus);
const optimisticNextStep = buildNextStep(expenseReport, predictedNextStatus, undefined, undefined, true);
const optimisticReportActionsData: OnyxUpdate = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`,
Expand Down Expand Up @@ -9497,7 +9497,6 @@ function reopenReport(expenseReport: OnyxEntry<OnyxTypes.Report>) {
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`,
value: {
[optimisticReopenedReportAction.reportActionID]: {
pendingAction: null,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes failing request bug

errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.other'),
},
},
Expand Down