diff --git a/src/CONST.js b/src/CONST.js index 82528f555656..78a2c2a8896c 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -285,6 +285,9 @@ const CONST = { ANNOUNCE: '#announce', ADMINS: '#admins', }, + STATE: { + SUBMITTED: 'SUBMITTED', + }, STATE_NUM: { OPEN: 0, PROCESSING: 1, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d884c770e419..e48939c5e7e9 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -12,6 +12,7 @@ import md5 from './md5'; import Navigation from './Navigation/Navigation'; import ROUTES from '../ROUTES'; import * as NumberUtils from './NumberUtils'; +import * as NumberFormatUtils from './NumberFormatUtils'; let sessionEmail; Onyx.connect({ @@ -571,6 +572,29 @@ function hasReportNameError(report) { return !_.isEmpty(lodashGet(report, 'errorFields.reportName', {})); } +/* + * Builds an optimistic IOU report with a randomly generated reportID + */ +function buildOptimisticIOUReport(ownerEmail, recipientEmail, total, chatReportID, currency, locale) { + const formattedTotal = NumberFormatUtils.format(locale, + total, { + style: 'currency', + currency, + }); + return { + cachedTotal: formattedTotal, + chatReportID, + currency, + hasOutstandingIOU: true, + managerEmail: recipientEmail, + ownerEmail, + reportID: generateReportID(), + state: CONST.REPORT.STATE.SUBMITTED, + stateNum: 1, + total, + }; +} + /** * Builds an optimistic IOU reportAction object * @@ -672,6 +696,7 @@ export { navigateToDetailsPage, generateReportID, hasReportNameError, + buildOptimisticIOUReport, buildOptimisticIOUReportAction, isUnread, }; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 3d57b70b25ea..7755bdbd6a9e 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -811,7 +811,7 @@ function createWorkspace() { expenseChatReportID, expenseChatData, expenseReportActionData, - } = Report.createOptimisticWorkspaceChats(policyID, workspaceName); + } = Report.buildOptimisticWorkspaceChats(policyID, workspaceName); // We need to use makeRequestWithSideEffects as we try to redirect to the policy right after creation // The policy hasn't been merged in Onyx data at this point, leading to an intermittent Not Found screen diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 105ca3964226..80e2e7918421 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -585,7 +585,7 @@ function fetchAllReports( } /** - * Creates an optimistic chat report with a randomly generated reportID and as much information as we currently have + * Builds an optimistic chat report with a randomly generated reportID and as much information as we currently have * * @param {Array} participantList * @param {String} reportName @@ -596,7 +596,7 @@ function fetchAllReports( * @param {String} oldPolicyName * @returns {Object} */ -function createOptimisticChatReport( +function buildOptimisticChatReport( participantList, reportName = 'Chat Report', chatType = '', @@ -635,7 +635,7 @@ function createOptimisticChatReport( * @param {String} ownerEmail * @returns {Object} */ -function createOptimisticCreatedReportAction(ownerEmail) { +function buildOptimisticCreatedReportAction(ownerEmail) { return { 0: { actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, @@ -675,8 +675,8 @@ function createOptimisticCreatedReportAction(ownerEmail) { * @param {String} policyName * @returns {Object} */ -function createOptimisticWorkspaceChats(policyID, policyName) { - const announceChatData = createOptimisticChatReport( +function buildOptimisticWorkspaceChats(policyID, policyName) { + const announceChatData = buildOptimisticChatReport( [currentUserEmail], CONST.REPORT.WORKSPACE_CHAT_ROOMS.ANNOUNCE, CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE, @@ -686,15 +686,15 @@ function createOptimisticWorkspaceChats(policyID, policyName) { policyName, ); const announceChatReportID = announceChatData.reportID; - const announceReportActionData = createOptimisticCreatedReportAction(announceChatData.ownerEmail); + const announceReportActionData = buildOptimisticCreatedReportAction(announceChatData.ownerEmail); - const adminsChatData = createOptimisticChatReport([currentUserEmail], CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS, CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, policyID, null, false, policyName); + const adminsChatData = buildOptimisticChatReport([currentUserEmail], CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS, CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, policyID, null, false, policyName); const adminsChatReportID = adminsChatData.reportID; - const adminsReportActionData = createOptimisticCreatedReportAction(adminsChatData.ownerEmail); + const adminsReportActionData = buildOptimisticCreatedReportAction(adminsChatData.ownerEmail); - const expenseChatData = createOptimisticChatReport([currentUserEmail], '', CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, currentUserEmail, true, policyName); + const expenseChatData = buildOptimisticChatReport([currentUserEmail], '', CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID, currentUserEmail, true, policyName); const expenseChatReportID = expenseChatData.reportID; - const expenseReportActionData = createOptimisticCreatedReportAction(expenseChatData.ownerEmail); + const expenseReportActionData = buildOptimisticCreatedReportAction(expenseChatData.ownerEmail); return { announceChatReportID, @@ -1631,9 +1631,9 @@ export { readOldestAction, openReport, openPaymentDetailsPage, - createOptimisticWorkspaceChats, - createOptimisticChatReport, - createOptimisticCreatedReportAction, + buildOptimisticWorkspaceChats, + buildOptimisticChatReport, + buildOptimisticCreatedReportAction, updatePolicyRoomName, clearPolicyRoomNameErrors, };