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

Add an option for distance requests #23048

Merged
merged 31 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d09e353
Add beta check for distance requests
neil-marcellini Jul 17, 2023
6c0487b
Tab for distance requests if on beta
neil-marcellini Jul 17, 2023
57ef1de
Extract tab constants
neil-marcellini Jul 17, 2023
980ed82
WIP add distance request tab
neil-marcellini Jul 17, 2023
3538981
Add dummy DistanceRequest component
neil-marcellini Jul 18, 2023
8f3c610
Fix simple distance request component
neil-marcellini Jul 18, 2023
f32c077
Add car Expensicon
neil-marcellini Jul 19, 2023
65d12b5
Merge branch 'andrew-scan' into neil-distance-option
neil-marcellini Jul 19, 2023
7810fb0
Translate distance tab selector
neil-marcellini Jul 19, 2023
623be15
Fix tab contents
neil-marcellini Jul 20, 2023
8045c1a
accessibility label is required
neil-marcellini Jul 20, 2023
f7326a4
Create empty transaction linked to iou
neil-marcellini Jul 20, 2023
2ff0b3d
Merge branch 'andrew-scan' into neil-distance-option
neil-marcellini Jul 20, 2023
8f75d97
Make tab title required for accessibility
neil-marcellini Jul 20, 2023
a1421ba
Remove unused props for now
neil-marcellini Jul 20, 2023
f68f998
Clean up and prettify
neil-marcellini Jul 20, 2023
f72a4af
Use selector per checklist
neil-marcellini Jul 20, 2023
26abf92
Destructure props
AndrewGable Jul 21, 2023
d937bac
Fix lint
AndrewGable Jul 21, 2023
1d8e02b
Merge branch 'andrew-scan' into neil-distance-option
neil-marcellini Jul 21, 2023
e48d614
conditionally render tab content in returned jsx
neil-marcellini Jul 21, 2023
7947230
Add JSDoc for convention
neil-marcellini Jul 21, 2023
704434a
Clean up after merge
neil-marcellini Jul 21, 2023
33a9356
Merge branch 'main' into neil-distance-option
neil-marcellini Aug 3, 2023
5a50ab9
Fix selector
neil-marcellini Aug 3, 2023
5395245
Fix distance tab after merge
neil-marcellini Aug 3, 2023
92b7b4b
Merge branch 'main' into neil-distance-option
neil-marcellini Aug 4, 2023
c7a4be1
Use version of this file that's on main
neil-marcellini Aug 4, 2023
ca0d60d
Fix access on undefined in selector
neil-marcellini Aug 4, 2023
c861785
Fix routes
neil-marcellini Aug 5, 2023
5da8d78
Show tabs if you can use scan or distance
neil-marcellini Aug 5, 2023
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
15 changes: 15 additions & 0 deletions assets/images/car.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const CONST = {
TASKS: 'tasks',
THREADS: 'threads',
SCAN_RECEIPTS: 'scanReceipts',
DISTANCE_REQUESTS: 'distanceRequests',
},
BUTTON_STATES: {
DEFAULT: 'default',
Expand Down Expand Up @@ -2567,6 +2568,7 @@ const CONST = {
RECEIPT_TAB_ID: 'ReceiptTab',
MANUAL: 'manual',
SCAN: 'scan',
DISTANCE: 'distance',
},
};

Expand Down
1 change: 1 addition & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default {
MONEY_REQUEST_DESCRIPTION: ':iouType/new/description/:reportID?',
MONEY_REQUEST_MANUAL_TAB: ':iouType/new/:reportID?/manual',
MONEY_REQUEST_SCAN_TAB: ':iouType/new/:reportID?/scan',
MONEY_REQUEST_DISTANCE_TAB: ':iouType/new/:reportID?/distance',
IOU_SEND_ADD_BANK_ACCOUNT: `${IOU_SEND}/add-bank-account`,
IOU_SEND_ADD_DEBIT_CARD: `${IOU_SEND}/add-debit-card`,
IOU_SEND_ENABLE_PAYMENTS: `${IOU_SEND}/enable-payments`,
Expand Down
40 changes: 40 additions & 0 deletions src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {useEffect} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import Text from './Text';
import * as IOU from '../libs/actions/IOU';
import styles from '../styles/styles';
import ONYXKEYS from '../ONYXKEYS';

const propTypes = {
/** The transactionID of this request */
transactionID: PropTypes.string,
};

const defaultProps = {
transactionID: '',
};

function DistanceRequest(props) {
useEffect(() => {
if (props.transactionID) {
return;
}
IOU.createEmptyTransaction();
}, [props.transactionID]);

return (
<View style={[styles.flex1, styles.flexColumn, styles.w100, styles.alignItemsCenter, styles.mt4]}>
<Text>Distance Request</Text>
<Text>transactionID: {props.transactionID}</Text>
</View>
);
}

DistanceRequest.displayName = 'DistanceRequest';
DistanceRequest.propTypes = propTypes;
DistanceRequest.defaultProps = defaultProps;
export default withOnyx({
transactionID: {key: ONYXKEYS.IOU, selector: (iou) => (iou && iou.transactionID) || ''},
})(DistanceRequest);
2 changes: 2 additions & 0 deletions src/components/Icon/Expensicons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Bug from '../../../assets/images/bug.svg';
import Building from '../../../assets/images/building.svg';
import Calendar from '../../../assets/images/calendar.svg';
import Camera from '../../../assets/images/camera.svg';
import Car from '../../../assets/images/car.svg';
import Cash from '../../../assets/images/cash.svg';
import ChatBubble from '../../../assets/images/chatbubble.svg';
import Checkmark from '../../../assets/images/checkmark.svg';
Expand Down Expand Up @@ -136,6 +137,7 @@ export {
Building,
Calendar,
Camera,
Car,
Cash,
ChatBubble,
Checkmark,
Expand Down
11 changes: 10 additions & 1 deletion src/components/TabSelector/TabSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ const defaultProps = {
onTabPress: () => {},
};

const getIcon = (route) => (route === CONST.TAB.MANUAL ? Expensicons.Pencil : Expensicons.Receipt);
const getIcon = (route) => {
switch (route) {
case CONST.TAB.SCAN:
return Expensicons.Receipt;
case CONST.TAB.DISTANCE:
return Expensicons.Car;
default:
return Expensicons.Pencil;
}
};

function TabSelector({state, navigation, onTabPress}) {
const {translate} = useLocalize();
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export default {
tabSelector: {
manual: 'Manual',
scan: 'Scan',
distance: 'Distance',
},
receipt: {
upload: 'Upload receipt',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export default {
tabSelector: {
manual: 'Manual',
scan: 'Escanear',
distance: 'Distancia',
},
receipt: {
upload: 'Subir recibo',
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export default {
path: ROUTES.MONEY_REQUEST_SCAN_TAB,
exact: true,
},
distance: {
path: ROUTES.MONEY_REQUEST_DISTANCE_TAB,
exact: true,
},
},
},
Money_Request_Amount: ROUTES.MONEY_REQUEST_AMOUNT,
Expand Down
9 changes: 9 additions & 0 deletions src/libs/Permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ function canUseScanReceipts(betas) {
return _.contains(betas, CONST.BETAS.SCAN_RECEIPTS) || canUseAllBetas(betas);
}

/**
* @param {Array<String>} betas
* @returns {Boolean}
*/
function canUseDistanceRequests(betas) {
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
return _.contains(betas, CONST.BETAS.DISTANCE_REQUESTS) || canUseAllBetas(betas);
}

export default {
canUseChronos,
canUsePayWithExpensify,
Expand All @@ -105,4 +113,5 @@ export default {
canUsePolicyExpenseChat,
canUseTasks,
canUseScanReceipts,
canUseDistanceRequests,
};
8 changes: 8 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import TransactionUtils from '../TransactionUtils';
import * as ErrorUtils from '../ErrorUtils';
import * as UserUtils from '../UserUtils';
import * as Report from './Report';
import * as NumberUtils from '../NumberUtils';

let allReports;
Onyx.connect({
Expand Down Expand Up @@ -1509,6 +1510,12 @@ function setMoneyRequestReceipt(receiptPath, receiptSource) {
Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptSource});
}

function createEmptyTransaction() {
const transactionID = NumberUtils.rand64();
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {});
Onyx.merge(ONYXKEYS.IOU, {transactionID});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not reset the iou key rather just add transactionID as a key. Are you sure this is what we want to do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think other flows should handle resetting the iou key. It should be in a good state.

}

/**
* Navigates to the next IOU page based on where the IOU request was started
*
Expand Down Expand Up @@ -1562,5 +1569,6 @@ export {
setMoneyRequestDescription,
setMoneyRequestParticipants,
setMoneyRequestReceipt,
createEmptyTransaction,
navigateToNextPage,
};
23 changes: 16 additions & 7 deletions src/pages/iou/MoneyRequestSelectorPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import styles from '../../styles/styles';
import MoneyRequestAmount from './steps/MoneyRequestAmount';
import ReceiptSelector from './ReceiptSelector';
import * as IOU from '../../libs/actions/IOU';
import DistanceRequest from '../../components/DistanceRequest';
import DragAndDropProvider from '../../components/DragAndDrop/Provider';
import usePermissions from '../../hooks/usePermissions';
import OnyxTabNavigator, {TopTab} from '../../libs/Navigation/OnyxTabNavigator';
Expand Down Expand Up @@ -62,7 +63,7 @@ function MoneyRequestSelectorPage(props) {
const iouType = lodashGet(props.route, 'params.iouType', '');
const reportID = lodashGet(props.route, 'params.reportID', '');
const {translate} = useLocalize();
const {canUseScanReceipts} = usePermissions();
const {canUseScanReceipts, canUseDistanceRequests} = usePermissions();

const title = {
[CONST.IOU.MONEY_REQUEST_TYPE.REQUEST]: translate('iou.requestMoney'),
Expand All @@ -85,7 +86,7 @@ function MoneyRequestSelectorPage(props) {
title={title[iouType]}
onBackButtonPress={Navigation.dismissModal}
/>
{canUseScanReceipts && iouType === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST ? (
{(canUseScanReceipts || canUseDistanceRequests) && iouType === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST ? (
<OnyxTabNavigator
id={CONST.TAB.RECEIPT_TAB_ID}
tabBar={({state, navigation}) => (
Expand All @@ -101,11 +102,19 @@ function MoneyRequestSelectorPage(props) {
component={MoneyRequestAmount}
initialParams={{reportID, iouType}}
/>
<TopTab.Screen
name={CONST.TAB.SCAN}
component={ReceiptSelector}
initialParams={{reportID, iouType}}
/>
{canUseScanReceipts && (
<TopTab.Screen
name={CONST.TAB.SCAN}
component={ReceiptSelector}
initialParams={{reportID, iouType}}
/>
)}
{canUseDistanceRequests && (
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
<TopTab.Screen
name={CONST.TAB.DISTANCE}
component={DistanceRequest}
/>
)}
</OnyxTabNavigator>
) : (
<MoneyRequestAmount route={props.route} />
Expand Down
Loading