From 6310773a5034f6f76b7fe485c3ea2590edbce32c Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 11 Mar 2025 01:20:17 +0500 Subject: [PATCH 01/19] fix transaction comment changes --- src/libs/TransactionUtils/index.ts | 5 ++--- src/libs/actions/IOU.ts | 5 +++-- src/pages/iou/request/step/IOURequestStepAmount.tsx | 2 +- .../iou/request/step/IOURequestStepConfirmation.tsx | 4 ++-- .../iou/request/step/IOURequestStepScan/index.native.tsx | 8 ++++---- src/pages/iou/request/step/IOURequestStepScan/index.tsx | 8 ++++---- src/types/onyx/Transaction.ts | 9 ++++++--- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index f8374bfa358e..0e948cbaa3b4 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -218,7 +218,7 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T // Because JS can only handle 53-bit numbers, transactionIDs are strings in the front-end (just like reportActionID) const transactionID = existingTransactionID ?? NumberUtils.rand64(); - const commentJSON: Comment = {comment}; + const commentJSON: Comment = {comment, attendees}; if (source) { commentJSON.source = source; } @@ -256,7 +256,6 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T taxAmount, billable, reimbursable, - attendees, inserted: DateUtils.getDBTime(), }; } @@ -609,7 +608,7 @@ function getMerchantOrDescription(transaction: OnyxEntry) { * Return the list of modified attendees if present otherwise list of attendees */ function getAttendees(transaction: OnyxInputOrEntry): Attendee[] { - return transaction?.modifiedAttendees ? transaction.modifiedAttendees : transaction?.attendees ?? []; + return transaction?.modifiedAttendees ? transaction.modifiedAttendees : transaction?.comment?.attendees ?? []; } /** diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ef8674e2f16c..c5694f5326a9 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -751,7 +751,9 @@ function initMoneyRequest( return; } - const comment: Comment = {}; + const comment: Comment = { + attendees: formatCurrentUserToAttendee(currentUserPersonalDetails, reportID), + }; let requestCategory: string | null = null; // Add initial empty waypoints when starting a distance expense @@ -786,7 +788,6 @@ function initMoneyRequest( // Use set() here so that there is no way that data will be leaked between objects when it gets reset Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${newTransactionID}`, { amount: 0, - attendees: formatCurrentUserToAttendee(currentUserPersonalDetails, reportID), comment, created, currency, diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 97f872d3a0f9..fe3be9771c61 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -217,7 +217,7 @@ function IOURequestStepAmount({ currency, created: transaction?.created ?? '', merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, }, }); return; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index c133e833fc6d..2e43447dc2e2 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -300,7 +300,7 @@ function IOURequestStepConfirmation({ action, transactionParams: { amount: transaction.amount, - attendees: transaction.attendees, + attendees: transaction.comment?.attendees, currency: transaction.currency, created: transaction.created, merchant: transaction.merchant, @@ -792,7 +792,7 @@ function IOURequestStepConfirmation({ transaction={transaction} selectedParticipants={participants} iouAmount={Math.abs(transaction?.amount ?? 0)} - iouAttendees={transaction?.attendees ?? []} + iouAttendees={transaction?.comment?.attendees ?? []} iouComment={transaction?.comment?.comment ?? ''} iouCurrencyCode={transaction?.currency} iouIsBillable={transaction?.billable} diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 42326f5ccf90..71c05ef82274 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -280,7 +280,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -289,7 +289,7 @@ function IOURequestStepScan({ }); } }, - [currentUserPersonalDetails.accountID, currentUserPersonalDetails.login, iouType, report, transaction?.attendees, transaction?.created, transaction?.currency], + [currentUserPersonalDetails.accountID, currentUserPersonalDetails.login, iouType, report, transaction?.comment?.attendees, transaction?.created, transaction?.currency], ); const navigateToConfirmationStep = useCallback( (file: FileObject, source: string, locationPermissionGranted = false) => { @@ -398,7 +398,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -432,7 +432,7 @@ function IOURequestStepScan({ transaction?.isFromGlobalCreate, transaction?.currency, transaction?.created, - transaction?.attendees, + transaction?.comment?.attendees, iouType, report, transactionID, diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 3cdb62e0d42a..fe66591c243a 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -334,7 +334,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -343,7 +343,7 @@ function IOURequestStepScan({ }); } }, - [currentUserPersonalDetails.accountID, currentUserPersonalDetails.login, iouType, report, transaction?.attendees, transaction?.created, transaction?.currency], + [currentUserPersonalDetails.accountID, currentUserPersonalDetails.login, iouType, report, transaction?.comment?.attendees, transaction?.created, transaction?.currency], ); const navigateToConfirmationStep = useCallback( @@ -453,7 +453,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -487,7 +487,7 @@ function IOURequestStepScan({ transaction?.isFromGlobalCreate, transaction?.currency, transaction?.created, - transaction?.attendees, + transaction?.comment?.attendees, iouType, report, transactionID, diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index f60f2784d3fe..6a36f99282d8 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -54,6 +54,9 @@ type WaypointCollection = Record; /** Model of transaction comment */ type Comment = { + /** Selected attendees */ + attendees?: Attendee[]; + /** Content of the transaction comment */ comment?: string; @@ -385,9 +388,6 @@ type Transaction = OnyxCommon.OnyxValueWithOfflineFeedback< /** The original transaction amount */ amount: number; - /** Selected attendees */ - attendees?: Attendee[]; - /** The transaction tax amount */ taxAmount?: number; @@ -554,6 +554,9 @@ type AdditionalTransactionChanges = { /** Collection of modified waypoints */ waypoints?: WaypointCollection; + /** Collection of modified attendees */ + attendees?: Attendee[]; + /** The ID of the distance rate */ customUnitRateID?: string; From 3e78fcd0eb2786c2677198b43bbf95af00658f8f Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 11 Mar 2025 01:36:23 +0500 Subject: [PATCH 02/19] fix type errors --- src/libs/DebugUtils.ts | 17 +++---------- src/libs/actions/IOU.ts | 2 +- .../ReportActionItemImages.stories.tsx | 12 ++++------ tests/actions/IOUTest.ts | 4 ++-- tests/data/Invoice.ts | 24 +++++++++---------- tests/unit/ViolationUtilsTest.ts | 3 +-- tests/utils/collections/transaction.ts | 2 +- 7 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 43fcf0403839..716960222cae 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -9,6 +9,7 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx'; +import type { Comment } from '@src/types/onyx/Transaction'; import {getLinkedTransactionID} from './ReportActionsUtils'; import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils'; import SidebarUtils from './SidebarUtils'; @@ -1073,6 +1074,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string) comment: 'string', hold: 'string', waypoints: 'object', + attendees: 'array', isLoading: 'boolean', type: CONST.TRANSACTION.TYPE, customUnit: 'object', @@ -1082,21 +1084,8 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string) splits: 'array', dismissedViolations: 'object', }); - case 'attendees': - return validateArray>(value, { - email: 'string', - displayName: 'string', - avatarUrl: 'string', - accountID: 'number', - text: 'string', - login: 'string', - searchText: 'string', - selected: 'boolean', - iouType: CONST.IOU.TYPE, - reportID: 'string', - }); case 'modifiedAttendees': - return validateArray>(value, { + return validateArray>(value, { email: 'string', displayName: 'string', avatarUrl: 'string', diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c5694f5326a9..c8a66f0c4b4f 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -861,7 +861,7 @@ function setMoneyRequestMerchant(transactionID: string, merchant: string, isDraf } function setMoneyRequestAttendees(transactionID: string, attendees: Attendee[], isDraft: boolean) { - Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {attendees}); + Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {attendees}}); } function setMoneyRequestPendingFields(transactionID: string, pendingFields: OnyxTypes.Transaction['pendingFields']) { diff --git a/src/stories/ReportActionItemImages.stories.tsx b/src/stories/ReportActionItemImages.stories.tsx index ce7e4719a97f..f524f0ce0563 100644 --- a/src/stories/ReportActionItemImages.stories.tsx +++ b/src/stories/ReportActionItemImages.stories.tsx @@ -50,7 +50,6 @@ DisplayEReceipt.args = { thumbnail: '', transaction: { transactionID: 'FAKE_3', - attendees: [{email: 'test@expensify.com'}], amount: 1000, currency: 'USD', cardID: 5, @@ -58,7 +57,7 @@ DisplayEReceipt.args = { mccGroup: 'Commuter', created: '2023-07-24 13:46:20', hasEReceipt: true, - comment: {}, + comment: {attendees: [{email: 'test@expensify.com'}]}, reportID: 'REPORT_1', }, }, @@ -75,7 +74,6 @@ DisplayMultipleEReceipts.args = { thumbnail: '', transaction: { transactionID: 'FAKE_3', - attendees: [{email: 'test@expensify.com'}], amount: 1000, currency: 'USD', cardID: 5, @@ -83,7 +81,7 @@ DisplayMultipleEReceipts.args = { mccGroup: 'Commuter', created: '2023-07-24 13:46:20', hasEReceipt: true, - comment: {}, + comment: {attendees: [{email: 'test@expensify.com'}]}, reportID: 'REPORT_1', }, }, @@ -92,7 +90,6 @@ DisplayMultipleEReceipts.args = { thumbnail: '', transaction: { transactionID: 'FAKE_5', - attendees: [{email: 'test@expensify.com'}], amount: 230440, currency: 'USD', cardID: 4, @@ -100,7 +97,7 @@ DisplayMultipleEReceipts.args = { mccGroup: 'Goods', created: '2022-03-21 13:46:20', hasEReceipt: true, - comment: {}, + comment: {attendees: [{email: 'test@expensify.com'}]}, reportID: 'REPORT_2', }, }, @@ -109,7 +106,6 @@ DisplayMultipleEReceipts.args = { thumbnail: '', transaction: { transactionID: 'FAKE_2', - attendees: [{email: 'test@expensify.com'}], amount: 1000, currency: 'USD', cardID: 4, @@ -117,7 +113,7 @@ DisplayMultipleEReceipts.args = { mccGroup: 'Airlines', created: '2023-07-24 13:46:20', hasEReceipt: true, - comment: {}, + comment: {attendees: [{email: 'test@expensify.com'}]}, reportID: 'REPORT_3', }, }, diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 51e621909f60..292eed008c80 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -755,10 +755,10 @@ describe('actions/IOU', () => { }; const existingTransaction: Transaction = { transactionID: rand64(), - attendees: [{email: 'text@expensify.com'}], amount: 1000, comment: { comment: 'Existing transaction', + attendees: [{email: 'text@expensify.com'}], }, created: DateUtils.getDBTime(), currency: CONST.CURRENCY.USD, @@ -1332,10 +1332,10 @@ describe('actions/IOU', () => { jest.advanceTimersByTime(200); const julesExistingTransaction: OnyxEntry = { transactionID: rand64(), - attendees: [{email: 'text@expensify.com'}], amount: 1000, comment: { comment: 'This is an existing transaction', + attendees: [{email: 'text@expensify.com'}], }, created: DateUtils.getDBTime(), currency: '', diff --git a/tests/data/Invoice.ts b/tests/data/Invoice.ts index 57b0eff29500..ee389bdbeca2 100644 --- a/tests/data/Invoice.ts +++ b/tests/data/Invoice.ts @@ -173,22 +173,22 @@ const policy: OnyxEntry = { const transaction: OnyxEntry = { amount: 100, - attendees: [ - { - email: 'a1@53019.com', - login: 'a1@53019.com', - displayName: 'a1', - avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', - accountID: 32, - text: 'a1@53019.com', - selected: true, - reportID: '3634215302663162', - }, - ], comment: { customUnit: { customUnitRateID: '_FAKE_P2P_ID_', }, + attendees: [ + { + email: 'a1@53019.com', + login: 'a1@53019.com', + displayName: 'a1', + avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', + accountID: 32, + text: 'a1@53019.com', + selected: true, + reportID: '3634215302663162', + }, + ], }, created: '2024-12-13', currency: 'USD', diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index e47520baaf12..0dc4695383a1 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -78,10 +78,9 @@ describe('getViolationsOnyxData', () => { beforeEach(() => { transaction = { transactionID: '123', - attendees: [{email: 'text@expensify.com'}], reportID: '1234', amount: 100, - comment: {}, + comment: {attendees: [{email: 'text@expensify.com'}]}, created: '2023-07-24 13:46:20', merchant: 'United Airlines', currency: 'USD', diff --git a/tests/utils/collections/transaction.ts b/tests/utils/collections/transaction.ts index 067ccbffffaa..e8d12983d5b0 100644 --- a/tests/utils/collections/transaction.ts +++ b/tests/utils/collections/transaction.ts @@ -22,8 +22,8 @@ export default function createRandomTransaction(index: number): Transaction { name: randWord(), }, }, + attendees: [{email: randWord()}], }, - attendees: [{email: randWord()}], filename: randWord(), managedCard: randBoolean(), created: format(randPastDate(), CONST.DATE.FNS_DB_FORMAT_STRING), From b805797c9932ebb9bac6f40448b50ecc0738c677 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 11 Mar 2025 01:39:05 +0500 Subject: [PATCH 03/19] prettier --- src/libs/DebugUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 716960222cae..3cb96282ea9e 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -9,7 +9,7 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx'; -import type { Comment } from '@src/types/onyx/Transaction'; +import type {Comment} from '@src/types/onyx/Transaction'; import {getLinkedTransactionID} from './ReportActionsUtils'; import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils'; import SidebarUtils from './SidebarUtils'; From 1562008581a0f884d44c816d7e407abe7a4044fb Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 18 Mar 2025 11:47:01 +0500 Subject: [PATCH 04/19] update attendees command --- Mobile-Expensify | 2 +- src/libs/ReportUtils.ts | 2 +- src/libs/TransactionUtils/index.ts | 4 ++-- src/libs/actions/IOU.ts | 4 ++++ src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 5 ++++- src/types/onyx/IOU.ts | 6 +++--- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Mobile-Expensify b/Mobile-Expensify index b73bf43f7339..20e1d9c9ddb8 160000 --- a/Mobile-Expensify +++ b/Mobile-Expensify @@ -1 +1 @@ -Subproject commit b73bf43f7339efe3f813b1894de081ff3b2c056a +Subproject commit 20e1d9c9ddb828c40c07e9ca28f2eb29820adde9 diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fc4c70ac538a..0837f39400e5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -594,7 +594,7 @@ type OptimisticTaskReport = SetRequired< type TransactionDetails = { created: string; amount: number; - attendees: Attendee[]; + attendees: Attendee[] | string; taxAmount?: number; taxCode?: string; currency: string; diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 1c565acfd8f1..c7350a13dad8 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -293,10 +293,10 @@ function isMerchantMissing(transaction: OnyxEntry) { // eslint-disable-next-line @typescript-eslint/no-unused-vars function shouldShowAttendees(iouType: IOUType, policy: OnyxEntry): boolean { - return false; + // return false; // To be renabled once feature is complete: https://github.com/Expensify/App/issues/44725 // Keep this disabled for per diem expense - // return iouType === CONST.IOU.TYPE.SUBMIT && !!policy?.id && (policy?.type === CONST.POLICY.TYPE.CORPORATE || policy?.type === CONST.POLICY.TYPE.TEAM); + return iouType === CONST.IOU.TYPE.SUBMIT && !!policy?.id && (policy?.type === CONST.POLICY.TYPE.CORPORATE || policy?.type === CONST.POLICY.TYPE.TEAM); } /** diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 5d56ab4557f8..f7f05ceef68b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3721,6 +3721,10 @@ function getUpdateMoneyRequestParams( } } + if (Array.isArray(params?.attendees)) { + params.attendees = JSON.stringify(params?.attendees); + } + // Clear out the error fields and loading states on success successData.push({ onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index c21dbf03559a..9ab409779168 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -222,9 +222,12 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde accountID: option.accountID ?? -1, // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing login: option.login || option.text, - displayName: option.text, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + email: option.login || (option.text ?? ''), + displayName: option.text ?? '', selected: true, searchText: option.searchText, + avatarUrl: option.avatarUrl ?? '', iouType, }, ]; diff --git a/src/types/onyx/IOU.ts b/src/types/onyx/IOU.ts index df7002e29562..32d7b37b0729 100644 --- a/src/types/onyx/IOU.ts +++ b/src/types/onyx/IOU.ts @@ -172,13 +172,13 @@ type IOU = { /** Model of IOU attendee */ type Attendee = { /** IOU attendee email */ - email?: string; + email: string; /** IOU attendee display name */ - displayName?: string; + displayName: string; /** IOU attendee avatar url */ - avatarUrl?: string; + avatarUrl: string; /** Account ID */ accountID?: number; From e4832b33907d17870ac0f45f8b61b69617d7ff5f Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 25 Mar 2025 21:49:49 +0500 Subject: [PATCH 05/19] re-add mobile exfy --- Mobile-Expensify | 1 + 1 file changed, 1 insertion(+) create mode 160000 Mobile-Expensify diff --git a/Mobile-Expensify b/Mobile-Expensify new file mode 160000 index 000000000000..a28dfeb3ed5f --- /dev/null +++ b/Mobile-Expensify @@ -0,0 +1 @@ +Subproject commit a28dfeb3ed5fc0f85053fe9045d1d0447b3130fb From d497b33d613845dfccd224b6041b6b8db547e467 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 25 Mar 2025 23:56:28 +0500 Subject: [PATCH 06/19] fix lint errors --- .../ReportActionItem/MoneyRequestView.tsx | 4 +- src/libs/IOUUtils.ts | 8 +-- src/libs/actions/IOU.ts | 1 + src/pages/Share/SubmitDetailsPage.tsx | 2 +- .../request/MoneyRequestAttendeeSelector.tsx | 50 ++++++++++++------- .../ReportActionItemImages.stories.tsx | 8 +-- tests/actions/IOUTest.ts | 4 +- tests/unit/ViolationUtilsTest.ts | 2 +- tests/utils/collections/transaction.ts | 2 +- 9 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 4cbae25b2ff2..7681ef3609e2 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -761,9 +761,9 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals item?.displayName ?? item?.login).join(', ')} + title={Array.isArray(transactionAttendees) ? transactionAttendees.map((item) => item?.displayName ?? item?.login).join(', ') : ''} description={`${translate('iou.attendees')} ${ - transactionAttendees?.length && transactionAttendees.length > 1 ? `${formattedPerAttendeeAmount} ${translate('common.perPerson')}` : '' + Array.isArray(transactionAttendees) && transactionAttendees.length > 1 ? `${formattedPerAttendeeAmount} ${translate('common.perPerson')}` : '' }`} style={[styles.moneyRequestMenuItem]} titleStyle={styles.flex1} diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index a183666fbdcc..e357eed12835 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -178,10 +178,10 @@ function formatCurrentUserToAttendee(currentUser?: PersonalDetails, reportID?: s return; } const initialAttendee: Attendee = { - email: currentUser?.login, - login: currentUser?.login, - displayName: currentUser.displayName, - avatarUrl: currentUser.avatar?.toString(), + email: currentUser?.login ?? '', + login: currentUser?.login ?? '', + displayName: currentUser.displayName ?? '', + avatarUrl: currentUser.avatar?.toString() ?? '', accountID: currentUser.accountID, text: currentUser.login, selected: true, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index b6bc3deed0ab..bd938d80fde9 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4898,6 +4898,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { createdReportActionIDForThread, reimbursible, description: parsedComment, + attendees: attendees ? JSON.stringify(attendees) : undefined, }; // eslint-disable-next-line rulesdir/no-multiple-api-calls API.write(WRITE_COMMANDS.REQUEST_MONEY, parameters, onyxData); diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 3bdbdb21cf92..879b242bb001 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -74,7 +74,7 @@ function SubmitDetailsPage({ gpsPoints, action: CONST.IOU.TYPE.CREATE, transactionParams: { - attendees: transaction.attendees, + attendees: transaction.comment?.attendees, amount: transactionAmount, currency: transaction.currency, comment: trimmedComment, diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 9ab409779168..38ad97897983 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -16,10 +16,22 @@ import useNetwork from '@hooks/useNetwork'; import usePolicy from '@hooks/usePolicy'; import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as DeviceCapabilities from '@libs/DeviceCapabilities'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import * as Report from '@userActions/Report'; +import {canUseTouchScreen} from '@libs/DeviceCapabilities'; +import type {Section} from '@libs/OptionsListUtils'; +import { + filterAndOrderOptions, + formatSectionsFromSearchTerm, + getAttendeeOptions, + getEmptyOptions, + getHeaderMessage, + getParticipantsOption, + getPersonalDetailSearchTerms, + getPolicyExpenseReportOption, + isCurrentUser, + orderOptions, +} from '@libs/OptionsListUtils'; +import {isPaidGroupPolicy as isPaidGroupPolicyFn} from '@libs/PolicyUtils'; +import {searchInServer} from '@userActions/Report'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -62,18 +74,18 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const cleanSearchTerm = useMemo(() => debouncedSearchTerm.trim().toLowerCase(), [debouncedSearchTerm]); const offlineMessage: string = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''; - const isPaidGroupPolicy = useMemo(() => PolicyUtils.isPaidGroupPolicy(policy), [policy]); + const isPaidGroupPolicy = useMemo(() => isPaidGroupPolicyFn(policy), [policy]); const isCategorizeOrShareAction = [CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].some((option) => option === action); useEffect(() => { - Report.searchInServer(debouncedSearchTerm.trim()); + searchInServer(debouncedSearchTerm.trim()); }, [debouncedSearchTerm]); const defaultOptions = useMemo(() => { if (!areOptionsInitialized || !didScreenTransitionEnd) { - OptionsListUtils.getEmptyOptions(); + getEmptyOptions(); } - const optionList = OptionsListUtils.getAttendeeOptions( + const optionList = getAttendeeOptions( options.reports, options.personalDetails, betas, @@ -85,7 +97,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde action, ); if (isPaidGroupPolicy) { - const orderedOptions = OptionsListUtils.orderOptions(optionList, searchTerm, { + const orderedOptions = orderOptions(optionList, searchTerm, { preferChatroomsOverThreads: true, preferPolicyExpenseChat: !!action, preferRecentExpenseReports: action === CONST.IOU.ACTION.CREATE, @@ -123,7 +135,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde headerMessage: '', }; } - const newOptions = OptionsListUtils.filterAndOrderOptions(defaultOptions, debouncedSearchTerm, { + const newOptions = filterAndOrderOptions(defaultOptions, debouncedSearchTerm, { excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT, maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW, preferPolicyExpenseChat: isPaidGroupPolicy, @@ -136,7 +148,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde * Returns the sections needed for the OptionsSelector */ const [sections, header] = useMemo(() => { - const newSections: OptionsListUtils.Section[] = []; + const newSections: Section[] = []; if (!areOptionsInitialized || !didScreenTransitionEnd) { return [newSections, '']; } @@ -144,9 +156,9 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const restOfRecents = [...chatOptions.recentReports].slice(5); const contactsWithRestOfRecents = [...restOfRecents, ...chatOptions.personalDetails]; - const formatResults = OptionsListUtils.formatSectionsFromSearchTerm( + const formatResults = formatSectionsFromSearchTerm( debouncedSearchTerm, - attendees.map((attendee) => ({...attendee, reportID: attendee.reportID ?? '-1'})), + attendees.map((attendee) => ({...attendee, reportID: attendee.reportID ?? CONST.DEFAULT_NUMBER_ID.toString()})), chatOptions.recentReports, chatOptions.personalDetails, personalDetails, @@ -168,23 +180,23 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde if ( chatOptions.userToInvite && - !OptionsListUtils.isCurrentUser({...chatOptions.userToInvite, accountID: chatOptions.userToInvite?.accountID ?? -1, status: chatOptions.userToInvite?.status ?? undefined}) + !isCurrentUser({...chatOptions.userToInvite, accountID: chatOptions.userToInvite?.accountID ?? CONST.DEFAULT_NUMBER_ID, status: chatOptions.userToInvite?.status ?? undefined}) ) { newSections.push({ title: undefined, data: [chatOptions.userToInvite].map((participant) => { const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; - return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, personalDetails); + return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); }), shouldShow: true, }); } - const headerMessage = OptionsListUtils.getHeaderMessage( + const headerMessage = getHeaderMessage( (chatOptions.personalDetails ?? []).length + (chatOptions.recentReports ?? []).length !== 0, !!chatOptions?.userToInvite, debouncedSearchTerm.trim(), - attendees.some((attendee) => OptionsListUtils.getPersonalDetailSearchTerms(attendee).join(' ').toLowerCase().includes(cleanSearchTerm)), + attendees.some((attendee) => getPersonalDetailSearchTerms(attendee).join(' ').toLowerCase().includes(cleanSearchTerm)), ); return [newSections, headerMessage]; @@ -219,7 +231,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde newSelectedOptions = [ ...attendees, { - accountID: option.accountID ?? -1, + accountID: option.accountID ?? CONST.DEFAULT_NUMBER_ID, // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing login: option.login || option.text, // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -300,7 +312,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')} textInputHint={offlineMessage} onChangeText={setSearchTerm} - shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()} + shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()} onSelectRow={addAttendeeToSelection} shouldSingleExecuteRowSelect footerContent={footerContent} diff --git a/src/stories/ReportActionItemImages.stories.tsx b/src/stories/ReportActionItemImages.stories.tsx index f524f0ce0563..34e8df9c0266 100644 --- a/src/stories/ReportActionItemImages.stories.tsx +++ b/src/stories/ReportActionItemImages.stories.tsx @@ -57,7 +57,7 @@ DisplayEReceipt.args = { mccGroup: 'Commuter', created: '2023-07-24 13:46:20', hasEReceipt: true, - comment: {attendees: [{email: 'test@expensify.com'}]}, + comment: {attendees: [{email: 'test@expensify.com', displayName: 'Test User', avatarUrl: ''}]}, reportID: 'REPORT_1', }, }, @@ -81,7 +81,7 @@ DisplayMultipleEReceipts.args = { mccGroup: 'Commuter', created: '2023-07-24 13:46:20', hasEReceipt: true, - comment: {attendees: [{email: 'test@expensify.com'}]}, + comment: {attendees: [{email: 'test@expensify.com', displayName: 'Test User', avatarUrl: ''}]}, reportID: 'REPORT_1', }, }, @@ -97,7 +97,7 @@ DisplayMultipleEReceipts.args = { mccGroup: 'Goods', created: '2022-03-21 13:46:20', hasEReceipt: true, - comment: {attendees: [{email: 'test@expensify.com'}]}, + comment: {attendees: [{email: 'test@expensify.com', displayName: 'Test User', avatarUrl: ''}]}, reportID: 'REPORT_2', }, }, @@ -113,7 +113,7 @@ DisplayMultipleEReceipts.args = { mccGroup: 'Airlines', created: '2023-07-24 13:46:20', hasEReceipt: true, - comment: {attendees: [{email: 'test@expensify.com'}]}, + comment: {attendees: [{email: 'test@expensify.com', displayName: 'Test User', avatarUrl: ''}]}, reportID: 'REPORT_3', }, }, diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 57c7d2e2686f..c1178794d805 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -760,7 +760,7 @@ describe('actions/IOU', () => { amount: 1000, comment: { comment: 'Existing transaction', - attendees: [{email: 'text@expensify.com'}], + attendees: [{email: 'text@expensify.com', displayName: 'Test User', avatarUrl: ''}], }, created: DateUtils.getDBTime(), currency: CONST.CURRENCY.USD, @@ -1337,7 +1337,7 @@ describe('actions/IOU', () => { amount: 1000, comment: { comment: 'This is an existing transaction', - attendees: [{email: 'text@expensify.com'}], + attendees: [{email: 'text@expensify.com', displayName: 'Test User', avatarUrl: ''}], }, created: DateUtils.getDBTime(), currency: '', diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index 0dc4695383a1..b58ddfc6d443 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -80,7 +80,7 @@ describe('getViolationsOnyxData', () => { transactionID: '123', reportID: '1234', amount: 100, - comment: {attendees: [{email: 'text@expensify.com'}]}, + comment: {attendees: [{email: 'text@expensify.com', displayName: 'Test User', avatarUrl: ''}]}, created: '2023-07-24 13:46:20', merchant: 'United Airlines', currency: 'USD', diff --git a/tests/utils/collections/transaction.ts b/tests/utils/collections/transaction.ts index e8d12983d5b0..37d1e6ef3d65 100644 --- a/tests/utils/collections/transaction.ts +++ b/tests/utils/collections/transaction.ts @@ -22,7 +22,7 @@ export default function createRandomTransaction(index: number): Transaction { name: randWord(), }, }, - attendees: [{email: randWord()}], + attendees: [{email: randWord(), displayName: 'Test User', avatarUrl: ''}], }, filename: randWord(), managedCard: randBoolean(), From 40e161e1555d61ecdb703a1df5e7e90fbceb0850 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Wed, 26 Mar 2025 01:38:07 +0500 Subject: [PATCH 07/19] fix more lint --- src/libs/API/parameters/RequestMoneyParams.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/API/parameters/RequestMoneyParams.ts b/src/libs/API/parameters/RequestMoneyParams.ts index ea375f32fe0d..74a435600cd2 100644 --- a/src/libs/API/parameters/RequestMoneyParams.ts +++ b/src/libs/API/parameters/RequestMoneyParams.ts @@ -29,6 +29,7 @@ type RequestMoneyParams = { createdReportActionIDForThread: string | undefined; reimbursible?: boolean; description?: string; + attendees?: string; }; export default RequestMoneyParams; From e7c96d89a6c165a6d44b48df3802b447ddefc9b9 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Wed, 26 Mar 2025 02:02:14 +0500 Subject: [PATCH 08/19] fix last ts error --- .../iou/request/MoneyRequestAttendeeSelector.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 38ad97897983..3098fd1ef157 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -10,6 +10,7 @@ import {usePersonalDetails, useSession} from '@components/OnyxProvider'; import {useOptionsList} from '@components/OptionListContextProvider'; import SelectionList from '@components/SelectionList'; import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem'; +import type {SectionListDataType} from '@components/SelectionList/types'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -17,7 +18,6 @@ import usePolicy from '@hooks/usePolicy'; import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus'; import useThemeStyles from '@hooks/useThemeStyles'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; -import type {Section} from '@libs/OptionsListUtils'; import { filterAndOrderOptions, formatSectionsFromSearchTerm, @@ -148,7 +148,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde * Returns the sections needed for the OptionsSelector */ const [sections, header] = useMemo(() => { - const newSections: Section[] = []; + const newSections: Array> = []; if (!areOptionsInitialized || !didScreenTransitionEnd) { return [newSections, '']; } @@ -164,17 +164,17 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde personalDetails, true, ); - newSections.push(formatResults.section); + newSections.push(formatResults.section as SectionListDataType); newSections.push({ title: translate('common.recents'), - data: fiveRecents, + data: fiveRecents as Attendee[], shouldShow: fiveRecents.length > 0, }); newSections.push({ title: translate('common.contacts'), - data: contactsWithRestOfRecents, + data: contactsWithRestOfRecents as Attendee[], shouldShow: contactsWithRestOfRecents.length > 0, }); @@ -187,7 +187,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde data: [chatOptions.userToInvite].map((participant) => { const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); - }), + }) as Attendee[], shouldShow: true, }); } From d052937200981a5f60c0058dd20b0868f5944978 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Fri, 28 Mar 2025 01:45:10 +0500 Subject: [PATCH 09/19] remove gitmodules changes --- .gitmodules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitmodules b/.gitmodules index e69de29bb2d1..59abf2448f1d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Mobile-Expensify"] + path = Mobile-Expensify + url = git@github.com:Expensify/Mobile-Expensify.git From aa8a87bfda0c3be0cd7c9ca7454c7811d4741679 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Fri, 28 Mar 2025 02:03:09 +0500 Subject: [PATCH 10/19] fix incorrect modified expense message --- src/libs/ModifiedExpenseMessage.ts | 14 ++++---------- src/libs/ReportUtils.ts | 4 ++-- src/types/onyx/OriginalMessage.ts | 9 +++++---- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 0254059e4047..6d939dec357a 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -14,7 +14,7 @@ import {getCleanedTagName, getSortedTagKeys} from './PolicyUtils'; import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils'; // eslint-disable-next-line import/no-cycle import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getPolicyName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils'; -import {getTagArrayFromName} from './TransactionUtils'; +import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils'; let allPolicyTags: OnyxCollection = {}; Onyx.connect({ @@ -346,15 +346,9 @@ function getForReportAction({ const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'attendees' in reportActionOriginalMessage; if (hasModifiedAttendees) { - buildMessageFragmentForValue( - reportActionOriginalMessage.oldAttendees ?? '', - reportActionOriginalMessage.attendees ?? '', - translateLocal('iou.attendees'), - false, - setFragments, - removalFragments, - changeFragments, - ); + const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.attendees, reportActionOriginalMessage.oldAttendees); + + buildMessageFragmentForValue(oldAttendees, attendees, translateLocal('iou.attendees'), false, setFragments, removalFragments, changeFragments); } const message = diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2db28ac4d9c6..b0b18cd1a8a3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -176,7 +176,6 @@ import { getCategory, getCurrency, getDescription, - getFormattedAttendees, getFormattedCreated, getFormattedPostedDate, getMCCGroup, @@ -4196,7 +4195,8 @@ function getModifiedExpenseOriginalMessage( originalMessage.merchant = transactionChanges?.merchant; } if ('attendees' in transactionChanges) { - [originalMessage.oldAttendees, originalMessage.attendees] = getFormattedAttendees(transactionChanges?.attendees, getAttendees(oldTransaction)); + originalMessage.oldAttendees = getAttendees(oldTransaction); + originalMessage.attendees = transactionChanges?.attendees; } // The amount is always a combination of the currency and the number value so when one changes we need to store both diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 29f49f9e7a0b..dfe54ae62c47 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -1,6 +1,7 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; +import type {Attendee} from './IOU'; import type {OldDotOriginalMessageMap} from './OldDotAction'; import type {AllConnectionName} from './Policy'; import type ReportActionName from './ReportActionName'; @@ -492,11 +493,11 @@ type OriginalMessageModifiedExpense = { /** The ID of moved report */ movedToReportID?: string; - /** The old stringify list of attendees */ - oldAttendees?: string; + /** The old list of attendees */ + oldAttendees?: Attendee[]; - /** The stringify list of attendees */ - attendees?: string; + /** The list of attendees */ + attendees?: Attendee[]; }; /** Model of the `deleted transaction` report action */ From 19be7fdd3215fed02402e943fad46aacbcedb973 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Mon, 31 Mar 2025 05:58:55 +0500 Subject: [PATCH 11/19] Apply suggestions from code review Co-authored-by: Fedi Rajhi --- .../request/MoneyRequestAttendeeSelector.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 3098fd1ef157..dee4dcf3e942 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -11,6 +11,7 @@ import {useOptionsList} from '@components/OptionListContextProvider'; import SelectionList from '@components/SelectionList'; import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem'; import type {SectionListDataType} from '@components/SelectionList/types'; +import type {Option} from '@libs/OptionsListUtils'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -31,6 +32,7 @@ import { orderOptions, } from '@libs/OptionsListUtils'; import {isPaidGroupPolicy as isPaidGroupPolicyFn} from '@libs/PolicyUtils'; +import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; import {searchInServer} from '@userActions/Report'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; @@ -148,7 +150,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde * Returns the sections needed for the OptionsSelector */ const [sections, header] = useMemo(() => { - const newSections: Array> = []; + const newSections: Array> = []; if (!areOptionsInitialized || !didScreenTransitionEnd) { return [newSections, '']; } @@ -158,23 +160,28 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const formatResults = formatSectionsFromSearchTerm( debouncedSearchTerm, - attendees.map((attendee) => ({...attendee, reportID: attendee.reportID ?? CONST.DEFAULT_NUMBER_ID.toString()})), + attendees.map((attendee) => ({ + ...attendee, + reportID: attendee.reportID ?? CONST.DEFAULT_NUMBER_ID.toString(), + selected: true, + ...getPersonalDetailByEmail(attendee.email) + })), chatOptions.recentReports, chatOptions.personalDetails, personalDetails, true, ); - newSections.push(formatResults.section as SectionListDataType); + newSections.push(formatResults.section; newSections.push({ title: translate('common.recents'), - data: fiveRecents as Attendee[], + data: fiveRecents, shouldShow: fiveRecents.length > 0, }); newSections.push({ title: translate('common.contacts'), - data: contactsWithRestOfRecents as Attendee[], + data: contactsWithRestOfRecents, shouldShow: contactsWithRestOfRecents.length > 0, }); @@ -187,7 +194,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde data: [chatOptions.userToInvite].map((participant) => { const isPolicyExpenseChat = participant?.isPolicyExpenseChat ?? false; return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); - }) as Attendee[], + }), shouldShow: true, }); } From 4f5a19318ef99879a59291087e2be282c3412c91 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Mon, 31 Mar 2025 06:00:23 +0500 Subject: [PATCH 12/19] add patch --- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index dee4dcf3e942..3bcf10ef9b89 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -221,12 +221,16 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde ]); const addAttendeeToSelection = useCallback( - (option: Attendee) => { + (option: Option) => { const isOptionSelected = (selectedOption: Attendee) => { if (selectedOption.accountID && selectedOption.accountID === option?.accountID) { return true; } + if (selectedOption.email && selectedOption.email === option?.login) { + return true; + } + return false; }; const isOptionInList = attendees.some(isOptionSelected); @@ -246,7 +250,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde displayName: option.text ?? '', selected: true, searchText: option.searchText, - avatarUrl: option.avatarUrl ?? '', + avatarUrl: option.avatarUrl ?? option.icons?.[0]?.source?.toString() ?? '', iouType, }, ]; @@ -260,7 +264,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const shouldShowErrorMessage = attendees.length < 1; const handleConfirmSelection = useCallback( - (_keyEvent?: GestureResponderEvent | KeyboardEvent, option?: Attendee) => { + (_keyEvent?: GestureResponderEvent | KeyboardEvent, option?: Option) => { if (shouldShowErrorMessage || (!attendees.length && !option)) { return; } From 854bce0ebc557067ae55abfeeca408c18b781563 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Mon, 31 Mar 2025 06:05:07 +0500 Subject: [PATCH 13/19] fix ts error --- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 3bcf10ef9b89..ebbe50c889b1 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -171,7 +171,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde personalDetails, true, ); - newSections.push(formatResults.section; + newSections.push(formatResults.section); newSections.push({ title: translate('common.recents'), From 2c442bb73fe31036c947c778028d43ac0b937049 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Mon, 31 Mar 2025 06:08:51 +0500 Subject: [PATCH 14/19] prettier --- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index ebbe50c889b1..4cb794fbc6f3 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -11,7 +11,6 @@ import {useOptionsList} from '@components/OptionListContextProvider'; import SelectionList from '@components/SelectionList'; import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem'; import type {SectionListDataType} from '@components/SelectionList/types'; -import type {Option} from '@libs/OptionsListUtils'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -19,6 +18,7 @@ import usePolicy from '@hooks/usePolicy'; import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus'; import useThemeStyles from '@hooks/useThemeStyles'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; +import type {Option} from '@libs/OptionsListUtils'; import { filterAndOrderOptions, formatSectionsFromSearchTerm, @@ -31,8 +31,8 @@ import { isCurrentUser, orderOptions, } from '@libs/OptionsListUtils'; -import {isPaidGroupPolicy as isPaidGroupPolicyFn} from '@libs/PolicyUtils'; import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; +import {isPaidGroupPolicy as isPaidGroupPolicyFn} from '@libs/PolicyUtils'; import {searchInServer} from '@userActions/Report'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; @@ -161,10 +161,10 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const formatResults = formatSectionsFromSearchTerm( debouncedSearchTerm, attendees.map((attendee) => ({ - ...attendee, + ...attendee, reportID: attendee.reportID ?? CONST.DEFAULT_NUMBER_ID.toString(), selected: true, - ...getPersonalDetailByEmail(attendee.email) + ...getPersonalDetailByEmail(attendee.email), })), chatOptions.recentReports, chatOptions.personalDetails, From 36d0ffd01102c930156e3a2a940cab026150c378 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 1 Apr 2025 02:07:13 +0500 Subject: [PATCH 15/19] apply suggestion --- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 4cb794fbc6f3..87c426a82783 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -162,8 +162,9 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde debouncedSearchTerm, attendees.map((attendee) => ({ ...attendee, - reportID: attendee.reportID ?? CONST.DEFAULT_NUMBER_ID.toString(), + reportID: CONST.DEFAULT_NUMBER_ID.toString(), selected: true, + login: attendee.email, ...getPersonalDetailByEmail(attendee.email), })), chatOptions.recentReports, From 774c9c162e626218ef9b5183a6906caf95f755c8 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 1 Apr 2025 02:35:18 +0500 Subject: [PATCH 16/19] pass empty string --- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index 87c426a82783..a374e460ccc2 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -240,6 +240,8 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde if (isOptionInList) { newSelectedOptions = lodashReject(attendees, isOptionSelected); } else { + const iconSource = option.icons?.[0]?.source; + const icon = typeof iconSource === 'function' ? '' : iconSource?.toString() ?? ''; newSelectedOptions = [ ...attendees, { @@ -251,7 +253,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde displayName: option.text ?? '', selected: true, searchText: option.searchText, - avatarUrl: option.avatarUrl ?? option.icons?.[0]?.source?.toString() ?? '', + avatarUrl: option.avatarUrl ?? icon, iouType, }, ]; From 6b55a24153c6c57eb02fa232a8cb0e617675d6f3 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 1 Apr 2025 03:02:21 +0500 Subject: [PATCH 17/19] add suggestion --- src/pages/iou/request/MoneyRequestAttendeeSelector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx index a374e460ccc2..78804d1800cd 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -66,7 +66,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde const [betas] = useOnyx(ONYXKEYS.BETAS); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); const session = useSession(); - const isCurrentUserAttendee = attendees.some((attendee) => attendee.accountID === session?.accountID); + const isCurrentUserAttendee = attendees.some((attendee) => attendee.email === session?.email); const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES); const policy = usePolicy(activePolicyID); const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); From 418c938344501d0547d33777a73b2c0d9653dde3 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 1 Apr 2025 14:31:08 +0500 Subject: [PATCH 18/19] Apply suggestions from code review Co-authored-by: Francois Laithier --- src/libs/ModifiedExpenseMessage.ts | 4 ++-- src/libs/ReportUtils.ts | 2 +- src/types/onyx/OriginalMessage.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 6d939dec357a..c4a9028118dc 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -344,9 +344,9 @@ function getForReportAction({ ); } - const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'attendees' in reportActionOriginalMessage; + const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'newAttendees' in reportActionOriginalMessage; if (hasModifiedAttendees) { - const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.attendees, reportActionOriginalMessage.oldAttendees); + const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.newAttendees, reportActionOriginalMessage.oldAttendees); buildMessageFragmentForValue(oldAttendees, attendees, translateLocal('iou.attendees'), false, setFragments, removalFragments, changeFragments); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 412cf67afbc3..7054df97ae20 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4204,7 +4204,7 @@ function getModifiedExpenseOriginalMessage( } if ('attendees' in transactionChanges) { originalMessage.oldAttendees = getAttendees(oldTransaction); - originalMessage.attendees = transactionChanges?.attendees; + originalMessage.newAttendees = transactionChanges?.attendees; } // The amount is always a combination of the currency and the number value so when one changes we need to store both diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 949a07ebce23..00ff403011e2 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -497,7 +497,7 @@ type OriginalMessageModifiedExpense = { oldAttendees?: Attendee[]; /** The list of attendees */ - attendees?: Attendee[]; + newAttendees?: Attendee[]; }; /** Model of the `deleted transaction` report action */ From 7ce704f8fe782edcf7658b894bbbbc07d5eefa44 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 1 Apr 2025 15:03:44 +0500 Subject: [PATCH 19/19] add key for list --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index e4bc52093ddf..ac38ff401d24 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -496,7 +496,7 @@ function getParticipantsOption(participant: OptionData | Participant, personalDe const displayName = formatPhoneNumber(getDisplayNameOrDefault(detail, login || participant.text)); return { - keyForList: String(detail?.accountID), + keyForList: String(detail?.accountID ?? login), login, accountID: detail?.accountID, text: displayName,