Skip to content

Commit

Permalink
Flow clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mountiny committed Nov 2, 2023
1 parent cfe141b commit ae33908
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ const CONST = {
CREATED: 'CREATED',
IOU: 'IOU',
MODIFIEDEXPENSE: 'MODIFIEDEXPENSE',
MOVED: 'MOVED',
REIMBURSEMENTQUEUED: 'REIMBURSEMENTQUEUED',
RENAMED: 'RENAMED',
REPORTPREVIEW: 'REPORTPREVIEW',
Expand Down
2 changes: 1 addition & 1 deletion src/components/KYCWall/BaseKYCWall.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class KYCWall extends React.Component {
} else if (paymentMethod === CONST.PAYMENT_METHODS.DEBIT_CARD) {
Navigation.navigate(this.props.addDebitCardRoute);
} else if (paymentMethod === CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT) {
Policy.startCollectFlow(this.props.iouReport);
Policy.createWorkspaceFromIOUPayment(this.props.iouReport);
}
}

Expand Down
45 changes: 45 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,7 @@ function buildOptimisticIOUReportAction(
whisperedToAccountIDs: _.contains([CONST.IOU.RECEIPT_STATE.SCANREADY, CONST.IOU.RECEIPT_STATE.SCANNING], receipt.state) ? [currentUserAccountID] : [],
};
}

/**
* Builds an optimistic APPROVED report action with a randomly generated reportActionID.
*
Expand Down Expand Up @@ -2650,6 +2651,49 @@ function buildOptimisticApprovedReportAction(amount, currency, expenseReportID)
};
}

/**
* Builds an optimistic MOVED report action with a randomly generated reportActionID.
* This action is used when we move reports across workspaces.
*
* @param {String} fromPolicyID
* @param {String} toPolicyID
* @param {Number} newParentReportID
* @param {Number} movedReportID An ID of the report we are moveing across workspaces
*
* @returns {Object}
*/
function buildOptimisticMovedReportAction(fromPolicyID, toPolicyID, newParentReportID, movedReportID) {
const originalMessage = {
fromPolicyID,
toPolicyID,
newParentReportID,
movedReportID,
};

Check failure on line 2672 in src/libs/ReportUtils.js

View workflow job for this annotation

GitHub Actions / lint

'policyName' is assigned a value but never used
const policyName = getPolicyName(allReports[`${ONYXKEYS.COLLECTION.REPORT}${newParentReportID}`]);

return {
actionName: CONST.REPORT.ACTIONS.TYPE.MOVED,
actorAccountID: currentUserAccountID,
automatic: false,
avatar: lodashGet(currentUserPersonalDetails, 'avatar', UserUtils.getDefaultAvatarURL(currentUserAccountID)),
isAttachment: false,
originalMessage,
message: "moved report",
person: [
{
style: 'strong',
text: lodashGet(currentUserPersonalDetails, 'displayName', currentUserEmail),
type: 'TEXT',
},
],
reportActionID: NumberUtils.rand64(),
shouldShow: true,
created: DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};
}

/**
* Builds an optimistic SUBMITTED report action with a randomly generated reportActionID.
*
Expand Down Expand Up @@ -4216,6 +4260,7 @@ export {
buildOptimisticEditedTaskReportAction,
buildOptimisticIOUReport,
buildOptimisticApprovedReportAction,
buildOptimisticMovedReportAction,
buildOptimisticSubmittedReportAction,
buildOptimisticExpenseReport,
buildOptimisticIOUReportAction,
Expand Down
41 changes: 27 additions & 14 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ function buildOptimisticPolicyRecentlyUsedCategories(policyID, category) {
return lodashUnion([category], policyRecentlyUsedCategories);
}

function startCollectBottomUpFlow(iouReport, firstName, lastName) {
function createWorkspaceFromIOUPayment(iouReport) {
// This flow only works for IOU reports
if (!ReportUtils.isIOUReport(iouReport)) {
return;
Expand Down Expand Up @@ -1544,6 +1544,7 @@ function startCollectBottomUpFlow(iouReport, firstName, lastName) {
},
...employeeWorkspaceChat.onyxSuccessData,
];

const failureData = [
{
onyxMethod: Onyx.METHOD.SET,
Expand Down Expand Up @@ -1585,17 +1586,29 @@ function startCollectBottomUpFlow(iouReport, firstName, lastName) {
// Next we need to convert the IOU report to Expense report and clean up the DM chat
// Get the 1on1 chat where the request was originally made
const chatReportID = iouReport.chatReportID;

Check failure on line 1588 in src/libs/actions/Policy.js

View workflow job for this annotation

GitHub Actions / lint

'chatReportID' is assigned a value but never used
ReportUtils.getReport(iouReport.chatReportID);
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
value: {
...iouReport,
type: CONST.REPORT.TYPE.EXPENSE
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
value: iouReport,
});

const chatReport = ReportUtils.getReport(iouReport.chatReportID);

Check failure on line 1603 in src/libs/actions/Policy.js

View workflow job for this annotation

GitHub Actions / lint

'chatReport' is assigned a value but never used
const reportPreviewID = iouReport.parentReportActionID;

Check failure on line 1604 in src/libs/actions/Policy.js

View workflow job for this annotation

GitHub Actions / lint

'reportPreviewID' is assigned a value but never used

const membersData = [
{
accountID: employeeAccountID,
email: employeeEmail,
workspaceChatReportID: employeeWorkspaceChat.reportCreationData[employeeEmail].reportID,
workspaceChatCreatedReportActionID: employeeWorkspaceChat.reportCreationData[employeeEmail].reportActionID,
},
];
const memberData = {
accountID: Number(employeeAccountID),
email: employeeEmail,
workspaceChatReportID: Number(employeeWorkspaceChat.reportCreationData[employeeEmail].reportID),
workspaceChatCreatedReportActionID: Number(employeeWorkspaceChat.reportCreationData[employeeEmail].reportActionID),
};

API.write(
'CreateWorkspaceFromIOUPayment',
Expand All @@ -1604,7 +1617,7 @@ function startCollectBottomUpFlow(iouReport, firstName, lastName) {
announceChatReportID,
adminsChatReportID,
expenseChatReportID: workspaceChatReportID,
ownerEmail: sessionEmail,
ownerEmail: '',
makeMeAdmin: false,
policyName: workspaceName,
type: CONST.POLICY.TYPE.TEAM,
Expand All @@ -1614,11 +1627,11 @@ function startCollectBottomUpFlow(iouReport, firstName, lastName) {
customUnitID,
customUnitRateID,
iouReportID: iouReport.reportID,
membersData: JSON.stringify(membersData),
memberData: JSON.stringify(memberData),
reportActionID: 0,
},
{optimisticData, successData, failureData},
);
// Navigation.dismissModal(CONST.TEACHERS_UNITE.PUBLIC_ROOM_ID);
}

export {
Expand Down Expand Up @@ -1647,11 +1660,11 @@ export {
openWorkspaceMembersPage,
openWorkspaceInvitePage,
removeWorkspace,
createWorkspaceFromIOUPayment,
setWorkspaceInviteMembersDraft,
clearErrors,
dismissAddedWithPrimaryLoginMessages,
openDraftWorkspaceRequest,
buildOptimisticPolicyRecentlyUsedCategories,
createDraftInitialWorkspace,
startCollectBottomUpFlow,
};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function ReportActionItem(props) {
isHidden={isHidden}
style={[
_.contains(
[..._.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG), CONST.REPORT.ACTIONS.TYPE.IOU, CONST.REPORT.ACTIONS.TYPE.APPROVED],
[..._.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG), CONST.REPORT.ACTIONS.TYPE.IOU, CONST.REPORT.ACTIONS.TYPE.APPROVED, CONST.REPORT.ACTIONS.TYPE.MOVED],
props.action.actionName,
)
? styles.colorMuted
Expand Down

0 comments on commit ae33908

Please sign in to comment.