Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 24 additions & 56 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
};

let allReports: OnyxCollection<Report> = {};
Onyx.connect({

Check warning on line 123 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -129,7 +129,7 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 132 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
Expand All @@ -137,7 +137,7 @@

let deprecatedCurrentUserEmail = '';
let deprecatedCurrentUserAccountID = -1;
Onyx.connect({

Check warning on line 140 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
deprecatedCurrentUserEmail = val?.email ?? '';
Expand Down Expand Up @@ -451,7 +451,7 @@
* Determine if we should show the attendee selector for a given expense on a give policy.
*/
function shouldShowAttendees(iouType: IOUType, policy: OnyxEntry<Policy>): boolean {
if ((iouType !== CONST.IOU.TYPE.SUBMIT && iouType !== CONST.IOU.TYPE.CREATE && iouType !== CONST.IOU.TYPE.TRACK) || !policy?.id || policy?.type !== CONST.POLICY.TYPE.CORPORATE) {
if ((iouType !== CONST.IOU.TYPE.SUBMIT && iouType !== CONST.IOU.TYPE.CREATE) || !policy?.id || policy?.type !== CONST.POLICY.TYPE.CORPORATE) {
return false;
}

Expand Down Expand Up @@ -662,10 +662,6 @@
}

if (Object.hasOwn(transactionChanges, 'attendees')) {
updatedTransaction.comment = {
...updatedTransaction.comment,
attendees: transactionChanges.attendees,
};
updatedTransaction.modifiedAttendees = transactionChanges?.attendees;
}

Expand Down Expand Up @@ -887,61 +883,34 @@
return !isMerchantMissing(transaction) ? getMerchant(transaction) : getDescription(transaction);
}

/**
* Return report owner as default attendee
* @param transaction
*/
function getReportOwnerAsAttendee(transaction: OnyxInputOrEntry<Transaction>): Attendee | undefined {
if (transaction?.reportID === undefined) {
return;
}

// Get the creator of the transaction by looking at the owner of the report linked to the transaction
const report = getReportOrDraftReport(transaction?.reportID);
const creatorAccountID = report?.ownerAccountID;

if (creatorAccountID) {
const [creatorDetails] = getPersonalDetailsByIDs({accountIDs: [creatorAccountID], currentUserAccountID: deprecatedCurrentUserAccountID});
const creatorEmail = creatorDetails?.login ?? '';
const creatorDisplayName = creatorDetails?.displayName ?? creatorEmail;

if (creatorEmail) {
return {
email: creatorEmail,
login: creatorEmail,
displayName: creatorDisplayName,
accountID: creatorAccountID,
text: creatorDisplayName,
searchText: creatorDisplayName,
avatarUrl: creatorDetails?.avatarThumbnail ?? '',
selected: true,
};
}
}
}

/**
* Return the list of attendees present on the transaction, if it's empty return report owner as default attendee
* @param transaction
*/
function getOriginalAttendees(transaction: OnyxInputOrEntry<Transaction>): Attendee[] {
const attendees = transaction?.comment?.attendees ?? [];
const currentUserAsAttendee = getReportOwnerAsAttendee(transaction);
if (attendees.length === 0 && transaction?.reportID && currentUserAsAttendee !== undefined) {
attendees.push(currentUserAsAttendee);
}
return attendees;
}

/**
* Return the list of modified attendees if present otherwise list of attendees
* @param transaction
*/
function getAttendees(transaction: OnyxInputOrEntry<Transaction>): Attendee[] {
const attendees = transaction?.modifiedAttendees ? transaction.modifiedAttendees : (transaction?.comment?.attendees ?? []);
const currentUserAsAttendee = getReportOwnerAsAttendee(transaction);
if (attendees.length === 0 && transaction?.reportID && currentUserAsAttendee !== undefined) {
attendees.push(currentUserAsAttendee);
if (attendees.length === 0 && transaction?.reportID) {
// Get the creator of the transaction by looking at the owner of the report linked to the transaction
const report = getReportOrDraftReport(transaction.reportID);
const creatorAccountID = report?.ownerAccountID;

if (creatorAccountID) {
const [creatorDetails] = getPersonalDetailsByIDs({accountIDs: [creatorAccountID], currentUserAccountID: deprecatedCurrentUserAccountID});
const creatorEmail = creatorDetails?.login ?? '';
const creatorDisplayName = creatorDetails?.displayName ?? creatorEmail;

if (creatorEmail) {
attendees.push({
email: creatorEmail,
login: creatorEmail,
displayName: creatorDisplayName,
accountID: creatorAccountID,
text: creatorDisplayName,
searchText: creatorDisplayName,
avatarUrl: creatorDetails?.avatarThumbnail ?? '',
selected: true,
});
}
}
}
return attendees;
}
Expand Down Expand Up @@ -1126,7 +1095,7 @@
* Get all transaction violations of the transaction with given transactionID.
*/
function getTransactionViolations(
transaction: OnyxEntry<Transaction | SearchTransaction>,

Check failure on line 1098 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`SearchTransaction` is deprecated. - Use Transaction instead
transactionViolations: OnyxCollection<TransactionViolations>,
currentUserEmail?: string,
): TransactionViolations | undefined {
Expand Down Expand Up @@ -1159,7 +1128,7 @@
/**
* Check if there is broken connection violation.
*/
function hasBrokenConnectionViolation(transaction: Transaction | SearchTransaction, transactionViolations: OnyxCollection<TransactionViolations> | undefined): boolean {

Check failure on line 1131 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`SearchTransaction` is deprecated. - Use Transaction instead
const violations = getTransactionViolations(transaction, transactionViolations);
return !!violations?.find((violation) => isBrokenConnectionViolation(violation));
}
Expand Down Expand Up @@ -1274,7 +1243,7 @@
/**
* Check if there is pending rter violation in all transactionViolations with given transactionIDs.
*/
function allHavePendingRTERViolation(transactions: OnyxEntry<Transaction[] | SearchTransaction[]>, transactionViolations: OnyxCollection<TransactionViolations> | undefined): boolean {

Check failure on line 1246 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`SearchTransaction` is deprecated. - Use Transaction instead
if (!transactions) {
return false;
}
Expand All @@ -1296,7 +1265,7 @@
/**
* Check if there is any transaction without RTER violation within the given transactionIDs.
*/
function hasAnyTransactionWithoutRTERViolation(transactions: Transaction[] | SearchTransaction[], transactionViolations: OnyxCollection<TransactionViolations> | undefined): boolean {

Check failure on line 1268 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`SearchTransaction` is deprecated. - Use Transaction instead
return (
transactions.length > 0 &&
transactions.some((transaction) => {
Expand Down Expand Up @@ -1451,7 +1420,7 @@
);
}

function hasDuplicateTransactions(iouReportID?: string, allReportTransactions?: SearchTransaction[]): boolean {

Check failure on line 1423 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`SearchTransaction` is deprecated. - Use Transaction instead
const transactionsByIouReportID = getReportTransactions(iouReportID);
const reportTransactions = allReportTransactions ?? transactionsByIouReportID;

Expand Down Expand Up @@ -2229,7 +2198,6 @@
isCorporateCardTransaction,
isExpenseUnreported,
mergeProhibitedViolations,
getOriginalAttendees,
};

export type {TransactionChanges};
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepAttendees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useRestartOnReceiptFailure from '@hooks/useRestartOnReceiptFailure';
import useTransactionViolations from '@hooks/useTransactionViolations';
import {setMoneyRequestAttendees, updateMoneyRequestAttendees} from '@libs/actions/IOU';
import Navigation from '@libs/Navigation/Navigation';
import {getOriginalAttendees} from '@libs/TransactionUtils';
import {getAttendees} from '@libs/TransactionUtils';
import MoneyRequestAttendeeSelector from '@pages/iou/request/MoneyRequestAttendeeSelector';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -43,7 +43,7 @@ function IOURequestStepAttendees({
const isEditing = action === CONST.IOU.ACTION.EDIT;
// eslint-disable-next-line rulesdir/no-default-id-values
const [transaction] = useOnyx(`${isEditing ? ONYXKEYS.COLLECTION.TRANSACTION : ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID || CONST.DEFAULT_NUMBER_ID}`, {canBeMissing: true});
const [attendees, setAttendees] = useState<Attendee[]>(() => getOriginalAttendees(transaction));
const [attendees, setAttendees] = useState<Attendee[]>(() => getAttendees(transaction));
const previousAttendees = usePrevious(attendees);
const {translate} = useLocalize();
const transactionViolations = useTransactionViolations(transactionID);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ import {isPaidGroupPolicy} from '@libs/PolicyUtils';
import {doesReportReceiverMatchParticipant, generateReportID, getReportOrDraftReport, isProcessingReport, isReportOutstanding, isSelectedManagerMcTest} from '@libs/ReportUtils';
import {endSpan} from '@libs/telemetry/activeSpans';
import {
getAttendees,
getDefaultTaxCode,
getOriginalAttendees,
getRateID,
getRequestType,
getValidWaypoints,
Expand Down Expand Up @@ -1289,7 +1289,7 @@ function IOURequestStepConfirmation({
transaction={transaction}
selectedParticipants={participants}
iouAmount={transaction?.amount ?? 0}
iouAttendees={getOriginalAttendees(transaction)}
iouAttendees={getAttendees(transaction)}
iouComment={transaction?.comment?.comment ?? ''}
iouCurrencyCode={transaction?.currency}
iouIsBillable={transaction?.billable}
Expand Down
Loading