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

[CP staging] Followup/23961 edit request #24565

Merged
merged 9 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
2 changes: 2 additions & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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}
mountiny marked this conversation as resolved.
Show resolved Hide resolved
>
<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 @@ -44,6 +44,8 @@ function EditRequestPage({report, route}) {
const transactionAmount = TransactionUtils.getAmount(transaction, ReportUtils.isExpenseReport(ReportUtils.getParentReport(report)));
const transactionCurrency = TransactionUtils.getCurrency(transaction);

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

// Take only the YYYY-MM-DD value
const transactionCreatedDate = new Date(TransactionUtils.getCreated(transaction));
const transactionCreated = format(transactionCreatedDate, CONST.DATE.FNS_FORMAT_STRING);
Expand Down Expand Up @@ -91,19 +93,19 @@ function EditRequestPage({report, route}) {
return (
<EditRequestAmountPage
defaultAmount={transactionAmount}
defaultCurrency={transactionCurrency}
defaultCurrency={defaultCurrency}
reportID={report.reportID}
onSubmit={(transactionChanges) => {
const amount = CurrencyUtils.convertToSmallestUnit(transactionCurrency, Number.parseFloat(transactionChanges));
// In case the amount hasn't been changed, do not make the API request.
if (amount === transactionAmount) {
// In case the amount and the currency haven't been changed, do not make the API request.
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