-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable RequestMoney in Workspace chats #18215
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e4650f7
pass policyID as param
luacmartins 3abcaf9
Merge branch 'main' into cmartins-allowMoneyRequestInWorkspaceChat
luacmartins b29954d
Merge branch 'main' into cmartins-allowMoneyRequestInWorkspaceChat
luacmartins 89344f6
rm conditional in requestMoney
luacmartins d869430
rm policyID param
luacmartins bb3e41f
rename iouReport to moneyRequestReport
luacmartins ce7ee19
update logic to create expense reports
luacmartins dca7a27
create buildOptimisticExpenseReport
luacmartins 10690a8
add logic for report name
luacmartins a49f3be
update outputCurrency
luacmartins 5664779
add ownerEmail
luacmartins 6a0fe8e
add comment
luacmartins 30db683
Merge main to resolve conflicts
mountiny 8981a01
Update src/libs/ReportUtils.js
mountiny a4bc328
resolve conflicts
luacmartins 1a8b032
add report name to IOU reports
luacmartins 5c8688d
rm participant from iou action message
luacmartins 9c57548
get policyExpenseChat from global create
luacmartins 60bdf66
add comment
luacmartins fc03c3c
Merge branch 'main' into cmartins-allowMoneyRequestInWorkspaceChat
luacmartins 8b9803f
resolve conflicts
luacmartins 8878eed
fix more styles
luacmartins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1019,16 +1019,16 @@ function buildOptimisticAddCommentReportAction(text, file) { | |
/** | ||
* Builds an optimistic IOU report with a randomly generated reportID | ||
* | ||
* @param {String} ownerEmail - Email of the person generating the IOU. | ||
* @param {String} userEmail - Email of the other person participating in the IOU. | ||
* @param {String} payeeEmail - Email of the person generating the IOU. | ||
* @param {String} payerEmail - Email of the other person participating in the IOU. | ||
* @param {Number} total - IOU amount in the smallest unit of the currency. | ||
* @param {String} chatReportID - Report ID of the chat where the IOU is. | ||
* @param {String} currency - IOU currency. | ||
* @param {Boolean} isSendingMoney - If we send money the IOU should be created as settled | ||
* | ||
* @returns {Object} | ||
*/ | ||
function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, currency, isSendingMoney = false) { | ||
function buildOptimisticIOUReport(payeeEmail, payerEmail, total, chatReportID, currency, isSendingMoney = false) { | ||
const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency); | ||
return { | ||
// If we're sending money, hasOutstandingIOU should be false | ||
|
@@ -1037,26 +1037,63 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu | |
cachedTotal: formattedTotal, | ||
chatReportID, | ||
currency, | ||
managerEmail: userEmail, | ||
ownerEmail, | ||
managerEmail: payerEmail, | ||
ownerEmail: payeeEmail, | ||
reportID: generateReportID(), | ||
state: CONST.REPORT.STATE.SUBMITTED, | ||
stateNum: isSendingMoney ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.PROCESSING, | ||
total, | ||
|
||
// We don't translate reportName because the server response is always in English | ||
reportName: `${payerEmail} owes ${formattedTotal}`, | ||
}; | ||
} | ||
|
||
/** | ||
* Builds an optimistic Expense report with a randomly generated reportID | ||
* | ||
* @param {String} chatReportID - Report ID of the PolicyExpenseChat where the Expense Report is | ||
* @param {String} policyID - The policy ID of the PolicyExpenseChat | ||
* @param {String} payeeEmail - Email of the employee (payee) | ||
* @param {Number} total - Amount in cents | ||
* @param {String} currency | ||
* | ||
* @returns {Object} | ||
*/ | ||
function buildOptimisticExpenseReport(chatReportID, policyID, payeeEmail, total, currency) { | ||
const policyName = getPolicyName(allReports[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]); | ||
const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency); | ||
|
||
// The expense report is always created with the policy's output currency | ||
const outputCurrency = lodashGet(allPolicies, [`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, 'outputCurrency'], CONST.CURRENCY.USD); | ||
|
||
return { | ||
reportID: generateReportID(), | ||
chatReportID, | ||
policyID, | ||
type: CONST.REPORT.TYPE.EXPENSE, | ||
ownerEmail: payeeEmail, | ||
hasOutstandingIOU: true, | ||
currency: outputCurrency, | ||
|
||
// We don't translate reportName because the server response is always in English | ||
reportName: `${policyName} owes ${formattedTotal}`, | ||
state: CONST.REPORT.STATE.SUBMITTED, | ||
stateNum: CONST.REPORT.STATE_NUM.PROCESSING, | ||
total, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {String} type - IOUReportAction type. Can be oneOf(create, delete, pay, split) | ||
* @param {String} type - IOUReportAction type. Can be oneOf(create, decline, cancel, pay, split) | ||
* @param {Number} total - IOU total in cents | ||
* @param {Array} participants - List of logins for the IOU participants, excluding the current user login | ||
* @param {String} comment - IOU comment | ||
* @param {String} currency - IOU currency | ||
* @param {String} paymentType - IOU paymentMethodType. Can be oneOf(Elsewhere, Expensify, PayPal.me) | ||
* @param {Boolean} isSettlingUp - Whether we are settling up an IOU | ||
* @returns {Array} | ||
*/ | ||
function getIOUReportActionMessage(type, total, participants, comment, currency, paymentType = '', isSettlingUp = false) { | ||
function getIOUReportActionMessage(type, total, comment, currency, paymentType = '', isSettlingUp = false) { | ||
const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency}); | ||
let paymentMethodMessage; | ||
switch (paymentType) { | ||
|
@@ -1108,14 +1145,13 @@ function getIOUReportActionMessage(type, total, participants, comment, currency, | |
* @param {Number} amount - IOU amount in cents. | ||
* @param {String} currency | ||
* @param {String} comment - User comment for the IOU. | ||
* @param {Array} participants - An array with participants details. | ||
* @param {String} transactionID | ||
* @param {String} [paymentType] - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify). | ||
* @param {String} [iouReportID] - Only required if the IOUReportActions type is oneOf(decline, cancel, pay). Generates a randomID as default. | ||
* @param {Boolean} [isSettlingUp] - Whether we are settling up an IOU. | ||
* @returns {Object} | ||
*/ | ||
function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, transactionID, paymentType = '', iouReportID = '', isSettlingUp = false) { | ||
function buildOptimisticIOUReportAction(type, amount, currency, comment, transactionID, paymentType = '', iouReportID = '', isSettlingUp = false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's discuss a resolution in slack: https://expensify.slack.com/archives/C01GTK53T8Q/p1683719211068359 |
||
const IOUReportID = iouReportID || generateReportID(); | ||
const parser = new ExpensiMark(); | ||
const commentText = getParsedComment(comment); | ||
|
@@ -1152,7 +1188,7 @@ function buildOptimisticIOUReportAction(type, amount, currency, comment, partici | |
avatar: lodashGet(currentUserPersonalDetails, 'avatar', getDefaultAvatar(currentUserEmail)), | ||
isAttachment: false, | ||
originalMessage, | ||
message: getIOUReportActionMessage(type, amount, participants, textForNewCommentDecoded, currency, paymentType, isSettlingUp), | ||
message: getIOUReportActionMessage(type, amount, textForNewCommentDecoded, currency, paymentType, isSettlingUp), | ||
person: [ | ||
{ | ||
style: 'strong', | ||
|
@@ -1858,6 +1894,7 @@ export { | |
buildOptimisticClosedReportAction, | ||
buildOptimisticCreatedReportAction, | ||
buildOptimisticIOUReport, | ||
buildOptimisticExpenseReport, | ||
buildOptimisticIOUReportAction, | ||
buildOptimisticAddCommentReportAction, | ||
shouldReportBeInOptionList, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
state
and thestateNum
are not the same, I think they should be the same right?I also think that
state
is not really used, maybe we should remove it.This is also inconsistent here:
copy/paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I dont think they should be same/identical, right? @luacmartins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I don't know why we have state and we don't seem to use state for anything in App, so I agree that we can remove it to make it less confusing.