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
9 changes: 5 additions & 4 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ const ROUTES = {

const queryParams = [];

// When we are opening a transaction thread but don't have the transaction report created yet we need to pass the moneyRequestReportActionID and transactionID so we can send those to the OpenReport call and create the transaction report
if (moneyRequestReportActionID && transactionID) {
queryParams.push(`moneyRequestReportActionID=${moneyRequestReportActionID}`);
// When we are opening a transaction thread but don't have the transaction thread report created yet we need to pass the moneyRequestReportActionID and transactionID so we can send those to the OpenReport call and create the transaction report
if (transactionID) {
queryParams.push(`transactionID=${transactionID}`);
}
if (moneyRequestReportActionID) {
queryParams.push(`moneyRequestReportActionID=${moneyRequestReportActionID}`);
}

const queryString = queryParams.length > 0 ? (`${baseRoute}?${queryParams.join('&')}` as const) : baseRoute;

return getUrlWithBackToParam(queryString, backTo);
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
}

// If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user
if (isTransactionItem && reportID === '0' && item.moneyRequestReportActionID) {
if (isTransactionItem && reportID === CONST.REPORT.UNREPORTED_REPORTID) {
reportID = generateReportID();
updateSearchResultsWithTransactionThreadReportID(hash, item.transactionID, reportID);
Navigation.navigate(
Expand Down
10 changes: 10 additions & 0 deletions src/libs/API/parameters/OpenReportParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ type OpenReportParams = {
* If this flag is set to true, api will return oldest first starting from the beginning of report.
*/
useTableReportView?: boolean;
/**
* The ID of the unreported transaction to create a thread for.
* Used when displaying unreported expenses that have no transaction thread associated with them.
*/
transactionID?: string;
Comment thread
marcaaron marked this conversation as resolved.
Resolved
/**
* The ID of the report action to create for an unreported transaction thread.
* Used when we need to create a money request report action on the selfDM for an unreported expense.
*/
moneyRequestPreviewReportActionID?: string;
};

export default OpenReportParams;
61 changes: 61 additions & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ import {
buildOptimisticEmptyReport,
buildOptimisticExportIntegrationAction,
buildOptimisticGroupChatReport,
buildOptimisticIOUReportAction,
buildOptimisticRenamedRoomReportAction,
buildOptimisticReportPreview,
buildOptimisticRoomDescriptionUpdatedReportAction,
canUserPerformWriteAction as canUserPerformWriteActionReportUtils,
completeShortMention,
findLastAccessedReport,
findSelfDMReportID,
formatReportLastMessageText,
generateReportID,
getAllPolicyReports,
Expand Down Expand Up @@ -415,6 +417,20 @@ Onyx.connect({
},
});

let allTransactions: OnyxCollection<Transaction> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
allTransactions = {};
return;
}

allTransactions = value;
},
});

let environment: EnvironmentType;
getEnvironment().then((env) => {
environment = env;
Expand Down Expand Up @@ -935,6 +951,7 @@ function openReport(
participantAccountIDList: number[] = [],
avatar?: File | CustomRNImageManipulatorResult,
temporaryShouldUseTableReportView = false,
transactionID?: string,
) {
if (!reportID) {
return;
Expand Down Expand Up @@ -1002,8 +1019,52 @@ function openReport(
emailList: participantLoginList ? participantLoginList.join(',') : '',
accountIDList: participantAccountIDList ? participantAccountIDList.join(',') : '',
parentReportActionID,
transactionID,
};

// This is a legacy transactions that doesn't have either a transaction thread or a money request preview
if (transactionID && !parentReportActionID) {
Comment thread
marcaaron marked this conversation as resolved.
Resolved
const transaction = allTransactions?.[transactionID];

if (transaction) {
const selfDMReportID = findSelfDMReportID();

if (selfDMReportID) {
const generatedReportActionID = rand64();
const optimisticParentAction = buildOptimisticIOUReportAction({
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
amount: Math.abs(transaction.amount),
currency: transaction.currency,
comment: transaction.comment?.comment ?? '',
participants: [{accountID: currentUserAccountID, login: currentUserEmail ?? ''}],
transactionID,
isOwnPolicyExpenseChat: true,
});

optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
parentReportID: selfDMReportID,
parentReportActionID: generatedReportActionID,
},
});

optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}${generatedReportActionID}`,
value: {
...optimisticParentAction,
reportActionID: generatedReportActionID,
childReportID: reportID,
},
});

parameters.moneyRequestPreviewReportActionID = generatedReportActionID;
}
}
}

// temporary flag will be removed once ReportScreen supports MoneyRequestReportView - https://github.com/Expensify/App/issues/57509
if (temporaryShouldUseTableReportView) {
parameters.useTableReportView = true;
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const moneyRequestReportActionID: string | undefined = route.params?.moneyRequestReportActionID;
const transactionID: string | undefined = route.params?.transactionID;

// When we get here with a moneyRequestReportActionID and a transactionID from the route it means we don't have the trasaction thread created yet
// When we get here with a moneyRequestReportActionID and a transactionID from the route it means we don't have the transaction thread created yet
Comment thread
marcaaron marked this conversation as resolved.
Resolved
// so we have to call OpenReport in a way that the transaction thread will be created and attached to the parentReportAction
if (moneyRequestReportActionID && transactionID && currentUserEmail) {
openReport(reportIDFromRoute, '', [currentUserEmail], undefined, moneyRequestReportActionID);
if (transactionID && currentUserEmail) {
openReport(reportIDFromRoute, '', [currentUserEmail], undefined, moneyRequestReportActionID, false, [], undefined, undefined, transactionID);
return;
}
openReport(reportIDFromRoute, reportActionIDFromRoute);
Expand Down