11import React , { Component } from 'react'
22import PropTypes from 'prop-types'
33import debounce from 'lodash/debounce'
4- import Map from './components/Map'
4+ import { injectIntl , intlShape } from 'react-intl'
5+ import { helpers } from 'vtex.address-form'
6+
7+ import Map from './components/Map.jsx'
58import CloseButton from './components/CloseButton'
69import styles from './index.css'
710import ZoomControls from './components/ZoomControls'
@@ -10,14 +13,16 @@ import ModalState from './ModalState'
1013import Geolocation from './Geolocation'
1114import SearchArea from './components/SearchArea'
1215import SearchOverlay from './assets/components/SearchOverlay'
13- import { injectIntl , intlShape } from 'react-intl'
1416import { withGoogleMaps } from './containers/withGoogleMaps'
1517import { translate } from './utils/i18nUtils'
1618import { newAddress } from './utils/newAddress'
1719import { HIDE_MAP , SHOW_MAP } from './constants'
1820import { getPickupOptionGeolocations } from './utils/pickupUtils'
19- import { helpers } from 'vtex.address-form'
20- import { closePickupPointsModalEvent , openPickupPointsModalEvent , searchPickupAddressByGeolocationEvent } from './utils/metrics'
21+ import {
22+ closePickupPointsModalEvent ,
23+ openPickupPointsModalEvent ,
24+ searchPickupAddressByGeolocationEvent ,
25+ } from './utils/metrics'
2126
2227const { validateField, addValidation } = helpers
2328const NULL_VALUE = {
@@ -48,7 +53,8 @@ class PickupPointsModal extends Component {
4853 }
4954
5055 componentDidMount ( ) {
51- const style = document . body . style
56+ const { style } = document . body
57+
5258 style . overflow = 'hidden'
5359 style . position = 'fixed'
5460 style . width = '100%'
@@ -83,6 +89,7 @@ class PickupPointsModal extends Component {
8389 // On mobile browsers trigger the resize event when keyboard is opened
8490 // even though the screen size itself is the same
8591 const isWidthEqual = this . state . innerWidth === window . innerWidth
92+
8693 if ( ! this . state . isMounted || isWidthEqual ) return
8794 this . setState ( {
8895 isLargeScreen : window . innerWidth > 1023 ,
@@ -91,15 +98,15 @@ class PickupPointsModal extends Component {
9198 } )
9299 } , 200 )
93100
94- updateLocationTab = mapStatus => this . setState ( { mapStatus } )
101+ updateLocationTab = ( mapStatus ) => this . setState ( { mapStatus } )
95102
96103 activatePickupDetails = ( ) =>
97104 this . setState ( {
98105 isPickupDetailsActive : true ,
99106 mapStatus : HIDE_MAP ,
100107 } )
101108
102- getPostalCodeValue = address => {
109+ getPostalCodeValue = ( address ) => {
103110 // TODO move this to Address Form
104111 if (
105112 address &&
@@ -119,7 +126,7 @@ class PickupPointsModal extends Component {
119126 return address . postalCode && address . postalCode . value
120127 }
121128
122- getValidPostalCode = address => {
129+ getValidPostalCode = ( address ) => {
123130 if ( address . postalCode ) {
124131 const postalCodevalue = this . getPostalCodeValue ( address )
125132
@@ -149,10 +156,11 @@ class PickupPointsModal extends Component {
149156 visited : null ,
150157 }
151158 }
159+
152160 return NULL_VALUE
153161 }
154162
155- handleAddressChange = address => {
163+ handleAddressChange = ( address ) => {
156164 const { searchAddress } = this . props
157165
158166 const addressValidated = {
@@ -180,7 +188,8 @@ class PickupPointsModal extends Component {
180188 }
181189
182190 handleCloseModal = ( ) => {
183- const style = document . body . style
191+ const { style } = document . body
192+
184193 style . overflow = 'auto'
185194 style . position = ''
186195 if ( this . state . isLoadingGeolocation ) {
@@ -191,6 +200,7 @@ class PickupPointsModal extends Component {
191200 elapsedTime,
192201 } )
193202 }
203+
194204 this . props . closePickupPointsModal ( )
195205 }
196206
@@ -265,25 +275,29 @@ class PickupPointsModal extends Component {
265275 pickupOptions = { pickupOptions }
266276 salesChannel = { salesChannel }
267277 orderFormId = { orderFormId }
268- selectedPickupPoint = { selectedPickupPoint } >
278+ selectedPickupPoint = { selectedPickupPoint }
279+ >
269280 < Geolocation
270281 address = { searchAddressWithAddressQuery }
271282 askForGeolocation = { askForGeolocation }
272283 googleMaps = { googleMaps }
273284 onChangeAddress = { this . handleAddressChange }
274285 onChangeGeolocationState = { this . handleChangeGeolocationLoading }
275- rules = { rules } >
286+ rules = { rules }
287+ >
276288 < SearchArea
277289 address = { searchAddressWithAddressQuery }
278290 mapStatus = { mapStatus }
279291 shouldShow = { shouldShowMap }
280292 isLargeScreen = { isLargeScreen }
281293 />
282- < ZoomControls
283- isLargeScreen = { isLargeScreen }
284- mapStatus = { mapStatus }
285- shouldShow = { shouldShowMap }
286- />
294+ { /*
295+ * Used for rendering the <ZoomControls /> component. This is
296+ * currently done this way because the ZoomControls must be a child of <Map />
297+ * to be able to consume the <GoogleMaps /> context, but it must be placed in
298+ * this position for the layout to work
299+ */ }
300+ < div id = "controls-wrapper" />
287301
288302 { shouldUseMaps && (
289303 < Map
@@ -301,7 +315,13 @@ class PickupPointsModal extends Component {
301315 selectedPickupPointGeolocation = { getPickupOptionGeolocations (
302316 selectedPickupPoint
303317 ) }
304- />
318+ >
319+ < ZoomControls
320+ isLargeScreen = { isLargeScreen }
321+ mapStatus = { mapStatus }
322+ shouldShow = { shouldShowMap }
323+ />
324+ </ Map >
305325 ) }
306326 < SearchOverlay />
307327 < StateHandler
0 commit comments