-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Remove NewRequestAmountPage #35833
Remove NewRequestAmountPage #35833
Changes from 11 commits
6364ee9
02a8a18
a719511
ae15fd5
0f990c9
df76562
0a4f634
8b9ff58
1301dc4
b10eb48
15d6a41
d842adc
fe2e60c
e793792
d11cf73
a20a9e5
556ef3a
78195ae
db1aa3f
8982f33
11da8b2
77f6451
39c365a
3135246
40e301f
f7a76c6
744f3fb
8db0d5c
a588842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {useFocusEffect} from '@react-navigation/native'; | ||
import lodashGet from 'lodash/get'; | ||
import lodashIsEmpty from 'lodash/isEmpty'; | ||
import PropTypes from 'prop-types'; | ||
import React, {useCallback, useEffect, useRef} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
|
@@ -34,6 +35,9 @@ const propTypes = { | |
/** The transaction object being modified in Onyx */ | ||
transaction: transactionPropTypes, | ||
|
||
/** The draft transaction that holds data to be persisted on the current transaction */ | ||
splitDraftTransaction: transactionPropTypes, | ||
|
||
/** The policy of the report */ | ||
policy: PropTypes.shape({ | ||
/** | ||
|
@@ -56,6 +60,7 @@ const propTypes = { | |
const defaultProps = { | ||
report: {}, | ||
transaction: {}, | ||
splitDraftTransaction: {}, | ||
policy: {}, | ||
}; | ||
|
||
|
@@ -67,9 +72,10 @@ const getTaxAmount = (transaction, defaultTaxValue, amount) => { | |
function IOURequestStepAmount({ | ||
report, | ||
route: { | ||
params: {iouType, reportID, transactionID, backTo}, | ||
params: {iouType, reportID, transactionID, backTo, action}, | ||
}, | ||
transaction, | ||
splitDraftTransaction, | ||
transaction: {currency}, | ||
policy, | ||
}) { | ||
|
@@ -79,6 +85,10 @@ function IOURequestStepAmount({ | |
const isSaveButtonPressed = useRef(false); | ||
const originalCurrency = useRef(null); | ||
const iouRequestType = getRequestType(transaction); | ||
const isEditing = action === CONST.IOU.ACTION.EDIT; | ||
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; | ||
const isEditingSplitBill = isEditing && isSplitBill; | ||
const {amount: transactionAmount} = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction); | ||
|
||
const taxRates = lodashGet(policy, 'taxRates', {}); | ||
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)); | ||
|
@@ -154,21 +164,40 @@ function IOURequestStepAmount({ | |
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, reportID)); | ||
}; | ||
|
||
const saveAmountAndCurrency = ({amount}) => { | ||
const newAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); | ||
|
||
// If the value hasn't changed, don't request to save changes on the server and just close the modal | ||
if (newAmount === TransactionUtils.getAmount(transaction) && currency === TransactionUtils.getCurrency(transaction)) { | ||
Navigation.dismissModal(); | ||
return; | ||
} | ||
|
||
if (isSplitBill) { | ||
IOU.setDraftSplitTransaction(transactionID, {amount: newAmount, currency}); | ||
Navigation.goBack(backTo); | ||
return; | ||
} | ||
|
||
IOU.updateMoneyRequestAmountAndCurrency(transactionID, reportID, currency, newAmount); | ||
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. In the creating flow, we only should set new value to ONYX instead of call API to BE |
||
Navigation.dismissModal(); | ||
}; | ||
|
||
return ( | ||
<StepScreenWrapper | ||
headerTitle={translate('iou.amount')} | ||
onBackButtonPress={navigateBack} | ||
testID={IOURequestStepAmount.displayName} | ||
shouldShowWrapper={Boolean(backTo)} | ||
shouldShowWrapper={Boolean(backTo || isEditing)} | ||
includeSafeAreaPaddingBottom | ||
> | ||
<MoneyRequestAmountForm | ||
isEditing={Boolean(backTo)} | ||
isEditing={Boolean(backTo || isEditing)} | ||
currency={currency} | ||
amount={transaction.amount} | ||
amount={Math.abs(transactionAmount)} | ||
ref={(e) => (textInput.current = e)} | ||
onCurrencyButtonPress={navigateToCurrencySelectionPage} | ||
onSubmitButtonPress={navigateToNextPage} | ||
onSubmitButtonPress={isEditing ? saveAmountAndCurrency : navigateToNextPage} | ||
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.
@DylanDylann this function is only called if we're editting the request. 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. @dukenv0307 Let's move all logic to 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. @DylanDylann Updated. |
||
selectedTab={iouRequestType} | ||
/> | ||
</StepScreenWrapper> | ||
|
@@ -183,6 +212,12 @@ export default compose( | |
withWritableReportOrNotFound, | ||
withFullTransactionOrNotFound, | ||
withOnyx({ | ||
splitDraftTransaction: { | ||
key: ({route}) => { | ||
const transactionID = lodashGet(route, 'params.transactionID', 0); | ||
return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`; | ||
}, | ||
}, | ||
policy: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, | ||
}, | ||
|
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.
This page is only used in the edit page. So we don't need a condition to check here
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.
Updated.