Skip to content

Commit 5cb0345

Browse files
authored
Merge pull request Expensify#67306 from parasharrajat/parasharrajat/attendee-cleanup
Assign expense creator as the default assignee for expenses where no assignee is present
2 parents 1c550a3 + c5859af commit 5cb0345

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

src/libs/TransactionUtils/index.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {toLocaleDigit} from '@libs/LocaleDigitUtils';
1818
import {translateLocal} from '@libs/Localize';
1919
import Log from '@libs/Log';
2020
import {rand64, roundToTwoDecimalPlaces} from '@libs/NumberUtils';
21-
import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils';
21+
import {getPersonalDetailsByIDs} from '@libs/PersonalDetailsUtils';
2222
import {
2323
getCommaSeparatedTagNameWithSanitizedColons,
2424
getDistanceRateCustomUnitRate,
@@ -731,18 +731,29 @@ function getMerchantOrDescription(transaction: OnyxEntry<Transaction>) {
731731
*/
732732
function getAttendees(transaction: OnyxInputOrEntry<Transaction>): Attendee[] {
733733
const attendees = transaction?.modifiedAttendees ? transaction.modifiedAttendees : (transaction?.comment?.attendees ?? []);
734-
if (attendees.length === 0) {
735-
const details = getPersonalDetailByEmail(currentUserEmail);
736-
attendees.push({
737-
email: currentUserEmail,
738-
login: details?.login ?? currentUserEmail,
739-
displayName: details?.displayName ?? currentUserEmail,
740-
accountID: currentUserAccountID,
741-
text: details?.displayName ?? currentUserEmail,
742-
searchText: details?.displayName ?? currentUserEmail,
743-
avatarUrl: details?.avatarThumbnail ?? '',
744-
selected: true,
745-
});
734+
if (attendees.length === 0 && transaction?.reportID) {
735+
// Get the creator of the transaction by looking at the owner of the report linked to the transaction
736+
const report = getReportOrDraftReport(transaction.reportID);
737+
const creatorAccountID = report?.ownerAccountID;
738+
739+
if (creatorAccountID) {
740+
const [creatorDetails] = getPersonalDetailsByIDs({accountIDs: [creatorAccountID], currentUserAccountID});
741+
const creatorEmail = creatorDetails?.login ?? '';
742+
const creatorDisplayName = creatorDetails?.displayName ?? creatorEmail;
743+
744+
if (creatorEmail) {
745+
attendees.push({
746+
email: creatorEmail,
747+
login: creatorEmail,
748+
displayName: creatorDisplayName,
749+
accountID: creatorAccountID,
750+
text: creatorDisplayName,
751+
searchText: creatorDisplayName,
752+
avatarUrl: creatorDetails?.avatarThumbnail ?? '',
753+
selected: true,
754+
});
755+
}
756+
}
746757
}
747758
return attendees;
748759
}

0 commit comments

Comments
 (0)