Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate adminAccountID of a report action #39042

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -435,6 +439,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'
rezkiy37 marked this conversation as resolved.
Show resolved Hide resolved
? 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 @@ -206,7 +206,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 @@ -3545,7 +3557,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 @@ -3555,6 +3567,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 @@ -5706,6 +5719,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;
}
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -5930,6 +5956,7 @@ export {
isGroupChat,
isTrackExpenseReport,
hasActionsWithErrors,
getReportActionActorAccountID,
getGroupChatName,
};

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 @@ -4779,12 +4779,13 @@ 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 optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED);
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 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
Loading