Skip to content
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

Adapt Split Bill to workspace chats #24058

Merged
merged 13 commits into from
Aug 17, 2023
13 changes: 12 additions & 1 deletion src/components/ReportActionItem/IOUPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ function IOUPreview(props) {
const sessionAccountID = lodashGet(props.session, 'accountID', null);
const managerID = props.iouReport.managerID || '';
const ownerAccountID = props.iouReport.ownerAccountID || '';
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(props.chatReport);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add this chatReport to the propTypes and defaultProps


const participantAccountIDs = props.isBillSplit ? lodashGet(props.action, 'originalMessage.participantAccountIDs', []) : [managerID, ownerAccountID];
const participantAvatars = OptionsListUtils.getAvatarsForAccountIDs(participantAccountIDs, props.personalDetails);
if (isPolicyExpenseChat && props.isBillSplit) {
participantAvatars.push(ReportUtils.getWorkspaceIcon(props.chatReport));
}

// Pay button should only be visible to the manager of the report.
const isCurrentUserManager = managerID === sessionAccountID;
Expand Down Expand Up @@ -237,7 +242,10 @@ function IOUPreview(props) {
{props.isBillSplit && !_.isEmpty(participantAccountIDs) && (
<Text style={[styles.textLabel, styles.colorMuted, styles.ml1]}>
{props.translate('iou.amountEach', {
amount: CurrencyUtils.convertToDisplayString(IOUUtils.calculateAmount(participantAccountIDs.length - 1, requestAmount), requestCurrency),
amount: CurrencyUtils.convertToDisplayString(
IOUUtils.calculateAmount(isPolicyExpenseChat ? 1 : participantAccountIDs.length - 1, requestAmount),
requestCurrency,
),
})}
</Text>
)}
Expand Down Expand Up @@ -275,6 +283,9 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
},
iouReport: {
key: ({iouReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ function MoneyRequestAction(props) {
<RenderHTML html={`<comment>${props.translate('parentReportAction.deletedRequest')}</comment>`} />
) : (
<IOUPreview
iouReportID={props.requestReportID}
chatReportID={props.chatReportID}
iouReportID={props.requestReportID}
isBillSplit={isSplitBillAction}
action={props.action}
contextMenuAnchor={props.contextMenuAnchor}
Expand Down
28 changes: 25 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,22 @@ function isPolicyExpenseChat(report) {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT;
}

/** Wether the provided report belongs to a Control policy and is an epxense chat
* @param {Object} report
* @returns {Boolean}
*/
function isControlPolicyExpenseChat(report) {
return isPolicyExpenseChat(report) && getPolicyType(report, allPolicies) === CONST.POLICY.TYPE.CORPORATE;
}

/** Wether the provided report belongs to a Control policy and is an epxense report
* @param {Object} report
* @returns {Boolean}
*/
function isControlPolicyExpenseReport(report) {
return isExpenseReport(report) && getPolicyType(report, allPolicies) === CONST.POLICY.TYPE.CORPORATE;
}

/**
* Whether the provided report is a chat room
* @param {Object} report
Expand Down Expand Up @@ -1797,6 +1813,7 @@ function buildOptimisticIOUReportAction(
isSettlingUp = false,
isSendMoneyFlow = false,
receipt = {},
isPolicyExpenseChat = false,
) {
const IOUReportID = iouReportID || generateReportID();

Expand All @@ -1820,8 +1837,12 @@ function buildOptimisticIOUReportAction(

// IOUs of type split only exist in group DMs and those don't have an iouReport so we need to delete the IOUReportID key
if (type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT) {
delete originalMessage.IOUReportID;
originalMessage.participantAccountIDs = [currentUserAccountID, ..._.pluck(participants, 'accountID')];
if (isPolicyExpenseChat) {
youssef-lr marked this conversation as resolved.
Show resolved Hide resolved
originalMessage.participantAccountIDs = [currentUserAccountID];
} else {
delete originalMessage.IOUReportID;
originalMessage.participantAccountIDs = [currentUserAccountID, ..._.pluck(participants, 'accountID')];
}
}

return {
Expand Down Expand Up @@ -2668,7 +2689,7 @@ function getMoneyRequestOptions(report, reportParticipants, betas) {
// unless there are no participants at all (e.g. #admins room for a policy with only 1 admin)
// DM chats will have the Split Bill option only when there are at least 3 people in the chat.
// There is no Split Bill option for Workspace chats
if (isChatRoom(report) || (hasMultipleParticipants && !isPolicyExpenseChat(report))) {
if (isChatRoom(report) || (hasMultipleParticipants && !isPolicyExpenseChat(report)) || isControlPolicyExpenseChat(report)) {
return [CONST.IOU.MONEY_REQUEST_TYPE.SPLIT];
}

Expand Down Expand Up @@ -2975,6 +2996,7 @@ export {
getAllPolicyReports,
getIOUReportActionMessage,
getDisplayNameForParticipant,
getWorkspaceIcon,
isOptimisticPersonalDetail,
shouldDisableDetailPage,
isChatReport,
Expand Down
Loading