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

Allow split actions to be edited and implement IOU action completeSplitBill #29064

Merged
merged 68 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
8c8d3ff
Make SplitBillDetailsPage editable when receipt is scanning or SS failed
youssef-lr Oct 8, 2023
12b9043
Only show SmartScan fields splitting manually or editting a split
youssef-lr Oct 8, 2023
7fba50a
Create EditSplitBillPage
youssef-lr Oct 8, 2023
bd7c4b2
Create routes for EditSplitBillPage
youssef-lr Oct 8, 2023
4b95154
Configure inputs on split details page and link them with routes
youssef-lr Oct 8, 2023
8f3f426
Save split transaction edits to a draft transaction
youssef-lr Oct 9, 2023
60bca0e
Cleanup
youssef-lr Oct 9, 2023
914985f
Add useCallback dep
youssef-lr Oct 9, 2023
b3c4a3e
Add proptype
youssef-lr Oct 9, 2023
d62883c
Fix code removed by mistake
youssef-lr Oct 9, 2023
08d7577
Bug fix and lint
youssef-lr Oct 9, 2023
f516e3b
wip
youssef-lr Oct 9, 2023
5812464
Merge branch 'youssef_startSplitBill' into youssef_completeSplitBill
youssef-lr Oct 9, 2023
7950ce7
Merge branch 'youssef_startSplitBill' into youssef_completeSplitBill
youssef-lr Oct 10, 2023
4096fe2
Remove deprecated method and use withOnyx
youssef-lr Oct 10, 2023
dd69105
Add completeSplitBill action
youssef-lr Oct 10, 2023
46b6398
Send necessary params to completeSplitBill
youssef-lr Oct 10, 2023
f134e3f
Show right icon next to all fields in split details
youssef-lr Oct 10, 2023
01d37b7
Fix a few bugs
youssef-lr Oct 10, 2023
f495a29
Merge branch 'main' into youssef_completeSplitBill
youssef-lr Oct 10, 2023
5ad7a0a
Cleanup
youssef-lr Oct 10, 2023
322e20f
Update src/libs/TransactionUtils.ts
youssef-lr Oct 10, 2023
11883ed
Add nagivation to editting currency route
youssef-lr Oct 10, 2023
20be465
Add success & failure data to original transaction
youssef-lr Oct 10, 2023
9311976
Merge branch 'youssef_completeSplitBill' of github.com:Expensify/App …
youssef-lr Oct 10, 2023
1e71502
Cleanup splitOrRequestOptions
youssef-lr Oct 11, 2023
e3dc941
Fix typo
youssef-lr Oct 11, 2023
45d90fb
Apply suggestions from code review
youssef-lr Oct 11, 2023
3231d67
Add failure data reverting changes made in optimistic data
youssef-lr Oct 11, 2023
cc9a41c
Fix typo
youssef-lr Oct 11, 2023
b87312d
Optimize retrieval of Onyx data
youssef-lr Oct 11, 2023
6a8de3f
Optimize Onyx data more
youssef-lr Oct 11, 2023
c25228c
Address comments
youssef-lr Oct 11, 2023
ba0174c
Trim merchant
youssef-lr Oct 11, 2023
4e54b1b
Always navigate back to split details
youssef-lr Oct 11, 2023
63733b2
Fix jerky animation (might be reverted not sure if this is okay)
youssef-lr Oct 11, 2023
a518d61
Show error fields next to missing fields
youssef-lr Oct 11, 2023
cdf376b
Linting
youssef-lr Oct 11, 2023
95dc96f
Remove testing code
youssef-lr Oct 11, 2023
cc00910
Lint
youssef-lr Oct 11, 2023
5aad7a8
Delete draft split transaction in success data
youssef-lr Oct 11, 2023
be6be0f
Display form error when SmartScan fails
youssef-lr Oct 11, 2023
b274a70
Merge branch 'main' into youssef_completeSplitBill
youssef-lr Oct 11, 2023
56dc410
Rename param
youssef-lr Oct 11, 2023
2f976ef
Include current user in splits
youssef-lr Oct 11, 2023
f80a658
Lint
youssef-lr Oct 11, 2023
6a28df3
Dismiss modal and notify users after completing split bill
youssef-lr Oct 11, 2023
1e21419
Update translations
youssef-lr Oct 11, 2023
c7b5482
Use existing timeout logic for focusing text input
youssef-lr Oct 11, 2023
26a7311
Display form error when completing split bill with missing fields
youssef-lr Oct 11, 2023
48d684b
Bug fix
youssef-lr Oct 11, 2023
362a1ae
Use areRequiredFieldsEmpty
youssef-lr Oct 11, 2023
f8484ae
Fix lint and change form error when user completes split bill
youssef-lr Oct 11, 2023
583a607
Display field errors next to missing smartscan fields when use confirms
youssef-lr Oct 11, 2023
bf021a5
Cleanup
youssef-lr Oct 11, 2023
5867982
Apply suggestions from code review
youssef-lr Oct 11, 2023
7a6f4b2
Revert change, should be handled in follow up clean up
youssef-lr Oct 11, 2023
a740150
Fix isScanning state to also check for required fields being empty
youssef-lr Oct 11, 2023
f73674d
Fix areRequiredFieldsEmpty to check for non existent modified fields
youssef-lr Oct 11, 2023
0126d5f
Use non-interactive style instead of disabled style
youssef-lr Oct 11, 2023
9107a5a
Merge branch 'main' into youssef_completeSplitBill
youssef-lr Oct 11, 2023
272fb9b
Merge branch 'main' into youssef_completeSplitBill
youssef-lr Oct 11, 2023
5cd7d9b
Fix MenuItem console warning and checking for modified amount
youssef-lr Oct 11, 2023
95b3b9f
Fix checking for modifiedAmount
youssef-lr Oct 11, 2023
7945675
Keep merchant error if it equal partial marchant (none)
youssef-lr Oct 11, 2023
ddc2214
Merge branch 'main' into youssef_completeSplitBill
mountiny Oct 11, 2023
1a51105
Fix console warning
mountiny Oct 11, 2023
69c0df9
resolve conflicts
luacmartins Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const ONYXKEYS = {
REPORT_USER_IS_LEAVING_ROOM: 'reportUserIsLeavingRoom_',
SECURITY_GROUP: 'securityGroup_',
TRANSACTION: 'transactions_',
SPLIT_TRANSACTION_DRAFT: 'splitTransactionDraft_',
PRIVATE_NOTES_DRAFT: 'privateNotesDraft_',

// Manual request tab selector
Expand Down
8 changes: 8 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ export default {
route: 'r/:reportID/split/:reportActionID',
getRoute: (reportID: string, reportActionID: string) => `r/${reportID}/split/${reportActionID}`,
},
EDIT_SPLIT_BILL: {
route: `r/:reportID/split/:reportActionID/edit/:field`,
getRoute: (reportID: string, reportActionID: string, field: ValueOf<typeof CONST.EDIT_REQUEST_FIELD>) => `r/${reportID}/split/${reportActionID}/edit/${field}`,
},
EDIT_SPLIT_BILL_CURRENCY: {
route: 'r/:reportID/split/:reportActionID/edit/currency',
getRoute: (reportID: string, reportActionID: string, currency: string, backTo: string) => `r/${reportID}/split/${reportActionID}/edit/currency?currency=${currency}&backTo=${backTo}`,
},
TASK_TITLE: {
route: 'r/:reportID/title',
getRoute: (reportID: string) => `r/${reportID}/title`,
Expand Down
126 changes: 100 additions & 26 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ const propTypes = {
/** Whether the money request is a distance request */
isDistanceRequest: PropTypes.bool,

/** Whether the receipt associated with this report is being scanned */
isScanning: PropTypes.bool,
/** Whether we should show the amount, date, and merchant fields. */
shouldShowSmartScanFields: PropTypes.bool,

/** A flag for verifying that the current report is a sub-report of a workspace chat */
isPolicyExpenseChat: PropTypes.bool,
Expand Down Expand Up @@ -182,17 +182,19 @@ const defaultProps = {
transaction: {},
mileageRate: {unit: CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate: 0, currency: 'USD'},
isDistanceRequest: false,
isScanning: false,
shouldShowSmartScanFields: true,
isPolicyExpenseChat: false,
};

function MoneyRequestConfirmationList(props) {
// Destructure functions from props to pass it as a dependecy to useCallback/useMemo hooks.
// Prop functions pass props itself as a "this" value to the function which means they change every time props change.
const {onSendMoney, onConfirm, onSelectParticipant, transaction} = props;
const {onSendMoney, onConfirm, onSelectParticipant} = props;
const {translate, toLocaleDigit} = useLocalize();
const transaction = props.isEditingSplitBill ? props.draftTransaction || props.transaction : props.transaction;
Copy link
Contributor

Choose a reason for hiding this comment

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

@youssef-lr This was not added to the prop type definition for this component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on a follow up PR to clean things up, we wanted this merged quickly so we can test 🙏🏼


const isTypeRequest = props.iouType === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST;
const isSplitBill = props.iouType === CONST.IOU.MONEY_REQUEST_TYPE.SPLIT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should keep the name consistent and use isTypeSplit.


const {unit, rate, currency} = props.mileageRate;
const distance = lodashGet(transaction, 'routes.route0.distance', 0);
Expand All @@ -202,13 +204,9 @@ function MoneyRequestConfirmationList(props) {
const shouldShowCategories =
props.isPolicyExpenseChat && Permissions.canUseCategories(props.betas) && (props.iouCategory || OptionsListUtils.hasEnabledOptions(_.values(props.policyCategories)));

// A flag for showing SmartScan fields: date, merchant, and amount, only when we don't have a receiptPath (e.g. manual request)
// or in the split details page which is ReadOnly
const shouldShowSmartScanFields = (!props.receiptPath || props.isReadOnly) && !props.isScanning;

// A flag and a toggler for showing the rest of the form fields
const [shouldExpandFields, toggleShouldExpandFields] = useReducer((state) => !state, false);
const shouldShowAllFields = props.isDistanceRequest || shouldExpandFields || !shouldShowSmartScanFields;
const shouldShowAllFields = props.isDistanceRequest || shouldExpandFields || props.isEditingSplitBill || !props.shouldShowSmartScanFields;

// Fetches the first tag list of the policy
const policyTag = PolicyUtils.getTag(props.policyTags);
Expand All @@ -232,10 +230,30 @@ function MoneyRequestConfirmationList(props) {

const isFocused = useIsFocused();
const [formError, setFormError] = useState('');

const [didConfirm, setDidConfirm] = useState(false);
const [didConfirmSplit, setDidConfirmSplit] = useState(false);

const shouldDisplayFieldError = useMemo(() => {
if (!props.isEditingSplitBill) {
return false;
}

return (props.hasSmartScanFailed && TransactionUtils.hasMissingSmartscanFields(transaction)) || (didConfirmSplit && TransactionUtils.areRequiredFieldsEmpty(transaction));
}, [props.isEditingSplitBill, props.hasSmartScanFailed, transaction, didConfirmSplit]);

useEffect(() => {
if (shouldDisplayFieldError && props.hasSmartScanFailed) {
setFormError('iou.receiptScanningFailed');
return;
}
if (shouldDisplayFieldError && didConfirmSplit) {
setFormError('iou.error.genericSmartscanFailureMessage');
return;
}
// reset the form error whenever the screen gains or loses focus
setFormError('');
}, [isFocused]);
}, [isFocused, transaction, shouldDisplayFieldError, props.hasSmartScanFailed, didConfirmSplit]);

useEffect(() => {
if (!shouldCalculateDistanceAmount) {
Expand All @@ -262,25 +280,28 @@ function MoneyRequestConfirmationList(props) {
[props.iouAmount, props.iouCurrencyCode],
);

const [didConfirm, setDidConfirm] = useState(false);
// If completing a split bill fails, set didConfirm to false to allow the user to edit the fields again
if (props.isEditingSplitBill && didConfirm) {
setDidConfirm(false);
}
Comment on lines +290 to +293
Copy link
Contributor

Choose a reason for hiding this comment

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

If completing a split bill fails, we don't even set didConfirm to true. So this is not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I wasn't hiding the modal when I implemented this. Will remove.


const splitOrRequestOptions = useMemo(() => {
let text;
if (props.receiptPath && props.hasMultipleParticipants && props.iouAmount === 0) {
if (isSplitBill && props.iouAmount === 0) {
text = translate('iou.split');
} else if (props.receiptPath || isDistanceRequestWithoutRoute) {
} else if ((props.receiptPath && isTypeRequest) || isDistanceRequestWithoutRoute) {
text = translate('iou.request');
} else {
const translationKey = props.hasMultipleParticipants ? 'iou.splitAmount' : 'iou.requestAmount';
const translationKey = isSplitBill ? 'iou.splitAmount' : 'iou.requestAmount';
text = translate(translationKey, {amount: formattedAmount});
}
return [
{
text: text[0].toUpperCase() + text.slice(1),
value: props.hasMultipleParticipants ? CONST.IOU.MONEY_REQUEST_TYPE.SPLIT : CONST.IOU.MONEY_REQUEST_TYPE.REQUEST,
value: props.iouType,
},
];
}, [props.hasMultipleParticipants, props.iouAmount, props.receiptPath, translate, formattedAmount, isDistanceRequestWithoutRoute]);
}, [isSplitBill, isTypeRequest, props.iouType, props.iouAmount, props.receiptPath, formattedAmount, isDistanceRequestWithoutRoute, translate]);

const selectedParticipants = useMemo(() => _.filter(props.selectedParticipants, (participant) => participant.selected), [props.selectedParticipants]);
const payeePersonalDetails = useMemo(() => props.payeePersonalDetails || props.currentUserPersonalDetails, [props.payeePersonalDetails, props.currentUserPersonalDetails]);
Expand Down Expand Up @@ -417,11 +438,28 @@ function MoneyRequestConfirmationList(props) {
return;
}

if (props.isEditingSplitBill && TransactionUtils.areRequiredFieldsEmpty(transaction)) {
setDidConfirmSplit(true);
setFormError('iou.error.genericSmartscanFailureMessage');
return;
}

setDidConfirm(true);
onConfirm(selectedParticipants);
}
},
[selectedParticipants, onSendMoney, onConfirm, props.iouType, props.isDistanceRequest, isDistanceRequestWithoutRoute, props.iouCurrencyCode, props.iouAmount],
[
selectedParticipants,
onSendMoney,
onConfirm,
props.isEditingSplitBill,
props.iouType,
props.isDistanceRequest,
isDistanceRequestWithoutRoute,
props.iouCurrencyCode,
props.iouAmount,
transaction,
],
);

const footerContent = useMemo(() => {
Expand Down Expand Up @@ -510,23 +548,40 @@ function MoneyRequestConfirmationList(props) {
isAuthTokenRequired={!_.isEmpty(receiptThumbnail)}
/>
)}
{shouldShowSmartScanFields && (
{props.shouldShowSmartScanFields && (
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly && !props.isDistanceRequest}
title={formattedAmount}
description={translate('iou.amount')}
onPress={() => !props.isDistanceRequest && Navigation.navigate(ROUTES.MONEY_REQUEST_AMOUNT.getRoute(props.iouType, props.reportID))}
onPress={() => {
if (props.isDistanceRequest) {
return;
}
if (props.isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.AMOUNT));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_AMOUNT.getRoute(props.iouType, props.reportID));
}}
style={[styles.moneyRequestMenuItem, styles.mt2]}
titleStyle={styles.moneyRequestConfirmationAmount}
disabled={didConfirm || props.isReadOnly}
brickRoadIndicator={shouldDisplayFieldError && transaction.modifiedAmount === 0 && CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR}
error={shouldDisplayFieldError && transaction.modifiedAmount === 0 && translate('common.error.enterAmount')}
youssef-lr marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly}
shouldParseTitle
title={props.iouComment}
description={translate('common.description')}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_DESCRIPTION.getRoute(props.iouType, props.reportID))}
onPress={() => {
if (props.isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.DESCRIPTION));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_DESCRIPTION.getRoute(props.iouType, props.reportID));
}}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
disabled={didConfirm || props.isReadOnly}
Expand All @@ -549,15 +604,23 @@ function MoneyRequestConfirmationList(props) {
)}
{shouldShowAllFields && (
<>
{shouldShowSmartScanFields && (
{props.shouldShowSmartScanFields && (
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly && isTypeRequest}
shouldShowRightIcon={!props.isReadOnly}
title={props.iouCreated || format(new Date(), CONST.DATE.FNS_FORMAT_STRING)}
description={translate('common.date')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_DATE.getRoute(props.iouType, props.reportID))}
onPress={() => {
if (props.isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.DATE));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_DATE.getRoute(props.iouType, props.reportID));
}}
disabled={didConfirm || props.isReadOnly}
brickRoadIndicator={shouldDisplayFieldError && _.isEmpty(transaction.modifiedCreated) && CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR}
error={shouldDisplayFieldError && _.isEmpty(transaction.modifiedCreated) && translate('common.error.enterDate')}
/>
)}
{props.isDistanceRequest && (
Expand All @@ -571,15 +634,23 @@ function MoneyRequestConfirmationList(props) {
disabled={didConfirm || props.isReadOnly || !isTypeRequest}
/>
)}
{shouldShowSmartScanFields && (
{props.shouldShowSmartScanFields && (
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly && isTypeRequest}
shouldShowRightIcon={!props.isReadOnly}
title={props.iouMerchant}
description={translate('common.merchant')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_MERCHANT.getRoute(props.iouType, props.reportID))}
onPress={() => {
if (props.isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.MERCHANT));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_MERCHANT.getRoute(props.iouType, props.reportID));
}}
disabled={didConfirm || props.isReadOnly}
brickRoadIndicator={shouldDisplayFieldError && _.isEmpty(transaction.modifiedMerchant) && CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR}
error={shouldDisplayFieldError && _.isEmpty(transaction.modifiedMerchant) && translate('common.error.enterMerchant')}
/>
)}
{shouldShowCategories && (
Expand Down Expand Up @@ -640,6 +711,9 @@ export default compose(
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
selector: DistanceRequestUtils.getDefaultMileageRate,
},
draftTransaction: {
key: ({transactionID}) => `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`,
},
transaction: {
key: ({transactionID}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
},
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ export default {
receiptMissingDetails: 'Receipt missing details',
receiptStatusTitle: 'Scanning…',
receiptStatusText: "Only you can see this receipt when it's scanning. Check back later or enter the details now.",
receiptScanningFailed: 'Receipt scanning failed. Enter the details manually.',
requestCount: ({count, scanningReceipts = 0}: RequestCountParams) => `${count} requests${scanningReceipts > 0 ? `, ${scanningReceipts} scanning` : ''}`,
deleteRequest: 'Delete request',
deleteConfirmation: 'Are you sure that you want to delete this request?',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export default {
receiptMissingDetails: 'Recibo con campos vacíos',
receiptStatusTitle: 'Escaneando…',
receiptStatusText: 'Solo tú puedes ver este recibo cuando se está escaneando. Vuelve más tarde o introduce los detalles ahora.',
receiptScanningFailed: 'El escaneo de recibo ha fallado. Introduce los detalles manualmente.',
requestCount: ({count, scanningReceipts = 0}: RequestCountParams) => `${count} solicitudes${scanningReceipts > 0 ? `, ${scanningReceipts} escaneando` : ''}`,
deleteRequest: 'Eliminar pedido',
deleteConfirmation: '¿Estás seguro de que quieres eliminar este pedido?',
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator({

const SplitDetailsModalStackNavigator = createModalStackNavigator({
SplitDetails_Root: () => require('../../../pages/iou/SplitBillDetailsPage').default,
SplitDetails_Edit_Request: () => require('../../../pages/EditSplitBillPage').default,
SplitDetails_Edit_Currency: () => require('../../../pages/iou/IOUCurrencySelection').default,
});

const DetailsModalStackNavigator = createModalStackNavigator({
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ export default {
SplitDetails: {
screens: {
SplitDetails_Root: ROUTES.SPLIT_BILL_DETAILS.route,
SplitDetails_Edit_Request: ROUTES.EDIT_SPLIT_BILL.route,
SplitDetails_Edit_Currency: ROUTES.EDIT_SPLIT_BILL_CURRENCY.route,
},
},
Task_Details: {
Expand Down
11 changes: 9 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function areRequiredFieldsEmpty(transaction: Transaction): boolean {
/**
* Given the edit made to the money request, return an updated transaction object.
*/
function getUpdatedTransaction(transaction: Transaction, transactionChanges: TransactionChanges, isFromExpenseReport: boolean): Transaction {
function getUpdatedTransaction(transaction: Transaction, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, shouldUpdateReceiptState = true): Transaction {
// Only changing the first level fields so no need for deep clone now
const updatedTransaction = {...transaction};
let shouldStopSmartscan = false;
Expand Down Expand Up @@ -143,7 +143,13 @@ function getUpdatedTransaction(transaction: Transaction, transactionChanges: Tra
updatedTransaction.tag = transactionChanges.tag;
}

if (shouldStopSmartscan && transaction?.receipt && Object.keys(transaction.receipt).length > 0 && transaction?.receipt?.state !== CONST.IOU.RECEIPT_STATE.OPEN) {
if (
shouldUpdateReceiptState &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why this function handles updating a receipt, the function name is getUpdatedTransaction, but seems like the function has a side effect.

shouldStopSmartscan &&
transaction?.receipt &&
Object.keys(transaction.receipt).length > 0 &&
transaction?.receipt?.state !== CONST.IOU.RECEIPT_STATE.OPEN
) {
updatedTransaction.receipt.state = CONST.IOU.RECEIPT_STATE.OPEN;
}

Expand Down Expand Up @@ -396,6 +402,7 @@ export {
getValidWaypoints,
isDistanceRequest,
getWaypoints,
areRequiredFieldsEmpty,
hasMissingSmartscanFields,
getWaypointIndex,
waypointHasValidAddress,
Expand Down
Loading
Loading