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

Remove NewRequestAmountPage #35833

Merged
merged 29 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6364ee9
remove NewRequestAmountPage
dukenv0307 Feb 5, 2024
02a8a18
fix negative amount case
dukenv0307 Feb 5, 2024
a719511
fix the case edit split
dukenv0307 Feb 5, 2024
ae15fd5
delete old page
dukenv0307 Feb 5, 2024
0f990c9
Merge branch 'main' into 34614
dukenv0307 Feb 5, 2024
df76562
merge main
dukenv0307 Feb 5, 2024
0a4f634
merge main
dukenv0307 Feb 19, 2024
8b9ff58
fix ts check
dukenv0307 Feb 19, 2024
1301dc4
resolve conflict
dukenv0307 Mar 20, 2024
b10eb48
resolve another conflict
dukenv0307 Mar 20, 2024
15d6a41
fix ts check
dukenv0307 Mar 20, 2024
d842adc
Merge branch 'main' into 34614
dukenv0307 Mar 21, 2024
fe2e60c
remove unnecessary code
dukenv0307 Mar 21, 2024
e793792
Merge branch 'main' into 34614
dukenv0307 Mar 22, 2024
d11cf73
add type for step amount page
dukenv0307 Mar 22, 2024
a20a9e5
update route of currency page
dukenv0307 Mar 22, 2024
556ef3a
resolve conflict
dukenv0307 Mar 25, 2024
78195ae
add temporary solution for edit currency
dukenv0307 Mar 25, 2024
db1aa3f
remove un-use function
dukenv0307 Mar 25, 2024
8982f33
remove edit amount page and revert the unnecessary change
dukenv0307 Mar 25, 2024
11da8b2
update saveAmountAndCurrency function to include the create case
dukenv0307 Mar 25, 2024
77f6451
Merge branch 'main' into 34614
dukenv0307 Mar 28, 2024
39c365a
merge main
dukenv0307 Mar 28, 2024
3135246
fix lint
dukenv0307 Mar 28, 2024
40e301f
Merge branch 'main' into 34614
dukenv0307 Mar 28, 2024
f7a76c6
merge main
dukenv0307 Apr 1, 2024
744f3fb
resolve conflict
dukenv0307 Apr 1, 2024
8db0d5c
merge main
dukenv0307 Apr 1, 2024
a588842
complete resolve conflict
dukenv0307 Apr 1, 2024
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
16 changes: 9 additions & 7 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,18 @@ const ROUTES = {
getRoute: (iouType: string, reportID = '') => `${iouType}/new/address/${reportID}` as const,
},
MONEY_REQUEST_CREATE: {
route: 'create/:iouType/start/:transactionID/:reportID',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}` as const,
route: ':action/:iouType/start/:transactionID/:reportID',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string) =>
`${action}/${iouType}/start/${transactionID}/${reportID}` as const,
},
MONEY_REQUEST_STEP_CONFIRMATION: {
route: 'create/:iouType/confirmation/:transactionID/:reportID',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string) => `create/${iouType}/confirmation/${transactionID}/${reportID}` as const,
},
MONEY_REQUEST_STEP_AMOUNT: {
route: 'create/:iouType/amount/:transactionID/:reportID',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`create/${iouType}/amount/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/amount/:transactionID/:reportID',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/amount/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAX_RATE: {
route: 'create/:iouType/taxRate/:transactionID/:reportID?',
Expand Down Expand Up @@ -399,8 +400,9 @@ const ROUTES = {
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}/distance` as const,
},
MONEY_REQUEST_CREATE_TAB_MANUAL: {
route: 'create/:iouType/start/:transactionID/:reportID/manual',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}/manual` as const,
route: ':action/:iouType/start/:transactionID/:reportID/manual',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string) =>
`${action}/${iouType}/start/${transactionID}/${reportID}/manual` as const,
},
MONEY_REQUEST_CREATE_TAB_SCAN: {
route: 'create/:iouType/start/:transactionID/:reportID/scan',
Expand Down
7 changes: 2 additions & 5 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,8 @@ function MoneyRequestConfirmationList({
if (isDistanceRequest) {
return;
}
if (isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(reportID, reportActionID ?? '', CONST.EDIT_REQUEST_FIELD.AMOUNT));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_AMOUNT.getRoute(iouType, reportID));
const action = isEditingSplitBill ? CONST.IOU.ACTION.EDIT : CONST.IOU.ACTION.CREATE;
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(action, iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams()));
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

}}
style={[styles.moneyRequestMenuItem, styles.mt2]}
titleStyle={styles.moneyRequestConfirmationAmount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(reportID, reportActionID, CONST.EDIT_REQUEST_FIELD.AMOUNT));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(CONST.IOU.ACTION.CREATE, iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()),
);
}}
style={[styles.moneyRequestMenuItem, styles.mt2]}
titleStyle={styles.moneyRequestConfirmationAmount}
Expand Down
4 changes: 3 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ function MoneyRequestView({
titleStyle={styles.textHeadlineH2}
interactive={canEditAmount}
shouldShowRightIcon={canEditAmount}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID))
}
brickRoadIndicator={getErrorForField('amount') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('amount')}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function navigateToStartMoneyRequestStep(requestType: ValueOf<typeof CONST.IOU.R
Navigation.goBack(ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(iouType, transactionID, reportID));
break;
default:
Navigation.goBack(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(iouType, transactionID, reportID));
Navigation.goBack(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function getActiveRouteIndex(stateOrRoute: StateOrRoute, index?: number): number
function parseHybridAppUrl(url: HybridAppRoute | Route): Route {
switch (url) {
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE:
return ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID());
return ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID());
default:
return url;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function updateMoneyRequestTypeParams(routes: StackNavigationState<ParamListBase
// eslint-disable-next-line @typescript-eslint/naming-convention
function startMoneyRequest(iouType: ValueOf<typeof CONST.IOU.TYPE>, reportID: string) {
clearMoneyRequest(CONST.IOU.OPTIMISTIC_TRANSACTION_ID);
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, reportID));
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, reportID));
}

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/IOURequestRedirectToStartPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function IOURequestRedirectToStartPage({
if (iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE) {
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID));
} else if (iouRequestType === CONST.IOU.REQUEST_TYPE.MANUAL) {
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID));
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(CONST.IOU.ACTION.CREATE, iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID));
} else if (iouRequestType === CONST.IOU.REQUEST_TYPE.SCAN) {
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID));
}
Expand Down
45 changes: 40 additions & 5 deletions src/pages/iou/request/step/IOURequestStepAmount.js
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';
Expand Down Expand Up @@ -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({
/**
Expand All @@ -56,6 +60,7 @@ const propTypes = {
const defaultProps = {
report: {},
transaction: {},
splitDraftTransaction: {},
policy: {},
};

Expand All @@ -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,
}) {
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@DylanDylann this function is only called if we're editting the request.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dukenv0307 Let's move all logic to saveAmountAndCurrency function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DylanDylann Updated.

selectedTab={iouRequestType}
/>
</StepScreenWrapper>
Expand All @@ -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'}`,
},
Expand Down
Loading