From a2e0bbf6b5677524ddd60ce2617de75871a6f4c3 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:01:18 +0530 Subject: [PATCH 01/44] add delegate prop to OriginalMessage --- src/types/onyx/OriginalMessage.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index fcab54b470bf..557ec4c39867 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -68,6 +68,9 @@ type OriginalMessageIOU = { /** Collection of accountIDs of users mentioned in message */ whisperedTo?: number[]; + + /** Email of the delegate */ + delegate: string; }; /** Names of moderation decisions */ @@ -124,6 +127,9 @@ type OriginalMessageAddComment = { /** List accountIDs are mentioned in message */ mentionedAccountIDs?: number[]; + + /** Email of the delegate */ + delegate: string; }; /** Model of `actionable mention whisper` report action */ @@ -157,6 +163,9 @@ type OriginalMessageSubmitted = { /** Report ID of the expense */ expenseReportID: string; + + /** Email of the delegate */ + email: string; }; /** Model of `closed` report action */ @@ -430,6 +439,9 @@ type OriginalMessageApproved = { /** Report ID of the expense */ expenseReportID: string; + + /** Email of the delegate */ + delegate: string; }; /** Model of `forwarded` report action */ @@ -489,6 +501,9 @@ type OriginalMessageUnapproved = { /** Report ID of the expense */ expenseReportID: string; + + /** Email of the delegate */ + delegate: string; }; /** From 27d7bcac23167ae490a191c97201872a76bd3233 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:01:29 +0530 Subject: [PATCH 02/44] add delegate prop to OriginalMessage --- src/types/onyx/OriginalMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 557ec4c39867..e55c6a509222 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -165,7 +165,7 @@ type OriginalMessageSubmitted = { expenseReportID: string; /** Email of the delegate */ - email: string; + email:string }; /** Model of `closed` report action */ From deca9750ec4cc76df385ae1c084bb9d241852ded Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:20:48 +0530 Subject: [PATCH 03/44] add delegate in original message --- src/libs/ReportUtils.ts | 25 +++++++++++++++++++++---- src/types/onyx/OriginalMessage.ts | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7b226b2e5c8e..2a4a87ff21c4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4091,6 +4091,7 @@ function getPolicyDescriptionText(policy: OnyxEntry): string { } function buildOptimisticAddCommentReportAction( + delegate: string, text?: string, file?: FileObject, actorAccountID?: number, @@ -4136,6 +4137,7 @@ function buildOptimisticAddCommentReportAction( originalMessage: { html: htmlForNewComment, whisperedTo: [], + delegate: delegate, }, isFirstItem: false, isAttachmentOnly, @@ -4197,6 +4199,7 @@ function updateOptimisticParentReportAction(parentReportAction: OnyxEntry, @@ -4547,6 +4553,7 @@ function buildOptimisticIOUReportAction( isOwnPolicyExpenseChat = false, created = DateUtils.getDBTime(), linkedExpenseReportAction?: OnyxEntry, + delegate = '', ): OptimisticIOUReportAction { const IOUReportID = iouReportID || generateReportID(); @@ -4557,6 +4564,7 @@ function buildOptimisticIOUReportAction( IOUTransactionID: transactionID, IOUReportID, type, + delegate, }; if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) { @@ -4616,11 +4624,12 @@ function buildOptimisticIOUReportAction( /** * Builds an optimistic APPROVED report action with a randomly generated reportActionID. */ -function buildOptimisticApprovedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticApprovedReportAction { +function buildOptimisticApprovedReportAction(amount: number, currency: string, expenseReportID: string, delegate: string): OptimisticApprovedReportAction { const originalMessage = { amount, currency, expenseReportID, + delegate, }; return { @@ -4648,7 +4657,7 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e /** * Builds an optimistic APPROVED report action with a randomly generated reportActionID. */ -function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticUnapprovedReportAction { +function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string, delegate: string): OptimisticUnapprovedReportAction { return { actionName: CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, actorAccountID: currentUserAccountID, @@ -4659,6 +4668,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, amount, currency, expenseReportID, + delegate, }, message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, Math.abs(amount), '', currency), person: [ @@ -4721,11 +4731,18 @@ 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, adminAccountID: number | undefined): OptimisticSubmittedReportAction { +function buildOptimisticSubmittedReportAction( + amount: number, + currency: string, + expenseReportID: string, + adminAccountID: number | undefined, + delegate: string, +): OptimisticSubmittedReportAction { const originalMessage = { amount, currency, expenseReportID, + delegate, }; return { diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index e55c6a509222..557ec4c39867 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -165,7 +165,7 @@ type OriginalMessageSubmitted = { expenseReportID: string; /** Email of the delegate */ - email:string + email: string; }; /** Model of `closed` report action */ From daa0c9cd9574caaa45d4dba561b75767e1a38c8d Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:25:34 +0530 Subject: [PATCH 04/44] fix OriginalMessageSubmitted typo --- src/types/onyx/OriginalMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 557ec4c39867..ad6280547284 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -165,7 +165,7 @@ type OriginalMessageSubmitted = { expenseReportID: string; /** Email of the delegate */ - email: string; + delegate: string; }; /** Model of `closed` report action */ From c18f61f9c8b03ef77b85bb6ce4c81f1906082781 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:45:32 +0530 Subject: [PATCH 05/44] update optimistic actions to include delegate email --- src/components/DelegateNoAccessModal.tsx | 38 ++++++++++++++++++++++++ src/hooks/useDelegateUserDetails.ts | 18 +++++++++++ src/libs/actions/IOU.ts | 9 ++++-- src/libs/actions/Report.ts | 13 ++++---- 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/components/DelegateNoAccessModal.tsx create mode 100644 src/hooks/useDelegateUserDetails.ts diff --git a/src/components/DelegateNoAccessModal.tsx b/src/components/DelegateNoAccessModal.tsx new file mode 100644 index 000000000000..8bb61b783fd1 --- /dev/null +++ b/src/components/DelegateNoAccessModal.tsx @@ -0,0 +1,38 @@ +import React from 'react'; +import useLocalize from '@hooks/useLocalize'; +import CONST from '@src/CONST'; +import ConfirmModal from './ConfirmModal'; +import Text from './Text'; +import TextLink from './TextLink'; + +type DelegateNoAccessModalProps = { + isNoDelegateAccessMenuVisible: boolean; + onConfirm: () => void; + delegatorEmail: string; +}; + +export default function DelegateNoAccessModal({isNoDelegateAccessMenuVisible = false, onConfirm, delegatorEmail = ''}: DelegateNoAccessModalProps) { + const {translate} = useLocalize(); + const basicnoDelegateAccessPromptStart = translate('delegate.notAllowedMessageStart', {accountOwnerEmail: delegatorEmail}); + const basicnoDelegateAccessHyperLinked = translate('delegate.notAllowedMessageHyperLinked'); + const basicnoDelegateAccessPromptEnd = translate('delegate.notAllowedMessageEnd'); + + const delegateNoAccessPrompt = ( + + {basicnoDelegateAccessPromptStart} + {basicnoDelegateAccessHyperLinked} + {basicnoDelegateAccessPromptEnd} + + ); + + return ( + + ); +} \ No newline at end of file diff --git a/src/hooks/useDelegateUserDetails.ts b/src/hooks/useDelegateUserDetails.ts new file mode 100644 index 000000000000..79b10e438b73 --- /dev/null +++ b/src/hooks/useDelegateUserDetails.ts @@ -0,0 +1,18 @@ +import {useOnyx} from 'react-native-onyx'; +import AccountUtils from '@libs/AccountUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; + +function useDelegateUserDetails() { + const currentUserDeatils = useCurrentUserPersonalDetails(); + const [currentUserAccountDetails] = useOnyx(ONYXKEYS.ACCOUNT); + const delegatorEmail = currentUserDeatils?.login; + const delegateEmail = currentUserAccountDetails?.delegatedAccess?.delegate ?? ''; + + return { + delegatorEmail, + delegateEmail + }; +} + +export default useDelegateUserDetails; \ No newline at end of file diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 29d481737790..227970964637 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4,6 +4,7 @@ import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} import Onyx from 'react-native-onyx'; import type {PartialDeep, SetRequired, ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; +import useDelegateUserDetails from '@hooks/useDelegateUserDetails' import * as API from '@libs/API'; import type { ApproveMoneyRequestParams, @@ -272,6 +273,8 @@ Onyx.connect({ callback: (value) => (activePolicyID = value), }); +const { delegateEmail } = useDelegateUserDetails() + /** * Find the report preview action from given chat report and iou report */ @@ -6912,7 +6915,7 @@ function approveMoneyRequest(expenseReport: OnyxEntry, full?: if (hasHeldExpenses && !full && !!expenseReport?.unheldTotal) { total = expenseReport?.unheldTotal; } - const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1'); + const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1', delegateEmail); const approvalChain = ReportUtils.getApprovalChain(PolicyUtils.getPolicy(expenseReport?.policyID), expenseReport?.ownerAccountID ?? -1, expenseReport?.total ?? 0); @@ -7068,7 +7071,7 @@ function unapproveExpenseReport(expenseReport: OnyxEntry) { const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; - const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID); + const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, delegateEmail); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); const optimisticReportActionData: OnyxUpdate = { @@ -7162,7 +7165,7 @@ function submitReport(expenseReport: OnyxTypes.Report) { 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 optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, adminAccountID, delegateEmail); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED); const optimisticData: OnyxUpdate[] = !isSubmitAndClosePolicy diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index bd31d3832605..ba6c9ad77c09 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -5,6 +5,7 @@ import isEmpty from 'lodash/isEmpty'; import {DeviceEventEmitter, InteractionManager, Linking} from 'react-native'; import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import useDelegateUserDetails from '@hooks/useDelegateUserDetails' import type {PartialDeep, ValueOf} from 'type-fest'; import type {Emoji} from '@assets/emojis/types'; import type {FileObject} from '@components/AttachmentModal'; @@ -280,6 +281,8 @@ registerPaginationConfig({ isLastItem: (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, }); +const { delegateEmail } = useDelegateUserDetails() + function clearGroupChat() { Onyx.set(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, null); } @@ -453,7 +456,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { let commandName: typeof WRITE_COMMANDS.ADD_COMMENT | typeof WRITE_COMMANDS.ADD_ATTACHMENT | typeof WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT = WRITE_COMMANDS.ADD_COMMENT; if (text && !file) { - const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(text, undefined, undefined, undefined, undefined, reportID); + const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, text, undefined, undefined, undefined, undefined, reportID); reportCommentAction = reportComment.reportAction; reportCommentText = reportComment.commentText; } @@ -462,7 +465,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { // When we are adding an attachment we will call AddAttachment. // It supports sending an attachment with an optional comment and AddComment supports adding a single text comment only. commandName = WRITE_COMMANDS.ADD_ATTACHMENT; - const attachment = ReportUtils.buildOptimisticAddCommentReportAction(text, file, undefined, undefined, undefined, reportID); + const attachment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, text, file, undefined, undefined, undefined, reportID); attachmentAction = attachment.reportAction; } @@ -3340,7 +3343,7 @@ function completeOnboarding( const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {}; // Introductory message - const introductionComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ONBOARDING_INTRODUCTION, undefined, actorAccountID); + const introductionComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ONBOARDING_INTRODUCTION, undefined, actorAccountID); const introductionCommentAction: OptimisticAddCommentReportAction = introductionComment.reportAction; const introductionMessage: AddCommentOrAttachementParams = { reportID: targetChatReportID, @@ -3349,7 +3352,7 @@ function completeOnboarding( }; // Text message - const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined, actorAccountID, 1); + const textComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, data.message, undefined, actorAccountID, 1); const textCommentAction: OptimisticAddCommentReportAction = textComment.reportAction; const textMessage: AddCommentOrAttachementParams = { reportID: targetChatReportID, @@ -3360,7 +3363,7 @@ function completeOnboarding( let videoCommentAction: OptimisticAddCommentReportAction | null = null; let videoMessage: AddCommentOrAttachementParams | null = null; if (data.video) { - const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 2); + const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 2); videoCommentAction = videoComment.reportAction; videoMessage = { reportID: targetChatReportID, From f45020ad800eae075e97092c6f00e7475c6b10a7 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:46:36 +0530 Subject: [PATCH 06/44] remove delegate component --- src/components/DelegateNoAccessModal.tsx | 38 ------------------------ 1 file changed, 38 deletions(-) delete mode 100644 src/components/DelegateNoAccessModal.tsx diff --git a/src/components/DelegateNoAccessModal.tsx b/src/components/DelegateNoAccessModal.tsx deleted file mode 100644 index 8bb61b783fd1..000000000000 --- a/src/components/DelegateNoAccessModal.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import React from 'react'; -import useLocalize from '@hooks/useLocalize'; -import CONST from '@src/CONST'; -import ConfirmModal from './ConfirmModal'; -import Text from './Text'; -import TextLink from './TextLink'; - -type DelegateNoAccessModalProps = { - isNoDelegateAccessMenuVisible: boolean; - onConfirm: () => void; - delegatorEmail: string; -}; - -export default function DelegateNoAccessModal({isNoDelegateAccessMenuVisible = false, onConfirm, delegatorEmail = ''}: DelegateNoAccessModalProps) { - const {translate} = useLocalize(); - const basicnoDelegateAccessPromptStart = translate('delegate.notAllowedMessageStart', {accountOwnerEmail: delegatorEmail}); - const basicnoDelegateAccessHyperLinked = translate('delegate.notAllowedMessageHyperLinked'); - const basicnoDelegateAccessPromptEnd = translate('delegate.notAllowedMessageEnd'); - - const delegateNoAccessPrompt = ( - - {basicnoDelegateAccessPromptStart} - {basicnoDelegateAccessHyperLinked} - {basicnoDelegateAccessPromptEnd} - - ); - - return ( - - ); -} \ No newline at end of file From dd7947d069ff499fe94d6859ffe1e62ba1fcfbc9 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Thu, 5 Sep 2024 02:54:00 +0530 Subject: [PATCH 07/44] fix unit test --- tests/actions/IOUTest.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 8a7095af6f7f..dd94fbd76aa5 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -417,6 +417,7 @@ describe('actions/IOU', () => { const comment = 'Giv money plz'; const chatReportID = '1234'; const iouReportID = '5678'; + const delegate = '' let chatReport: OnyxEntry = { reportID: chatReportID, type: CONST.REPORT.TYPE.CHAT, @@ -460,6 +461,7 @@ describe('actions/IOU', () => { currency: CONST.CURRENCY.USD, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, participantAccountIDs: [RORY_ACCOUNT_ID, CARLOS_ACCOUNT_ID], + delegate: delegate, }, }; let newIOUAction: OnyxEntry>; From e7162f3a101891bd828777aaaaf1f073d0b93738 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 00:53:20 +0530 Subject: [PATCH 08/44] fix lint --- src/hooks/useDelegateUserDetails.ts | 5 ++--- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/IOU.ts | 17 +++++++++++++---- src/libs/actions/Report.ts | 7 ++++--- tests/actions/IOUTest.ts | 4 ++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/hooks/useDelegateUserDetails.ts b/src/hooks/useDelegateUserDetails.ts index 79b10e438b73..d1542be67463 100644 --- a/src/hooks/useDelegateUserDetails.ts +++ b/src/hooks/useDelegateUserDetails.ts @@ -1,5 +1,4 @@ import {useOnyx} from 'react-native-onyx'; -import AccountUtils from '@libs/AccountUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; @@ -11,8 +10,8 @@ function useDelegateUserDetails() { return { delegatorEmail, - delegateEmail + delegateEmail, }; } -export default useDelegateUserDetails; \ No newline at end of file +export default useDelegateUserDetails; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2a4a87ff21c4..bc82ed723dea 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4137,7 +4137,7 @@ function buildOptimisticAddCommentReportAction( originalMessage: { html: htmlForNewComment, whisperedTo: [], - delegate: delegate, + delegate, }, isFirstItem: false, isAttachmentOnly, @@ -4224,7 +4224,7 @@ function buildOptimisticTaskCommentReportAction( html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction), taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID, whisperedTo: [], - delegate: delegate, + delegate, }; reportAction.reportAction.childReportID = taskReportID; reportAction.reportAction.parentReportID = parentReportID; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 227970964637..4ef052f75957 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4,7 +4,7 @@ import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} import Onyx from 'react-native-onyx'; import type {PartialDeep, SetRequired, ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; -import useDelegateUserDetails from '@hooks/useDelegateUserDetails' +import useDelegateUserDetails from '@hooks/useDelegateUserDetails'; import * as API from '@libs/API'; import type { ApproveMoneyRequestParams, @@ -273,8 +273,6 @@ Onyx.connect({ callback: (value) => (activePolicyID = value), }); -const { delegateEmail } = useDelegateUserDetails() - /** * Find the report preview action from given chat report and iou report */ @@ -6915,6 +6913,8 @@ function approveMoneyRequest(expenseReport: OnyxEntry, full?: if (hasHeldExpenses && !full && !!expenseReport?.unheldTotal) { total = expenseReport?.unheldTotal; } + const {delegateEmail} = useDelegateUserDetails(); + const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1', delegateEmail); const approvalChain = ReportUtils.getApprovalChain(PolicyUtils.getPolicy(expenseReport?.policyID), expenseReport?.ownerAccountID ?? -1, expenseReport?.total ?? 0); @@ -7070,6 +7070,7 @@ function unapproveExpenseReport(expenseReport: OnyxEntry) { } const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; + const {delegateEmail} = useDelegateUserDetails(); const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, delegateEmail); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); @@ -7165,7 +7166,15 @@ function submitReport(expenseReport: OnyxTypes.Report) { 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, delegateEmail); + const {delegateEmail} = useDelegateUserDetails(); + + const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction( + expenseReport?.total ?? 0, + expenseReport.currency ?? '', + expenseReport.reportID, + adminAccountID, + delegateEmail, + ); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED); const optimisticData: OnyxUpdate[] = !isSubmitAndClosePolicy diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ba6c9ad77c09..1c3abce65372 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -5,10 +5,10 @@ import isEmpty from 'lodash/isEmpty'; import {DeviceEventEmitter, InteractionManager, Linking} from 'react-native'; import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; -import useDelegateUserDetails from '@hooks/useDelegateUserDetails' import type {PartialDeep, ValueOf} from 'type-fest'; import type {Emoji} from '@assets/emojis/types'; import type {FileObject} from '@components/AttachmentModal'; +import useDelegateUserDetails from '@hooks/useDelegateUserDetails'; import AccountUtils from '@libs/AccountUtils'; import * as ActiveClientManager from '@libs/ActiveClientManager'; import * as API from '@libs/API'; @@ -281,7 +281,6 @@ registerPaginationConfig({ isLastItem: (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, }); -const { delegateEmail } = useDelegateUserDetails() function clearGroupChat() { Onyx.set(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, null); @@ -454,6 +453,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { let reportCommentAction: OptimisticAddCommentReportAction | undefined; let attachmentAction: OptimisticAddCommentReportAction | undefined; let commandName: typeof WRITE_COMMANDS.ADD_COMMENT | typeof WRITE_COMMANDS.ADD_ATTACHMENT | typeof WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT = WRITE_COMMANDS.ADD_COMMENT; + const {delegateEmail} = useDelegateUserDetails(); if (text && !file) { const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, text, undefined, undefined, undefined, undefined, reportID); @@ -3341,7 +3341,8 @@ function completeOnboarding( const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail])[0]; const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID, currentUserAccountID]); const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {}; - + const {delegateEmail} = useDelegateUserDetails(); + // Introductory message const introductionComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ONBOARDING_INTRODUCTION, undefined, actorAccountID); const introductionCommentAction: OptimisticAddCommentReportAction = introductionComment.reportAction; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index dd94fbd76aa5..7a228fa5af7d 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -417,7 +417,7 @@ describe('actions/IOU', () => { const comment = 'Giv money plz'; const chatReportID = '1234'; const iouReportID = '5678'; - const delegate = '' + const delegate = ''; let chatReport: OnyxEntry = { reportID: chatReportID, type: CONST.REPORT.TYPE.CHAT, @@ -461,7 +461,7 @@ describe('actions/IOU', () => { currency: CONST.CURRENCY.USD, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, participantAccountIDs: [RORY_ACCOUNT_ID, CARLOS_ACCOUNT_ID], - delegate: delegate, + delegate, }, }; let newIOUAction: OnyxEntry>; From beb642d337a356101360b82f1b070481f00a7821 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 01:16:41 +0530 Subject: [PATCH 09/44] remove usage of hook --- src/hooks/useDelegateUserDetails.ts | 17 ----------------- src/libs/actions/IOU.ts | 12 ++++++++---- src/libs/actions/Report.ts | 13 ++++++++----- 3 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 src/hooks/useDelegateUserDetails.ts diff --git a/src/hooks/useDelegateUserDetails.ts b/src/hooks/useDelegateUserDetails.ts deleted file mode 100644 index d1542be67463..000000000000 --- a/src/hooks/useDelegateUserDetails.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {useOnyx} from 'react-native-onyx'; -import ONYXKEYS from '@src/ONYXKEYS'; -import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; - -function useDelegateUserDetails() { - const currentUserDeatils = useCurrentUserPersonalDetails(); - const [currentUserAccountDetails] = useOnyx(ONYXKEYS.ACCOUNT); - const delegatorEmail = currentUserDeatils?.login; - const delegateEmail = currentUserAccountDetails?.delegatedAccess?.delegate ?? ''; - - return { - delegatorEmail, - delegateEmail, - }; -} - -export default useDelegateUserDetails; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index e01b2b745460..32ebfb1e516f 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4,7 +4,6 @@ import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} import Onyx from 'react-native-onyx'; import type {PartialDeep, SetRequired, ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; -import useDelegateUserDetails from '@hooks/useDelegateUserDetails'; import * as API from '@libs/API'; import type { ApproveMoneyRequestParams, @@ -247,6 +246,14 @@ Onyx.connect({ }, }); +let delegateEmail = ''; +Onyx.connect({ + key: ONYXKEYS.ACCOUNT, + callback: (value) => { + delegateEmail = value?.delegatedAccess?.delegate ?? ''; + }, +}); + let quickAction: OnyxEntry = {}; Onyx.connect({ key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, @@ -6915,7 +6922,6 @@ function approveMoneyRequest(expenseReport: OnyxEntry, full?: if (hasHeldExpenses && !full && !!expenseReport?.unheldTotal) { total = expenseReport?.unheldTotal; } - const {delegateEmail} = useDelegateUserDetails(); const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1', delegateEmail); @@ -7072,7 +7078,6 @@ function unapproveExpenseReport(expenseReport: OnyxEntry) { } const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; - const {delegateEmail} = useDelegateUserDetails(); const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, delegateEmail); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); @@ -7168,7 +7173,6 @@ function submitReport(expenseReport: OnyxTypes.Report) { const isCurrentUserManager = currentUserPersonalDetails?.accountID === expenseReport.managerID; const isSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); const adminAccountID = policy?.role === CONST.POLICY.ROLE.ADMIN ? currentUserPersonalDetails?.accountID : undefined; - const {delegateEmail} = useDelegateUserDetails(); const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction( expenseReport?.total ?? 0, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index bdde156bf644..874cc04f9e10 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -8,7 +8,6 @@ import Onyx from 'react-native-onyx'; import type {PartialDeep, ValueOf} from 'type-fest'; import type {Emoji} from '@assets/emojis/types'; import type {FileObject} from '@components/AttachmentModal'; -import useDelegateUserDetails from '@hooks/useDelegateUserDetails'; import * as ActiveClientManager from '@libs/ActiveClientManager'; import * as API from '@libs/API'; import type { @@ -265,6 +264,13 @@ Onyx.connect({ waitForCollectionCallback: true, callback: (value) => (allReportDraftComments = value), }); +let delegateEmail = ''; +Onyx.connect({ + key: ONYXKEYS.ACCOUNT, + callback: (value) => { + delegateEmail = value?.delegatedAccess?.delegate ?? ''; + }, +}); let environmentURL: string; Environment.getEnvironmentURL().then((url: string) => (environmentURL = url)); @@ -280,7 +286,6 @@ registerPaginationConfig({ isLastItem: (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, }); - function clearGroupChat() { Onyx.set(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, null); } @@ -452,7 +457,6 @@ function addActions(reportID: string, text = '', file?: FileObject) { let reportCommentAction: OptimisticAddCommentReportAction | undefined; let attachmentAction: OptimisticAddCommentReportAction | undefined; let commandName: typeof WRITE_COMMANDS.ADD_COMMENT | typeof WRITE_COMMANDS.ADD_ATTACHMENT | typeof WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT = WRITE_COMMANDS.ADD_COMMENT; - const {delegateEmail} = useDelegateUserDetails(); if (text && !file) { const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, text, undefined, undefined, undefined, undefined, reportID); @@ -3323,8 +3327,7 @@ function completeOnboarding( const actorAccountID = CONST.ACCOUNT_ID.CONCIERGE; const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID, currentUserAccountID]); const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {}; - const {delegateEmail} = useDelegateUserDetails(); - + // Introductory message const introductionComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ONBOARDING_INTRODUCTION, undefined, actorAccountID); const introductionCommentAction: OptimisticAddCommentReportAction = introductionComment.reportAction; From b6272e331288c58d1d36e07ad45bf97741ffed83 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 03:24:59 +0530 Subject: [PATCH 10/44] part 1: update reportactionitemsingle to display delegate details --- src/libs/Permissions.ts | 2 +- src/libs/ReportActionsUtils.ts | 6 +++++ .../home/report/ReportActionItemSingle.tsx | 27 ++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 0e67dc270518..3ff753dfa067 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return true; } function canUseDefaultRooms(betas: OnyxEntry): boolean { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4d126cf9cbf4..378052285c26 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -209,6 +209,11 @@ function getOriginalMessage(reportAction: OnyxInputO return reportAction.originalMessage; } +function getOriginalMessageForDelegate(reportAction: OnyxInputOrEntry){ + + return reportAction?.originalMessage ?? {}; +} + function isExportIntegrationAction(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION; } @@ -1737,6 +1742,7 @@ export { isTransactionThread, isTripPreview, isWhisperAction, + getOriginalMessageForDelegate, isSubmittedAction, isApprovedAction, isForwardedAction, diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 95a7332f0606..c7063cb7af79 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -20,7 +20,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import ControlSelection from '@libs/ControlSelection'; import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {getReportActionMessage} from '@libs/ReportActionsUtils'; +import {getOriginalMessage, getOriginalMessageForDelegate, getReportActionMessage} from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -30,6 +30,8 @@ import type {Icon} from '@src/types/onyx/OnyxCommon'; import type ChildrenProps from '@src/types/utils/ChildrenProps'; import ReportActionItemDate from './ReportActionItemDate'; import ReportActionItemFragment from './ReportActionItemFragment'; +import { getAccountIDsByLogins, getPersonalDetailByEmail } from '@libs/PersonalDetailsUtils'; +import ReportActionItemBasicMessage from './ReportActionItemBasicMessage'; type ReportActionItemSingleProps = Partial & { /** All the data of the action */ @@ -83,7 +85,10 @@ function ReportActionItemSingle({ const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT; const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); + const message = getOriginalMessage(action) + const delegateEmail = message?.delegate + console.log('delegateEmail::::', delegateEmail) let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -102,15 +107,15 @@ function ReportActionItemSingle({ actorHint = displayName; avatarSource = ReportUtils.getWorkspaceAvatar(report); avatarId = report.policyID; - } else if (action?.delegateAccountID && personalDetails[action?.delegateAccountID]) { + } else if (delegateEmail) { // We replace the actor's email, name, and avatar with the Copilot manually for now. And only if we have their // details. This will be improved upon when the Copilot feature is implemented. - const delegateDetails = personalDetails[action.delegateAccountID]; + const delegateAccount = getPersonalDetailByEmail(delegateEmail) + const delegateDetails = delegateAccount; const delegateDisplayName = delegateDetails?.displayName; - actorHint = `${delegateDisplayName} (${translate('reportAction.asCopilot')} ${displayName})`; - displayName = actorHint; + displayName = delegateDisplayName ?? ''; avatarSource = delegateDetails?.avatar; - avatarId = action.delegateAccountID; + avatarId = delegateAccount?.accountID; } else if (isReportPreviewAction && isTripRoom) { displayName = report?.reportName ?? ''; } @@ -235,7 +240,16 @@ function ReportActionItemSingle({ const formattedDate = DateUtils.getStatusUntilDate(status?.clearAfter ?? ''); const statusText = status?.text ?? ''; const statusTooltipText = formattedDate ? `${statusText ? `${statusText} ` : ''}(${formattedDate})` : statusText; + const actionTypes = [ + CONST.REPORT.ACTIONS.TYPE.SUBMITTED, + CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + CONST.REPORT.ACTIONS.TYPE.APPROVED, + CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT, + CONST.REPORT.ACTIONS.TYPE.HOLD, + CONST.REPORT.ACTIONS.TYPE.UNHOLD, + ]; + return ( ) : null} + {actionTypes.includes(action?.actionName) && ()} {children} From 79192b27d15e72f0c643650eb5f52ef9bd177769 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 03:28:34 +0530 Subject: [PATCH 11/44] Update Permissions.ts --- src/libs/Permissions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 3ff753dfa067..0e67dc270518 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return true; + return !!betas?.includes(CONST.BETAS.ALL); } function canUseDefaultRooms(betas: OnyxEntry): boolean { From 3d136e4fa8ecb70df5ab382258bb8d7db4db73b9 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 12:07:26 +0530 Subject: [PATCH 12/44] part 2: add delegator name --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/pages/home/report/ReportActionItemSingle.tsx | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index c2902dc3d8a5..ca58e53eec0c 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -4600,5 +4600,6 @@ export default { } }, genericError: 'Oops, something went wrong. Please try again.', + onBehalfOfMessage: (delegator: string) => `on behalf of ${delegator}`, }, } satisfies TranslationBase; diff --git a/src/languages/es.ts b/src/languages/es.ts index 9ce98e12b135..7b3baf6a9796 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -5117,5 +5117,6 @@ export default { } }, genericError: '¡Ups! Ha ocurrido un error. Por favor, inténtalo de nuevo.', + onBehalfOfMessage: ({delegator}: string) => `on behalf of ${delegator}`, }, } satisfies EnglishTranslation; diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index c7063cb7af79..b2325c367aa1 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -83,14 +83,15 @@ function ReportActionItemSingle({ const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT; + const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); const message = getOriginalMessage(action) const delegateEmail = message?.delegate - console.log('delegateEmail::::', delegateEmail) let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; + const accountOwnerDetails = getPersonalDetailByEmail(login ?? '') // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); const isTripRoom = ReportUtils.isTripRoom(report); @@ -299,7 +300,7 @@ function ReportActionItemSingle({ ) : null} - {actionTypes.includes(action?.actionName) && ()} + {(delegateEmail && actionTypes.includes(action?.actionName)) && ()} {children} From 9a2f8b72bcc91f2a2405abf30eecdb078ef07521 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 12:09:28 +0530 Subject: [PATCH 13/44] fix spanish translation --- src/languages/es.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index 7b3baf6a9796..9492ea36aa90 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -5117,6 +5117,6 @@ export default { } }, genericError: '¡Ups! Ha ocurrido un error. Por favor, inténtalo de nuevo.', - onBehalfOfMessage: ({delegator}: string) => `on behalf of ${delegator}`, + onBehalfOfMessage: (delegator: string) => `en nombre de ${delegator}`, }, } satisfies EnglishTranslation; From 4b13c3c194f058adf9f34ebe566d415be821a387 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 12:48:47 +0530 Subject: [PATCH 14/44] add delegator display name --- src/libs/ReportActionsUtils.ts | 3 +-- .../home/report/ReportActionItemSingle.tsx | 20 +++++++++---------- src/styles/index.ts | 10 ++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 378052285c26..916951f00ea7 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -209,8 +209,7 @@ function getOriginalMessage(reportAction: OnyxInputO return reportAction.originalMessage; } -function getOriginalMessageForDelegate(reportAction: OnyxInputOrEntry){ - +function getOriginalMessageForDelegate(reportAction: OnyxInputOrEntry) { return reportAction?.originalMessage ?? {}; } diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index b2325c367aa1..765febd99d87 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -20,7 +20,8 @@ import useThemeStyles from '@hooks/useThemeStyles'; import ControlSelection from '@libs/ControlSelection'; import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {getOriginalMessage, getOriginalMessageForDelegate, getReportActionMessage} from '@libs/ReportActionsUtils'; +import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; +import {getOriginalMessage, getReportActionMessage} from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -30,8 +31,6 @@ import type {Icon} from '@src/types/onyx/OnyxCommon'; import type ChildrenProps from '@src/types/utils/ChildrenProps'; import ReportActionItemDate from './ReportActionItemDate'; import ReportActionItemFragment from './ReportActionItemFragment'; -import { getAccountIDsByLogins, getPersonalDetailByEmail } from '@libs/PersonalDetailsUtils'; -import ReportActionItemBasicMessage from './ReportActionItemBasicMessage'; type ReportActionItemSingleProps = Partial & { /** All the data of the action */ @@ -86,12 +85,12 @@ function ReportActionItemSingle({ const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); - const message = getOriginalMessage(action) - const delegateEmail = message?.delegate + const message = getOriginalMessage(action); + const delegateEmail = message?.delegate; let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; - const accountOwnerDetails = getPersonalDetailByEmail(login ?? '') + const accountOwnerDetails = getPersonalDetailByEmail(login ?? ''); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); const isTripRoom = ReportUtils.isTripRoom(report); @@ -111,7 +110,7 @@ function ReportActionItemSingle({ } else if (delegateEmail) { // We replace the actor's email, name, and avatar with the Copilot manually for now. And only if we have their // details. This will be improved upon when the Copilot feature is implemented. - const delegateAccount = getPersonalDetailByEmail(delegateEmail) + const delegateAccount = getPersonalDetailByEmail(delegateEmail); const delegateDetails = delegateAccount; const delegateDisplayName = delegateDetails?.displayName; displayName = delegateDisplayName ?? ''; @@ -248,9 +247,8 @@ function ReportActionItemSingle({ CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT, CONST.REPORT.ACTIONS.TYPE.HOLD, CONST.REPORT.ACTIONS.TYPE.UNHOLD, + ]; - ]; - return ( ) : null} - {(delegateEmail && actionTypes.includes(action?.actionName)) && ()} + {delegateEmail && actionTypes.includes(action?.actionName) && ( + {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')} + )} {children} diff --git a/src/styles/index.ts b/src/styles/index.ts index 179e886d08ff..43769cbfcea8 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -2070,6 +2070,16 @@ const styles = (theme: ThemeColors) => ...wordBreak.breakWord, }, + chatDelegateMessage: { + color: theme.textSupporting, + fontSize: 11, + ...FontUtils.fontFamily.platform.EXP_NEUE, + lineHeight: variables.lineHeightXLarge, + maxWidth: '100%', + ...whiteSpace.preWrap, + ...wordBreak.breakWord, + }, + renderHTMLTitle: { color: theme.text, fontSize: variables.fontSizeNormal, From 1c497dab18cdf453f8667dca76ab363be613ab20 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 13:13:03 +0530 Subject: [PATCH 15/44] fix system message --- src/pages/home/report/ReportActionItemSingle.tsx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 765febd99d87..9f18b8f18f0c 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -86,7 +86,7 @@ function ReportActionItemSingle({ const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); const message = getOriginalMessage(action); - const delegateEmail = message?.delegate; + const delegateEmail = (message as any)?.delegate; let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; @@ -240,14 +240,6 @@ function ReportActionItemSingle({ const formattedDate = DateUtils.getStatusUntilDate(status?.clearAfter ?? ''); const statusText = status?.text ?? ''; const statusTooltipText = formattedDate ? `${statusText ? `${statusText} ` : ''}(${formattedDate})` : statusText; - const actionTypes = [ - CONST.REPORT.ACTIONS.TYPE.SUBMITTED, - CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, - CONST.REPORT.ACTIONS.TYPE.APPROVED, - CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT, - CONST.REPORT.ACTIONS.TYPE.HOLD, - CONST.REPORT.ACTIONS.TYPE.UNHOLD, - ]; return ( @@ -298,9 +290,7 @@ function ReportActionItemSingle({ ) : null} - {delegateEmail && actionTypes.includes(action?.actionName) && ( - {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')} - )} + {delegateEmail && {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')}} {children} From 96eb90f4030ad54ac45210bbb9ca16254ac726ea Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 16:41:35 +0530 Subject: [PATCH 16/44] fix grouping of messages --- src/libs/ReportActionsUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 916951f00ea7..8b7a996b2300 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -525,7 +525,7 @@ function findPreviousAction(reportActions: ReportAction[] | undefined, actionInd function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | undefined, actionIndex: number): boolean { const previousAction = findPreviousAction(reportActions, actionIndex); const currentAction = reportActions?.[actionIndex]; - + // It's OK for there to be no previous action, and in that case, false will be returned // so that the comment isn't grouped if (!currentAction || !previousAction) { @@ -548,7 +548,7 @@ function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | } // Do not group if the delegate account ID is different - if (previousAction.delegateAccountID !== currentAction.delegateAccountID) { + if (previousAction.originalMessage?.delegate !== currentAction.originalMessage?.delegate) { return false; } From fc3cae1b8cbaed3646174bea2f69460232e18849 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 16:52:13 +0530 Subject: [PATCH 17/44] revert to previous check --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 8b7a996b2300..f147d283294f 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -548,7 +548,7 @@ function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | } // Do not group if the delegate account ID is different - if (previousAction.originalMessage?.delegate !== currentAction.originalMessage?.delegate) { + if (previousAction.delegateAccountID !== currentAction.delegateAccountID) { return false; } From 47a098ecf34baf41e64535f1efcc5d3069fc82fa Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 16:53:01 +0530 Subject: [PATCH 18/44] get delegate account details --- src/libs/ReportActionsUtils.ts | 2 +- src/libs/ReportUtils.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index f147d283294f..916951f00ea7 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -525,7 +525,7 @@ function findPreviousAction(reportActions: ReportAction[] | undefined, actionInd function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | undefined, actionIndex: number): boolean { const previousAction = findPreviousAction(reportActions, actionIndex); const currentAction = reportActions?.[actionIndex]; - + // It's OK for there to be no previous action, and in that case, false will be returned // so that the comment isn't grouped if (!currentAction || !previousAction) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6bc4f98f9a4a..d1bf1767f4ac 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -126,6 +126,7 @@ type OptimisticAddCommentReportAction = Pick< | 'childCommenterCount' | 'childLastVisibleActionCreated' | 'childOldestFourAccountIDs' + | 'delegateAccountID' > & {isOptimisticAction: boolean}; type OptimisticReportAction = { @@ -4107,7 +4108,7 @@ function buildOptimisticAddCommentReportAction( const isAttachmentOnly = file && !text; const isAttachmentWithText = !!text && file !== undefined; const accountID = actorAccountID ?? currentUserAccountID ?? -1; - + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); // Remove HTML from text when applying optimistic offline comment return { commentText, @@ -4144,6 +4145,7 @@ function buildOptimisticAddCommentReportAction( pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, shouldShow: true, isOptimisticAction: true, + delegateAccountID: delegateAccountDetails?.accountID, }, }; } From e48b2b1131ef1c010a4d139084a61088b81bc756 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 17:04:37 +0530 Subject: [PATCH 19/44] add delegateaccountID --- src/libs/ReportUtils.ts | 36 +++++++++++++++++-- .../home/report/ReportActionItemSingle.tsx | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d1bf1767f4ac..ffe970758b56 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -196,12 +196,36 @@ type ReportOfflinePendingActionAndErrors = { type OptimisticApprovedReportAction = Pick< ReportAction, - '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, - '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< @@ -219,6 +243,7 @@ type OptimisticSubmittedReportAction = Pick< | 'shouldShow' | 'created' | 'pendingAction' + | 'delegateAccountID' >; type OptimisticHoldReportAction = Pick< @@ -4632,6 +4657,7 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e expenseReportID, delegate, }; + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); return { actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, @@ -4652,6 +4678,7 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e shouldShow: true, created: DateUtils.getDBTime(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + delegateAccountID: delegateAccountDetails?.accountID, }; } @@ -4659,6 +4686,7 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e * Builds an optimistic APPROVED report action with a randomly generated reportActionID. */ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string, delegate: string): OptimisticUnapprovedReportAction { + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); return { actionName: CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, actorAccountID: currentUserAccountID, @@ -4683,6 +4711,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, shouldShow: true, created: DateUtils.getDBTime(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + delegateAccountID: delegateAccountDetails?.accountID, }; } @@ -4746,6 +4775,8 @@ function buildOptimisticSubmittedReportAction( delegate, }; + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + return { actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, actorAccountID: currentUserAccountID, @@ -4766,6 +4797,7 @@ function buildOptimisticSubmittedReportAction( shouldShow: true, created: DateUtils.getDBTime(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + delegateAccountID: delegateAccountDetails?.accountID, }; } diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 9f18b8f18f0c..a47c044620eb 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -107,7 +107,7 @@ function ReportActionItemSingle({ actorHint = displayName; avatarSource = ReportUtils.getWorkspaceAvatar(report); avatarId = report.policyID; - } else if (delegateEmail) { + } else if (action?.delegateAccountID && personalDetails[action?.delegateAccountID]) { // We replace the actor's email, name, and avatar with the Copilot manually for now. And only if we have their // details. This will be improved upon when the Copilot feature is implemented. const delegateAccount = getPersonalDetailByEmail(delegateEmail); From 1b268e8e1500abdc945519e7ff928cba9fe73cc8 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 17:05:55 +0530 Subject: [PATCH 20/44] remove unused util --- src/libs/ReportActionsUtils.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 916951f00ea7..4d126cf9cbf4 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -209,10 +209,6 @@ function getOriginalMessage(reportAction: OnyxInputO return reportAction.originalMessage; } -function getOriginalMessageForDelegate(reportAction: OnyxInputOrEntry) { - return reportAction?.originalMessage ?? {}; -} - function isExportIntegrationAction(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION; } @@ -1741,7 +1737,6 @@ export { isTransactionThread, isTripPreview, isWhisperAction, - getOriginalMessageForDelegate, isSubmittedAction, isApprovedAction, isForwardedAction, From 4b784e707de3bae3aedd12587a7df244cd28df2d Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 17:23:19 +0530 Subject: [PATCH 21/44] cleanup --- src/pages/home/report/ReportActionItemSingle.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index a47c044620eb..14b00ab2e986 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -85,8 +85,9 @@ function ReportActionItemSingle({ const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); - const message = getOriginalMessage(action); - const delegateEmail = (message as any)?.delegate; + const delegatePersonalDetails = personalDetails[action?.delegateAccountID ?? '']; + + const delegateEmail = delegatePersonalDetails?.login; let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; @@ -110,12 +111,9 @@ function ReportActionItemSingle({ } else if (action?.delegateAccountID && personalDetails[action?.delegateAccountID]) { // We replace the actor's email, name, and avatar with the Copilot manually for now. And only if we have their // details. This will be improved upon when the Copilot feature is implemented. - const delegateAccount = getPersonalDetailByEmail(delegateEmail); - const delegateDetails = delegateAccount; - const delegateDisplayName = delegateDetails?.displayName; - displayName = delegateDisplayName ?? ''; - avatarSource = delegateDetails?.avatar; - avatarId = delegateAccount?.accountID; + displayName = delegatePersonalDetails?.displayName ?? ''; + avatarSource = delegatePersonalDetails?.avatar; + avatarId = delegatePersonalDetails?.accountID; } else if (isReportPreviewAction && isTripRoom) { displayName = report?.reportName ?? ''; } From 53e5e6136ebdb1e3daacab772deeb6fdc591ed22 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 17:47:44 +0530 Subject: [PATCH 22/44] fix lint --- src/pages/home/report/ReportActionItemSingle.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 14b00ab2e986..d69f47fe6a5a 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -21,7 +21,7 @@ import ControlSelection from '@libs/ControlSelection'; import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; -import {getOriginalMessage, getReportActionMessage} from '@libs/ReportActionsUtils'; +import {getReportActionMessage} from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; From d8cccb625a827bafebe420098cd4e5e35921c3b4 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 18:07:17 +0530 Subject: [PATCH 23/44] add delegate AccountID for IOU --- src/libs/ReportUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ffe970758b56..754b32b7d352 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -180,6 +180,7 @@ type OptimisticIOUReportAction = Pick< | 'childReportID' | 'childVisibleActionCount' | 'childCommenterCount' + | 'delegateAccountID' >; type PartialReportAction = OnyxInputOrEntry | Partial | OptimisticIOUReportAction | OptimisticApprovedReportAction | OptimisticSubmittedReportAction | undefined; @@ -4593,6 +4594,8 @@ function buildOptimisticIOUReportAction( delegate, }; + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) { // In pay someone flow, we store amount, comment, currency in IOUDetails when type = pay if (isSendMoneyFlow) { @@ -4644,6 +4647,7 @@ function buildOptimisticIOUReportAction( shouldShow: true, created, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + delegateAccountID: delegateAccountDetails?.accountID, }; } From c500a0b0b386d39f02b0c8db594e206b0b69c04e Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 6 Sep 2024 18:49:53 +0530 Subject: [PATCH 24/44] Update AvatarWithDelegateAvatar.tsx --- src/pages/home/sidebar/AvatarWithDelegateAvatar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/AvatarWithDelegateAvatar.tsx b/src/pages/home/sidebar/AvatarWithDelegateAvatar.tsx index 0192d3d8423a..05f4c5aec343 100644 --- a/src/pages/home/sidebar/AvatarWithDelegateAvatar.tsx +++ b/src/pages/home/sidebar/AvatarWithDelegateAvatar.tsx @@ -9,7 +9,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ProfileAvatarWithIndicator from './ProfileAvatarWithIndicator'; type AvatarWithDelegateAvatarProps = { - /** Emoji status */ + /** Original account of delegate */ delegateEmail: string; /** Whether the avatar is selected */ From 699edecd6b712490cb7fbc1daa0b68561c3b6fa4 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 18:58:16 +0530 Subject: [PATCH 25/44] fix modified expense report actions --- src/libs/ReportUtils.ts | 29 +++++++++++++++++++++++++---- src/libs/actions/IOU.ts | 16 ++++++++++++---- src/libs/actions/Report.ts | 1 - src/types/onyx/OriginalMessage.ts | 3 +++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 508e01faca7a..ea9a4d93e277 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -367,7 +367,19 @@ type OptimisticWorkspaceChats = { type OptimisticModifiedExpenseReportAction = Pick< ReportAction, - '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< @@ -3475,13 +3487,14 @@ function getReportPreviewMessage( * At the moment, we only allow changing one transaction field at a time. */ function getModifiedExpenseOriginalMessage( + delegate: string, oldTransaction: OnyxInputOrEntry, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, policy: OnyxInputOrEntry, updatedTransaction?: OnyxInputOrEntry, ): OriginalMessageModifiedExpense { - const originalMessage: OriginalMessageModifiedExpense = {}; + const originalMessage: OriginalMessageModifiedExpense = {delegate: delegate}; // Remark: Comment field is the only one which has new/old prefixes for the keys (newComment/ oldComment), // all others have old/- pattern such as oldCreated/created if ('comment' in transactionChanges) { @@ -4948,6 +4961,7 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe * Builds an optimistic modified expense action with a randomly generated reportActionID. */ function buildOptimisticModifiedExpenseReportAction( + delegate: string, transactionThread: OnyxInputOrEntry, oldTransaction: OnyxInputOrEntry, transactionChanges: TransactionChanges, @@ -4955,7 +4969,9 @@ function buildOptimisticModifiedExpenseReportAction( policy: OnyxInputOrEntry, updatedTransaction?: OnyxInputOrEntry, ): OptimisticModifiedExpenseReportAction { - const originalMessage = getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); + const originalMessage = getModifiedExpenseOriginalMessage(delegate, oldTransaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + return { actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, actorAccountID: currentUserAccountID, @@ -4983,6 +4999,7 @@ function buildOptimisticModifiedExpenseReportAction( reportActionID: NumberUtils.rand64(), reportID: transactionThread?.reportID, shouldShow: true, + delegateAccountID: delegateAccountDetails?.accountID, }; } @@ -4991,7 +5008,9 @@ function buildOptimisticModifiedExpenseReportAction( * @param transactionThreadID - The reportID of the transaction thread * @param movedToReportID - The reportID of the report the transaction is moved to */ -function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction { +function buildOptimisticMovedTrackedExpenseModifiedReportAction(delegate: string, transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction { + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + return { actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, actorAccountID: currentUserAccountID, @@ -5009,6 +5028,7 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea ], originalMessage: { movedToReportID, + delegate, }, person: [ { @@ -5021,6 +5041,7 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea reportActionID: NumberUtils.rand64(), reportID: transactionThreadID, shouldShow: true, + delegateAccountID: delegateAccountDetails?.accountID, }; } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 2c3a69bbced8..1a634a17086d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2552,7 +2552,15 @@ function getUpdateMoneyRequestParams( // - we're updating the distance rate while the waypoints are still pending // In these cases, there isn't a valid optimistic mileage data we can use, // and the report action is created on the server with the distance-related response from the MapBox API - const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); + const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction( + delegateEmail, + transactionThread, + transaction, + transactionChanges, + isFromExpenseReport, + policy, + updatedTransaction, + ); if (!hasPendingWaypoints && !(hasModifiedDistanceRate && TransactionUtils.isFetchingWaypointsFromServer(transaction))) { params.reportActionID = updatedReportAction.reportActionID; @@ -2873,7 +2881,7 @@ function getUpdateTrackExpenseParams( // - we're updating the distance rate while the waypoints are still pending // In these cases, there isn't a valid optimistic mileage data we can use, // and the report action is created on the server with the distance-related response from the MapBox API - const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, false, policy); + const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(delegateEmail, transactionThread, transaction, transactionChanges, false, policy); if (!hasPendingWaypoints && !(hasModifiedDistanceRate && TransactionUtils.isFetchingWaypointsFromServer(transaction))) { params.reportActionID = updatedReportAction.reportActionID; @@ -3239,7 +3247,7 @@ const getConvertTrackedExpenseInformation = ( failureData?.push(...deleteFailureData); // Build modified expense report action with the transaction changes - const modifiedExpenseReportAction = ReportUtils.buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadReportID, moneyRequestReportID); + const modifiedExpenseReportAction = ReportUtils.buildOptimisticMovedTrackedExpenseModifiedReportAction(delegateEmail, transactionThreadReportID, moneyRequestReportID); optimisticData?.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -5243,7 +5251,7 @@ function editRegularMoneyRequest( const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); // STEP 2: Build new modified expense report action. - const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy); + const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(delegateEmail, transactionThread, transaction, transactionChanges, isFromExpenseReport, policy); const updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : null; // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3d66cf592542..2b89b11b0433 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3373,7 +3373,6 @@ function completeOnboarding( let videoCommentAction: OptimisticAddCommentReportAction | null = null; let videoMessage: AddCommentOrAttachementParams | null = null; - if ('video' in data && data.video) { const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 2); videoCommentAction = videoComment.reportAction; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 8a112edc80c1..11d6c361babb 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -361,6 +361,9 @@ type OriginalMessageModifiedExpense = { /** The ID of moved report */ movedToReportID?: string; + + /** Email of the delegate */ + delegate: string; }; /** Model of `reimbursement queued` report action */ From d5eb8af5bc0cd55b142ba3cfa0788d2a96afbdca Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 19:19:28 +0530 Subject: [PATCH 26/44] remove delegate from original Message (Deprecated) --- src/libs/ReportUtils.ts | 14 +++----------- src/types/onyx/OriginalMessage.ts | 18 ------------------ 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ea9a4d93e277..4f72ef9682d7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3487,14 +3487,13 @@ function getReportPreviewMessage( * At the moment, we only allow changing one transaction field at a time. */ function getModifiedExpenseOriginalMessage( - delegate: string, oldTransaction: OnyxInputOrEntry, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, policy: OnyxInputOrEntry, updatedTransaction?: OnyxInputOrEntry, ): OriginalMessageModifiedExpense { - const originalMessage: OriginalMessageModifiedExpense = {delegate: delegate}; + const originalMessage: OriginalMessageModifiedExpense = {}; // Remark: Comment field is the only one which has new/old prefixes for the keys (newComment/ oldComment), // all others have old/- pattern such as oldCreated/created if ('comment' in transactionChanges) { @@ -4222,7 +4221,6 @@ function buildOptimisticAddCommentReportAction( originalMessage: { html: htmlForNewComment, whisperedTo: [], - delegate, }, isFirstItem: false, isAttachmentOnly, @@ -4311,7 +4309,6 @@ function buildOptimisticTaskCommentReportAction( html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction), taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID, whisperedTo: [], - delegate, }; reportAction.reportAction.childReportID = taskReportID; reportAction.reportAction.parentReportID = parentReportID; @@ -4657,8 +4654,7 @@ function buildOptimisticIOUReportAction( currency, IOUTransactionID: transactionID, IOUReportID, - type, - delegate, + type }; const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); @@ -4726,7 +4722,6 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e amount, currency, expenseReportID, - delegate, }; const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); @@ -4768,7 +4763,6 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, amount, currency, expenseReportID, - delegate, }, message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, Math.abs(amount), '', currency), person: [ @@ -4843,7 +4837,6 @@ function buildOptimisticSubmittedReportAction( amount, currency, expenseReportID, - delegate, }; const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); @@ -4969,7 +4962,7 @@ function buildOptimisticModifiedExpenseReportAction( policy: OnyxInputOrEntry, updatedTransaction?: OnyxInputOrEntry, ): OptimisticModifiedExpenseReportAction { - const originalMessage = getModifiedExpenseOriginalMessage(delegate, oldTransaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); + const originalMessage = getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); return { @@ -5028,7 +5021,6 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(delegate: string ], originalMessage: { movedToReportID, - delegate, }, person: [ { diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 11d6c361babb..c330d009a43d 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -68,9 +68,6 @@ type OriginalMessageIOU = { /** Collection of accountIDs of users mentioned in message */ whisperedTo?: number[]; - - /** Email of the delegate */ - delegate: string; }; /** Names of moderation decisions */ @@ -127,9 +124,6 @@ type OriginalMessageAddComment = { /** List accountIDs are mentioned in message */ mentionedAccountIDs?: number[]; - - /** Email of the delegate */ - delegate: string; }; /** Model of `actionable mention whisper` report action */ @@ -163,9 +157,6 @@ type OriginalMessageSubmitted = { /** Report ID of the expense */ expenseReportID: string; - - /** Email of the delegate */ - delegate: string; }; /** Model of `closed` report action */ @@ -361,9 +352,6 @@ type OriginalMessageModifiedExpense = { /** The ID of moved report */ movedToReportID?: string; - - /** Email of the delegate */ - delegate: string; }; /** Model of `reimbursement queued` report action */ @@ -445,9 +433,6 @@ type OriginalMessageApproved = { /** Report ID of the expense */ expenseReportID: string; - - /** Email of the delegate */ - delegate: string; }; /** Model of `forwarded` report action */ @@ -507,9 +492,6 @@ type OriginalMessageUnapproved = { /** Report ID of the expense */ expenseReportID: string; - - /** Email of the delegate */ - delegate: string; }; /** Model of `Removed From Approval Chain` report action */ From 922953657a54aa33c31d18a70a2ccbd539997ebb Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 19:25:44 +0530 Subject: [PATCH 27/44] fix prettier --- src/libs/ReportUtils.ts | 2 +- tests/actions/IOUTest.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4f72ef9682d7..f5bef248f57e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4654,7 +4654,7 @@ function buildOptimisticIOUReportAction( currency, IOUTransactionID: transactionID, IOUReportID, - type + type, }; const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index ecb3fb4f22cb..662eae8d7b21 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -423,7 +423,6 @@ describe('actions/IOU', () => { const comment = 'Giv money plz'; const chatReportID = '1234'; const iouReportID = '5678'; - const delegate = ''; let chatReport: OnyxEntry = { reportID: chatReportID, type: CONST.REPORT.TYPE.CHAT, @@ -467,7 +466,6 @@ describe('actions/IOU', () => { currency: CONST.CURRENCY.USD, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, participantAccountIDs: [RORY_ACCOUNT_ID, CARLOS_ACCOUNT_ID], - delegate, }, }; let newIOUAction: OnyxEntry>; From d632c5f80e599c2e83d4768d49a7f77c405d2f8e Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 20:26:49 +0530 Subject: [PATCH 28/44] add delegate for task --- src/libs/ReportUtils.ts | 25 ++++++++++++++++++------- src/libs/actions/Task.ts | 22 ++++++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f5bef248f57e..84abd96ab24e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -260,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< @@ -275,7 +275,7 @@ type OptimisticDismissedViolationReportAction = Pick< type OptimisticCreatedReportAction = Pick< ReportAction, - 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'pendingAction' | 'actionName' + 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'pendingAction' | 'actionName' | 'delegateAccountID' >; type OptimisticRenamedReportAction = Pick< @@ -348,6 +348,7 @@ type OptimisticTaskReportAction = Pick< | 'previousMessage' | 'errors' | 'linkMetadata' + | 'delegateAccountID' >; type OptimisticWorkspaceChats = { @@ -4286,6 +4287,7 @@ function updateOptimisticParentReportAction(parentReportAction: OnyxEntry, policy: OnyxEntry { + delegateEmail = value?.delegatedAccess?.delegate ?? ''; + }, +}); + /** * Clears out the task info from the store */ @@ -121,7 +129,7 @@ function createTaskAndNavigate( // Parent ReportAction indicating that a task has been created const optimisticTaskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmail); - const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); + const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(delegateEmail, taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID; const currentTime = DateUtils.getDBTimeWithSkew(); @@ -201,6 +209,7 @@ function createTaskAndNavigate( if (assigneeChatReport) { assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( + delegateEmail, currentUserAccountID, assigneeAccountID, taskReportID, @@ -327,7 +336,7 @@ function getOutstandingChildTask(taskReport: OnyxEntry) { function completeTask(taskReport: OnyxEntry) { const taskReportID = taskReport?.reportID ?? '-1'; const message = `marked as complete`; - const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, message); + const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(delegateEmail, taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, message); const parentReport = getParentReport(taskReport); const optimisticData: OnyxUpdate[] = [ { @@ -413,7 +422,7 @@ function completeTask(taskReport: OnyxEntry) { function reopenTask(taskReport: OnyxEntry) { const taskReportID = taskReport?.reportID ?? '-1'; const message = `marked as incomplete`; - const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED, message); + const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(delegateEmail, taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED, message); const parentReport = getParentReport(taskReport); const hasOutstandingChildTask = taskReport?.managerID === currentUserAccountID ? true : parentReport?.hasOutstandingChildTask; @@ -493,7 +502,7 @@ function reopenTask(taskReport: OnyxEntry) { function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task) { // Create the EditedReportAction on the task - const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskFieldReportAction({title, description}); + const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskFieldReportAction({title, description}, delegateEmail); // Sometimes title or description is undefined, so we need to check for that, and we provide it to multiple functions const reportName = (title ?? report?.reportName)?.trim(); @@ -570,7 +579,7 @@ function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, assigneeEmail: string, assigneeAccountID: number | null = 0, assigneeChatReport?: OnyxEntry) { // Create the EditedReportAction on the task - const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? 0); + const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(delegateEmail, assigneeAccountID ?? 0); const reportName = report.reportName?.trim(); let assigneeChatReportOnyxData; @@ -675,6 +684,7 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as }; assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( + delegateEmail, currentUserAccountID, assigneeAccountID, report.reportID, @@ -942,7 +952,7 @@ function deleteTask(report: OnyxEntry) { return; } const message = `deleted task: ${report.reportName}`; - const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(report.reportID ?? '-1', CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message); + const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(delegateEmail, report.reportID ?? '-1', CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message); const optimisticReportActionID = optimisticCancelReportAction.reportActionID; const parentReportAction = getParentReportAction(report); const parentReport = getParentReport(report); From 80e28ae7b1f103842016c4bcf4ce3d7f63c8495d Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 20:37:49 +0530 Subject: [PATCH 29/44] fix lint --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/Report.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 84abd96ab24e..1f2655efcecc 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5252,7 +5252,7 @@ function buildOptimisticGroupChatReport( * Returns the necessary reportAction onyx data to indicate that the chat has been created optimistically * @param [created] - Action created time */ -function buildOptimisticCreatedReportAction(emailCreatingAction: string, created = DateUtils.getDBTime() ): OptimisticCreatedReportAction { +function buildOptimisticCreatedReportAction(emailCreatingAction: string, created = DateUtils.getDBTime()): OptimisticCreatedReportAction { return { reportActionID: NumberUtils.rand64(), actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2b89b11b0433..731ba0bbc5b7 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3404,6 +3404,7 @@ function completeOnboarding( ); const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(CONST.EMAIL.CONCIERGE); const taskReportAction = ReportUtils.buildOptimisticTaskCommentReportAction( + delegateEmail, currentTask.reportID, task.title, 0, @@ -3415,7 +3416,7 @@ function completeOnboarding( currentTask.parentReportActionID = taskReportAction.reportAction.reportActionID; const completedTaskReportAction = task.autoCompleted - ? ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2) + ? ReportUtils.buildOptimisticTaskReportAction(delegateEmail, currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2) : null; return { From 90f28c6e4a5b719a4101f78b6f4fdb7fd4ad143a Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 21:03:48 +0530 Subject: [PATCH 30/44] Do not display delegate message on report preview --- src/pages/home/report/ReportActionItemSingle.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index bf802ad2249e..48baadad833f 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -288,7 +288,7 @@ function ReportActionItemSingle({ ) : null} - {delegateEmail && {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')}} + {(delegateEmail && !isReportPreviewAction) && {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')}} {children} From 35b5431ad70716bffc917886b312798e7891dead Mon Sep 17 00:00:00 2001 From: Gandalf Date: Fri, 20 Sep 2024 21:10:47 +0530 Subject: [PATCH 31/44] fix lint --- src/pages/home/report/ReportActionItemSingle.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 48baadad833f..8071c1157a4b 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -288,7 +288,9 @@ function ReportActionItemSingle({ ) : null} - {(delegateEmail && !isReportPreviewAction) && {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')}} + {delegateEmail && !isReportPreviewAction && ( + {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')} + )} {children} From 317115663dc350ddeb6d39e83d13c5d9add332c6 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 15:51:51 +0530 Subject: [PATCH 32/44] fix pay someone limited delegate action --- .../AttachmentPickerWithMenuItems.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 6e3c3a48de74..c6e5a2baffc3 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -1,5 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; -import React, {useCallback, useEffect, useMemo} from 'react'; +import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; @@ -25,8 +25,10 @@ import * as SubscriptionUtils from '@libs/SubscriptionUtils'; import * as IOU from '@userActions/IOU'; import * as Report from '@userActions/Report'; import * as Task from '@userActions/Task'; +import DelegateNoAccessModal from '@src/components/DelegateNoAccessModal'; import type {IOUType} from '@src/CONST'; import CONST from '@src/CONST'; +import useDelegateUserDetails from '@src/hooks/useDelegateUserDetails'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; @@ -121,6 +123,8 @@ function AttachmentPickerWithMenuItems({ const {translate} = useLocalize(); const {windowHeight, windowWidth} = useWindowDimensions(); const {shouldUseNarrowLayout} = useResponsiveLayout(); + const {isDelegateAccessRestricted, delegatorEmail} = useDelegateUserDetails(); + const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); /** * Returns the list of IOU Options @@ -149,7 +153,13 @@ function AttachmentPickerWithMenuItems({ [CONST.IOU.TYPE.PAY]: { icon: getIconForAction(CONST.IOU.TYPE.SEND), text: translate('iou.paySomeone', {name: ReportUtils.getPayeeName(report)}), - onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.PAY, report?.reportID ?? '-1'), false), + onSelected: () => { + if (isDelegateAccessRestricted) { + setIsNoDelegateAccessMenuVisible(true); + return; + } + selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.PAY, report?.reportID ?? '-1'), false); + }, }, [CONST.IOU.TYPE.TRACK]: { icon: getIconForAction(CONST.IOU.TYPE.TRACK), @@ -327,6 +337,11 @@ function AttachmentPickerWithMenuItems({ withoutOverlay anchorRef={actionButtonRef} /> + setIsNoDelegateAccessMenuVisible(false)} + delegatorEmail={delegatorEmail ?? ''} + /> ); }} From 0a745a3c2db5ee53fa92eb39d5b349ace4d47fb0 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 16:06:11 +0530 Subject: [PATCH 33/44] migrate from withOnyx --- .../AttachmentPickerWithMenuItems.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index c6e5a2baffc3..111e5640e237 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -2,7 +2,7 @@ import {useIsFocused} from '@react-navigation/native'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {FileObject} from '@components/AttachmentModal'; import AttachmentPicker from '@components/AttachmentPicker'; import Icon from '@components/Icon'; @@ -35,12 +35,7 @@ import type * as OnyxTypes from '@src/types/onyx'; type MoneyRequestOptions = Record, PopoverMenuItem>; -type AttachmentPickerWithMenuItemsOnyxProps = { - /** The policy tied to the report */ - policy: OnyxEntry; -}; - -type AttachmentPickerWithMenuItemsProps = AttachmentPickerWithMenuItemsOnyxProps & { +type AttachmentPickerWithMenuItemsProps = { /** The report currently being looked at */ report: OnyxEntry; @@ -99,7 +94,6 @@ type AttachmentPickerWithMenuItemsProps = AttachmentPickerWithMenuItemsOnyxProps */ function AttachmentPickerWithMenuItems({ report, - policy, reportParticipantIDs, displayFileInModal, isFullComposerAvailable, @@ -125,6 +119,7 @@ function AttachmentPickerWithMenuItems({ const {shouldUseNarrowLayout} = useResponsiveLayout(); const {isDelegateAccessRestricted, delegatorEmail} = useDelegateUserDetails(); const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); /** * Returns the list of IOU Options @@ -351,9 +346,4 @@ function AttachmentPickerWithMenuItems({ AttachmentPickerWithMenuItems.displayName = 'AttachmentPickerWithMenuItems'; -export default withOnyx({ - policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, - initialValue: {} as OnyxTypes.Policy, - }, -})(AttachmentPickerWithMenuItems); +export default AttachmentPickerWithMenuItems; From fc19a5cfb9930b6e687108c5ea21c434ea65b02c Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 16:16:13 +0530 Subject: [PATCH 34/44] remove commented section --- src/pages/home/report/ReportActionItemSingle.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 8071c1157a4b..cb68d36f60ce 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -109,8 +109,6 @@ function ReportActionItemSingle({ avatarSource = ReportUtils.getWorkspaceIcon(report).source; avatarId = report.policyID; } else if (action?.delegateAccountID && personalDetails[action?.delegateAccountID]) { - // We replace the actor's email, name, and avatar with the Copilot manually for now. And only if we have their - // details. This will be improved upon when the Copilot feature is implemented. displayName = delegatePersonalDetails?.displayName ?? ''; avatarSource = delegatePersonalDetails?.avatar; avatarId = delegatePersonalDetails?.accountID; From e2b43f60bc0e14fd78e13a217fb73e31de6134fc Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 16:24:06 +0530 Subject: [PATCH 35/44] add delegate dependency --- .../ReportActionCompose/AttachmentPickerWithMenuItems.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 111e5640e237..28d985537ff5 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -171,7 +171,7 @@ function AttachmentPickerWithMenuItems({ return ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipantIDs ?? []).map((option) => ({ ...options[option], })); - }, [translate, report, policy, reportParticipantIDs]); + }, [translate, report, policy, reportParticipantIDs, isDelegateAccessRestricted]); /** * Determines if we can show the task option From 24eff7dc864df57c0b52f6645268d581089c5fb4 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 17:04:32 +0530 Subject: [PATCH 36/44] fix offline case for pay expense --- src/libs/actions/IOU.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1a634a17086d..c83b1bff2f7b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6710,6 +6710,11 @@ function getPayMoneyRequestParams( paymentMethodType, iouReport.reportID, true, + undefined, + undefined, + undefined, + undefined, + delegateEmail, ); // In some instances, the report preview action might not be available to the payer (only whispered to the requestor) From f64cfbd6c29ceb4ff837c1738a8f5375598df365 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 17:53:42 +0530 Subject: [PATCH 37/44] fix offline submission of expense --- src/libs/ReportUtils.ts | 2 ++ src/libs/actions/IOU.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1f2655efcecc..0c11069295b3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5830,6 +5830,7 @@ function buildOptimisticMoneyRequestEntities( isPersonalTrackingExpense?: boolean, existingTransactionThreadReportID?: string, linkedTrackedExpenseReportAction?: ReportAction, + delegate?: string, ): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null] { const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail); @@ -5851,6 +5852,7 @@ function buildOptimisticMoneyRequestEntities( isOwnPolicyExpenseChat, iouActionCreationTime, linkedTrackedExpenseReportAction, + delegate, ); // Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c83b1bff2f7b..2ac15a58448d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2136,6 +2136,7 @@ function getMoneyRequestInformation( undefined, linkedTrackedExpenseReportAction?.childReportID, linkedTrackedExpenseReportAction, + delegateEmail, ); let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); From 3b0742c456b25e10d5dc6fa26dc17d7a97246caa Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 18:29:39 +0530 Subject: [PATCH 38/44] fix jest hopefully --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/IOU.ts | 8 +++----- src/pages/home/report/ReportActionsView.tsx | 1 + tests/unit/ReportUtilsTest.ts | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b7d597c81153..0bc5f9b37671 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4610,6 +4610,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num * @param delegate - Email of the delegate of the account */ function buildOptimisticIOUReportAction( + delegate = '', type: ValueOf, amount: number, currency: string, @@ -4623,7 +4624,6 @@ function buildOptimisticIOUReportAction( isOwnPolicyExpenseChat = false, created = DateUtils.getDBTime(), linkedExpenseReportAction?: OnyxEntry, - delegate = '', ): OptimisticIOUReportAction { const IOUReportID = iouReportID || generateReportID(); diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9a4c4a48ab85..aca25a1af9a0 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4000,6 +4000,7 @@ function createSplitsAndOnyxData( // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat const splitCreatedReportAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmailForIOUSplit); const splitIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + undefined, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, amount, currency, @@ -4578,6 +4579,7 @@ function startSplitBill({ // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat const splitChatCreatedReportAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmailForIOUSplit); const splitIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + undefined, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, 0, CONST.CURRENCY.USD, @@ -6702,6 +6704,7 @@ function getPayMoneyRequestParams( } const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + delegateEmail, CONST.IOU.REPORT_ACTION_TYPE.PAY, ReportUtils.isExpenseReport(iouReport) ? -total : total, iouReport.currency ?? '', @@ -6711,11 +6714,6 @@ function getPayMoneyRequestParams( paymentMethodType, iouReport.reportID, true, - undefined, - undefined, - undefined, - undefined, - delegateEmail, ); // In some instances, the report preview action might not be available to the payer (only whispered to the requestor) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 1460942931fc..42302b721059 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -181,6 +181,7 @@ function ReportActionsView({ if (report.total && moneyRequestActions.length < (reportPreviewAction?.childMoneyRequestCount ?? 0) && isEmptyObject(transactionThreadReport)) { const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( + undefined, CONST.IOU.REPORT_ACTION_TYPE.CREATE, 0, CONST.CURRENCY.USD, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index f8d23e89ca5a..8e86c625b57a 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -766,6 +766,7 @@ describe('ReportUtils', () => { it('should disable thread on split expense actions', () => { const reportAction = ReportUtils.buildOptimisticIOUReportAction( + undefined, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, 50000, CONST.CURRENCY.USD, From d36fd070e893ef7ff9ad203bf73a0801523c6619 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 18:30:26 +0530 Subject: [PATCH 39/44] fix --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0bc5f9b37671..d6114696726d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5817,6 +5817,7 @@ function buildOptimisticMoneyRequestEntities( const createdActionForIOUReport = buildOptimisticCreatedReportAction(payeeEmail, DateUtils.subtractMillisecondsFromDateTime(iouActionCreationTime, 1)); const iouAction = buildOptimisticIOUReportAction( + delegate, type, amount, currency, @@ -5830,7 +5831,6 @@ function buildOptimisticMoneyRequestEntities( isOwnPolicyExpenseChat, iouActionCreationTime, linkedTrackedExpenseReportAction, - delegate, ); // Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined From d851429d606718e178d213c79a91eb893d19eeaf Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 18:42:31 +0530 Subject: [PATCH 40/44] make delegateEmail accessible in reportUtils itself --- src/libs/ReportUtils.ts | 60 +++++++++------------ src/libs/actions/IOU.ts | 40 +++----------- src/libs/actions/Report.ts | 20 +++---- src/libs/actions/Task.ts | 22 +++----- src/pages/home/report/ReportActionsView.tsx | 1 - tests/unit/ReportUtilsTest.ts | 1 - 6 files changed, 45 insertions(+), 99 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d6114696726d..0da381eaf7b8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -676,6 +676,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; } @@ -4154,7 +4162,6 @@ function getPolicyDescriptionText(policy: OnyxEntry): string { } function buildOptimisticAddCommentReportAction( - delegate: string, text?: string, file?: FileObject, actorAccountID?: number, @@ -4171,7 +4178,7 @@ function buildOptimisticAddCommentReportAction( const isAttachmentOnly = file && !text; const isAttachmentWithText = !!text && file !== undefined; const accountID = actorAccountID ?? currentUserAccountID ?? -1; - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); // Remove HTML from text when applying optimistic offline comment return { commentText, @@ -4262,10 +4269,8 @@ function updateOptimisticParentReportAction(parentReportAction: OnyxEntry, amount: number, currency: string, @@ -4636,7 +4639,7 @@ function buildOptimisticIOUReportAction( type, }; - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + 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 @@ -4696,13 +4699,13 @@ function buildOptimisticIOUReportAction( /** * Builds an optimistic APPROVED report action with a randomly generated reportActionID. */ -function buildOptimisticApprovedReportAction(amount: number, currency: string, expenseReportID: string, delegate: string): OptimisticApprovedReportAction { +function buildOptimisticApprovedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticApprovedReportAction { const originalMessage = { amount, currency, expenseReportID, }; - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, @@ -4730,8 +4733,8 @@ function buildOptimisticApprovedReportAction(amount: number, currency: string, e /** * Builds an optimistic APPROVED report action with a randomly generated reportActionID. */ -function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string, delegate: string): OptimisticUnapprovedReportAction { - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); +function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticUnapprovedReportAction { + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { actionName: CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, actorAccountID: currentUserAccountID, @@ -4805,20 +4808,14 @@ 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, - adminAccountID: number | undefined, - delegate: string, -): OptimisticSubmittedReportAction { +function buildOptimisticSubmittedReportAction(amount: number, currency: string, expenseReportID: string, adminAccountID: number | undefined): OptimisticSubmittedReportAction { const originalMessage = { amount, currency, expenseReportID, }; - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, @@ -4933,7 +4930,6 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe * Builds an optimistic modified expense action with a randomly generated reportActionID. */ function buildOptimisticModifiedExpenseReportAction( - delegate: string, transactionThread: OnyxInputOrEntry, oldTransaction: OnyxInputOrEntry, transactionChanges: TransactionChanges, @@ -4942,7 +4938,7 @@ function buildOptimisticModifiedExpenseReportAction( updatedTransaction?: OnyxInputOrEntry, ): OptimisticModifiedExpenseReportAction { const originalMessage = getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, @@ -4980,8 +4976,8 @@ function buildOptimisticModifiedExpenseReportAction( * @param transactionThreadID - The reportID of the transaction thread * @param movedToReportID - The reportID of the report the transaction is moved to */ -function buildOptimisticMovedTrackedExpenseModifiedReportAction(delegate: string, transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction { - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); +function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadID: string, movedToReportID: string): OptimisticModifiedExpenseReportAction { + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, @@ -5075,7 +5071,6 @@ function updateReportPreview( } function buildOptimisticTaskReportAction( - delegate: string, taskReportID: string, actionName: typeof CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED | typeof CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED | typeof CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message = '', @@ -5089,7 +5084,7 @@ function buildOptimisticTaskReportAction( html: message, whisperedTo: [], }; - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { actionName, @@ -5429,7 +5424,7 @@ function buildOptimisticUnHoldReportAction(created = DateUtils.getDBTime()): Opt }; } -function buildOptimisticEditedTaskFieldReportAction({title, description}: Task, delegate: string): OptimisticEditedTaskReportAction { +function buildOptimisticEditedTaskFieldReportAction({title, description}: Task): OptimisticEditedTaskReportAction { // We do not modify title & description in one request, so we need to create a different optimistic action for each field modification let field = ''; let value = ''; @@ -5447,7 +5442,7 @@ function buildOptimisticEditedTaskFieldReportAction({title, description}: Task, } else if (field) { changelog = `removed the ${field}`; } - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { reportActionID: NumberUtils.rand64(), @@ -5476,8 +5471,8 @@ function buildOptimisticEditedTaskFieldReportAction({title, description}: Task, }; } -function buildOptimisticChangedTaskAssigneeReportAction(delegate: string, assigneeAccountID: number): OptimisticEditedTaskReportAction { - const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegate); +function buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID: number): OptimisticEditedTaskReportAction { + const delegateAccountDetails = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail); return { reportActionID: NumberUtils.rand64(), @@ -5808,7 +5803,6 @@ function buildOptimisticMoneyRequestEntities( isPersonalTrackingExpense?: boolean, existingTransactionThreadReportID?: string, linkedTrackedExpenseReportAction?: ReportAction, - delegate?: string, ): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null] { const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail); @@ -5817,7 +5811,6 @@ function buildOptimisticMoneyRequestEntities( const createdActionForIOUReport = buildOptimisticCreatedReportAction(payeeEmail, DateUtils.subtractMillisecondsFromDateTime(iouActionCreationTime, 1)); const iouAction = buildOptimisticIOUReportAction( - delegate, type, amount, currency, @@ -6898,7 +6891,6 @@ function canEditRoomVisibility(report: OnyxEntry, policy: OnyxEntry { - delegateEmail = value?.delegatedAccess?.delegate ?? ''; - }, -}); - let quickAction: OnyxEntry = {}; Onyx.connect({ key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, @@ -2136,7 +2128,6 @@ function getMoneyRequestInformation( undefined, linkedTrackedExpenseReportAction?.childReportID, linkedTrackedExpenseReportAction, - delegateEmail, ); let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); @@ -2553,15 +2544,7 @@ function getUpdateMoneyRequestParams( // - we're updating the distance rate while the waypoints are still pending // In these cases, there isn't a valid optimistic mileage data we can use, // and the report action is created on the server with the distance-related response from the MapBox API - const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction( - delegateEmail, - transactionThread, - transaction, - transactionChanges, - isFromExpenseReport, - policy, - updatedTransaction, - ); + const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction); if (!hasPendingWaypoints && !(hasModifiedDistanceRate && TransactionUtils.isFetchingWaypointsFromServer(transaction))) { params.reportActionID = updatedReportAction.reportActionID; @@ -2882,7 +2865,7 @@ function getUpdateTrackExpenseParams( // - we're updating the distance rate while the waypoints are still pending // In these cases, there isn't a valid optimistic mileage data we can use, // and the report action is created on the server with the distance-related response from the MapBox API - const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(delegateEmail, transactionThread, transaction, transactionChanges, false, policy); + const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, false, policy); if (!hasPendingWaypoints && !(hasModifiedDistanceRate && TransactionUtils.isFetchingWaypointsFromServer(transaction))) { params.reportActionID = updatedReportAction.reportActionID; @@ -3248,7 +3231,7 @@ const getConvertTrackedExpenseInformation = ( failureData?.push(...deleteFailureData); // Build modified expense report action with the transaction changes - const modifiedExpenseReportAction = ReportUtils.buildOptimisticMovedTrackedExpenseModifiedReportAction(delegateEmail, transactionThreadReportID, moneyRequestReportID); + const modifiedExpenseReportAction = ReportUtils.buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadReportID, moneyRequestReportID); optimisticData?.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -4000,7 +3983,6 @@ function createSplitsAndOnyxData( // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat const splitCreatedReportAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmailForIOUSplit); const splitIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( - undefined, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, amount, currency, @@ -4579,7 +4561,6 @@ function startSplitBill({ // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat const splitChatCreatedReportAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmailForIOUSplit); const splitIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( - undefined, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, 0, CONST.CURRENCY.USD, @@ -5254,7 +5235,7 @@ function editRegularMoneyRequest( const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); // STEP 2: Build new modified expense report action. - const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(delegateEmail, transactionThread, transaction, transactionChanges, isFromExpenseReport, policy); + const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy); const updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : null; // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct @@ -6704,7 +6685,6 @@ function getPayMoneyRequestParams( } const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( - delegateEmail, CONST.IOU.REPORT_ACTION_TYPE.PAY, ReportUtils.isExpenseReport(iouReport) ? -total : total, iouReport.currency ?? '', @@ -7046,7 +7026,7 @@ function approveMoneyRequest(expenseReport: OnyxEntry, full?: total = expenseReport?.unheldTotal; } - const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1', delegateEmail); + const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1'); const approvalChain = ReportUtils.getApprovalChain(PolicyUtils.getPolicy(expenseReport?.policyID), expenseReport?.ownerAccountID ?? -1, expenseReport?.total ?? 0); @@ -7202,7 +7182,7 @@ function unapproveExpenseReport(expenseReport: OnyxEntry) { const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; - const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, delegateEmail); + const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); const optimisticReportActionData: OnyxUpdate = { @@ -7297,13 +7277,7 @@ function submitReport(expenseReport: OnyxTypes.Report) { 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, - delegateEmail, - ); + 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 diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ea154d326064..b038f16d003d 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -264,13 +264,6 @@ Onyx.connect({ waitForCollectionCallback: true, callback: (value) => (allReportDraftComments = value), }); -let delegateEmail = ''; -Onyx.connect({ - key: ONYXKEYS.ACCOUNT, - callback: (value) => { - delegateEmail = value?.delegatedAccess?.delegate ?? ''; - }, -}); let environmentURL: string; Environment.getEnvironmentURL().then((url: string) => (environmentURL = url)); @@ -459,7 +452,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { let commandName: typeof WRITE_COMMANDS.ADD_COMMENT | typeof WRITE_COMMANDS.ADD_ATTACHMENT | typeof WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT = WRITE_COMMANDS.ADD_COMMENT; if (text && !file) { - const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, text, undefined, undefined, undefined, undefined, reportID); + const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(text, undefined, undefined, undefined, undefined, reportID); reportCommentAction = reportComment.reportAction; reportCommentText = reportComment.commentText; } @@ -468,7 +461,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { // When we are adding an attachment we will call AddAttachment. // It supports sending an attachment with an optional comment and AddComment supports adding a single text comment only. commandName = WRITE_COMMANDS.ADD_ATTACHMENT; - const attachment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, text, file, undefined, undefined, undefined, reportID); + const attachment = ReportUtils.buildOptimisticAddCommentReportAction(text, file, undefined, undefined, undefined, reportID); attachmentAction = attachment.reportAction; } @@ -3350,7 +3343,7 @@ function completeOnboarding( const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {}; // Introductory message - const introductionComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ONBOARDING_INTRODUCTION, undefined, actorAccountID); + const introductionComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ONBOARDING_INTRODUCTION, undefined, actorAccountID); const introductionCommentAction: OptimisticAddCommentReportAction = introductionComment.reportAction; const introductionMessage: AddCommentOrAttachementParams = { reportID: targetChatReportID, @@ -3359,7 +3352,7 @@ function completeOnboarding( }; // Text message - const textComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, data.message, undefined, actorAccountID, 1); + const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined, actorAccountID, 1); const textCommentAction: OptimisticAddCommentReportAction = textComment.reportAction; const textMessage: AddCommentOrAttachementParams = { reportID: targetChatReportID, @@ -3370,7 +3363,7 @@ function completeOnboarding( let videoCommentAction: OptimisticAddCommentReportAction | null = null; let videoMessage: AddCommentOrAttachementParams | null = null; if ('video' in data && data.video) { - const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(delegateEmail, CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 2); + const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 2); videoCommentAction = videoComment.reportAction; videoMessage = { reportID: targetChatReportID, @@ -3400,7 +3393,6 @@ function completeOnboarding( ); const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(CONST.EMAIL.CONCIERGE); const taskReportAction = ReportUtils.buildOptimisticTaskCommentReportAction( - delegateEmail, currentTask.reportID, task.title, 0, @@ -3412,7 +3404,7 @@ function completeOnboarding( currentTask.parentReportActionID = taskReportAction.reportAction.reportActionID; const completedTaskReportAction = task.autoCompleted - ? ReportUtils.buildOptimisticTaskReportAction(delegateEmail, currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2) + ? ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2) : null; return { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 7c5df18aa466..41ccfee1786b 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -78,14 +78,6 @@ Onyx.connect({ }, }); -let delegateEmail = ''; -Onyx.connect({ - key: ONYXKEYS.ACCOUNT, - callback: (value) => { - delegateEmail = value?.delegatedAccess?.delegate ?? ''; - }, -}); - /** * Clears out the task info from the store */ @@ -129,7 +121,7 @@ function createTaskAndNavigate( // Parent ReportAction indicating that a task has been created const optimisticTaskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmail); - const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(delegateEmail, taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); + const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID; const currentTime = DateUtils.getDBTimeWithSkew(); @@ -209,7 +201,6 @@ function createTaskAndNavigate( if (assigneeChatReport) { assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( - delegateEmail, currentUserAccountID, assigneeAccountID, taskReportID, @@ -336,7 +327,7 @@ function getOutstandingChildTask(taskReport: OnyxEntry) { function completeTask(taskReport: OnyxEntry) { const taskReportID = taskReport?.reportID ?? '-1'; const message = `marked as complete`; - const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(delegateEmail, taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, message); + const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, message); const parentReport = getParentReport(taskReport); const optimisticData: OnyxUpdate[] = [ { @@ -422,7 +413,7 @@ function completeTask(taskReport: OnyxEntry) { function reopenTask(taskReport: OnyxEntry) { const taskReportID = taskReport?.reportID ?? '-1'; const message = `marked as incomplete`; - const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(delegateEmail, taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED, message); + const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED, message); const parentReport = getParentReport(taskReport); const hasOutstandingChildTask = taskReport?.managerID === currentUserAccountID ? true : parentReport?.hasOutstandingChildTask; @@ -502,7 +493,7 @@ function reopenTask(taskReport: OnyxEntry) { function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task) { // Create the EditedReportAction on the task - const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskFieldReportAction({title, description}, delegateEmail); + const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskFieldReportAction({title, description}); // Sometimes title or description is undefined, so we need to check for that, and we provide it to multiple functions const reportName = (title ?? report?.reportName)?.trim(); @@ -579,7 +570,7 @@ function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, assigneeEmail: string, assigneeAccountID: number | null = 0, assigneeChatReport?: OnyxEntry) { // Create the EditedReportAction on the task - const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(delegateEmail, assigneeAccountID ?? 0); + const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? 0); const reportName = report.reportName?.trim(); let assigneeChatReportOnyxData; @@ -684,7 +675,6 @@ function editTaskAssignee(report: OnyxTypes.Report, sessionAccountID: number, as }; assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( - delegateEmail, currentUserAccountID, assigneeAccountID, report.reportID, @@ -952,7 +942,7 @@ function deleteTask(report: OnyxEntry) { return; } const message = `deleted task: ${report.reportName}`; - const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(delegateEmail, report.reportID ?? '-1', CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message); + const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(report.reportID ?? '-1', CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED, message); const optimisticReportActionID = optimisticCancelReportAction.reportActionID; const parentReportAction = getParentReportAction(report); const parentReport = getParentReport(report); diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 42302b721059..1460942931fc 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -181,7 +181,6 @@ function ReportActionsView({ if (report.total && moneyRequestActions.length < (reportPreviewAction?.childMoneyRequestCount ?? 0) && isEmptyObject(transactionThreadReport)) { const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( - undefined, CONST.IOU.REPORT_ACTION_TYPE.CREATE, 0, CONST.CURRENCY.USD, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 8e86c625b57a..f8d23e89ca5a 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -766,7 +766,6 @@ describe('ReportUtils', () => { it('should disable thread on split expense actions', () => { const reportAction = ReportUtils.buildOptimisticIOUReportAction( - undefined, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, 50000, CONST.CURRENCY.USD, From 60f097a3091550868753b57c9acea874df3063e6 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 18:44:49 +0530 Subject: [PATCH 41/44] remove whitespaces --- src/libs/actions/IOU.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index eca0a532d9dd..daaa766145ed 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7025,7 +7025,6 @@ function approveMoneyRequest(expenseReport: OnyxEntry, full?: if (hasHeldExpenses && !full && !!expenseReport?.unheldTotal) { total = expenseReport?.unheldTotal; } - const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport?.currency ?? '', expenseReport?.reportID ?? '-1'); const approvalChain = ReportUtils.getApprovalChain(PolicyUtils.getPolicy(expenseReport?.policyID), expenseReport?.ownerAccountID ?? -1, expenseReport?.total ?? 0); @@ -7276,7 +7275,6 @@ function submitReport(expenseReport: OnyxTypes.Report) { 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); From e5778d7e1a8a690c38a45dc1e9d57813b5469694 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 19:09:07 +0530 Subject: [PATCH 42/44] Check for delegate report action directly from actions --- src/pages/home/report/ReportActionItemSingle.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index cb68d36f60ce..e93dfa8ea759 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -86,9 +86,6 @@ function ReportActionItemSingle({ const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); const delegatePersonalDetails = personalDetails[action?.delegateAccountID ?? '']; - - const delegateEmail = delegatePersonalDetails?.login; - let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; const accountOwnerDetails = getPersonalDetailByEmail(login ?? ''); @@ -286,7 +283,7 @@ function ReportActionItemSingle({ ) : null} - {delegateEmail && !isReportPreviewAction && ( + {action?.delegateAccountID && !isReportPreviewAction && ( {translate('delegate.onBehalfOfMessage', accountOwnerDetails?.displayName ?? '')} )} {children} From c081907cbebfb93d12e6379afcd3c9f5a5250037 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 24 Sep 2024 20:12:17 +0530 Subject: [PATCH 43/44] remove white space --- src/pages/home/report/ReportActionItemSingle.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 76e413a4b6d1..7e512b192d4f 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -82,7 +82,6 @@ function ReportActionItemSingle({ const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT; - const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); const delegatePersonalDetails = personalDetails[action?.delegateAccountID ?? '']; const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); From d5e34283d0b7262a22e95cf533c0c659442ffe7a Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 25 Sep 2024 13:53:07 +0530 Subject: [PATCH 44/44] Update src/libs/ReportUtils.ts Co-authored-by: Daniel Gale-Rosen <5487802+dangrous@users.noreply.github.com> --- src/libs/ReportUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ed167cf123f4..f179cd35827f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4179,6 +4179,7 @@ function buildOptimisticAddCommentReportAction( 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 { commentText,