@vtex/pickup-points-modal
Advanced tools
Comparing version 0.1.20 to 0.1.22
@@ -18,2 +18,4 @@ 'use strict'; | ||
var _metrics = require('../utils/metrics'); | ||
var _UserGeolocation = require('../components/UserGeolocation'); | ||
@@ -54,8 +56,12 @@ | ||
function AskForGeolocation(props) { | ||
function AskForGeolocation() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, AskForGeolocation); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this.getCurrentPositionSuccess = function (position) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.getCurrentPositionSuccess = function (position) { | ||
(0, _CurrentPosition.handleGetAddressByGeolocation)({ | ||
@@ -70,12 +76,10 @@ newPosition: { | ||
rules: _this.props.rules, | ||
address: _this.address | ||
address: _this.props.address | ||
}); | ||
_this.setState({ askForGeolocationStatus: _constants.SEARCHING }); | ||
searchPickupAddressByGeolocationEvent({ | ||
_this.handleGeolocationStatus(_constants.SEARCHING); | ||
(0, _metrics.searchPickupAddressByGeolocationEvent)({ | ||
searchedAddressByGeolocation: true, | ||
confirmedGeolocation: true | ||
}); | ||
}; | ||
_this.getCurrentPositionError = function (error) { | ||
}, _this.getCurrentPositionError = function (error) { | ||
switch (error.code) { | ||
@@ -85,3 +89,3 @@ case 0: | ||
_this.props.onAskForGeolocation(false); | ||
searchPickupAddressByGeolocationEvent({ | ||
(0, _metrics.searchPickupAddressByGeolocationEvent)({ | ||
confirmedGeolocation: true, | ||
@@ -94,3 +98,3 @@ browserError: true | ||
_this.props.onAskForGeolocation(false); | ||
searchPickupAddressByGeolocationEvent({ | ||
(0, _metrics.searchPickupAddressByGeolocationEvent)({ | ||
deniedGeolocation: true | ||
@@ -102,3 +106,3 @@ }); | ||
_this.props.onAskForGeolocation(false); | ||
searchPickupAddressByGeolocationEvent({ | ||
(0, _metrics.searchPickupAddressByGeolocationEvent)({ | ||
confirmedGeolocation: true, | ||
@@ -111,3 +115,3 @@ positionUnavailable: true | ||
_this.props.onAskForGeolocation(false); | ||
searchPickupAddressByGeolocationEvent({ | ||
(0, _metrics.searchPickupAddressByGeolocationEvent)({ | ||
dismissedGeolocation: true | ||
@@ -119,22 +123,11 @@ }); | ||
} | ||
}; | ||
_this.handleGeolocationStatus = function (status) { | ||
_this.setState({ status: status || _constants.WAITING }); | ||
}; | ||
_this.handleManualGeolocation = function () { | ||
}, _this.handleGeolocationStatus = function (status) { | ||
_this.props.onAskForGeolocationStatus(status); | ||
}, _this.handleManualGeolocation = function () { | ||
_this.props.onAskForGeolocation(false); | ||
}; | ||
_this.translate = function (id) { | ||
}, _this.translate = function (id) { | ||
return _this.props.intl.formatMessage({ | ||
id: 'pickupPointsModal.' + id | ||
}); | ||
}; | ||
_this.state = { | ||
status: props.status || _constants.WAITING | ||
}; | ||
return _this; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
@@ -144,5 +137,10 @@ | ||
if (this.props.askForGeolocation) { | ||
this.setState({ askForGeolocationStatus: _constants.WAITING }); | ||
this.handleGeolocationStatus(_constants.WAITING); | ||
if (window.location.protocol !== _constants.HTTPS) { | ||
this.props.onAskForGeolocation(false); | ||
this.getCurrentPositionSuccess({ | ||
coords: { | ||
latitude: -22.9432587, | ||
longitude: -43.1862642 | ||
} | ||
}); | ||
return; | ||
@@ -155,3 +153,3 @@ } | ||
AskForGeolocation.prototype.render = function render() { | ||
var status = this.state.status; | ||
var status = this.props.status; | ||
@@ -258,2 +256,3 @@ | ||
address: _AddressShapeWithValidation2.default, | ||
askForGeolocation: _propTypes2.default.bool.isRequired, | ||
googleMaps: _propTypes2.default.object, | ||
@@ -263,7 +262,8 @@ intl: _reactIntl.intlShape, | ||
onAskForGeolocation: _propTypes2.default.func.isRequired, | ||
askForGeolocation: _propTypes2.default.bool.isRequired, | ||
onAskForGeolocationStatus: _propTypes2.default.func.isRequired, | ||
pickupOptionGeolocations: _propTypes2.default.array, | ||
rules: _propTypes2.default.object | ||
rules: _propTypes2.default.object, | ||
status: _propTypes2.default.string.isRequired | ||
} : {}; | ||
exports.default = (0, _reactIntl.injectIntl)(AskForGeolocation); |
@@ -15,6 +15,2 @@ 'use strict'; | ||
var _geolocationAutoCompleteAddress = require('@vtex/address-form/lib/geolocation/geolocationAutoCompleteAddress'); | ||
var _geolocationAutoCompleteAddress2 = _interopRequireDefault(_geolocationAutoCompleteAddress); | ||
var _AddressShapeWithValidation = require('@vtex/address-form/lib/propTypes/AddressShapeWithValidation'); | ||
@@ -21,0 +17,0 @@ |
@@ -64,4 +64,2 @@ 'use strict'; | ||
var _metrics = require('./utils/metrics'); | ||
var _close_icon = require('./assets/icons/close_icon.svg'); | ||
@@ -89,8 +87,20 @@ | ||
_this.getPickupSlaString = function (slas) { | ||
return slas.reduce(function (accumulatedString, currentPickupPoint) { | ||
return currentPickupPoint.id ? accumulatedString + currentPickupPoint.id : ''; | ||
}, ''); | ||
}; | ||
_this.handleAskForGeolocation = function (ask) { | ||
_this.setState({ | ||
showAskForGeolocation: ask || true | ||
showAskForGeolocation: ask | ||
}); | ||
}; | ||
_this.handleAskForGeolocationStatus = function (status) { | ||
_this.setState({ | ||
askForGeolocationStatus: status | ||
}); | ||
}; | ||
_this.resize = (0, _debounce2.default)(function () { | ||
@@ -173,6 +183,9 @@ if (!_this.state.isMounted) return; | ||
PickupPointsModal.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
PickupPointsModal.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextState) { | ||
var thisPickupOptions = this.getPickupSlaString(this.props.pickupOptions); | ||
var nextPickupOptions = this.getPickupSlaString(nextProps.pickupOptions); | ||
this.setState({ | ||
showAskForGeolocation: nextProps.askForGeolocation, | ||
askForGeolocationStatus: nextProps.askForGeolocation ? _constants.WAITING : null, | ||
showAskForGeolocation: thisPickupOptions !== nextPickupOptions && this.state.askForGeolocationStatus === _constants.SEARCHING ? false : nextProps.askForGeolocation, | ||
askForGeolocationStatus: thisPickupOptions !== nextPickupOptions && this.state.askForGeolocationStatus === _constants.SEARCHING ? null : this.state.askForGeolocationStatus, | ||
selectedPickupPoint: nextProps.selectedPickupPoint, | ||
@@ -299,2 +312,3 @@ filteredPickupOptions: nextProps.pickupOptions.filter(function (option) { | ||
status: askForGeolocationStatus, | ||
onAskForGeolocationStatus: _this2.handleAskForGeolocationStatus, | ||
askForGeolocation: askForGeolocation | ||
@@ -301,0 +315,0 @@ }) : _react2.default.createElement( |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -9,2 +9,9 @@ exports.__esModule = true; | ||
exports.handleGetAddressByGeolocation = handleGetAddressByGeolocation; | ||
var _geolocationAutoCompleteAddress = require('@vtex/address-form/lib/geolocation/geolocationAutoCompleteAddress'); | ||
var _geolocationAutoCompleteAddress2 = _interopRequireDefault(_geolocationAutoCompleteAddress); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getCurrentPosition(successCallback, errorCallback) { | ||
@@ -34,3 +41,3 @@ return navigator.geolocation.getCurrentPosition(function (position) { | ||
var googleAddress = results[0]; | ||
var autoCompletedAddress = geolocationAutoCompleteAddress(address, googleAddress, rules); | ||
var autoCompletedAddress = (0, _geolocationAutoCompleteAddress2.default)(address, googleAddress, rules); | ||
onChangeAddress(_extends({}, autoCompletedAddress, { | ||
@@ -46,5 +53,5 @@ complement: { | ||
} else { | ||
console.warn("Google Maps Error: " + status); | ||
console.warn('Google Maps Error: ' + status); | ||
} | ||
}); | ||
} |
{ | ||
"name": "@vtex/pickup-points-modal", | ||
"version": "0.1.20", | ||
"version": "0.1.22", | ||
"description": "Pickup Points Modal React component", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
202748
4542