Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
208f430
Create WaypointEditor bones
thienlnam Aug 8, 2023
cc0352a
Start DistanceRequest actions
thienlnam Aug 8, 2023
8dd750b
Add route navigation
thienlnam Aug 8, 2023
4192bcb
Update linkingConfig.js
thienlnam Aug 8, 2023
b63cdbb
Update passed in props
thienlnam Aug 8, 2023
975863c
Add navigation and form draft
thienlnam Aug 9, 2023
3aa122c
Have draft keys shown
thienlnam Aug 9, 2023
98fbf35
return the lat/long/address!
thienlnam Aug 9, 2023
e8b0c98
Make it so waypoint form only updates the waypoint index
thienlnam Aug 9, 2023
fdcdc46
Prevent you from inputting null keys
thienlnam Aug 9, 2023
f3296cd
Save waypoint to transaction
thienlnam Aug 10, 2023
68d1d68
Handle saving an empty waypoint
thienlnam Aug 10, 2023
6ac9183
Add offline functionality
thienlnam Aug 10, 2023
5b5fc38
comments & translations
thienlnam Aug 10, 2023
9724ebe
Merge branch 'main' into jack-branchedWaypointEditor
thienlnam Aug 10, 2023
55586ab
prettier
thienlnam Aug 10, 2023
8b9e4d9
Merge branch 'main' into jack-branchedWaypointEditor
thienlnam Aug 11, 2023
146ec44
Merge branch 'main' into jack-branchedWaypointEditor
thienlnam Aug 11, 2023
9aef1fc
Merge branch 'main' into jack-branchedWaypointEditor
thienlnam Aug 11, 2023
948b91c
Remove the onSubmit
thienlnam Aug 11, 2023
702d216
icon color update / remove const
thienlnam Aug 11, 2023
83bdef2
Add save button
thienlnam Aug 11, 2023
9a4aeb4
Move DistanceRequest action to Transaction actions
thienlnam Aug 12, 2023
3357bf1
Use destructuring
thienlnam Aug 12, 2023
203a174
Use lodashGet for safer access
thienlnam Aug 12, 2023
5f5746e
Add missing renamedInputKeys
thienlnam Aug 12, 2023
95153d7
Merge branch 'main' into jack-branchedWaypointEditor
thienlnam Aug 14, 2023
c2dc396
prevent empty spaces / showing error on failure
thienlnam Aug 14, 2023
6a859a4
Add no results to AddressSearch component
thienlnam Aug 14, 2023
f0e1c4a
Lint
thienlnam Aug 14, 2023
194ec27
remove the transactionID from the route
thienlnam Aug 14, 2023
1b8cea9
Add network to google places
thienlnam Aug 14, 2023
d296547
Add network to WaypointEditor
thienlnam Aug 14, 2023
072c408
Fix values not aligning
thienlnam Aug 14, 2023
3969344
Update WaypointEditor.js
thienlnam Aug 14, 2023
05a3c41
add props to validate on change and on blur
thienlnam Aug 14, 2023
92e11a7
Add auto-focus
thienlnam Aug 15, 2023
4a1490c
prettier
thienlnam Aug 15, 2023
b14be0b
Have it pull the transaction data
thienlnam Aug 15, 2023
378c4a5
Add handling to remove waypoints and reindex them
thienlnam Aug 15, 2023
602d87a
fix lint issue
thienlnam Aug 15, 2023
868ea3d
Prettier
thienlnam Aug 15, 2023
72887b1
Add new page so WaypointEditor can use transactionID as a prop
thienlnam Aug 16, 2023
d52aa16
Update WaypointEditor.js
thienlnam Aug 16, 2023
1bdc6aa
Fix issue with initial waypoints not showing up
thienlnam Aug 16, 2023
dda94c5
fix numbering
thienlnam Aug 16, 2023
b9f346b
prettier / fix issue with onyx not removing key
thienlnam Aug 16, 2023
4c71b91
review comment
thienlnam Aug 16, 2023
dcc10d7
review comments
thienlnam Aug 16, 2023
7ee2726
Merge branch 'main' into jack-branchedWaypointEditor
thienlnam Aug 16, 2023
957233c
Update Transaction.js
thienlnam Aug 16, 2023
4bda6ad
Update to goBack
thienlnam Aug 16, 2023
5a383c7
Add goback route
thienlnam Aug 17, 2023
9f57e7f
add prop lol
thienlnam Aug 17, 2023
10c6a56
Add translation for Waypoint Editor
thienlnam Aug 17, 2023
d0ae0fd
Oops, swap the waypoints
thienlnam Aug 17, 2023
ff4a775
Add approved copy
thienlnam Aug 17, 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
2 changes: 2 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ export default {
MONEY_REQUEST_CREATED_FORM: 'moneyRequestCreatedForm',
NEW_CONTACT_METHOD_FORM: 'newContactMethodForm',
PAYPAL_FORM: 'payPalForm',
WAYPOINT_FORM: 'waypointForm',
WAYPOINT_FORM_DRAFT: 'waypointFormDraft',
SETTINGS_STATUS_SET_FORM: 'settingsStatusSetForm',
SETTINGS_STATUS_CLEAR_AFTER_FORM: 'settingsStatusClearAfterForm',
SETTINGS_STATUS_SET_CLEAR_AFTER_FORM: 'settingsStatusSetClearAfterForm',
Expand Down
3 changes: 3 additions & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default {
MONEY_REQUEST_MANUAL_TAB: ':iouType/new/:reportID?/manual',
MONEY_REQUEST_SCAN_TAB: ':iouType/new/:reportID?/scan',
MONEY_REQUEST_DISTANCE_TAB: ':iouType/new/:reportID?/distance',
MONEY_REQUEST_WAYPOINT: ':iouType/new/waypoint/:waypointIndex',
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 All @@ -104,6 +105,8 @@ export default {
getMoneyRequestConfirmationRoute: (iouType, reportID = '') => `${iouType}/new/confirmation/${reportID}`,
getMoneyRequestCurrencyRoute: (iouType, reportID = '', currency, backTo) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}`,
getMoneyRequestDescriptionRoute: (iouType, reportID = '') => `${iouType}/new/description/${reportID}`,
getMoneyRequestDistanceTabRoute: (iouType, reportID = '') => `${iouType}/new/${reportID}/distance`,
getMoneyRequestWaypointRoute: (iouType, waypointIndex) => `${iouType}/new/waypoint/${waypointIndex}`,
SPLIT_BILL_DETAILS: `r/:reportID/split/:reportActionID`,
getSplitBillDetailsRoute: (reportID, reportActionID) => `r/${reportID}/split/${reportActionID}`,
getNewTaskRoute: (reportID) => `${NEW_TASK}/${reportID}`,
Expand Down
36 changes: 34 additions & 2 deletions src/components/AddressSearch/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import _ from 'underscore';
import React, {useMemo, useRef, useState} from 'react';
import PropTypes from 'prop-types';
import {LogBox, ScrollView, View} from 'react-native';
import {LogBox, ScrollView, View, Text} from 'react-native';
import {GooglePlacesAutocomplete} from 'react-native-google-places-autocomplete';
import lodashGet from 'lodash/get';
import compose from '../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import styles from '../../styles/styles';
import themeColors from '../../styles/themes/default';
Expand All @@ -14,6 +15,8 @@ import CONST from '../../CONST';
import * as StyleUtils from '../../styles/StyleUtils';
import resetDisplayListViewBorderOnBlur from './resetDisplayListViewBorderOnBlur';
import variables from '../../styles/variables';
import {withNetwork} from '../OnyxProvider';
import networkPropTypes from '../networkPropTypes';

// The error that's being thrown below will be ignored until we fork the
// react-native-google-places-autocomplete repo and replace the
Expand Down Expand Up @@ -48,6 +51,9 @@ const propTypes = {
/** A callback function when the value of this field has changed */
onInputChange: PropTypes.func.isRequired,

/** A callback function when an address has been auto-selected */
onPress: PropTypes.func,

/** Customize the TextInput container */
// eslint-disable-next-line react/forbid-prop-types
containerStyles: PropTypes.arrayOf(PropTypes.object),
Expand All @@ -58,21 +64,28 @@ const propTypes = {
/** A map of inputID key names */
renamedInputKeys: PropTypes.shape({
street: PropTypes.string,
street2: PropTypes.string,
city: PropTypes.string,
state: PropTypes.string,
lat: PropTypes.string,
lng: PropTypes.string,
zipCode: PropTypes.string,
}),

/** Maximum number of characters allowed in search input */
maxInputLength: PropTypes.number,

/** Information about the network */
network: networkPropTypes.isRequired,

...withLocalizePropTypes,
};

const defaultProps = {
inputID: undefined,
shouldSaveDraft: false,
onBlur: () => {},
onPress: () => {},
errorText: '',
hint: '',
value: undefined,
Expand All @@ -81,9 +94,12 @@ const defaultProps = {
isLimitedToUSA: true,
renamedInputKeys: {
street: 'addressStreet',
street2: 'addressStreet2',
city: 'addressCity',
state: 'addressState',
zipCode: 'addressZipCode',
lat: 'addressLat',
lng: 'addressLng',
},
maxInputLength: undefined,
};
Expand Down Expand Up @@ -166,6 +182,9 @@ function AddressSearch(props) {
zipCode,
country: '',
state: state || stateAutoCompleteFallback,
lat: lodashGet(details, 'geometry.location.lat', 0),
lng: lodashGet(details, 'geometry.location.lng', 0),
address: lodashGet(details, 'formatted_address', ''),
};

// If the address is not in the US, use the full length state name since we're displaying the address's
Expand Down Expand Up @@ -194,11 +213,16 @@ function AddressSearch(props) {
if (props.inputID) {
_.each(values, (value, key) => {
const inputKey = lodashGet(props.renamedInputKeys, key, key);
if (!inputKey) {
return;
}
props.onInputChange(value, inputKey);
});
} else {
props.onInputChange(values);
}

props.onPress(values);
};

return (
Expand Down Expand Up @@ -226,6 +250,11 @@ function AddressSearch(props) {
fetchDetails
suppressDefaultStyles
enablePoweredByContainer={false}
ListEmptyComponent={
props.network.isOffline ? null : (
<Text style={[styles.textLabel, styles.colorMuted, styles.pv4, styles.ph3, styles.overflowAuto]}>{props.translate('common.noResultsFound')}</Text>
)
}
onPress={(data, details) => {
saveLocationDetails(data, details);

Expand Down Expand Up @@ -306,7 +335,10 @@ AddressSearch.propTypes = propTypes;
AddressSearch.defaultProps = defaultProps;
AddressSearch.displayName = 'AddressSearch';

export default withLocalize(
export default compose(
withNetwork(),
withLocalize,
)(
React.forwardRef((props, ref) => (
<AddressSearch
// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
13 changes: 9 additions & 4 deletions src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Button from './Button';
import styles from '../styles/styles';
import variables from '../styles/variables';
import LinearGradient from './LinearGradient';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';

const MAX_WAYPOINTS = 25;
const MAX_WAYPOINTS_TO_DISPLAY = 4;
Expand Down Expand Up @@ -66,12 +68,12 @@ function DistanceRequest({transactionID, transaction, translate}) {
const scrollContainerMaxHeight = variables.baseMenuItemHeight * MAX_WAYPOINTS_TO_DISPLAY + halfMenuItemHeight;

useEffect(() => {
if (!transaction.transactionID || !_.isEmpty(waypoints)) {
if (!transactionID || !_.isEmpty(waypoints)) {
return;
}
// Create the initial start and stop waypoints
Transaction.createInitialWaypoints(transaction.transactionID);
}, [transaction.transactionID, waypoints]);
Transaction.createInitialWaypoints(transactionID);
}, [transactionID, waypoints]);

const updateGradientVisibility = (event = {}) => {
// If a waypoint extends past the bottom of the visible area show the gradient, else hide it.
Expand Down Expand Up @@ -111,10 +113,13 @@ function DistanceRequest({transactionID, transaction, translate}) {
return (
<MenuItemWithTopDescription
description={translate(descriptionKey)}
title={lodashGet(waypoints, [`waypoint${index}`, 'address'], '')}
icon={Expensicons.DragHandles}
iconFill={theme.icon}
secondaryIcon={waypointIcon}
secondaryIconFill={theme.icon}
shouldShowRightIcon
onPress={() => Navigation.navigate(ROUTES.getMoneyRequestWaypointRoute('request', index))}
key={key}
/>
);
Expand All @@ -131,7 +136,7 @@ function DistanceRequest({transactionID, transaction, translate}) {
<Button
small
icon={Expensicons.Plus}
onPress={() => Transaction.addStop(transactionID, lastWaypointIndex + 1)}
onPress={() => Transaction.addStop(transactionID)}
text={translate('distance.addStop')}
isDisabled={numberOfWaypoints === MAX_WAYPOINTS}
innerStyles={[styles.ph10]}
Expand Down
19 changes: 16 additions & 3 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const propTypes = {
/** Whether the form submit action is dangerous */
isSubmitActionDangerous: PropTypes.bool,

/** Whether the validate() method should run on input changes */
shouldValidateOnChange: PropTypes.bool,

/** Whether the validate() method should run on blur */
shouldValidateOnBlur: PropTypes.bool,

/** Whether ScrollWithContext should be used instead of regular ScrollView.
* Set to true when there's a nested Picker component in Form.
*/
Expand Down Expand Up @@ -89,6 +95,8 @@ const defaultProps = {
enabledWhenOffline: false,
isSubmitActionDangerous: false,
scrollContextEnabled: false,
shouldValidateOnChange: true,
shouldValidateOnBlur: true,
footerContent: null,
style: [],
validate: () => ({}),
Expand Down Expand Up @@ -306,7 +314,9 @@ function Form(props) {
// web and mobile web platforms.
setTimeout(() => {
setTouchedInput(inputID);
onValidate(inputValues);
if (props.shouldValidateOnBlur) {
onValidate(inputValues);
}
}, 200);
}

Expand All @@ -324,7 +334,10 @@ function Form(props) {
...prevState,
[inputKey]: value,
};
onValidate(newState);

if (props.shouldValidateOnChange) {
onValidate(newState);
}
return newState;
});

Expand All @@ -341,7 +354,7 @@ function Form(props) {

return childrenElements;
},
[errors, inputRefs, inputValues, onValidate, props.draftValues, props.formID, props.formState, setTouchedInput],
[errors, inputRefs, inputValues, onValidate, props.draftValues, props.formID, props.formState, setTouchedInput, props.shouldValidateOnBlur, props.shouldValidateOnChange],
);

const scrollViewContent = useCallback(
Expand Down
5 changes: 5 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,16 @@ export default {
},
distance: {
addStop: 'Add stop',
address: 'Address',
waypointEditor: 'Waypoint Editor',
waypointDescription: {
start: 'Start',
finish: 'Finish',
stop: 'Stop',
},
errors: {
selectSuggestedAddress: 'Please select a suggested address',
},
},
countrySelectorModal: {
placeholderText: 'Search to see options',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -2052,11 +2052,16 @@ export default {
},
distance: {
addStop: 'Agregar parada',
address: 'Dirección',
waypointEditor: 'Editor de puntos de ruta',
waypointDescription: {
start: 'Comienzo',
finish: 'Final',
stop: 'Parada',
},
errors: {
selectSuggestedAddress: 'Por favor, selecciona una dirección sugerida',
},
},
countrySelectorModal: {
placeholderText: 'Buscar para ver opciones',
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 @@ -97,6 +97,13 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator([
},
name: 'IOU_Send_Enable_Payments',
},
{
getComponent: () => {
const WaypointEditorPage = require('../../../pages/iou/WaypointEditorPage').default;
return WaypointEditorPage;
},
name: 'Money_Request_Waypoint',
},
]);

const SplitDetailsModalStackNavigator = createModalStackNavigator([
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 @@ -321,6 +321,7 @@ export default {
Money_Request_Confirmation: ROUTES.MONEY_REQUEST_CONFIRMATION,
Money_Request_Currency: ROUTES.MONEY_REQUEST_CURRENCY,
Money_Request_Description: ROUTES.MONEY_REQUEST_DESCRIPTION,
Money_Request_Waypoint: ROUTES.MONEY_REQUEST_WAYPOINT,
IOU_Send_Enable_Payments: ROUTES.IOU_SEND_ENABLE_PAYMENTS,
IOU_Send_Add_Bank_Account: ROUTES.IOU_SEND_ADD_BANK_ACCOUNT,
IOU_Send_Add_Debit_Card: ROUTES.IOU_SEND_ADD_DEBIT_CARD,
Expand Down
Loading