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
8 changes: 2 additions & 6 deletions src/hooks/useDeleteTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
const [allPolicyRecentlyUsedCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {canBeMissing: true});
const [allReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserPersonalDetails.accountID;
const currentUserLogin = currentUserPersonalDetails.login ?? '';
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});

const {isBetaEnabled} = usePermissions();
Expand Down Expand Up @@ -129,8 +127,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
iouReport,
firstIOU: originalTransactionIouActions.at(0),
isASAPSubmitBetaEnabled: isBetaEnabled(CONST.BETAS.ASAP_SUBMIT),
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserLogin,
currentUserPersonalDetails,
transactionViolations,
});
}
Expand Down Expand Up @@ -175,8 +172,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
policy,
archivedReportsIdSet,
isBetaEnabled,
currentUserAccountID,
currentUserLogin,
currentUserPersonalDetails,
transactionViolations,
],
);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11064,7 +11064,7 @@ function createDraftTransactionAndNavigateToParticipantSelector(
const policyExpenseReport = getPolicyExpenseChat(currentUserAccountID, preferredPolicyID);

if (policyExpenseReport) {
setMoneyRequestParticipantsFromReport(transactionID, policyExpenseReport).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, policyExpenseReport, currentUserAccountID).then(() => {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.SUBMIT, CONST.IOU.TYPE.SUBMIT, transactionID, policyExpenseReport.reportID));
});
return;
Expand Down
31 changes: 14 additions & 17 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ type UpdateSplitTransactionsParams = {
iouReport: OnyxEntry<OnyxTypes.Report>;
firstIOU: OnyxEntry<OnyxTypes.ReportAction> | undefined;
isASAPSubmitBetaEnabled: boolean;
currentUserAccountIDParam: number;
currentUserEmailParam: string;
currentUserPersonalDetails: CurrentUserPersonalDetails;
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
};

Expand Down Expand Up @@ -11881,10 +11880,9 @@ function replaceReceipt({transactionID, file, source, transactionPolicyCategorie
* @param transactionID of the transaction to set the participants of
* @param report attached to the transaction
*/
function getMoneyRequestParticipantsFromReport(report: OnyxEntry<OnyxTypes.Report>): Participant[] {
function getMoneyRequestParticipantsFromReport(report: OnyxEntry<OnyxTypes.Report>, currentUserAccountID?: number): Participant[] {
// If the report is iou or expense report, we should get the chat report to set participant for request money
const chatReport = isMoneyRequestReportReportUtils(report) ? getReportOrDraftReport(report?.chatReportID) : report;
const currentUserAccountID = deprecatedCurrentUserPersonalDetails?.accountID;
const shouldAddAsReport = !isEmptyObject(chatReport) && isSelfDM(chatReport);
let participants: Participant[] = [];

Expand Down Expand Up @@ -11915,8 +11913,8 @@ function getMoneyRequestParticipantsFromReport(report: OnyxEntry<OnyxTypes.Repor
* @param report attached to the transaction
* @param participantsAutoAssigned whether participants were auto assigned
*/
function setMoneyRequestParticipantsFromReport(transactionID: string, report: OnyxEntry<OnyxTypes.Report>, participantsAutoAssigned = true) {
const participants = getMoneyRequestParticipantsFromReport(report);
function setMoneyRequestParticipantsFromReport(transactionID: string, report: OnyxEntry<OnyxTypes.Report>, currentUserAccountID?: number, participantsAutoAssigned = true) {
const participants = getMoneyRequestParticipantsFromReport(report, currentUserAccountID);
return Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
participants,
participantsAutoAssigned,
Expand Down Expand Up @@ -12705,8 +12703,8 @@ function updateLastLocationPermissionPrompt() {
Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, new Date().toISOString());
}

function setMultipleMoneyRequestParticipantsFromReport(transactionIDs: string[], reportValue: OnyxEntry<OnyxTypes.Report>) {
const participants = getMoneyRequestParticipantsFromReport(reportValue);
function setMultipleMoneyRequestParticipantsFromReport(transactionIDs: string[], reportValue: OnyxEntry<OnyxTypes.Report>, currentUserAccountID: number) {
const participants = getMoneyRequestParticipantsFromReport(reportValue, currentUserAccountID);
const updatedTransactions: Record<`${typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${string}`, NullishDeep<OnyxTypes.Transaction>> = {};
for (const transactionID of transactionIDs) {
updatedTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`] = {
Expand Down Expand Up @@ -14066,8 +14064,7 @@ function updateSplitTransactions({
iouReport,
firstIOU,
isASAPSubmitBetaEnabled,
currentUserAccountIDParam,
currentUserEmailParam,
currentUserPersonalDetails,
transactionViolations,
}: UpdateSplitTransactionsParams) {
const transactionReport = getReportOrDraftReport(transactionData?.reportID);
Expand All @@ -14079,7 +14076,7 @@ function updateSplitTransactions({
const originalTransactionDetails = getTransactionDetails(originalTransaction);

const policyTags = getPolicyTagsData(expenseReport?.policyID);
const participants = getMoneyRequestParticipantsFromReport(expenseReport);
const participants = getMoneyRequestParticipantsFromReport(expenseReport, currentUserPersonalDetails.accountID);
const splitExpenses = transactionData?.splitExpenses ?? [];

// List of all child transactions that have been created after split
Expand Down Expand Up @@ -14154,8 +14151,8 @@ function updateSplitTransactions({
const requestMoneyInformation = {
participantParams: {
participant: participants.at(0) ?? ({} as Participant),
payeeEmail: deprecatedCurrentUserPersonalDetails?.login ?? '',
payeeAccountID: deprecatedCurrentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
payeeEmail: currentUserPersonalDetails?.login ?? '',
payeeAccountID: currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
},
policyParams: {
policy,
Expand All @@ -14182,8 +14179,8 @@ function updateSplitTransactions({
parentChatReport: getReportOrDraftReport(getReportOrDraftReport(expenseReport?.chatReportID)?.parentReportID),
existingTransaction: originalTransaction,
isASAPSubmitBetaEnabled,
currentUserAccountIDParam,
currentUserEmailParam,
currentUserAccountIDParam: currentUserPersonalDetails?.accountID,
currentUserEmailParam: currentUserPersonalDetails?.login ?? '',
transactionViolations,
} as MoneyRequestInformationParams;

Expand Down Expand Up @@ -14219,8 +14216,8 @@ function updateSplitTransactions({
isSplitExpense: true,
currentReportActionID: currentReportAction?.reportActionID,
isASAPSubmitBetaEnabled,
currentUserAccountIDParam,
currentUserEmailParam,
currentUserAccountIDParam: currentUserPersonalDetails?.accountID,
currentUserEmailParam: currentUserPersonalDetails?.login ?? '',
transactionViolations,
});

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ function SearchPage({route}: SearchPageProps) {
const transactionReportID = shouldAutoReport ? activePolicyExpenseChat?.reportID : CONST.REPORT.UNREPORTED_REPORT_ID;
const setParticipantsPromises = newReceiptFiles.map((receiptFile) => {
setTransactionReport(receiptFile.transactionID, {reportID: transactionReportID}, true);
return setMoneyRequestParticipantsFromReport(receiptFile.transactionID, activePolicyExpenseChat);
return setMoneyRequestParticipantsFromReport(receiptFile.transactionID, activePolicyExpenseChat, currentUserPersonalDetails.accountID);
});
Promise.all(setParticipantsPromises).then(() =>
Navigation.navigate(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function SubmitDetailsPage({
});
}, [reportOrAccountID, policy, report, parentReport, currentDate, currentUserPersonalDetails]);

const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report);
const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) =>
participant?.accountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, reportAttributesDerived),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function useAttachmentUploadValidation({
});
const newTransactionID = newTransaction?.transactionID ?? CONST.IOU.OPTIMISTIC_TRANSACTION_ID;
setMoneyRequestReceipt(newTransactionID, source, file.name ?? '', true, file.type);
setMoneyRequestParticipantsFromReport(newTransactionID, report);
setMoneyRequestParticipantsFromReport(newTransactionID, report, currentUserPersonalDetails.accountID);
}
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
Expand Down
8 changes: 2 additions & 6 deletions src/pages/iou/SplitExpensePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
const splitFieldDataFromChildTransactions = useMemo(() => childTransactions.map((currentTransaction) => initSplitExpenseItemData(currentTransaction)), [childTransactions]);
const splitFieldDataFromOriginalTransaction = useMemo(() => initSplitExpenseItemData(transaction), [transaction]);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserPersonalDetails.accountID;
const currentUserLogin = currentUserPersonalDetails.login ?? '';
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});

const {isBetaEnabled} = usePermissions();
Expand Down Expand Up @@ -193,8 +191,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
iouReport,
firstIOU: iouActions.at(0),
isASAPSubmitBetaEnabled: isBetaEnabled(CONST.BETAS.ASAP_SUBMIT),
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserLogin,
currentUserPersonalDetails,
transactionViolations,
});
}, [
Expand All @@ -218,14 +215,13 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
policyRecentlyUsedCategories,
iouReport,
iouActions,
currentUserPersonalDetails,
splitFieldDataFromOriginalTransaction,
translate,
transactionID,
transactionDetails?.currency,
isBetaEnabled,
transactionViolations,
currentUserAccountID,
currentUserLogin,
]);

const onSplitExpenseAmountChange = useCallback(
Expand Down
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function IOURequestStepAmount({
// to the confirm step.
// If the user is started this flow using the Create expense option (combined submit/track flow), they should be redirected to the participants page.
if (report?.reportID && !isReportArchived && iouType !== CONST.IOU.TYPE.CREATE) {
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
const selectedParticipants = getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) => {
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, reportAttributesDerived);
Expand Down Expand Up @@ -255,7 +255,7 @@ function IOURequestStepAmount({
const participantAccountIDs = Object.keys(report.participants).map((accountID) => Number(accountID));
setSplitShares(transaction, amountInSmallestCurrencyUnits, currency || CONST.CURRENCY.USD, participantAccountIDs);
}
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, report, currentUserPersonalDetails.accountID).then(() => {
navigateToConfirmationPage();
});
return;
Expand All @@ -276,7 +276,7 @@ function IOURequestStepAmount({

const resetToDefaultWorkspace = () => {
setTransactionReport(transactionID, {reportID: transactionReportID}, true);
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat, currentUserPersonalDetails.accountID).then(() => {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, transactionID, activePolicyExpenseChat?.reportID));
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepDestination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function IOURequestStepDestination({
const shouldAutoReport = !!policy?.autoReporting || !!personalPolicy?.autoReporting || action !== CONST.IOU.ACTION.CREATE || !transaction?.isFromGlobalCreate;
const transactionReportID = shouldAutoReport ? policyExpenseReport?.reportID : CONST.REPORT.UNREPORTED_REPORT_ID;
setTransactionReport(transactionID, {reportID: transactionReportID}, true);
setMoneyRequestParticipantsFromReport(transactionID, policyExpenseReport);
setMoneyRequestParticipantsFromReport(transactionID, policyExpenseReport, accountID);
setCustomUnitID(transactionID, customUnit.customUnitID);
setMoneyRequestCategory(transactionID, customUnit?.defaultCategory ?? '');
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function IOURequestStepDistance({
// to the confirm step.
// If the user started this flow using the Create expense option (combined submit/track flow), they should be redirected to the participants page.
if (report?.reportID && !isArchivedReport(reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) {
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
const selectedParticipants = getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) => {
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, reportAttributesDerived);
Expand Down Expand Up @@ -381,7 +381,7 @@ function IOURequestStepDistance({
});
return;
}
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, report, currentUserPersonalDetails.accountID).then(() => {
navigateToConfirmationPage();
});
return;
Expand All @@ -406,7 +406,7 @@ function IOURequestStepDistance({
});
setTransactionReport(transactionID, {reportID: transactionReportID}, true);
setCustomUnitRateID(transactionID, rateID);
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat, currentUserPersonalDetails.accountID).then(() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
CONST.IOU.ACTION.CREATE,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistanceManual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function IOURequestStepDistanceManual({
}

if (report?.reportID && !isArchivedReport(reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) {
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
const selectedParticipants = getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) => {
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant, reportAttributesDerived);
Expand Down Expand Up @@ -237,7 +237,7 @@ function IOURequestStepDistanceManual({
});
return;
}
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, report, currentUserPersonalDetails.accountID).then(() => {
navigateToConfirmationPage();
});
return;
Expand All @@ -262,7 +262,7 @@ function IOURequestStepDistanceManual({
});
setTransactionReport(transactionID, {reportID: transactionReportID}, true);
setCustomUnitRateID(transactionID, rateID);
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat, currentUserPersonalDetails.accountID).then(() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
CONST.IOU.ACTION.CREATE,
Expand Down
Loading