Skip to content

Commit

Permalink
refactor(toasts): Show correct place name in saved place toast confir…
Browse files Browse the repository at this point in the history
…mations.
  • Loading branch information
binh-dam-ibigroup committed Sep 21, 2023
1 parent 1bc97f5 commit e1c6453
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ actions:
genericError: "An error was encountered: {err}"
itineraryExistenceCheckFailed: Error checking whether your selected trip is possible.
mustBeLoggedInToSavePlace: Please log in to save locations.
placeRemembered: "Your {placeType} has been set to: {address}."
placeRemembered: The settings for this place have been saved.
preferencesSaved: Your preferences have been saved.
smsInvalidCode: The code you entered is invalid. Please try again.
smsResendThrottled: >-
Expand Down
2 changes: 1 addition & 1 deletion i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ actions:
genericError: "Une erreur s'est produite : {err}"
itineraryExistenceCheckFailed: Erreur lors de la vérification de la validité du trajet choisi.
mustBeLoggedInToSavePlace: Veuillez vous connecter pour enregistrer des lieux.
placeRemembered: "Votre {placeType} est maintenant au : {address}."
placeRemembered: Les informations pour ce lieu ont été enregistrées.
preferencesSaved: Vos préférences ont été enregistrées.
smsInvalidCode: Le code saisi est incorrect. Veuillez réessayer.
smsResendThrottled: >-
Expand Down
7 changes: 2 additions & 5 deletions lib/components/map/connected-endpoints-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import EndpointsOverlay from '@opentripplanner/endpoints-overlay'
import React, { ComponentProps, useCallback } from 'react'

import { clearLocation } from '../../actions/form'
import {
convertToPlace,
getUserLocations,
toastOnPlaceSaved
} from '../../util/user'
import { convertToPlace, getUserLocations } from '../../util/user'
import {
forgetPlace,
rememberPlace,
UserActionResult
} from '../../actions/user'
import { getActiveSearch, getShowUserSettings } from '../../util/state'
import { setLocation } from '../../actions/map'
import { toastOnPlaceSaved } from '../util/toasts'

type Props = ComponentProps<typeof EndpointsOverlay> & {
forgetPlace: (place: string, intl: IntlShape) => void
Expand Down
3 changes: 2 additions & 1 deletion lib/components/user/places/favorite-place-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { PageHeading } from '../styled'
import { CREATE_ACCOUNT_PLACES_PATH } from '../../../util/constants'
import { getFormattedPlaces } from '../../../util/i18n'
import { isBlank, navigateBack, RETURN_TO_CURRENT_ROUTE } from '../../../util/ui'
import { isHomeOrWork, PLACE_TYPES, toastOnPlaceSaved } from '../../../util/user'
import { isHomeOrWork, PLACE_TYPES } from '../../../util/user'
import withLoggedInUserSupport from '../with-logged-in-user-support'
import { InlineLoading } from '../../narrative/loading'
import PageTitle from '../../util/page-title'
import { toastOnPlaceSaved } from '../../util/toasts'

import PlaceEditor from './place-editor'

Expand Down
27 changes: 27 additions & 0 deletions lib/components/util/toasts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { IntlShape } from 'react-intl'
import React from 'react'
import toast from 'react-hot-toast'

import { getPlaceMainText } from '../../util/user'
import { UserSavedLocation } from '../user/types'

// Note: the HTML for toasts is rendered outside of the IntlProvider context,
// so intl.formatMessage and others have to be used instead of <FormattedMessage> tags.

/**
* Helper that will display a toast notification when a place is saved.
*/
export function toastOnPlaceSaved(
place: UserSavedLocation,
intl: IntlShape
): void {
toast.success(
<span>
<strong>{getPlaceMainText(place, intl)}</strong>
<br />
{intl.formatMessage({
id: 'actions.user.placeRemembered'
})}
</span>
)
}
20 changes: 0 additions & 20 deletions lib/util/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { addInParentheses } from '@opentripplanner/location-field/lib/utils'
import coreUtils from '@opentripplanner/core-utils'
import toast from 'react-hot-toast'

import {
CREATE_ACCOUNT_PLACES_PATH,
Expand Down Expand Up @@ -222,22 +221,3 @@ export function getPlaceMainText(place, intl) {
? toSentenceCase(getFormattedPlaces(place.type, intl))
: place.name || place.address
}

/**
* Helper that will display a toast notification when a place is saved.
*/
export function toastOnPlaceSaved(place, intl) {
toast.success(
intl.formatMessage(
{
id: 'actions.user.placeRemembered'
},
{
address: place.address,
placeType: intl.formatMessage({
id: `common.places.${place.type}`
})
}
)
)
}

0 comments on commit e1c6453

Please sign in to comment.