Skip to content

Commit

Permalink
Merge pull request #27172 from waterim/feat-26128-billable-toggle-ui
Browse files Browse the repository at this point in the history
Feat: Add Billable Toggle UI
  • Loading branch information
amyevans authored Sep 18, 2023
2 parents 5b24715 + caf0cf6 commit 9b302c9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {format} from 'date-fns';
import _ from 'underscore';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
import Text from './Text';
import styles from '../styles/styles';
import * as ReportUtils from '../libs/ReportUtils';
import * as OptionsListUtils from '../libs/OptionsListUtils';
Expand All @@ -30,6 +31,7 @@ import Image from './Image';
import useLocalize from '../hooks/useLocalize';
import * as ReceiptUtils from '../libs/ReceiptUtils';
import categoryPropTypes from './categoryPropTypes';
import Switch from './Switch';
import tagPropTypes from './tagPropTypes';
import ConfirmedRoute from './ConfirmedRoute';
import transactionPropTypes from './transactionPropTypes';
Expand Down Expand Up @@ -531,6 +533,16 @@ function MoneyRequestConfirmationList(props) {
disabled={didConfirm || props.isReadOnly}
/>
)}
{canUseTags && !lodashGet(props.policy, 'disabledFields.defaultBillable', true) && (
<View style={[styles.flexRow, styles.mb4, styles.justifyContentBetween, styles.alignItemsCenter, styles.ml5, styles.mr8]}>
<Text color={!props.iouIsBillable ? themeColors.textSupporting : undefined}>{translate('common.billable')}</Text>
<Switch
accessibilityLabel={translate('common.billable')}
isOn={props.iouIsBillable}
onToggle={props.onToggleBillable}
/>
</View>
)}
</>
)}
</OptionsSelector>
Expand Down Expand Up @@ -562,5 +574,8 @@ export default compose(
transaction: {
key: ({transactionID}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
},
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
}),
)(MoneyRequestConfirmationList);
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export default {
showMore: 'Show more',
merchant: 'Merchant',
category: 'Category',
billable: 'Billable',
tag: 'Tag',
receipt: 'Receipt',
replace: 'Replace',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export default {
showMore: 'Mostrar más',
merchant: 'Comerciante',
category: 'Categoría',
billable: 'Facturable',
tag: 'Etiqueta',
receipt: 'Recibo',
replace: 'Sustituir',
Expand Down
3 changes: 3 additions & 0 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Onyx.connect({
* @param {String} [filename]
* @param {String} [existingTransactionID] When creating a distance request, an empty transaction has already been created with a transactionID. In that case, the transaction here needs to have it's transactionID match what was already generated.
* @param {String} [category]
* @param {Boolean} [billable]
* @returns {Object}
*/
function buildOptimisticTransaction(
Expand All @@ -49,6 +50,7 @@ function buildOptimisticTransaction(
filename = '',
existingTransactionID = null,
category = '',
billable = false,
) {
// transactionIDs are random, positive, 64-bit numeric strings.
// Because JS can only handle 53-bit numbers, transactionIDs are strings in the front-end (just like reportActionID)
Expand Down Expand Up @@ -77,6 +79,7 @@ function buildOptimisticTransaction(
receipt,
filename,
category,
billable,
};
}

Expand Down
17 changes: 16 additions & 1 deletion src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function resetMoneyRequestInfo(id = '') {
receiptPath: '',
receiptSource: '',
transactionID: '',
billable: null,
});
}

Expand Down Expand Up @@ -341,6 +342,7 @@ function buildOnyxDataForMoneyRequest(
* @param {Object} [receipt]
* @param {String} [existingTransactionID]
* @param {String} [category]
* @param {Boolean} [billable]
* @returns {Object} data
* @returns {String} data.payerEmail
* @returns {Object} data.iouReport
Expand Down Expand Up @@ -368,6 +370,7 @@ function getMoneyRequestInformation(
receipt = undefined,
existingTransactionID = undefined,
category = undefined,
billable = undefined,
) {
const payerEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login);
const payerAccountID = Number(participant.accountID);
Expand Down Expand Up @@ -433,6 +436,7 @@ function getMoneyRequestInformation(
filename,
existingTransactionID,
category,
billable,
);

const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories
Expand Down Expand Up @@ -600,8 +604,9 @@ function createDistanceRequest(report, participant, comment, created, transactio
* @param {String} comment
* @param {Object} [receipt]
* @param {String} [category]
* @param {Boolean} [billable]
*/
function requestMoney(report, amount, currency, created, merchant, payeeEmail, payeeAccountID, participant, comment, receipt = undefined, category = undefined) {
function requestMoney(report, amount, currency, created, merchant, payeeEmail, payeeAccountID, participant, comment, receipt = undefined, category = undefined, billable = undefined) {
// If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;
Expand All @@ -618,6 +623,7 @@ function requestMoney(report, amount, currency, created, merchant, payeeEmail, p
receipt,
undefined,
category,
billable,
);

API.write(
Expand All @@ -638,6 +644,7 @@ function requestMoney(report, amount, currency, created, merchant, payeeEmail, p
reportPreviewReportActionID: reportPreviewAction.reportActionID,
receipt,
category,
billable,
},
onyxData,
);
Expand Down Expand Up @@ -1948,6 +1955,13 @@ function resetMoneyRequestCategory() {
Onyx.merge(ONYXKEYS.IOU, {category: ''});
}

/**
* @param {Boolean} billable
*/
function setMoneyRequestBillable(billable) {
Onyx.merge(ONYXKEYS.IOU, {billable});
}

/**
* @param {Object[]} participants
*/
Expand Down Expand Up @@ -2032,6 +2046,7 @@ export {
setMoneyRequestMerchant,
setMoneyRequestCategory,
resetMoneyRequestCategory,
setMoneyRequestBillable,
setMoneyRequestParticipants,
setMoneyRequestReceipt,
createEmptyTransaction,
Expand Down
13 changes: 13 additions & 0 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ function MoneyRequestConfirmPage(props) {
if (policyExpenseChat) {
Policy.openDraftWorkspaceRequest(policyExpenseChat.policyID);
}
// Verification to reset billable with a default value, when value in IOU was changed
if (typeof props.iou.billable !== 'boolean') {
IOU.setMoneyRequestBillable(lodashGet(props.policy, 'defaultBillable', false));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down Expand Up @@ -135,6 +139,7 @@ function MoneyRequestConfirmPage(props) {
trimmedComment,
receipt,
props.iou.category,
props.iou.billable,
);
},
[
Expand All @@ -146,6 +151,7 @@ function MoneyRequestConfirmPage(props) {
props.currentUserPersonalDetails.login,
props.currentUserPersonalDetails.accountID,
props.iou.category,
props.iou.billable,
],
);

Expand Down Expand Up @@ -295,6 +301,8 @@ function MoneyRequestConfirmPage(props) {
iouAmount={props.iou.amount}
iouComment={props.iou.comment}
iouCurrencyCode={props.iou.currency}
iouIsBillable={props.iou.billable}
onToggleBillable={IOU.setMoneyRequestBillable}
iouCategory={props.iou.category}
iouTag={props.iou.tag}
onConfirm={createTransaction}
Expand Down Expand Up @@ -364,4 +372,9 @@ export default compose(
key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`,
},
}),
withOnyx({
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
},
}),
)(MoneyRequestConfirmPage);

0 comments on commit 9b302c9

Please sign in to comment.