From 16922864c1f310f2ff88d807d5e075f2dd5f1e1a Mon Sep 17 00:00:00 2001 From: brunovjk Date: Wed, 7 Feb 2024 16:14:02 -0300 Subject: [PATCH 01/11] Merge branch 'Expensify:main' into fix/34608 --- src/ROUTES.ts | 10 +- src/SCREENS.ts | 1 - .../MoneyRequestConfirmationList.js | 14 +- ...oraryForRefactorRequestConfirmationList.js | 8 +- .../ReportActionItem/MoneyRequestView.tsx | 12 +- .../AppNavigator/ModalStackNavigators.tsx | 1 - src/libs/Navigation/linkingConfig/config.ts | 1 - src/libs/Navigation/types.ts | 9 +- src/libs/actions/IOU.ts | 11 +- src/pages/EditRequestCreatedPage.js | 55 -------- src/pages/EditRequestPage.js | 23 ---- src/pages/EditSplitBillPage.js | 11 -- src/pages/iou/MoneyRequestDatePage.js | 126 ------------------ .../iou/request/step/IOURequestStepDate.js | 35 ++++- 14 files changed, 67 insertions(+), 250 deletions(-) delete mode 100644 src/pages/EditRequestCreatedPage.js delete mode 100644 src/pages/iou/MoneyRequestDatePage.js diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 5617c063bb57..f06ebcdf6055 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -273,10 +273,6 @@ const ROUTES = { route: ':iouType/new/confirmation/:reportID?', getRoute: (iouType: string, reportID = '') => `${iouType}/new/confirmation/${reportID}` as const, }, - MONEY_REQUEST_DATE: { - route: ':iouType/new/date/:reportID?', - getRoute: (iouType: string, reportID = '') => `${iouType}/new/date/${reportID}` as const, - }, MONEY_REQUEST_CURRENCY: { route: ':iouType/new/currency/:reportID?', getRoute: (iouType: string, reportID: string, currency: string, backTo: string) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}` as const, @@ -338,9 +334,9 @@ const ROUTES = { getUrlWithBackToParam(`create/${iouType}/currency/${transactionID}/${reportID}/${pageIndex}`, backTo), }, MONEY_REQUEST_STEP_DATE: { - route: 'create/:iouType/date/:transactionID/:reportID', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/date/${transactionID}/${reportID}`, backTo), + route: ':action/:iouType/date/:transactionID/:reportID', + getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action}/${iouType}/date/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_DESCRIPTION: { route: ':action/:iouType/description/:transactionID/:reportID', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 538c72addc9a..3782848305aa 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -149,7 +149,6 @@ const SCREENS = { PARTICIPANTS: 'Money_Request_Participants', CONFIRMATION: 'Money_Request_Confirmation', CURRENCY: 'Money_Request_Currency', - DATE: 'Money_Request_Date', CATEGORY: 'Money_Request_Category', MERCHANT: 'Money_Request_Merchant', WAYPOINT: 'Money_Request_Waypoint', diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index e9a5f2ba635e..45747c8ddd7b 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -697,11 +697,15 @@ function MoneyRequestConfirmationList(props) { style={[styles.moneyRequestMenuItem]} titleStyle={styles.flex1} onPress={() => { - if (props.isEditingSplitBill) { - Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.DATE)); - return; - } - Navigation.navigate(ROUTES.MONEY_REQUEST_DATE.getRoute(props.iouType, props.reportID)); + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_DATE.getRoute( + CONST.IOU.ACTION.EDIT, + props.iouType, + transaction.transactionID, + props.reportID, + Navigation.getActiveRouteWithoutParams(), + ), + ); }} disabled={didConfirm} interactive={!props.isReadOnly} diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index e088dae0cadf..b2c9e0c4fefe 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -782,11 +782,9 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ style={[styles.moneyRequestMenuItem]} titleStyle={styles.flex1} onPress={() => { - if (isEditingSplitBill) { - Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(reportID, reportActionID, CONST.EDIT_REQUEST_FIELD.DATE)); - return; - } - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams())); + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(CONST.IOU.ACTION.CREATE, iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()), + ); }} disabled={didConfirm} interactive={!isReadOnly} diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 8055290c8892..02c07db113f2 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -322,7 +322,17 @@ function MoneyRequestView({ interactive={canEditDate} shouldShowRightIcon={canEditDate} titleStyle={styles.flex1} - onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))} + onPress={() => + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_DATE.getRoute( + CONST.IOU.ACTION.EDIT, + CONST.IOU.TYPE.REQUEST, + transaction?.transactionID ?? '', + report.reportID, + Navigation.getActiveRouteWithoutParams(), + ), + ) + } brickRoadIndicator={hasViolations('date') || (hasErrors && transactionDate === '') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} error={hasErrors && transactionDate === '' ? translate('common.error.enterDate') : ''} /> diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx index 0e2863fed5f1..d7e0fb598793 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx @@ -98,7 +98,6 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator require('../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CONFIRMATION]: () => require('../../../pages/iou/steps/MoneyRequestConfirmPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CURRENCY]: () => require('../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, - [SCREENS.MONEY_REQUEST.DATE]: () => require('../../../pages/iou/MoneyRequestDatePage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CATEGORY]: () => require('../../../pages/iou/MoneyRequestCategoryPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.MERCHANT]: () => require('../../../pages/iou/MoneyRequestMerchantPage').default as React.ComponentType, [SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: () => require('../../../pages/AddPersonalBankAccountPage').default as React.ComponentType, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 1eeede4506cc..428c4ccfed56 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -402,7 +402,6 @@ const config: LinkingOptions['config'] = { [SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: ROUTES.MONEY_REQUEST_STEP_TAX_RATE.route, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: ROUTES.MONEY_REQUEST_PARTICIPANTS.route, [SCREENS.MONEY_REQUEST.CONFIRMATION]: ROUTES.MONEY_REQUEST_CONFIRMATION.route, - [SCREENS.MONEY_REQUEST.DATE]: ROUTES.MONEY_REQUEST_DATE.route, [SCREENS.MONEY_REQUEST.CURRENCY]: ROUTES.MONEY_REQUEST_CURRENCY.route, [SCREENS.MONEY_REQUEST.CATEGORY]: ROUTES.MONEY_REQUEST_CATEGORY.route, [SCREENS.MONEY_REQUEST.MERCHANT]: ROUTES.MONEY_REQUEST_MERCHANT.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 0abe267bdaa3..addf027e974b 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -209,11 +209,12 @@ type MoneyRequestNavigatorParamList = { currency: string; backTo: string; }; - [SCREENS.MONEY_REQUEST.DATE]: { - iouType: string; + [SCREENS.MONEY_REQUEST.STEP_DATE]: { + action: ValueOf; + iouType: ValueOf; + transactionID: string; reportID: string; - field: string; - threadReportID: string; + backTo: string; }; [SCREENS.MONEY_REQUEST.STEP_DESCRIPTION]: { action: ValueOf; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 0ce540bea456..6b19bccbd95c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -268,8 +268,8 @@ function setMoneyRequestAmount_temporaryForRefactor(transactionID: string, amoun } // eslint-disable-next-line @typescript-eslint/naming-convention -function setMoneyRequestCreated_temporaryForRefactor(transactionID: string, created: string) { - Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {created}); +function setMoneyRequestCreated(transactionID: string, created: string, isDraft: boolean) { + Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {created}); } // eslint-disable-next-line @typescript-eslint/naming-convention @@ -3545,10 +3545,6 @@ function setMoneyRequestAmount(amount: number) { Onyx.merge(ONYXKEYS.IOU, {amount}); } -function setMoneyRequestCreated(created: string) { - Onyx.merge(ONYXKEYS.IOU, {created}); -} - function setMoneyRequestCurrency(currency: string) { Onyx.merge(ONYXKEYS.IOU, {currency}); } @@ -3691,7 +3687,7 @@ export { setMoneyRequestAmount_temporaryForRefactor, setMoneyRequestBillable_temporaryForRefactor, setMoneyRequestCategory_temporaryForRefactor, - setMoneyRequestCreated_temporaryForRefactor, + setMoneyRequestCreated, setMoneyRequestCurrency_temporaryForRefactor, setMoneyRequestDescription, setMoneyRequestOriginalCurrency_temporaryForRefactor, @@ -3701,7 +3697,6 @@ export { setMoneyRequestAmount, setMoneyRequestBillable, setMoneyRequestCategory, - setMoneyRequestCreated, setMoneyRequestCurrency, setMoneyRequestId, setMoneyRequestMerchant, diff --git a/src/pages/EditRequestCreatedPage.js b/src/pages/EditRequestCreatedPage.js deleted file mode 100644 index 2b5a8abaa349..000000000000 --- a/src/pages/EditRequestCreatedPage.js +++ /dev/null @@ -1,55 +0,0 @@ -import PropTypes from 'prop-types'; -import React from 'react'; -import DatePicker from '@components/DatePicker'; -import FormProvider from '@components/Form/FormProvider'; -import InputWrapper from '@components/Form/InputWrapper'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import ScreenWrapper from '@components/ScreenWrapper'; -import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; - -const propTypes = { - /** Transaction defailt created value */ - defaultCreated: PropTypes.string.isRequired, - - /** Callback to fire when the Save button is pressed */ - onSubmit: PropTypes.func.isRequired, -}; - -function EditRequestCreatedPage({defaultCreated, onSubmit}) { - const styles = useThemeStyles(); - const {translate} = useLocalize(); - - return ( - - - - - - - ); -} - -EditRequestCreatedPage.propTypes = propTypes; -EditRequestCreatedPage.displayName = 'EditRequestCreatedPage'; - -export default EditRequestCreatedPage; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 7e1a9f7d9b7b..8c07e5bbbd8a 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -21,7 +21,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import EditRequestAmountPage from './EditRequestAmountPage'; import EditRequestCategoryPage from './EditRequestCategoryPage'; -import EditRequestCreatedPage from './EditRequestCreatedPage'; import EditRequestDistancePage from './EditRequestDistancePage'; import EditRequestMerchantPage from './EditRequestMerchantPage'; import EditRequestReceiptPage from './EditRequestReceiptPage'; @@ -124,19 +123,6 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep [transaction, report], ); - const saveCreated = useCallback( - ({created: newCreated}) => { - // If the value hasn't changed, don't request to save changes on the server and just close the modal - if (newCreated === TransactionUtils.getCreated(transaction)) { - Navigation.dismissModal(); - return; - } - IOU.updateMoneyRequestDate(transaction.transactionID, report.reportID, newCreated); - Navigation.dismissModal(); - }, - [transaction, report], - ); - const saveMerchant = useCallback( ({merchant: newMerchant}) => { const newTrimmedMerchant = newMerchant.trim(); @@ -178,15 +164,6 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep [transactionCategory, transaction.transactionID, report.reportID], ); - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DATE) { - return ( - - ); - } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT) { return ( - ); - } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT) { return ( { - const moneyRequestId = `${iouType}${reportID}`; - const shouldReset = iou.id !== moneyRequestId; - if (shouldReset) { - IOU.resetMoneyRequestInfo(moneyRequestId); - } - - if (!isDistanceRequest && (_.isEmpty(iou.participants) || (iou.amount === 0 && !iou.receiptPath) || shouldReset)) { - Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType, reportID), true); - } - }, [iou.id, iou.participants, iou.amount, iou.receiptPath, iouType, reportID, isDistanceRequest]); - - function navigateBack() { - Navigation.goBack(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, reportID)); - } - - /** - * Sets the money request comment by saving it to Onyx. - * - * @param {Object} value - * @param {String} value.moneyRequestCreated - */ - function updateDate(value) { - IOU.setMoneyRequestCreated(value.moneyRequestCreated); - navigateBack(); - } - - return ( - - navigateBack()} - /> - updateDate(value)} - submitButtonText={translate('common.save')} - enabledWhenOffline - > - - - - ); -} - -MoneyRequestDatePage.propTypes = propTypes; -MoneyRequestDatePage.defaultProps = defaultProps; -MoneyRequestDatePage.displayName = 'MoneyRequestDatePage'; - -export default withOnyx({ - iou: { - key: ONYXKEYS.IOU, - }, - selectedTab: { - key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`, - }, -})(MoneyRequestDatePage); diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 84a67c30a4d4..313e3f9e32f1 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -1,3 +1,4 @@ +import lodashIsEmpty from 'lodash/isEmpty'; import React from 'react'; import DatePicker from '@components/DatePicker'; import FormProvider from '@components/Form/FormProvider'; @@ -8,6 +9,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import compose from '@libs/compose'; import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as TransactionUtils from '@libs/TransactionUtils'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -24,21 +26,30 @@ const propTypes = { /** Onyx Props */ /** Holds data related to Money Request view state, rather than the underlying Money Request data. */ transaction: transactionPropTypes, + + /** The draft transaction that holds data to be persisted on the current transaction */ + splitDraftTransaction: transactionPropTypes, }; const defaultProps = { transaction: {}, + splitDraftTransaction: {}, }; function IOURequestStepDate({ route: { - params: {iouType, backTo, transactionID}, + params: {action, iouType, reportID, backTo}, }, transaction, + splitDraftTransaction, }) { const styles = useThemeStyles(); const {translate} = useLocalize(); + // In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value + const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && action === CONST.IOU.ACTION.EDIT; + const currentCreated = isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? TransactionUtils.getCreated(splitDraftTransaction) : TransactionUtils.getCreated(transaction); + const navigateBack = () => { Navigation.goBack(backTo || ROUTES.HOME); }; @@ -48,7 +59,27 @@ function IOURequestStepDate({ * @param {String} value.moneyRequestCreated */ const updateDate = (value) => { - IOU.setMoneyRequestCreated_temporaryForRefactor(transactionID, value.moneyRequestCreated); + const newCreated = value.moneyRequestCreated.trim(); + + // Only update created if it has changed + if (newCreated === currentCreated) { + navigateBack(); + return; + } + + // In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value + if (isEditingSplitBill) { + IOU.setDraftSplitTransaction(transaction.transactionID, {created: newCreated}); + navigateBack(); + return; + } + + IOU.setMoneyRequestCreated(transaction.transactionID, newCreated, action === CONST.IOU.ACTION.CREATE); + + if (action === CONST.IOU.ACTION.EDIT) { + IOU.updateMoneyRequestDate(transaction.transactionID, reportID, newCreated); + } + navigateBack(); }; From c084c92b6ff44ea300ca0b19eb7cfa23341181d9 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Wed, 7 Feb 2024 16:39:06 -0300 Subject: [PATCH 02/11] In 'IOURequestStepDate' get 'splitDraftTransaction' from Onyx and use it --- .../iou/request/step/IOURequestStepDate.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 313e3f9e32f1..3c9b4cfe822c 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -1,5 +1,6 @@ import lodashIsEmpty from 'lodash/isEmpty'; import React from 'react'; +import {withOnyx} from 'react-native-onyx'; import DatePicker from '@components/DatePicker'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; @@ -18,6 +19,7 @@ import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; +import lodashGet from 'lodash/get'; const propTypes = { /** Navigation route context info provided by react navigation */ @@ -102,7 +104,7 @@ function IOURequestStepDate({ InputComponent={DatePicker} inputID="moneyRequestCreated" label={translate('common.date')} - defaultValue={transaction.created} + defaultValue={currentCreated} maxDate={CONST.CALENDAR_PICKER.MAX_DATE} minDate={CONST.CALENDAR_PICKER.MIN_DATE} /> @@ -115,4 +117,15 @@ IOURequestStepDate.propTypes = propTypes; IOURequestStepDate.defaultProps = defaultProps; IOURequestStepDate.displayName = 'IOURequestStepDate'; -export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepDate); +export default compose( + withWritableReportOrNotFound, + withFullTransactionOrNotFound, + withOnyx({ + splitDraftTransaction: { + key: ({route}) => { + const transactionID = lodashGet(route, 'params.transactionID', 0); + return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`; + }, + }, + }), +)(IOURequestStepDate); From 58c09d3f86c796051153f92d99ea44ac38959418 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Wed, 7 Feb 2024 17:04:45 -0300 Subject: [PATCH 03/11] run prettier --- src/pages/iou/request/step/IOURequestStepDate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 3c9b4cfe822c..10b86b7fc19e 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -1,3 +1,4 @@ +import lodashGet from 'lodash/get'; import lodashIsEmpty from 'lodash/isEmpty'; import React from 'react'; import {withOnyx} from 'react-native-onyx'; @@ -19,7 +20,6 @@ import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; -import lodashGet from 'lodash/get'; const propTypes = { /** Navigation route context info provided by react navigation */ From 03f08d597f8cc9fcbaef9b3a05b71ec06d6ef1b5 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Thu, 8 Feb 2024 07:56:57 -0300 Subject: [PATCH 04/11] Remove 'trim' from 'created' field --- src/pages/iou/request/step/IOURequestStepDate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 10b86b7fc19e..07e96d37ffab 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -61,7 +61,7 @@ function IOURequestStepDate({ * @param {String} value.moneyRequestCreated */ const updateDate = (value) => { - const newCreated = value.moneyRequestCreated.trim(); + const newCreated = value.moneyRequestCreated; // Only update created if it has changed if (newCreated === currentCreated) { From 3fc8ac6c75a2826ec1f85f4fe2c6b4efd2712474 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Thu, 8 Feb 2024 18:02:21 -0300 Subject: [PATCH 05/11] Added 'created' parameter to SplitBillParams type --- src/libs/API/parameters/SplitBillParams.ts | 1 + src/libs/actions/IOU.ts | 18 ++++++++++++------ .../request/step/IOURequestStepConfirmation.js | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libs/API/parameters/SplitBillParams.ts b/src/libs/API/parameters/SplitBillParams.ts index 23d4ff3d6d78..c3284ef05952 100644 --- a/src/libs/API/parameters/SplitBillParams.ts +++ b/src/libs/API/parameters/SplitBillParams.ts @@ -3,6 +3,7 @@ type SplitBillParams = { amount: number; splits: string; comment: string; + created: string; currency: string; merchant: string; category: string; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1287032619ce..530c92c4ed6d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1377,6 +1377,7 @@ function createSplitsAndOnyxData( currentUserAccountID: number, amount: number, comment: string, + created: string, currency: string, merchant: string, category: string, @@ -1398,7 +1399,7 @@ function createSplitsAndOnyxData( currency, CONST.REPORT.SPLIT_REPORTID, comment, - '', + created, '', '', merchant || Localize.translateLocal('iou.request'), @@ -1610,7 +1611,7 @@ function createSplitsAndOnyxData( currency, oneOnOneIOUReport.reportID, comment, - '', + created, CONST.IOU.TYPE.SPLIT, splitTransaction.transactionID, merchant || Localize.translateLocal('iou.request'), @@ -1738,6 +1739,7 @@ function splitBill( currentUserAccountID: number, amount: number, comment: string, + created: string, currency: string, merchant: string, category: string, @@ -1751,6 +1753,7 @@ function splitBill( currentUserAccountID, amount, comment, + created, currency, merchant, category, @@ -1763,10 +1766,11 @@ function splitBill( reportID: splitData.chatReportID, amount, splits: JSON.stringify(splits), - currency, comment, - category, + created, + currency, merchant, + category, tag, billable, transactionID: splitData.transactionID, @@ -1791,21 +1795,23 @@ function splitBillAndOpenReport( currentUserAccountID: number, amount: number, comment: string, + created: string, currency: string, merchant: string, category: string, tag: string, billable: boolean, ) { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, tag); + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, created, currency, merchant, category, tag); const parameters: SplitBillParams = { reportID: splitData.chatReportID, amount, splits: JSON.stringify(splits), + comment, + created, currency, merchant, - comment, category, tag, billable, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 207aa9ff47b1..f92ec4069b3e 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -240,6 +240,7 @@ function IOURequestStepConfirmation({ const createTransaction = useCallback( (selectedParticipants) => { const trimmedComment = lodashGet(transaction, 'comment.comment', '').trim(); + const transactionCreated = TransactionUtils.getCreated(transaction); // Don't let the form be submitted multiple times while the navigator is waiting to take the user to a different page if (formHasBeenSubmitted.current) { @@ -273,6 +274,7 @@ function IOURequestStepConfirmation({ currentUserPersonalDetails.accountID, transaction.amount, trimmedComment, + transactionCreated, transaction.currency, transaction.merchant, transaction.category, @@ -291,6 +293,7 @@ function IOURequestStepConfirmation({ currentUserPersonalDetails.accountID, transaction.amount, trimmedComment, + transactionCreated, transaction.currency, transaction.merchant, transaction.category, From 85c30287fc3be2125196b6604016603bd7588413 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Fri, 9 Feb 2024 21:05:16 -0300 Subject: [PATCH 06/11] Remove backTo for money request view --- src/components/ReportActionItem/MoneyRequestView.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 80d535406a9c..7e95d579caa1 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -321,7 +321,6 @@ function MoneyRequestView({ CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID, - Navigation.getActiveRouteWithoutParams(), ), ) } From 06e11dceaa0648ee24a209744fe101826bbdc5b4 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Fri, 9 Feb 2024 21:07:26 -0300 Subject: [PATCH 07/11] Revert "Added 'created' parameter to SplitBillParams type" This reverts commit 3fc8ac6c75a2826ec1f85f4fe2c6b4efd2712474. --- src/libs/API/parameters/SplitBillParams.ts | 1 - src/libs/actions/IOU.ts | 18 ++++++------------ .../request/step/IOURequestStepConfirmation.js | 3 --- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/libs/API/parameters/SplitBillParams.ts b/src/libs/API/parameters/SplitBillParams.ts index c3284ef05952..23d4ff3d6d78 100644 --- a/src/libs/API/parameters/SplitBillParams.ts +++ b/src/libs/API/parameters/SplitBillParams.ts @@ -3,7 +3,6 @@ type SplitBillParams = { amount: number; splits: string; comment: string; - created: string; currency: string; merchant: string; category: string; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 4ddf29ecf742..56cea2a6d4e8 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1473,7 +1473,6 @@ function createSplitsAndOnyxData( currentUserAccountID: number, amount: number, comment: string, - created: string, currency: string, merchant: string, category: string, @@ -1495,7 +1494,7 @@ function createSplitsAndOnyxData( currency, CONST.REPORT.SPLIT_REPORTID, comment, - created, + '', '', '', merchant || Localize.translateLocal('iou.request'), @@ -1707,7 +1706,7 @@ function createSplitsAndOnyxData( currency, oneOnOneIOUReport.reportID, comment, - created, + '', CONST.IOU.TYPE.SPLIT, splitTransaction.transactionID, merchant || Localize.translateLocal('iou.request'), @@ -1835,7 +1834,6 @@ function splitBill( currentUserAccountID: number, amount: number, comment: string, - created: string, currency: string, merchant: string, category: string, @@ -1849,7 +1847,6 @@ function splitBill( currentUserAccountID, amount, comment, - created, currency, merchant, category, @@ -1862,11 +1859,10 @@ function splitBill( reportID: splitData.chatReportID, amount, splits: JSON.stringify(splits), - comment, - created, currency, - merchant, + comment, category, + merchant, tag, billable, transactionID: splitData.transactionID, @@ -1891,23 +1887,21 @@ function splitBillAndOpenReport( currentUserAccountID: number, amount: number, comment: string, - created: string, currency: string, merchant: string, category: string, tag: string, billable: boolean, ) { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, created, currency, merchant, category, tag); + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, merchant, category, tag); const parameters: SplitBillParams = { reportID: splitData.chatReportID, amount, splits: JSON.stringify(splits), - comment, - created, currency, merchant, + comment, category, tag, billable, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 3cd0ccfc0a32..cf4e6a461bc1 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -242,7 +242,6 @@ function IOURequestStepConfirmation({ const createTransaction = useCallback( (selectedParticipants) => { const trimmedComment = lodashGet(transaction, 'comment.comment', '').trim(); - const transactionCreated = TransactionUtils.getCreated(transaction); // Don't let the form be submitted multiple times while the navigator is waiting to take the user to a different page if (formHasBeenSubmitted.current) { @@ -276,7 +275,6 @@ function IOURequestStepConfirmation({ currentUserPersonalDetails.accountID, transaction.amount, trimmedComment, - transactionCreated, transaction.currency, transaction.merchant, transaction.category, @@ -295,7 +293,6 @@ function IOURequestStepConfirmation({ currentUserPersonalDetails.accountID, transaction.amount, trimmedComment, - transactionCreated, transaction.currency, transaction.merchant, transaction.category, From 473e1881bbe26a57548ec5d6a5921c28a474d56d Mon Sep 17 00:00:00 2001 From: brunovjk Date: Fri, 9 Feb 2024 21:28:21 -0300 Subject: [PATCH 08/11] run prettier --- src/components/ReportActionItem/MoneyRequestView.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 7e95d579caa1..bec6990f8e4f 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -315,14 +315,7 @@ function MoneyRequestView({ shouldShowRightIcon={canEditDate} titleStyle={styles.flex1} onPress={() => - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_DATE.getRoute( - CONST.IOU.ACTION.EDIT, - CONST.IOU.TYPE.REQUEST, - transaction?.transactionID ?? '', - report.reportID, - ), - ) + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID)) } brickRoadIndicator={hasViolations('date') || (hasErrors && transactionDate === '') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} error={hasErrors && transactionDate === '' ? translate('common.error.enterDate') : ''} From 7e3e9747853d5e17d0c8f40ae267a81283a82d62 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Sat, 10 Feb 2024 10:49:20 -0300 Subject: [PATCH 09/11] Update 'IOU.updateMoneyRequestDate' call to use 'policy, policyTags and policyCategories' params --- .../iou/request/step/IOURequestStepDate.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 9538027f7864..2eecfc149c68 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -1,10 +1,13 @@ import lodashGet from 'lodash/get'; import lodashIsEmpty from 'lodash/isEmpty'; +import PropTypes from 'prop-types'; import React from 'react'; import {withOnyx} from 'react-native-onyx'; +import categoryPropTypes from '@components/categoryPropTypes'; import DatePicker from '@components/DatePicker'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; +import tagPropTypes from '@components/tagPropTypes'; import transactionPropTypes from '@components/transactionPropTypes'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -15,6 +18,7 @@ import * as TransactionUtils from '@libs/TransactionUtils'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import {policyPropTypes} from '@src/pages/workspace/withPolicy'; import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; @@ -30,11 +34,23 @@ const propTypes = { /** The draft transaction that holds data to be persisted on the current transaction */ splitDraftTransaction: transactionPropTypes, + + /** The policy of the report */ + policy: policyPropTypes.policy, + + /** Collection of categories attached to a policy */ + policyCategories: PropTypes.objectOf(categoryPropTypes), + + /** Collection of tags attached to a policy */ + policyTags: tagPropTypes, }; const defaultProps = { transaction: {}, splitDraftTransaction: {}, + policy: null, + policyTags: null, + policyCategories: null, }; function IOURequestStepDate({ @@ -43,6 +59,9 @@ function IOURequestStepDate({ }, transaction, splitDraftTransaction, + policy, + policyTags, + policyCategories, }) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -78,7 +97,7 @@ function IOURequestStepDate({ IOU.setMoneyRequestCreated(transaction.transactionID, newCreated, action === CONST.IOU.ACTION.CREATE); if (action === CONST.IOU.ACTION.EDIT) { - IOU.updateMoneyRequestDate(transaction.transactionID, reportID, newCreated); + IOU.updateMoneyRequestDate(transaction.transactionID, reportID, newCreated, policy, policyTags, policyCategories); } navigateBack(); @@ -126,5 +145,14 @@ export default compose( return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`; }, }, + policy: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, + }, + policyCategories: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, + }, + policyTags: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, + }, }), )(IOURequestStepDate); From 422ab7e9d0e9740b4d560b8d445b862c7413ea05 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Sat, 10 Feb 2024 10:58:50 -0300 Subject: [PATCH 10/11] Use 'isEditing' --- src/pages/iou/request/step/IOURequestStepDate.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 2eecfc149c68..4f27567b5346 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -67,7 +67,8 @@ function IOURequestStepDate({ const {translate} = useLocalize(); // In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value - const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && action === CONST.IOU.ACTION.EDIT; + const isEditing = action === CONST.IOU.ACTION.EDIT; + const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && isEditing; const currentCreated = isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? TransactionUtils.getCreated(splitDraftTransaction) : TransactionUtils.getCreated(transaction); const navigateBack = () => { @@ -96,7 +97,7 @@ function IOURequestStepDate({ IOU.setMoneyRequestCreated(transaction.transactionID, newCreated, action === CONST.IOU.ACTION.CREATE); - if (action === CONST.IOU.ACTION.EDIT) { + if (isEditing) { IOU.updateMoneyRequestDate(transaction.transactionID, reportID, newCreated, policy, policyTags, policyCategories); } From 588d43a9f081c12dfceef2f5c1d7948217f3baf9 Mon Sep 17 00:00:00 2001 From: brunovjk Date: Sun, 11 Feb 2024 08:15:06 -0300 Subject: [PATCH 11/11] Organize comment --- src/pages/iou/request/step/IOURequestStepDate.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepDate.js b/src/pages/iou/request/step/IOURequestStepDate.js index 4f27567b5346..d25ca4d26706 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.js +++ b/src/pages/iou/request/step/IOURequestStepDate.js @@ -65,9 +65,8 @@ function IOURequestStepDate({ }) { const styles = useThemeStyles(); const {translate} = useLocalize(); - - // In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value const isEditing = action === CONST.IOU.ACTION.EDIT; + // In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && isEditing; const currentCreated = isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? TransactionUtils.getCreated(splitDraftTransaction) : TransactionUtils.getCreated(transaction);