Skip to content

Commit 66cbac1

Browse files
authored
Merge pull request Expensify#60482 from nkdengineer/fix/59752
Add system message on report with bottom up flow
2 parents 1f86bd1 + ba66599 commit 66cbac1

3 files changed

Lines changed: 41 additions & 4 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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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});

0 commit comments

Comments
 (0)