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
16 changes: 16 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ function isReportPreviewAction(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW;
}

function isReportActionSubmitted(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED;
}

function isModifiedExpenseAction(reportAction: OnyxEntry<ReportAction> | ReportAction | Record<string, never>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE;
}
Expand Down Expand Up @@ -450,6 +454,18 @@ function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] |
return false;
}

if (isReportActionSubmitted(currentAction)) {
const currentActionAdminAccountID = currentAction.adminAccountID;

return currentActionAdminAccountID === previousAction.actorAccountID || currentActionAdminAccountID === previousAction.adminAccountID;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @rezkiy37 Why do we not check if typeof currentActionAdminAccountID is number, just like we do below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, good question. Looks like this condition can be added here as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

}

if (isReportActionSubmitted(previousAction)) {
return typeof previousAction.adminAccountID === 'number'
? currentAction.actorAccountID === previousAction.adminAccountID
: currentAction.actorAccountID === previousAction.actorAccountID;
}

return currentAction.actorAccountID === previousAction.actorAccountID;
}

Expand Down
31 changes: 29 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,19 @@ type OptimisticApprovedReportAction = Pick<

type OptimisticSubmittedReportAction = Pick<
ReportAction,
'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction'
| 'actionName'
| 'actorAccountID'
| 'adminAccountID'
| 'automatic'
| 'avatar'
| 'isAttachment'
| 'originalMessage'
| 'message'
| 'person'
| 'reportActionID'
| 'shouldShow'
| 'created'
| 'pendingAction'
>;

type OptimisticHoldReportAction = Pick<
Expand Down Expand Up @@ -3559,7 +3571,7 @@ function buildOptimisticMovedReportAction(fromPolicyID: string, toPolicyID: stri
* Builds an optimistic SUBMITTED report action with a randomly generated reportActionID.
*
*/
function buildOptimisticSubmittedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticSubmittedReportAction {
function buildOptimisticSubmittedReportAction(amount: number, currency: string, expenseReportID: string, adminAccountID: number | undefined): OptimisticSubmittedReportAction {
const originalMessage = {
amount,
currency,
Expand All @@ -3569,6 +3581,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string,
return {
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
actorAccountID: currentUserAccountID,
adminAccountID,
automatic: false,
avatar: getCurrentUserAvatarOrDefault(),
isAttachment: false,
Expand Down Expand Up @@ -5726,6 +5739,19 @@ function hasActionsWithErrors(reportID: string): boolean {
return Object.values(reportActions ?? {}).some((action) => !isEmptyObject(action.errors));
}

function getReportActionActorAccountID(reportAction: OnyxEntry<ReportAction>, iouReport: OnyxEntry<Report> | undefined): number | undefined {
switch (reportAction?.actionName) {
case CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW:
return iouReport ? iouReport.managerID : reportAction?.actorAccountID;

case CONST.REPORT.ACTIONS.TYPE.SUBMITTED:
return reportAction?.adminAccountID ?? reportAction?.actorAccountID;

default:
return reportAction?.actorAccountID;
}
}

/**
* @returns the object to update `report.hasOutstandingChildRequest`
*/
Expand Down Expand Up @@ -5977,6 +6003,7 @@ export {
isGroupChat,
isTrackExpenseReport,
hasActionsWithErrors,
getReportActionActorAccountID,
getGroupChatName,
getOutstandingChildRequest,
};
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4969,11 +4969,12 @@ function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject, full

function submitReport(expenseReport: OnyxTypes.Report) {
const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null;
const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID);
const parentReport = ReportUtils.getReport(expenseReport.parentReportID);
const policy = getPolicy(expenseReport.policyID);
const isCurrentUserManager = currentUserPersonalDetails.accountID === expenseReport.managerID;
const isSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy);
const adminAccountID = policy.role === CONST.POLICY.ROLE.ADMIN ? currentUserPersonalDetails.accountID : undefined;
const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, adminAccountID);
const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED);

const optimisticData: OnyxUpdate[] = !isSubmitAndClosePolicy
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function ReportActionItemSingle({
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT;
const actorAccountID = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && iouReport ? iouReport.managerID : action?.actorAccountID;
const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport);

let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID);
const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {};
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down
22 changes: 12 additions & 10 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function ReportActionsListItemRenderer({
error: reportAction.error,
created: reportAction.created,
actorAccountID: reportAction.actorAccountID,
adminAccountID: reportAction.adminAccountID,
childVisibleActionCount: reportAction.childVisibleActionCount,
childOldestFourAccountIDs: reportAction.childOldestFourAccountIDs,
childType: reportAction.childType,
Expand All @@ -98,25 +99,26 @@ function ReportActionsListItemRenderer({
childMoneyRequestCount: reportAction.childMoneyRequestCount,
} as ReportAction),
[
reportAction.reportActionID,
reportAction.message,
reportAction.pendingAction,
reportAction.actionName,
reportAction.childCommenterCount,
reportAction.childLastVisibleActionCreated,
reportAction.childReportID,
reportAction.created,
reportAction.error,
reportAction.errors,
reportAction.linkMetadata,
reportAction.message,
reportAction.originalMessage,
reportAction.pendingAction,
reportAction.reportActionID,
reportAction.childCommenterCount,
reportAction.linkMetadata,
reportAction.childReportID,
reportAction.childLastVisibleActionCreated,
reportAction.whisperedToAccountIDs,
reportAction.error,
reportAction.created,
reportAction.actorAccountID,
reportAction.adminAccountID,
reportAction.childVisibleActionCount,
reportAction.childOldestFourAccountIDs,
reportAction.childType,
reportAction.person,
reportAction.isOptimisticAction,
reportAction.childType,
reportAction.delegateAccountID,
reportAction.previousMessage,
reportAction.attachmentInfo,
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{

/** Flag for checking if data is from optimistic data */
isOptimisticAction?: boolean;

/** The admins's ID */
adminAccountID?: number;
}>;

type ReportAction = ReportActionBase & OriginalMessage;
Expand Down