Skip to content

Commit

Permalink
Merge pull request #48594 from allgandalf/issue46926P2
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrous authored Sep 26, 2024
2 parents 7743f38 + d47e156 commit 4f93277
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4818,6 +4818,7 @@ const translations = {
}
},
genericError: 'Oops, something went wrong. Please try again.',
onBehalfOfMessage: (delegator: string) => `on behalf of ${delegator}`,
accessLevel: 'Access level',
confirmCopilot: 'Confirm your copilot below.',
accessLevelDescription: 'Choose an access level below. Both Full and Limited access allow copilots to view all conversations and expenses.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5338,6 +5338,7 @@ const translations = {
}
},
genericError: '¡Ups! Ha ocurrido un error. Por favor, inténtalo de nuevo.',
onBehalfOfMessage: (delegator: string) => `en nombre de ${delegator}`,
accessLevel: 'Nivel de acceso',
confirmCopilot: 'Confirma tu copiloto a continuación.',
accessLevelDescription: 'Elige un nivel de acceso a continuación. Tanto el acceso Completo como el Limitado permiten a los copilotos ver todas las conversaciones y gastos.',
Expand Down
84 changes: 79 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type OptimisticAddCommentReportAction = Pick<
| 'childCommenterCount'
| 'childLastVisibleActionCreated'
| 'childOldestFourAccountIDs'
| 'delegateAccountID'
> & {isOptimisticAction: boolean};

type OptimisticReportAction = {
Expand Down Expand Up @@ -180,6 +181,7 @@ type OptimisticIOUReportAction = Pick<
| 'childReportID'
| 'childVisibleActionCount'
| 'childCommenterCount'
| 'delegateAccountID'
>;

type PartialReportAction = OnyxInputOrEntry<ReportAction> | Partial<ReportAction> | OptimisticIOUReportAction | OptimisticApprovedReportAction | OptimisticSubmittedReportAction | undefined;
Expand All @@ -196,12 +198,36 @@ type ReportOfflinePendingActionAndErrors = {

type OptimisticApprovedReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.APPROVED>,
'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction'
| 'actionName'
| 'actorAccountID'
| 'automatic'
| 'avatar'
| 'isAttachmentOnly'
| 'originalMessage'
| 'message'
| 'person'
| 'reportActionID'
| 'shouldShow'
| 'created'
| 'pendingAction'
| 'delegateAccountID'
>;

type OptimisticUnapprovedReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.UNAPPROVED>,
'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachmentOnly' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction'
| 'actionName'
| 'actorAccountID'
| 'automatic'
| 'avatar'
| 'isAttachmentOnly'
| 'originalMessage'
| 'message'
| 'person'
| 'reportActionID'
| 'shouldShow'
| 'created'
| 'pendingAction'
| 'delegateAccountID'
>;

type OptimisticSubmittedReportAction = Pick<
Expand All @@ -219,6 +245,7 @@ type OptimisticSubmittedReportAction = Pick<
| 'shouldShow'
| 'created'
| 'pendingAction'
| 'delegateAccountID'
>;

type OptimisticHoldReportAction = Pick<
Expand All @@ -233,7 +260,7 @@ type OptimisticCancelPaymentReportAction = Pick<

type OptimisticEditedTaskReportAction = Pick<
ReportAction,
'reportActionID' | 'actionName' | 'pendingAction' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'shouldShow' | 'message' | 'person'
'reportActionID' | 'actionName' | 'pendingAction' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'shouldShow' | 'message' | 'person' | 'delegateAccountID'
>;

type OptimisticClosedReportAction = Pick<
Expand All @@ -248,7 +275,7 @@ type OptimisticDismissedViolationReportAction = Pick<

type OptimisticCreatedReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CREATED>,
'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'pendingAction' | 'actionName'
'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'pendingAction' | 'actionName' | 'delegateAccountID'
>;

type OptimisticRenamedReportAction = Pick<
Expand Down Expand Up @@ -321,6 +348,7 @@ type OptimisticTaskReportAction = Pick<
| 'previousMessage'
| 'errors'
| 'linkMetadata'
| 'delegateAccountID'
>;

type OptimisticWorkspaceChats = {
Expand All @@ -340,7 +368,19 @@ type OptimisticWorkspaceChats = {

type OptimisticModifiedExpenseReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE>,
'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'isAttachmentOnly' | 'message' | 'originalMessage' | 'person' | 'pendingAction' | 'reportActionID' | 'shouldShow'
| 'actionName'
| 'actorAccountID'
| 'automatic'
| 'avatar'
| 'created'
| 'isAttachmentOnly'
| 'message'
| 'originalMessage'
| 'person'
| 'pendingAction'
| 'reportActionID'
| 'shouldShow'
| 'delegateAccountID'
> & {reportID?: string};

type OptimisticTaskReport = Pick<
Expand Down Expand Up @@ -637,6 +677,14 @@ Onyx.connect({
callback: (value) => (onboarding = value),
});

let delegateEmail = '';
Onyx.connect({
key: ONYXKEYS.ACCOUNT,
callback: (value) => {
delegateEmail = value?.delegatedAccess?.delegate ?? '';
},
});

function getCurrentUserAvatar(): AvatarSource | undefined {
return currentUserPersonalDetails?.avatar;
}
Expand Down Expand Up @@ -4149,6 +4197,7 @@ function buildOptimisticAddCommentReportAction(
const isAttachmentOnly = file && !text;
const isAttachmentWithText = !!text && file !== undefined;
const accountID = actorAccountID ?? currentUserAccountID ?? -1;
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

// Remove HTML from text when applying optimistic offline comment
return {
Expand Down Expand Up @@ -4185,6 +4234,7 @@ function buildOptimisticAddCommentReportAction(
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
shouldShow: true,
isOptimisticAction: true,
delegateAccountID: delegateAccountDetails?.accountID,
},
};
}
Expand Down Expand Up @@ -4613,6 +4663,8 @@ function buildOptimisticIOUReportAction(
type,
};

const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
// In pay someone flow, we store amount, comment, currency in IOUDetails when type = pay
if (isSendMoneyFlow) {
Expand Down Expand Up @@ -4664,6 +4716,7 @@ function buildOptimisticIOUReportAction(
shouldShow: true,
created,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand All @@ -4676,6 +4729,7 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e
currency,
expenseReportID,
};
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED,
Expand All @@ -4696,13 +4750,15 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e
shouldShow: true,
created: DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

/**
* Builds an optimistic APPROVED report action with a randomly generated reportActionID.
*/
function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticUnapprovedReportAction {
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);
return {
actionName: CONST.REPORT.ACTIONS.TYPE.UNAPPROVED,
actorAccountID: currentUserAccountID,
Expand All @@ -4726,6 +4782,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string,
shouldShow: true,
created: DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand Down Expand Up @@ -4782,6 +4839,8 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string,
expenseReportID,
};

const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
actorAccountID: currentUserAccountID,
Expand All @@ -4802,6 +4861,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string,
shouldShow: true,
created: DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand Down Expand Up @@ -4902,6 +4962,8 @@ function buildOptimisticModifiedExpenseReportAction(
updatedTransaction?: OnyxInputOrEntry<Transaction>,
): OptimisticModifiedExpenseReportAction {
const originalMessage = getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction);
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
actorAccountID: currentUserAccountID,
Expand Down Expand Up @@ -4929,6 +4991,7 @@ function buildOptimisticModifiedExpenseReportAction(
reportActionID: NumberUtils.rand64(),
reportID: transactionThread?.reportID,
shouldShow: true,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand All @@ -4938,6 +5001,8 @@ function buildOptimisticModifiedExpenseReportAction(
* @param movedToReportID - The reportID of the report the transaction is moved to
*/
function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction {
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
actorAccountID: currentUserAccountID,
Expand Down Expand Up @@ -4967,6 +5032,7 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea
reportActionID: NumberUtils.rand64(),
reportID: transactionThreadID,
shouldShow: true,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand Down Expand Up @@ -5042,6 +5108,8 @@ function buildOptimisticTaskReportAction(
html: message,
whisperedTo: [],
};
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
actionName,
actorAccountID,
Expand All @@ -5068,6 +5136,7 @@ function buildOptimisticTaskReportAction(
created: DateUtils.getDBTimeWithSkew(Date.now() + createdOffset),
isFirstItem: false,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand Down Expand Up @@ -5397,6 +5466,7 @@ function buildOptimisticEditedTaskFieldReportAction({title, description}: Task):
} else if (field) {
changelog = `removed the ${field}`;
}
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
reportActionID: NumberUtils.rand64(),
Expand All @@ -5421,10 +5491,13 @@ function buildOptimisticEditedTaskFieldReportAction({title, description}: Task):
avatar: getCurrentUserAvatar(),
created: DateUtils.getDBTime(),
shouldShow: false,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: number): OptimisticEditedTaskReportAction {
const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.TASK_EDITED,
Expand All @@ -5448,6 +5521,7 @@ function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: numbe
avatar: getCurrentUserAvatar(),
created: DateUtils.getDBTime(),
shouldShow: false,
delegateAccountID: delegateAccountDetails?.accountID,
};
}

Expand Down
Loading

0 comments on commit 4f93277

Please sign in to comment.