Skip to content

Commit dbcfb81

Browse files
committed
Merge branch 'main' into perf/report-transactions-derived-value
2 parents 8e32537 + 70224c4 commit dbcfb81

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

src/libs/API/parameters/CreateWorkspaceFromIOUPaymentParams.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type CreateWorkspaceFromIOUPaymentParams = {
1313
iouReportID: string;
1414
memberData: string;
1515
reportActionID: string | undefined;
16+
expenseMovedReportActionID: string | undefined;
1617
};
1718

1819
export default CreateWorkspaceFromIOUPaymentParams;

src/libs/ReportUtils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,7 @@ function getIconsForInvoiceReport(
32363236
*/
32373237
function getIcons(
32383238
report: OnyxInputOrEntry<Report>,
3239-
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
3239+
personalDetails: OnyxInputOrEntry<PersonalDetailsList> = allPersonalDetails,
32403240
defaultIcon: AvatarSource | null = null,
32413241
defaultName = '',
32423242
defaultAccountID = -1,
@@ -6388,7 +6388,14 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string,
63886388
* Builds an optimistic MOVED report action with a randomly generated reportActionID.
63896389
* This action is used when we move reports across workspaces.
63906390
*/
6391-
function buildOptimisticMovedReportAction(fromPolicyID: string | undefined, toPolicyID: string, newParentReportID: string, movedReportID: string, policyName: string): ReportAction {
6391+
function buildOptimisticMovedReportAction(
6392+
fromPolicyID: string | undefined,
6393+
toPolicyID: string,
6394+
newParentReportID: string,
6395+
movedReportID: string,
6396+
policyName: string,
6397+
isIouReport = false,
6398+
): ReportAction {
63926399
const originalMessage = {
63936400
fromPolicyID,
63946401
toPolicyID,
@@ -6398,8 +6405,10 @@ function buildOptimisticMovedReportAction(fromPolicyID: string | undefined, toPo
63986405

63996406
const movedActionMessage = [
64006407
{
6401-
html: `moved the report to the <a href='${CONST.NEW_EXPENSIFY_URL}r/${newParentReportID}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`,
6402-
text: `moved the report to the ${policyName} workspace`,
6408+
html: isIouReport
6409+
? `moved this <a href='${CONST.NEW_EXPENSIFY_URL}r/${movedReportID}' target='_blank' rel='noreferrer noopener'>report</a> to the <a href='${CONST.NEW_EXPENSIFY_URL}r/${newParentReportID}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`
6410+
: `moved this report to the <a href='${CONST.NEW_EXPENSIFY_URL}r/${newParentReportID}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`,
6411+
text: `moved this report to the ${policyName} workspace`,
64036412
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
64046413
},
64056414
];

src/libs/actions/Policy/Policy.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,33 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
29692969
}
29702970

29712971
// Create the MOVED report action and add it to the DM chat which indicates to the user where the report has been moved
2972-
const movedReportAction = ReportUtils.buildOptimisticMovedReportAction(oldPersonalPolicyID, policyID, memberData.workspaceChatReportID, iouReportID, workspaceName);
2972+
const movedReportAction = ReportUtils.buildOptimisticMovedReportAction(oldPersonalPolicyID, policyID, memberData.workspaceChatReportID, iouReportID, workspaceName, true);
2973+
2974+
const movedIouReportAction = ReportUtils.buildOptimisticMovedReportAction(oldPersonalPolicyID, policyID, memberData.workspaceChatReportID, iouReportID, workspaceName);
2975+
2976+
optimisticData.push({
2977+
onyxMethod: Onyx.METHOD.MERGE,
2978+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`,
2979+
value: {[movedIouReportAction.reportActionID]: movedIouReportAction},
2980+
});
2981+
2982+
successData.push({
2983+
onyxMethod: Onyx.METHOD.MERGE,
2984+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`,
2985+
value: {
2986+
[movedIouReportAction.reportActionID]: {
2987+
...movedIouReportAction,
2988+
pendingAction: null,
2989+
},
2990+
},
2991+
});
2992+
2993+
failureData.push({
2994+
onyxMethod: Onyx.METHOD.MERGE,
2995+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`,
2996+
value: {[movedIouReportAction.reportActionID]: null},
2997+
});
2998+
29732999
optimisticData.push({
29743000
onyxMethod: Onyx.METHOD.MERGE,
29753001
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oldChatReportID}`,
@@ -3026,6 +3052,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
30263052
iouReportID,
30273053
memberData: JSON.stringify(memberData),
30283054
reportActionID: movedReportAction.reportActionID,
3055+
expenseMovedReportActionID: movedIouReportAction.reportActionID,
30293056
};
30303057

30313058
API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData});

src/pages/iou/request/step/IOURequestStepParticipants.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {useOnyx} from 'react-native-onyx';
44
import FormHelpMessage from '@components/FormHelpMessage';
55
import useLocalize from '@hooks/useLocalize';
66
import useThemeStyles from '@hooks/useThemeStyles';
7+
import {setTransactionReport} from '@libs/actions/Transaction';
78
import {READ_COMMANDS} from '@libs/API/types';
89
import {isMobileSafari as isMobileSafariBrowser} from '@libs/Browser';
910
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
@@ -12,7 +13,7 @@ import HttpUtils from '@libs/HttpUtils';
1213
import {isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpenseIOUUtils, navigateToStartMoneyRequestStep} from '@libs/IOUUtils';
1314
import Navigation from '@libs/Navigation/Navigation';
1415
import Performance from '@libs/Performance';
15-
import {findSelfDMReportID, isInvoiceRoomWithID} from '@libs/ReportUtils';
16+
import {findSelfDMReportID, generateReportID, isInvoiceRoomWithID} from '@libs/ReportUtils';
1617
import {getRequestType, isPerDiemRequest} from '@libs/TransactionUtils';
1718
import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyRequestParticipantsSelector';
1819
import {
@@ -198,7 +199,7 @@ function IOURequestStepParticipants({
198199
}
199200

200201
// When a participant is selected, the reportID needs to be saved because that's the reportID that will be used in the confirmation step.
201-
selectedReportID.current = firstParticipantReportID ?? reportID;
202+
selectedReportID.current = firstParticipantReportID ?? generateReportID();
202203
},
203204
[iouType, transactions, isMovingTransactionFromTrackExpense, reportID, trackExpense],
204205
);
@@ -213,9 +214,13 @@ function IOURequestStepParticipants({
213214
setSplitShares(initialTransaction, initialTransaction.amount, initialTransaction.currency, participantAccountIDs);
214215
}
215216

217+
const newReportID = selectedReportID.current;
216218
transactions.forEach((transaction) => {
217219
setMoneyRequestTag(transaction.transactionID, '');
218220
setMoneyRequestCategory(transaction.transactionID, '');
221+
if (participants?.at(0)?.reportID !== newReportID) {
222+
setTransactionReport(transaction.transactionID, newReportID, true);
223+
}
219224
});
220225
if ((isCategorizing || isShareAction) && numberOfParticipants.current === 0) {
221226
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace();
@@ -245,7 +250,7 @@ function IOURequestStepParticipants({
245250
action,
246251
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
247252
initialTransactionID,
248-
selectedReportID.current || reportID,
253+
newReportID,
249254
);
250255

251256
const route = isCategorizing

0 commit comments

Comments
 (0)