-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 option to delete stop #25984
Merged
hayata-suenaga
merged 9 commits into
Expensify:main
from
Nikhil-Vats:25901_add_option_to_delete_stops
Aug 28, 2023
Merged
Add option to delete stop #25984
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aaf2e94
Add option to delete stop
Nikhil-Vats 35432fe
Hide the menu on start and finish endpoint
Nikhil-Vats af8bd7e
Merge branch 'main' into 25901_add_option_to_delete_stops
Nikhil-Vats 6cf66ad
Change method name
Nikhil-Vats ab468b1
Use hooks instead of HOC
Nikhil-Vats 7c26959
Merge branch 'main' into 25901_add_option_to_delete_stops
Nikhil-Vats 52275f8
Add translation for spanish
Nikhil-Vats bdc6ca3
Destructure props
Nikhil-Vats 873d918
Merge branch 'main' into 25901_add_option_to_delete_stops
Nikhil-Vats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||
import React, {useRef} from 'react'; | ||||||
import _ from 'underscore'; | ||||||
import React, {useRef, useState} from 'react'; | ||||||
import lodashGet from 'lodash/get'; | ||||||
import {View} from 'react-native'; | ||||||
import PropTypes from 'prop-types'; | ||||||
|
@@ -10,14 +11,15 @@ import Navigation from '../../libs/Navigation/Navigation'; | |||||
import ONYXKEYS from '../../ONYXKEYS'; | ||||||
import Form from '../../components/Form'; | ||||||
import styles from '../../styles/styles'; | ||||||
import compose from '../../libs/compose'; | ||||||
import useWindowDimensions from '../../hooks/useWindowDimensions'; | ||||||
import useLocalize from '../../hooks/useLocalize'; | ||||||
import useNetwork from '../../hooks/useNetwork'; | ||||||
import CONST from '../../CONST'; | ||||||
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; | ||||||
import * as Expensicons from '../../components/Icon/Expensicons'; | ||||||
import ConfirmModal from '../../components/ConfirmModal'; | ||||||
import * as Transaction from '../../libs/actions/Transaction'; | ||||||
import * as ValidationUtils from '../../libs/ValidationUtils'; | ||||||
import ROUTES from '../../ROUTES'; | ||||||
import {withNetwork} from '../../components/OnyxProvider'; | ||||||
import networkPropTypes from '../../components/networkPropTypes'; | ||||||
import transactionPropTypes from '../../components/transactionPropTypes'; | ||||||
|
||||||
const propTypes = { | ||||||
|
@@ -37,11 +39,6 @@ const propTypes = { | |||||
|
||||||
/** The optimistic transaction for this request */ | ||||||
transaction: transactionPropTypes, | ||||||
|
||||||
/** Information about the network */ | ||||||
network: networkPropTypes.isRequired, | ||||||
|
||||||
...withLocalizePropTypes, | ||||||
}; | ||||||
|
||||||
const defaultProps = { | ||||||
|
@@ -53,21 +50,28 @@ const defaultProps = { | |||||
transaction: {}, | ||||||
}; | ||||||
|
||||||
function WaypointEditor({transactionID, route: {params: {iouType = '', waypointIndex = ''} = {}} = {}, network, translate, transaction}) { | ||||||
function WaypointEditor({transactionID, route: {params: {iouType = '', waypointIndex = ''} = {}} = {}, transaction}) { | ||||||
const {windowWidth} = useWindowDimensions(); | ||||||
const {translate} = useLocalize(); | ||||||
const {isOffline} = useNetwork(); | ||||||
const textInput = useRef(null); | ||||||
const [isDeleteStopModalOpen, setIsDeleteStopModalOpen] = useState(false); | ||||||
const currentWaypoint = lodashGet(transaction, `comment.waypoints.waypoint${waypointIndex}`, {}); | ||||||
const waypointAddress = lodashGet(currentWaypoint, 'address', ''); | ||||||
const totalWaypoints = _.size(lodashGet(transaction, 'comment.waypoints', {})); | ||||||
// Hide the menu when there is only start and finish waypoint | ||||||
const shouldShowThreeDotsButton = totalWaypoints > 2; | ||||||
|
||||||
const validate = (values) => { | ||||||
const errors = {}; | ||||||
const waypointValue = values[`waypoint${waypointIndex}`] || ''; | ||||||
if (network.isOffline && waypointValue !== '' && !ValidationUtils.isValidAddress(waypointValue)) { | ||||||
if (isOffline && waypointValue !== '' && !ValidationUtils.isValidAddress(waypointValue)) { | ||||||
errors[`waypoint${waypointIndex}`] = 'bankAccount.error.address'; | ||||||
} | ||||||
|
||||||
// If the user is online and they are trying to save a value without using the autocomplete, show an error message instructing them to use a selected address instead. | ||||||
// That enables us to save the address with coordinates when it is selected | ||||||
if (!network.isOffline && waypointValue !== '') { | ||||||
if (!isOffline && waypointValue !== '') { | ||||||
errors[`waypoint${waypointIndex}`] = 'distance.errors.selectSuggestedAddress'; | ||||||
} | ||||||
|
||||||
|
@@ -84,7 +88,7 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI | |||||
|
||||||
// While the user is offline, the auto-complete address search will not work | ||||||
// Therefore, we're going to save the waypoint as just the address, and the lat/long will be filled in on the backend | ||||||
if (network.isOffline && waypointValue) { | ||||||
if (isOffline && waypointValue) { | ||||||
const waypoint = { | ||||||
address: waypointValue, | ||||||
}; | ||||||
|
@@ -96,6 +100,12 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI | |||||
Navigation.goBack(ROUTES.getMoneyRequestDistanceTabRoute(iouType)); | ||||||
}; | ||||||
|
||||||
const deleteStopAndHideModal = () => { | ||||||
Transaction.removeWaypoint(transactionID, waypointIndex); | ||||||
setIsDeleteStopModalOpen(false); | ||||||
Navigation.goBack(ROUTES.getMoneyRequestDistanceTabRoute(iouType)); | ||||||
}; | ||||||
|
||||||
const selectWaypoint = (values) => { | ||||||
const waypoint = { | ||||||
lat: values.lat, | ||||||
|
@@ -119,6 +129,25 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI | |||||
onBackButtonPress={() => { | ||||||
Navigation.goBack(ROUTES.getMoneyRequestDistanceTabRoute(iouType)); | ||||||
}} | ||||||
shouldShowThreeDotsButton={shouldShowThreeDotsButton} | ||||||
threeDotsAnchorPosition={styles.threeDotsPopoverOffset(windowWidth)} | ||||||
hayata-suenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
threeDotsMenuItems={[ | ||||||
{ | ||||||
icon: Expensicons.Trashcan, | ||||||
text: translate('distance.deleteWaypoint'), | ||||||
onSelected: () => setIsDeleteStopModalOpen(true), | ||||||
}, | ||||||
]} | ||||||
/> | ||||||
<ConfirmModal | ||||||
title={translate('distance.deleteWaypoint')} | ||||||
isVisible={isDeleteStopModalOpen} | ||||||
onConfirm={deleteStopAndHideModal} | ||||||
onCancel={() => setIsDeleteStopModalOpen(false)} | ||||||
prompt={translate('distance.deleteWaypointConfirmation')} | ||||||
confirmText={translate('common.delete')} | ||||||
cancelText={translate('common.cancel')} | ||||||
danger | ||||||
/> | ||||||
<Form | ||||||
style={[styles.flexGrow1, styles.mh5]} | ||||||
|
@@ -134,7 +163,7 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI | |||||
<AddressSearch | ||||||
inputID={`waypoint${waypointIndex}`} | ||||||
ref={(e) => (textInput.current = e)} | ||||||
hint={!network.isOffline ? translate('distance.errors.selectSuggestedAddress') : ''} | ||||||
hint={!isOffline ? translate('distance.errors.selectSuggestedAddress') : ''} | ||||||
containerStyles={[styles.mt4]} | ||||||
label={translate('distance.address')} | ||||||
defaultValue={waypointAddress} | ||||||
|
@@ -161,13 +190,9 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI | |||||
WaypointEditor.displayName = 'WaypointEditor'; | ||||||
WaypointEditor.propTypes = propTypes; | ||||||
WaypointEditor.defaultProps = defaultProps; | ||||||
export default compose( | ||||||
withLocalize, | ||||||
withNetwork(), | ||||||
withOnyx({ | ||||||
transaction: { | ||||||
key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION}${props.transactionID}`, | ||||||
selector: (transaction) => (transaction ? {transactionID: transaction.transactionID, comment: {waypoints: lodashGet(transaction, 'comment.waypoints')}} : null), | ||||||
}, | ||||||
}), | ||||||
)(WaypointEditor); | ||||||
export default withOnyx({ | ||||||
transaction: { | ||||||
key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION}${props.transactionID}`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a Blocker: you can de-structure here
Suggested change
|
||||||
selector: (transaction) => (transaction ? {transactionID: transaction.transactionID, comment: {waypoints: lodashGet(transaction, 'comment.waypoints')}} : null), | ||||||
}, | ||||||
})(WaypointEditor); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a regression in #35644 , The delete option should not be displayed for empty waypoints.