Skip to content

Commit

Permalink
Merge pull request Expensify#39042 from rezkiy37/fix/35263-owner-subm…
Browse files Browse the repository at this point in the history
…ission-message-2

Integrate adminAccountID of a report action
  • Loading branch information
marcochavezf authored Apr 11, 2024
2 parents 729bcca + caeb346 commit f20c041
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 14 deletions.
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;
}

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 @@ -4966,11 +4966,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

0 comments on commit f20c041

Please sign in to comment.