Skip to content

Commit

Permalink
Merge pull request #27875 from waterim/feat-26793-billable-edit
Browse files Browse the repository at this point in the history
Feat: Editable billable flag
  • Loading branch information
amyevans authored Sep 27, 2023
2 parents 4589844 + 8cb78cc commit 9b7d09e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
21 changes: 18 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import PropTypes from 'prop-types';
import reportPropTypes from '../../pages/reportPropTypes';
import ONYXKEYS from '../../ONYXKEYS';
import ROUTES from '../../ROUTES';
import Permissions from '../../libs/Permissions';
import Navigation from '../../libs/Navigation/Navigation';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes} from '../withCurrentUserPersonalDetails';
import compose from '../../libs/compose';
import Permissions from '../../libs/Permissions';
import MenuItemWithTopDescription from '../MenuItemWithTopDescription';
import styles from '../../styles/styles';
import themeColors from '../../styles/themes/default';
import * as ReportUtils from '../../libs/ReportUtils';
import * as IOU from '../../libs/actions/IOU';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
import * as StyleUtils from '../../styles/StyleUtils';
Expand All @@ -28,6 +30,8 @@ import * as ReceiptUtils from '../../libs/ReceiptUtils';
import useWindowDimensions from '../../hooks/useWindowDimensions';
import transactionPropTypes from '../transactionPropTypes';
import Image from '../Image';
import Text from '../Text';
import Switch from '../Switch';
import ReportActionItemImage from './ReportActionItemImage';
import * as TransactionUtils from '../../libs/TransactionUtils';
import OfflineWithFeedback from '../OfflineWithFeedback';
Expand Down Expand Up @@ -73,10 +77,9 @@ const defaultProps = {
policyTags: {},
};

function MoneyRequestView({report, betas, parentReport, policyCategories, shouldShowHorizontalRule, transaction, policyTags}) {
function MoneyRequestView({report, betas, parentReport, policyCategories, shouldShowHorizontalRule, transaction, policyTags, policy}) {
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();

const parentReportAction = ReportActionsUtils.getParentReportAction(report);
const moneyRequestReport = parentReport;
const {
Expand All @@ -85,6 +88,7 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should
currency: transactionCurrency,
comment: transactionDescription,
merchant: transactionMerchant,
billable: transactionBillable,
category: transactionCategory,
tag: transactionTag,
} = ReportUtils.getTransactionDetails(transaction);
Expand All @@ -104,6 +108,7 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should
// Flags for showing categories and tags
const shouldShowCategory = isPolicyExpenseChat && Permissions.canUseCategories(betas) && (transactionCategory || OptionsListUtils.hasEnabledOptions(lodashValues(policyCategories)));
const shouldShowTag = isPolicyExpenseChat && Permissions.canUseTags(betas) && (transactionTag || OptionsListUtils.hasEnabledOptions(lodashValues(policyTagsList)));
const shouldShowBillable = isPolicyExpenseChat && Permissions.canUseTags(betas) && (transactionBillable || !lodashGet(policy, 'disabledFields.defaultBillable', true));

let description = `${translate('iou.amount')}${translate('iou.cash')}`;
if (isSettled) {
Expand Down Expand Up @@ -229,6 +234,16 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should
/>
</OfflineWithFeedback>
)}
{shouldShowBillable && (
<View style={[styles.flexRow, styles.mb4, styles.justifyContentBetween, styles.alignItemsCenter, styles.ml5, styles.mr8]}>
<Text color={!transactionBillable ? themeColors.textSupporting : undefined}>{translate('common.billable')}</Text>
<Switch
accessibilityLabel={translate('common.billable')}
isOn={transactionBillable}
onToggle={(value) => IOU.editMoneyRequest(transaction.transactionID, report.reportID, {billable: value})}
/>
</View>
)}
<SpacerView
shouldShow={shouldShowHorizontalRule}
style={[shouldShowHorizontalRule ? styles.reportHorizontalRule : {}]}
Expand Down
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 {
merchant: 'Merchant',
category: 'Category',
billable: 'Billable',
nonBillable: 'Non-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 {
merchant: 'Comerciante',
category: 'Categoría',
billable: 'Facturable',
nonBillable: 'No facturable',
tag: 'Etiqueta',
receipt: 'Recibo',
replace: 'Sustituir',
Expand Down
12 changes: 12 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ function getTransactionDetails(transaction) {
comment: TransactionUtils.getDescription(transaction),
merchant: TransactionUtils.getMerchant(transaction),
category: TransactionUtils.getCategory(transaction),
billable: TransactionUtils.getBillable(transaction),
tag: TransactionUtils.getTag(transaction),
};
}
Expand Down Expand Up @@ -1615,6 +1616,11 @@ function getModifiedExpenseMessage(reportAction) {
if (hasModifiedTag) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.tag, reportActionOriginalMessage.oldTag, Localize.translateLocal('common.tag'), true);
}

const hasModifiedBillable = _.has(reportActionOriginalMessage, 'oldBillable') && _.has(reportActionOriginalMessage, 'billable');
if (hasModifiedBillable) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.billable, reportActionOriginalMessage.oldBillable, Localize.translateLocal('iou.request'), true);
}
}

/**
Expand Down Expand Up @@ -1665,6 +1671,12 @@ function getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, i
originalMessage.tag = transactionChanges.tag;
}

if (_.has(transactionChanges, 'billable')) {
const oldBillable = TransactionUtils.getBillable(oldTransaction);
originalMessage.oldBillable = oldBillable ? Localize.translateLocal('common.billable').toLowerCase() : Localize.translateLocal('common.nonBillable').toLowerCase();
originalMessage.billable = transactionChanges.billable ? Localize.translateLocal('common.billable').toLowerCase() : Localize.translateLocal('common.nonBillable').toLowerCase();
}

return originalMessage;
}

Expand Down
16 changes: 16 additions & 0 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep
shouldStopSmartscan = true;
}

if (_.has(transactionChanges, 'billable')) {
updatedTransaction.billable = transactionChanges.billable;
}

if (_.has(transactionChanges, 'category')) {
updatedTransaction.category = transactionChanges.category;
}
Expand All @@ -165,6 +169,7 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep
...(_.has(transactionChanges, 'amount') && {amount: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(_.has(transactionChanges, 'currency') && {currency: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(_.has(transactionChanges, 'merchant') && {merchant: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(_.has(transactionChanges, 'billable') && {billable: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(_.has(transactionChanges, 'category') && {category: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(_.has(transactionChanges, 'tag') && {tag: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
};
Expand Down Expand Up @@ -258,6 +263,16 @@ function getCategory(transaction) {
return lodashGet(transaction, 'category', '');
}

/**
* Return the billable field from the transaction. This "billable" field has no "modified" complement.
*
* @param {Object} transaction
* @return {Boolean}
*/
function getBillable(transaction) {
return lodashGet(transaction, 'billable', false);
}

/**
* Return the tag from the transaction. This "tag" field has no "modified" complement.
*
Expand Down Expand Up @@ -414,6 +429,7 @@ export {
getMerchant,
getCreated,
getCategory,
getBillable,
getTag,
getLinkedTransaction,
getAllReportTransactions,
Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,9 @@ function getMoneyRequestInformation(
* @param {Number} amount
* @param {String} currency
* @param {String} merchant
* @param {Boolean} [billable]
*/
function createDistanceRequest(report, participant, comment, created, transactionID, category, tag, amount, currency, merchant) {
function createDistanceRequest(report, participant, comment, created, transactionID, category, tag, amount, currency, merchant, billable) {
const optimisticReceipt = {
source: ReceiptGeneric,
state: CONST.IOU.RECEIPT_STATE.OPEN,
Expand All @@ -624,6 +625,7 @@ function createDistanceRequest(report, participant, comment, created, transactio
transactionID,
category,
tag,
billable,
);
API.write(
'CreateDistanceRequest',
Expand All @@ -640,6 +642,7 @@ function createDistanceRequest(report, participant, comment, created, transactio
created,
category,
tag,
billable,
},
onyxData,
);
Expand Down Expand Up @@ -1224,6 +1227,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
created: null,
currency: null,
merchant: null,
billable: null,
category: null,
tag: null,
},
Expand Down Expand Up @@ -1272,7 +1276,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
];

// STEP 6: Call the API endpoint
const {created, amount, currency, comment, merchant, category, tag} = ReportUtils.getTransactionDetails(updatedTransaction);
const {created, amount, currency, comment, merchant, category, billable, tag} = ReportUtils.getTransactionDetails(updatedTransaction);
API.write(
'EditMoneyRequest',
{
Expand All @@ -1284,6 +1288,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
comment,
merchant,
category,
billable,
tag,
},
{optimisticData, successData, failureData},
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ function MoneyRequestConfirmPage(props) {
props.iou.amount,
props.iou.currency,
props.iou.merchant,
props.iou.billable,
);
},
[props.report, props.iou.created, props.iou.transactionID, props.iou.category, props.iou.tag, props.iou.amount, props.iou.currency, props.iou.merchant],
[props.report, props.iou.created, props.iou.transactionID, props.iou.category, props.iou.tag, props.iou.amount, props.iou.currency, props.iou.merchant, props.iou.billable],
);

const createTransaction = useCallback(
Expand Down

0 comments on commit 9b7d09e

Please sign in to comment.