Skip to content

Commit

Permalink
Merge pull request #32764 from Expensify/tgolen-refactor-moneyrequest…
Browse files Browse the repository at this point in the history
…creation-cleanup

Remove old receipt selector
  • Loading branch information
johnmlee101 authored Jan 10, 2024
2 parents 5a3bc6e + d216913 commit 582b853
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 937 deletions.
4 changes: 4 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,10 @@ const CONST = {
EXPENSIFY: 'Expensify',
VBBA: 'ACH',
},
ACTION: {
EDIT: 'edit',
CREATE: 'create',
},
DEFAULT_AMOUNT: 0,
TYPE: {
SEND: 'send',
Expand Down
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ const ROUTES = {
getUrlWithBackToParam(`create/${iouType}/participants/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_SCAN: {
route: 'create/:iouType/scan/:transactionID/:reportID',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`create/${iouType}/scan/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/scan/:transactionID/:reportID',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/scan/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAG: {
route: 'create/:iouType/tag/:transactionID/:reportID',
Expand Down
10 changes: 9 additions & 1 deletion src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,15 @@ function AttachmentModal(props) {
text: props.translate('common.replace'),
onSelected: () => {
closeModal();
Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT));
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
CONST.IOU.TYPE.REQUEST,
props.transaction.transactionID,
props.report.reportID,
Navigation.getActiveRouteWithoutParams(),
),
);
},
});
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
threeDotsMenuItems.push({
icon: Expensicons.Receipt,
text: translate('receipt.addReceipt'),
onSelected: () => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT)),
onSelected: () =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
CONST.IOU.TYPE.REQUEST,
transaction.transactionID,
report.reportID,
Navigation.getActiveRouteWithoutParams(),
),
),
});
}
threeDotsMenuItems.push({
Expand Down
12 changes: 11 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,17 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
{!hasReceipt && canEditReceipt && canUseViolations && (
<ReceiptEmptyState
hasError={hasErrors}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT))}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
CONST.IOU.TYPE.REQUEST,
transaction.transactionID,
report.reportID,
Navigation.getActiveRouteWithoutParams(),
),
)
}
/>
)}
{canUseViolations && <ViolationMessages violations={getViolationsForField('receipt')} />}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function navigateToStartStepIfScanFileCannotBeRead(
}

const onFailure = () => {
IOU.setMoneyRequestReceipt_temporaryForRefactor(transactionID, '', '');
IOU.setMoneyRequestReceipt(transactionID, '', '', true);
if (requestType === CONST.IOU.REQUEST_TYPE.MANUAL) {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
return;
}
navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID);
Expand Down
31 changes: 13 additions & 18 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,13 @@ function setMoneyRequestParticipants_temporaryForRefactor(transactionID, partici
* @param {String} transactionID
* @param {String} source
* @param {String} filename
* @param {Boolean} isDraft
*/
function setMoneyRequestReceipt_temporaryForRefactor(transactionID, source, filename) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {receipt: {source}, filename});
function setMoneyRequestReceipt(transactionID, source, filename, isDraft) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
receipt: {source},
filename,
});
}

/**
Expand Down Expand Up @@ -3357,10 +3361,10 @@ function detachReceipt(transactionID) {

/**
* @param {String} transactionID
* @param {Object} receipt
* @param {String} filePath
* @param {Object} file
* @param {String} source
*/
function replaceReceipt(transactionID, receipt, filePath) {
function replaceReceipt(transactionID, file, source) {
const transaction = lodashGet(allTransactions, 'transactionID', {});
const oldReceipt = lodashGet(transaction, 'receipt', {});

Expand All @@ -3370,10 +3374,10 @@ function replaceReceipt(transactionID, receipt, filePath) {
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: {
receipt: {
source: filePath,
source,
state: CONST.IOU.RECEIPT_STATE.OPEN,
},
filename: receipt.name,
filename: file.name,
},
},
];
Expand All @@ -3389,7 +3393,7 @@ function replaceReceipt(transactionID, receipt, filePath) {
},
];

API.write('ReplaceReceipt', {transactionID, receipt}, {optimisticData, failureData});
API.write('ReplaceReceipt', {transactionID, receipt: file}, {optimisticData, failureData});
}

/**
Expand Down Expand Up @@ -3515,14 +3519,6 @@ function setMoneyRequestParticipants(participants, isSplitRequest) {
Onyx.merge(ONYXKEYS.IOU, {participants, isSplitRequest});
}

/**
* @param {String} receiptPath
* @param {String} receiptFilename
*/
function setMoneyRequestReceipt(receiptPath, receiptFilename) {
Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptFilename, merchant: ''});
}

function setUpDistanceTransaction() {
const transactionID = NumberUtils.rand64();
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
Expand Down Expand Up @@ -3626,7 +3622,7 @@ export {
setMoneyRequestDescription_temporaryForRefactor,
setMoneyRequestMerchant_temporaryForRefactor,
setMoneyRequestParticipants_temporaryForRefactor,
setMoneyRequestReceipt_temporaryForRefactor,
setMoneyRequestReceipt,
setMoneyRequestTag_temporaryForRefactor,
setMoneyRequestAmount,
setMoneyRequestBillable,
Expand All @@ -3637,7 +3633,6 @@ export {
setMoneyRequestId,
setMoneyRequestMerchant,
setMoneyRequestParticipantsFromReport,
setMoneyRequestReceipt,
setMoneyRequestTag,
setMoneyRequestTaxAmount,
setMoneyRequestTaxRate,
Expand Down
18 changes: 3 additions & 15 deletions src/pages/EditRequestReceiptPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import ReceiptSelector from './iou/ReceiptSelector';
import IOURequestStepScan from './iou/request/step/IOURequestStepScan';

const propTypes = {
/** React Navigation route */
Expand All @@ -21,16 +21,9 @@ const propTypes = {
reportID: PropTypes.string,
}),
}).isRequired,

/** The id of the transaction we're editing */
transactionID: PropTypes.string,
};

const defaultProps = {
transactionID: '',
};

function EditRequestReceiptPage({route, transactionID}) {
function EditRequestReceiptPage({route}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [isDraggingOver, setIsDraggingOver] = useState(false);
Expand All @@ -49,11 +42,7 @@ function EditRequestReceiptPage({route, transactionID}) {
title={translate('common.receipt')}
onBackButtonPress={Navigation.goBack}
/>
<ReceiptSelector
route={route}
transactionID={transactionID}
isInTabNavigator={false}
/>
<IOURequestStepScan route={route} />
</View>
</DragAndDropProvider>
)}
Expand All @@ -62,7 +51,6 @@ function EditRequestReceiptPage({route, transactionID}) {
}

EditRequestReceiptPage.propTypes = propTypes;
EditRequestReceiptPage.defaultProps = defaultProps;
EditRequestReceiptPage.displayName = 'EditRequestReceiptPage';

export default EditRequestReceiptPage;
8 changes: 2 additions & 6 deletions src/pages/iou/MoneyRequestSelectorPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import NewDistanceRequestPage from './NewDistanceRequestPage';
import ReceiptSelector from './ReceiptSelector';
import IOURequestStepScan from './request/step/IOURequestStepScan';
import NewRequestAmountPage from './steps/NewRequestAmountPage';

const propTypes = {
Expand Down Expand Up @@ -132,11 +132,7 @@ function MoneyRequestSelectorPage(props) {
component={NewRequestAmountPage}
initialParams={{reportID, iouType}}
/>
<TopTab.Screen
name={CONST.TAB_REQUEST.SCAN}
component={ReceiptSelector}
initialParams={{reportID, iouType, pageIndex: 1}}
/>
<TopTab.Screen name={CONST.TAB_REQUEST.SCAN}>{() => <IOURequestStepScan route={props.route} />}</TopTab.Screen>
{shouldDisplayDistanceRequest && (
<TopTab.Screen
name={CONST.TAB_REQUEST.DISTANCE}
Expand Down
12 changes: 0 additions & 12 deletions src/pages/iou/ReceiptSelector/CameraPermission/index.android.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/pages/iou/ReceiptSelector/CameraPermission/index.ios.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/pages/iou/ReceiptSelector/CameraPermission/index.js

This file was deleted.

80 changes: 0 additions & 80 deletions src/pages/iou/ReceiptSelector/NavigationAwareCamera/index.js

This file was deleted.

This file was deleted.

Loading

0 comments on commit 582b853

Please sign in to comment.