Skip to content

Commit

Permalink
Merge pull request Expensify#36845 from bernhardoj/fix/36623-amount-i…
Browse files Browse the repository at this point in the history
…snt-cleared

Fix money request draft amount isn't cleared when reopening the page
  • Loading branch information
MariaHCD authored Feb 21, 2024
2 parents 8d60f67 + 71ce33b commit c261148
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
11 changes: 8 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ Onyx.connect({
* @param reportID to attach the transaction to
* @param iouRequestType one of manual/scan/distance
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function startMoneyRequest_temporaryForRefactor(reportID: string, isFromGlobalCreate: boolean, iouRequestType: IOURequestType = CONST.IOU.REQUEST_TYPE.MANUAL) {
function initMoneyRequest(reportID: string, isFromGlobalCreate: boolean, iouRequestType: IOURequestType = CONST.IOU.REQUEST_TYPE.MANUAL) {
// Generate a brand new transactionID
const newTransactionID = CONST.IOU.OPTIMISTIC_TRANSACTION_ID;
// Disabling this line since currentDate can be an empty string
Expand Down Expand Up @@ -259,6 +258,12 @@ function clearMoneyRequest(transactionID: string) {
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, null);
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function startMoneyRequest_temporaryForRefactor(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));
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestAmount_temporaryForRefactor(transactionID: string, amount: number, currency: string, removeOriginalCurrency = false) {
if (removeOriginalCurrency) {
Expand Down Expand Up @@ -4095,11 +4100,11 @@ export {
payMoneyRequest,
sendMoneyWithWallet,
startMoneyRequest,
initMoneyRequest,
startMoneyRequest_temporaryForRefactor,
resetMoneyRequestCategory,
resetMoneyRequestCategory_temporaryForRefactor,
resetMoneyRequestInfo,
clearMoneyRequest,
setMoneyRequestAmount_temporaryForRefactor,
setMoneyRequestBillable_temporaryForRefactor,
setMoneyRequestCategory_temporaryForRefactor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as IOU from '@userActions/IOU';
import * as Report from '@userActions/Report';
import * as Task from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -145,12 +143,12 @@ function AttachmentPickerWithMenuItems({
[CONST.IOU.TYPE.SPLIT]: {
icon: Expensicons.Receipt,
text: translate('iou.splitBill'),
onSelected: () => Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.SPLIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID)),
onSelected: () => IOU.startMoneyRequest_temporaryForRefactor(CONST.IOU.TYPE.SPLIT, report.reportID),
},
[CONST.IOU.TYPE.REQUEST]: {
icon: Expensicons.MoneyCircle,
text: translate('iou.requestMoney'),
onSelected: () => Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID)),
onSelected: () => IOU.startMoneyRequest_temporaryForRefactor(CONST.IOU.TYPE.REQUEST, report.reportID),
},
[CONST.IOU.TYPE.SEND]: {
icon: Expensicons.Send,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ function FloatingActionButtonAndPopover(props) {
text: translate('iou.requestMoney'),
onSelected: () =>
interceptAnonymousUser(() =>
Navigation.navigate(
IOU.startMoneyRequest_temporaryForRefactor(
CONST.IOU.TYPE.REQUEST,
// When starting to create a money request from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used
// for all of the routes in the creation flow.
ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID()),
ReportUtils.generateReportID(),
),
),
},
Expand Down
12 changes: 2 additions & 10 deletions src/pages/iou/request/IOURequestStartPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ function IOURequestStartPage({
const previousIOURequestType = usePrevious(transactionRequestType.current);
const isFromGlobalCreate = _.isEmpty(report.reportID);

// Clear out the temporary money request when this component is unmounted
useEffect(
() => () => {
IOU.clearMoneyRequest(CONST.IOU.OPTIMISTIC_TRANSACTION_ID);
},
[reportID],
);

useEffect(() => {
const handler = (event) => {
if (event.code !== CONST.KEYBOARD_SHORTCUTS.TAB.shortcutKey) {
Expand All @@ -106,7 +98,7 @@ function IOURequestStartPage({
if (transaction.reportID === reportID) {
return;
}
IOU.startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, transactionRequestType.current);
IOU.initMoneyRequest(reportID, isFromGlobalCreate, transactionRequestType.current);
}, [transaction, reportID, iouType, isFromGlobalCreate]);

const isExpenseChat = ReportUtils.isPolicyExpenseChat(report);
Expand All @@ -125,7 +117,7 @@ function IOURequestStartPage({
if (newIouType === previousIOURequestType) {
return;
}
IOU.startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, newIouType);
IOU.initMoneyRequest(reportID, isFromGlobalCreate, newIouType);
transactionRequestType.current = newIouType;
},
[previousIOURequestType, reportID, isFromGlobalCreate],
Expand Down

0 comments on commit c261148

Please sign in to comment.