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
2 changes: 2 additions & 0 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function mergeDuplicates({transactionThreadReportID: optimisticTransactionThread
const allTransactionViolations = getAllTransactionViolations();
const allReports = getAllReports();
const currentUserEmail = getCurrentUserEmail();
const currentUserAccountID = getUserAccountID();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in later PRs...


const originalSelectedTransaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${params.transactionID}`];

Expand Down Expand Up @@ -221,6 +222,7 @@ function mergeDuplicates({transactionThreadReportID: optimisticTransactionThread
reportAction: iouAction,
updatedReportPreviewAction,
shouldAddUpdatedReportPreviewActionToOnyxData: Number(index) === iouActionsToDelete.length - 1,
currentUserAccountID,
});
cleanUpTransactionThreadReportsOptimisticData.push(...cleanUpTransactionThreadReportOnyxDataForIouAction.optimisticData);
cleanUpTransactionThreadReportsSuccessData.push(...cleanUpTransactionThreadReportOnyxDataForIouAction.successData);
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@ function updateSplitTransactions({
reportAction: currentReportAction,
updatedReportPreviewAction: (updatedReportPreviewAction ?? originalReportPreviewAction) as OnyxTypes.ReportAction,
shouldAddUpdatedReportPreviewActionToOnyxData: false,
currentUserAccountID: currentUserPersonalDetails.accountID,
});
updatedReportPreviewAction = cleanUpTransactionThreadReportOnyxData.updatedReportPreviewAction;
}
Expand Down Expand Up @@ -1857,6 +1858,7 @@ function updateSplitTransactions({
shouldDeleteTransactionThread: true,
reportAction: firstIOU,
updatedReportPreviewAction: updatedReportPreviewAction as OnyxTypes.ReportAction,
currentUserAccountID: currentUserPersonalDetails.accountID,
});

onyxData.optimisticData?.push(...optimisticData);
Expand Down
103 changes: 67 additions & 36 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 793 in src/libs/actions/IOU/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.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -923,7 +923,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 926 in src/libs/actions/IOU/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,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -937,7 +937,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 940 in src/libs/actions/IOU/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_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -946,7 +946,7 @@
});

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

Check warning on line 949 in src/libs/actions/IOU/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) => {
Expand All @@ -960,7 +960,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 963 in src/libs/actions/IOU/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.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -973,7 +973,7 @@
});

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

Check warning on line 976 in src/libs/actions/IOU/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 @@ -982,7 +982,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 985 in src/libs/actions/IOU/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_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -990,26 +990,26 @@
},
});

let userAccountID = -1;
let currentUserEmail = '';
let deprecatedUserAccountID = -1;
let deprecatedCurrentUserEmail = '';
Onyx.connect({

Check warning on line 995 in src/libs/actions/IOU/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: (value) => {
currentUserEmail = value?.email ?? '';
userAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
deprecatedCurrentUserEmail = value?.email ?? '';
deprecatedUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
},
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 1004 in src/libs/actions/IOU/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.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
deprecatedCurrentUserPersonalDetails = value?.[deprecatedUserAccountID] ?? undefined;
},
});

let allReportActions: OnyxCollection<OnyxTypes.ReportActions>;
Onyx.connect({

Check warning on line 1012 in src/libs/actions/IOU/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_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -1054,11 +1054,11 @@
}

function getCurrentUserEmail(): string {
return currentUserEmail;
return deprecatedCurrentUserEmail;
}

function getUserAccountID(): number {
return userAccountID;
return deprecatedUserAccountID;
}

/**
Expand Down Expand Up @@ -1841,8 +1841,8 @@
reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID,
});
// eslint-disable-next-line @typescript-eslint/no-deprecated
const text = Localize.translateLocal('testDrive.employeeInviteMessage', personalDetailsList?.[userAccountID]?.firstName ?? '');
const textComment = buildOptimisticAddCommentReportAction({text, actorAccountID: userAccountID, reportActionID: testDriveIOUParams.testDriveCommentReportActionID});
const text = Localize.translateLocal('testDrive.employeeInviteMessage', personalDetailsList?.[deprecatedUserAccountID]?.firstName ?? '');
const textComment = buildOptimisticAddCommentReportAction({text, actorAccountID: deprecatedUserAccountID, reportActionID: testDriveIOUParams.testDriveCommentReportActionID});
textComment.reportAction.created = DateUtils.subtractMillisecondsFromDateTime(testDriveIOUParams.iouOptimisticParams.createdAction.created, 1);

optimisticData.push(
Expand Down Expand Up @@ -3079,6 +3079,7 @@
const cleanUpTransactionThreadReportOnyxData = getCleanUpTransactionThreadReportOnyxData({
transactionThreadID,
shouldDeleteTransactionThread,
currentUserAccountID: deprecatedUserAccountID,
});
optimisticData.push(...cleanUpTransactionThreadReportOnyxData.optimisticData);

Expand Down Expand Up @@ -3272,7 +3273,7 @@
personalDetails,
betas,
} = moneyRequestInformation;
const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams;
const {payeeAccountID = deprecatedUserAccountID, payeeEmail = deprecatedCurrentUserEmail, participant} = participantParams;
const {policy, policyCategories, policyTagList, policyRecentlyUsedCategories, policyRecentlyUsedTags} = policyParams;
const {
attendees,
Expand Down Expand Up @@ -3710,7 +3711,7 @@
betas,
isSelfTourViewed,
} = params;
const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams;
const {payeeAccountID = deprecatedUserAccountID, payeeEmail = deprecatedCurrentUserEmail, participant} = participantParams;
const {policy} = policyParams;
const {
comment,
Expand Down Expand Up @@ -3756,7 +3757,7 @@
if (!chatReport) {
const currentTime = DateUtils.getDBTime();
const selfDMReport = buildOptimisticSelfDMReport(currentTime);
const selfDMCreatedReportAction = buildOptimisticCreatedReportAction(currentUserEmail ?? '', currentTime);
const selfDMCreatedReportAction = buildOptimisticCreatedReportAction(deprecatedCurrentUserEmail ?? '', currentTime);
optimisticReportID = selfDMReport.reportID;
optimisticReportActionID = selfDMCreatedReportAction.reportActionID;
chatReport = selfDMReport;
Expand Down Expand Up @@ -6013,7 +6014,7 @@
return;
}

const participantAccountIDs = getReportRecipientAccountIDs(iouReport, userAccountID);
const participantAccountIDs = getReportRecipientAccountIDs(iouReport, deprecatedUserAccountID);
const payerAccountID = participantAccountIDs.at(0);

if (!payerAccountID) {
Expand Down Expand Up @@ -6069,8 +6070,8 @@
}

const participantParams = {
payeeAccountID: userAccountID,
payeeEmail: currentUserEmail,
payeeAccountID: deprecatedUserAccountID,
payeeEmail: deprecatedCurrentUserEmail,
participant: {
accountID: payerAccountID,
login: payerEmail,
Expand Down Expand Up @@ -6221,7 +6222,7 @@
// If a draft policy was used, then the CategorizeTrackedExpense command will create a real one
// so let's track that conversion here
if (isDraftPolicy) {
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, userAccountID);
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, deprecatedUserAccountID);
}
}

Expand Down Expand Up @@ -7562,7 +7563,7 @@
personalDetailListAction: oneOnOnePersonalDetailListAction,
},
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
currentUserEmailParam: deprecatedCurrentUserEmail,
hasViolations,
quickAction,
personalDetails,
Expand Down Expand Up @@ -7776,8 +7777,8 @@
moneyRequestReportID,
participantParams: {
participant,
payeeAccountID: userAccountID,
payeeEmail: currentUserEmail,
payeeAccountID: deprecatedUserAccountID,
payeeEmail: deprecatedCurrentUserEmail,
},
policyParams: {
policy,
Expand Down Expand Up @@ -8453,13 +8454,15 @@
isChatIOUReportArchived,
updatedReportPreviewAction,
shouldAddUpdatedReportPreviewActionToOnyxData = true,
currentUserAccountID,
}: {
transactionThreadID?: string;
shouldDeleteTransactionThread: boolean;
reportAction?: ReportAction;
isChatIOUReportArchived?: boolean;
updatedReportPreviewAction?: ReportAction;
shouldAddUpdatedReportPreviewActionToOnyxData?: boolean;
currentUserAccountID: number;
}) {
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>> = [];
const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>> = [];
Expand All @@ -8484,7 +8487,7 @@
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
participants: {
[userAccountID]: {
[currentUserAccountID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
Expand Down Expand Up @@ -8695,7 +8698,14 @@
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
value: {
hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, updatedIOUReport, currentUserEmail, currentUserAccountID, allTransactionViolationsParam, undefined),
hasOutstandingChildRequest: hasOutstandingChildRequest(
chatReport,
updatedIOUReport,
deprecatedCurrentUserEmail,
currentUserAccountID,
allTransactionViolationsParam,
undefined,
),
},
});
}
Expand All @@ -8714,7 +8724,14 @@
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
value: {
hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport?.reportID, currentUserEmail, currentUserAccountID, allTransactionViolationsParam, undefined),
hasOutstandingChildRequest: hasOutstandingChildRequest(
chatReport,
iouReport?.reportID,
deprecatedCurrentUserEmail,
currentUserAccountID,
allTransactionViolationsParam,
undefined,
),
iouReportID: null,
...optimisticLastReportData,
},
Expand All @@ -8732,7 +8749,13 @@
});
}

const cleanUpTransactionThreadReportOnyxData = getCleanUpTransactionThreadReportOnyxData({shouldDeleteTransactionThread, transactionThreadID, reportAction, isChatIOUReportArchived});
const cleanUpTransactionThreadReportOnyxData = getCleanUpTransactionThreadReportOnyxData({
shouldDeleteTransactionThread,
transactionThreadID,
reportAction,
isChatIOUReportArchived,
currentUserAccountID,
});
optimisticData.push(...cleanUpTransactionThreadReportOnyxData.optimisticData);

const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION>> = [
Expand Down Expand Up @@ -9445,7 +9468,7 @@
successData: policySuccessData,
params,
} = buildPolicyData({
policyOwnerEmail: currentUserEmail,
policyOwnerEmail: deprecatedCurrentUserEmail,
makeMeAdmin: true,
policyID: payerPolicyID,
currentUserAccountIDParam: currentUserAccountIDParam ?? CONST.DEFAULT_NUMBER_ID,
Expand Down Expand Up @@ -9519,7 +9542,7 @@
const optimisticChatReport = {
...chatReport,
lastReadTime: DateUtils.getDBTime(),
hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport?.reportID, currentUserEmail, currentUserAccountIDParam, allTransactionViolations, undefined),
hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport?.reportID, deprecatedCurrentUserEmail, currentUserAccountIDParam, allTransactionViolations, undefined),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ MINOR SUGGESTION

Naming Consistency: Consider standardizing on currentUserAccountID across all call sites (currently uses currentUserAccountIDParam in some places, which is existing codebase convention).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the scope of this project. Will update later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree with the suggestion too. I'm fine if you update it in later PRs.

iouReportID: null,
lastMessageText: getReportActionText(optimisticIOUReportAction),
lastMessageHtml: getReportActionHtml(optimisticIOUReportAction),
Expand Down Expand Up @@ -9767,7 +9790,7 @@
}

const managerID = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID;
const isCurrentUserManager = managerID === userAccountID;
const isCurrentUserManager = managerID === deprecatedUserAccountID;
const isOpenExpenseReport = isOpenExpenseReportReportUtils(iouReport);
const isApproved = isReportApproved({report: iouReport});
const iouSettled = isSettled(iouReport);
Expand Down Expand Up @@ -9827,12 +9850,12 @@
return false;
}
if (chatReport?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL) {
return chatReport?.invoiceReceiver?.accountID === userAccountID;
return chatReport?.invoiceReceiver?.accountID === deprecatedUserAccountID;
}
return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN;
}

const isPayer = isPayerReportUtils(userAccountID, currentUserEmail, iouReport, bankAccountList, policy, onlyShowPayElsewhere);
const isPayer = isPayerReportUtils(deprecatedUserAccountID, deprecatedCurrentUserEmail, iouReport, bankAccountList, policy, onlyShowPayElsewhere);

const {reimbursableSpend} = getMoneyRequestSpendBreakdown(iouReport);
const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : canBeAutoReimbursed(iouReport, policy);
Expand Down Expand Up @@ -9926,8 +9949,8 @@
policy,
getReportTransactions(iouReport?.reportID),
allTransactionViolations,
currentUserEmail,
userAccountID,
deprecatedCurrentUserEmail,
deprecatedUserAccountID,
getAllReportActions(iouReport?.reportID),
);
if (isWaitingSubmitFromCurrentUser) {
Expand Down Expand Up @@ -11355,7 +11378,7 @@
return;
}

const personalDetailsListValues = Object.values(getPersonalDetailsForAccountIDs(userAccountID ? [userAccountID] : [], personalDetailsList));
const personalDetailsListValues = Object.values(getPersonalDetailsForAccountIDs(deprecatedUserAccountID ? [deprecatedUserAccountID] : [], personalDetailsList));
const personalDetails = personalDetailsListValues.at(0);

let onboardingPurpose = introSelected?.choice;
Expand Down Expand Up @@ -11982,7 +12005,7 @@
return false;
}

const suggestedSearches = getSuggestedSearches(userAccountID);
const suggestedSearches = getSuggestedSearches(deprecatedUserAccountID);
const submitQueryJSON = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.SUBMIT].searchQueryJSON;
const approveQueryJSON = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.APPROVE].searchQueryJSON;
const unapprovedCashSimilarSearchHash = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CASH].similarSearchHash;
Expand Down Expand Up @@ -12504,7 +12527,7 @@
amount: transactionAmount,
currency: getCurrency(transaction),
comment,
payeeEmail: currentUserEmail,
payeeEmail: deprecatedCurrentUserEmail,
participants: [{accountID: report?.ownerAccountID}],
transactionID: transaction.transactionID,
existingTransactionThreadReportID: childReportID,
Expand Down Expand Up @@ -12766,7 +12789,7 @@
const shouldHaveOutstandingChildRequest = hasOutstandingChildRequest(
policyExpenseChat,
excludedReportID,
currentUserEmail,
deprecatedCurrentUserEmail,
currentUserAccountIDParam,
allTransactionViolations,
undefined,
Expand Down Expand Up @@ -12826,7 +12849,7 @@
type: CONST.VIOLATION_TYPES.WARNING,
data: {
comment: comment ?? '',
rejectedBy: currentUserEmail,
rejectedBy: deprecatedCurrentUserEmail,
rejectedDate: DateUtils.getDBTime(),
},
showInReview: true,
Expand Down Expand Up @@ -13337,7 +13360,15 @@
// bulk-edit comments are visible immediately while still offline.
let didCreateThreadInThisIteration = false;
if (!transactionThreadReportID && iouReport?.reportID) {
const optimisticTransactionThread = createTransactionThreadReport(introSelected, currentUserEmail, userAccountID, betas, iouReport, reportAction, transaction);
const optimisticTransactionThread = createTransactionThreadReport(
introSelected,
deprecatedCurrentUserEmail,
deprecatedUserAccountID,
betas,
iouReport,
reportAction,
transaction,
);
if (optimisticTransactionThread?.reportID) {
transactionThreadReportID = optimisticTransactionThread.reportID;
transactionThread = optimisticTransactionThread;
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/MergeTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ function mergeTransactionRequest({
transactionThreadID: sourceTransactionThreadReportID,
shouldDeleteTransactionThread,
reportAction: sourceIouAction,
currentUserAccountID: currentUserAccountIDParam,
});
optimisticSourceReportActionData.push(...cleanUpSourceTransactionThreadReportOnyxData.optimisticData);
successSourceReportActionData.push(...cleanUpSourceTransactionThreadReportOnyxData.successData);
Expand Down
Loading