diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 5d87a7f5c3bd..78ce4db4e5d9 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -762,9 +762,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/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; diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 8c9fa67891b6..b21585d65a87 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/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/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 0254059e4047..c4a9028118dc 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({ @@ -344,17 +344,11 @@ function getForReportAction({ ); } - const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'attendees' in reportActionOriginalMessage; + const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'newAttendees' in reportActionOriginalMessage; if (hasModifiedAttendees) { - buildMessageFragmentForValue( - reportActionOriginalMessage.oldAttendees ?? '', - reportActionOriginalMessage.attendees ?? '', - translateLocal('iou.attendees'), - false, - setFragments, - removalFragments, - changeFragments, - ); + const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.newAttendees, reportActionOriginalMessage.oldAttendees); + + buildMessageFragmentForValue(oldAttendees, attendees, translateLocal('iou.attendees'), false, setFragments, removalFragments, changeFragments); } const message = 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, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3a5cbf37ce93..7054df97ae20 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -177,7 +177,6 @@ import { getCategory, getCurrency, getDescription, - getFormattedAttendees, getFormattedCreated, getFormattedPostedDate, getMCCGroup, @@ -604,7 +603,7 @@ type OptimisticTaskReport = SetRequired< type TransactionDetails = { created: string; amount: number; - attendees: Attendee[]; + attendees: Attendee[] | string; taxAmount?: number; taxCode?: string; currency: string; @@ -4204,7 +4203,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.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/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 087fd39444da..2dce1646e3e6 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -256,7 +256,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; } @@ -299,7 +299,6 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T taxAmount, billable, reimbursable, - attendees, inserted: DateUtils.getDBTime(), }; } @@ -331,10 +330,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); } /** @@ -656,7 +655,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 0373933f3b10..fdee9171531d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -774,7 +774,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 @@ -809,7 +811,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, @@ -883,7 +884,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']) { @@ -3854,6 +3855,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, @@ -4898,6 +4903,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 ad8c83e47e28..f29b7fea6c52 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -99,7 +99,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 c21dbf03559a..78804d1800cd 100644 --- a/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx +++ b/src/pages/iou/request/MoneyRequestAttendeeSelector.tsx @@ -10,16 +10,30 @@ 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'; 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 {Option} from '@libs/OptionsListUtils'; +import { + filterAndOrderOptions, + formatSectionsFromSearchTerm, + getAttendeeOptions, + getEmptyOptions, + getHeaderMessage, + getParticipantsOption, + getPersonalDetailSearchTerms, + getPolicyExpenseReportOption, + isCurrentUser, + orderOptions, +} from '@libs/OptionsListUtils'; +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'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -52,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}); @@ -62,18 +76,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 +99,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 +137,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 +150,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde * Returns the sections needed for the OptionsSelector */ const [sections, header] = useMemo(() => { - const newSections: OptionsListUtils.Section[] = []; + const newSections: Array> = []; if (!areOptionsInitialized || !didScreenTransitionEnd) { return [newSections, '']; } @@ -144,9 +158,15 @@ 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: CONST.DEFAULT_NUMBER_ID.toString(), + selected: true, + login: attendee.email, + ...getPersonalDetailByEmail(attendee.email), + })), chatOptions.recentReports, chatOptions.personalDetails, personalDetails, @@ -168,23 +188,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]; @@ -202,12 +222,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); @@ -216,15 +240,20 @@ 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, { - 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, - 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 ?? icon, iouType, }, ]; @@ -238,7 +267,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; } @@ -297,7 +326,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/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index e1dc5d94004c..1ff5c25c46ca 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -218,7 +218,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 0aa5e2e22dda..70c21b531de7 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -384,7 +384,7 @@ function IOURequestStepConfirmation({ action, transactionParams: { amount: transaction.amount, - attendees: transaction.attendees, + attendees: transaction.comment?.attendees, currency: transaction.currency, created: transaction.created, merchant: transaction.merchant, @@ -927,7 +927,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 8d902955e764..8778c9e56cdd 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -296,7 +296,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -305,7 +305,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( @@ -399,7 +399,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -460,7 +460,7 @@ function IOURequestStepScan({ backTo, 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 c3b110c90e98..fdadddb7aef4 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -318,7 +318,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -327,7 +327,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( @@ -421,7 +421,7 @@ function IOURequestStepScan({ }, transactionParams: { amount: 0, - attendees: transaction?.attendees, + attendees: transaction?.comment?.attendees, currency: transaction?.currency ?? 'USD', created: transaction?.created ?? '', merchant: '', @@ -482,7 +482,7 @@ function IOURequestStepScan({ backTo, transaction?.currency, transaction?.created, - transaction?.attendees, + transaction?.comment?.attendees, iouType, report, transactionID, diff --git a/src/stories/ReportActionItemImages.stories.tsx b/src/stories/ReportActionItemImages.stories.tsx index ce7e4719a97f..34e8df9c0266 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', displayName: 'Test User', avatarUrl: ''}]}, 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', displayName: 'Test User', avatarUrl: ''}]}, 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', displayName: 'Test User', avatarUrl: ''}]}, 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', displayName: 'Test User', avatarUrl: ''}]}, reportID: 'REPORT_3', }, }, 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; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index e3a4c069c0c4..00ff403011e2 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 */ + newAttendees?: Attendee[]; }; /** Model of the `deleted transaction` report action */ diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index c315dd37c2f9..50ef36770194 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; @@ -391,9 +394,6 @@ type Transaction = OnyxCommon.OnyxValueWithOfflineFeedback< /** The original transaction amount */ amount: number; - /** Selected attendees */ - attendees?: Attendee[]; - /** The transaction tax amount */ taxAmount?: number; @@ -560,6 +560,9 @@ type AdditionalTransactionChanges = { /** Collection of modified waypoints */ waypoints?: WaypointCollection; + /** Collection of modified attendees */ + attendees?: Attendee[]; + /** The ID of the distance rate */ customUnitRateID?: string; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 297849e3620d..6df79e8fa963 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -757,10 +757,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', displayName: 'Test User', avatarUrl: ''}], }, created: DateUtils.getDBTime(), currency: CONST.CURRENCY.USD, @@ -1334,10 +1334,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', displayName: 'Test User', avatarUrl: ''}], }, 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..b58ddfc6d443 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', 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 067ccbffffaa..37d1e6ef3d65 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(), displayName: 'Test User', avatarUrl: ''}], }, - attendees: [{email: randWord()}], filename: randWord(), managedCard: randBoolean(), created: format(randPastDate(), CONST.DATE.FNS_DB_FORMAT_STRING),