Skip to content

Commit

Permalink
Merge pull request #24565 from koko57/followup/23961-edit-request
Browse files Browse the repository at this point in the history
[CP staging] Followup/23961 edit request
  • Loading branch information
mountiny authored Aug 17, 2023
2 parents 0bdf183 + 7f62d47 commit 2de126f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export default {
REPORT_WITH_ID: 'r/:reportID?',
EDIT_REQUEST: 'r/:threadReportID/edit/:field',
getEditRequestRoute: (threadReportID, field) => `r/${threadReportID}/edit/${field}`,
EDIT_CURRENCY_REQUEST: 'r/:threadReportID/edit/currency',
getEditRequestCurrencyRoute: (threadReportID, currency, backTo) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}`,
getReportRoute: (reportID) => `r/${reportID}`,
REPORT_WITH_ID_DETAILS_SHARE_CODE: 'r/:reportID/details/shareCode',
getReportShareCodeRoute: (reportID) => `r/${reportID}/details/shareCode`,
Expand Down
15 changes: 3 additions & 12 deletions src/components/CurrencySymbolButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@ const propTypes = {

/** Function to call when currency button is pressed */
onCurrencyButtonPress: PropTypes.func.isRequired,

/** Flag to indicate if the button should be disabled */
disabled: PropTypes.bool,
};

const defaultProps = {
disabled: false,
};

function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol, disabled}) {
function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol}) {
const {translate} = useLocalize();
return (
<Tooltip text={!disabled && translate('iOUCurrencySelection.selectCurrency')}>
<Tooltip text={translate('iOUCurrencySelection.selectCurrency')}>
<PressableWithoutFeedback
onPress={onCurrencyButtonPress}
accessibilityLabel={!disabled && translate('iOUCurrencySelection.selectCurrency')}
accessibilityLabel={translate('iOUCurrencySelection.selectCurrency')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
disabled={disabled}
>
<Text style={styles.iouAmountText}>{currencySymbol}</Text>
</PressableWithoutFeedback>
Expand All @@ -40,6 +32,5 @@ function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol, disabled})

CurrencySymbolButton.propTypes = propTypes;
CurrencySymbolButton.displayName = 'CurrencySymbolButton';
CurrencySymbolButton.defaultProps = defaultProps;

export default CurrencySymbolButton;
5 changes: 0 additions & 5 deletions src/components/TextInputWithCurrencySymbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ const propTypes = {

/** Function to call when selection in text input is changed */
onSelectionChange: PropTypes.func,

/** Flag to indicate if the button should be disabled */
disabled: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -44,7 +41,6 @@ const defaultProps = {
onCurrencyButtonPress: () => {},
selection: undefined,
onSelectionChange: () => {},
disabled: false,
};

function TextInputWithCurrencySymbol(props) {
Expand All @@ -62,7 +58,6 @@ function TextInputWithCurrencySymbol(props) {
<CurrencySymbolButton
currencySymbol={currencySymbol}
onCurrencyButtonPress={props.onCurrencyButtonPress}
disabled={props.disabled}
/>
);

Expand Down
7 changes: 7 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,13 @@ const EditRequestStackNavigator = createModalStackNavigator([
},
name: 'EditRequest_Root',
},
{
getComponent: () => {
const IOUCurrencySelection = require('../../../pages/iou/IOUCurrencySelection').default;
return IOUCurrencySelection;
},
name: 'EditRequest_Currency',
},
]);

export {
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export default {
EditRequest: {
screens: {
EditRequest_Root: ROUTES.EDIT_REQUEST,
EditRequest_Currency: ROUTES.EDIT_CURRENCY_REQUEST,
},
},
},
Expand Down
15 changes: 12 additions & 3 deletions src/pages/EditRequestAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HeaderWithBackButton from '../components/HeaderWithBackButton';
import Navigation from '../libs/Navigation/Navigation';
import useLocalize from '../hooks/useLocalize';
import MoneyRequestAmountForm from './iou/steps/MoneyRequestAmountForm';
import ROUTES from '../ROUTES';

const propTypes = {
/** Transaction default amount value */
Expand All @@ -17,9 +18,12 @@ const propTypes = {

/** Callback to fire when the Save button is pressed */
onSubmit: PropTypes.func.isRequired,

/** reportID for the transaction thread */
reportID: PropTypes.string.isRequired,
};

function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit}) {
function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit, reportID}) {
const {translate} = useLocalize();
const textInput = useRef(null);

Expand All @@ -36,6 +40,12 @@ function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit}) {
});
};

const navigateToCurrencySelectionPage = () => {
// Remove query from the route and encode it.
const activeRoute = encodeURIComponent(Navigation.getActiveRoute().replace(/\?.*/, ''));
Navigation.navigate(ROUTES.getEditRequestCurrencyRoute(reportID, defaultCurrency, activeRoute));
};

useFocusEffect(
useCallback(() => {
focusTextInput();
Expand All @@ -53,11 +63,10 @@ function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit}) {
/>
<MoneyRequestAmountForm
isEditing
disableCurrency
currency={defaultCurrency}
amount={defaultAmount}
ref={(e) => (textInput.current = e)}
onCurrencyButtonPress={() => null}
onCurrencyButtonPress={navigateToCurrencySelectionPage}
onSubmitButtonPress={onSubmit}
/>
</ScreenWrapper>
Expand Down
10 changes: 6 additions & 4 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ function EditRequestPage({report, route, parentReport}) {
const transaction = TransactionUtils.getLinkedTransaction(parentReportAction);
const {amount: transactionAmount, currency: transactionCurrency, comment: transactionDescription} = ReportUtils.getTransactionDetails(transaction);

const defaultCurrency = lodashGet(route, 'params.currency', '') || transactionCurrency;

// Take only the YYYY-MM-DD value
const transactionCreated = TransactionUtils.getCreated(transaction);
const fieldToEdit = lodashGet(route, ['params', 'field'], '');
Expand Down Expand Up @@ -103,19 +105,19 @@ function EditRequestPage({report, route, parentReport}) {
return (
<EditRequestAmountPage
defaultAmount={transactionAmount}
defaultCurrency={transactionCurrency}
defaultCurrency={defaultCurrency}
reportID={report.reportID}
onSubmit={(transactionChanges) => {
const amount = CurrencyUtils.convertToBackendAmount(transactionCurrency, Number.parseFloat(transactionChanges));
const amount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(transactionChanges));
// In case the amount hasn't been changed, do not make the API request.
if (amount === transactionAmount) {
if (amount === transactionAmount && transactionCurrency === defaultCurrency) {
Navigation.dismissModal();
return;
}
// Temporarily disabling currency editing and it will be enabled as a quick follow up
editMoneyRequest({
amount,
currency: transactionCurrency,
currency: defaultCurrency,
});
}}
/>
Expand Down
7 changes: 1 addition & 6 deletions src/pages/iou/steps/MoneyRequestAmountForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ const propTypes = {

/** Fired when submit button pressed, saves the given amount and navigates to the next page */
onSubmitButtonPress: PropTypes.func.isRequired,

/** Flag to indicate if the button should be disabled */
disableCurrency: PropTypes.bool,
};

const defaultProps = {
amount: 0,
currency: CONST.CURRENCY.USD,
forwardedRef: null,
isEditing: false,
disableCurrency: false,
};

/**
Expand All @@ -61,7 +57,7 @@ const AMOUNT_VIEW_ID = 'amountView';
const NUM_PAD_CONTAINER_VIEW_ID = 'numPadContainerView';
const NUM_PAD_VIEW_ID = 'numPadView';

function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCurrencyButtonPress, onSubmitButtonPress, disableCurrency}) {
function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCurrencyButtonPress, onSubmitButtonPress}) {
const {translate, toLocaleDigit, numberFormat} = useLocalize();

const textInput = useRef(null);
Expand Down Expand Up @@ -207,7 +203,6 @@ function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCu
}
setSelection(e.nativeEvent.selection);
}}
disabled={disableCurrency}
/>
</View>
<View
Expand Down

0 comments on commit 2de126f

Please sign in to comment.