@ecomplus/storefront-components 1.0.0-beta.192 → 1.0.0-beta.194

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomplus/storefront-components",
3
- "version": "1.0.0-beta.192",
3
+ "version": "1.0.0-beta.194",
4
4
  "description": "Vue components for E-Com Plus Storefront",
5
5
  "main": "dist/storefront-components.min.js",
6
6
  "scripts": {
@@ -87,7 +87,7 @@
87
87
  </template>
88
88
 
89
89
  <a-alert
90
- :key="`alert-${alertVariant}-${localCouponCode}`"
90
+ :key="`alert-${alertVariant}-${localCouponCode}-${isCouponApplied}`"
91
91
  :can-show="!isLoading && Boolean(alertText)"
92
92
  :variant="alertVariant"
93
93
  @dismiss="alertText = null"
@@ -113,37 +113,55 @@ export default {
113
113
  }
114
114
  },
115
115
 
116
- fetchAddressInfo (zipCode, isRetry = false) {
116
+ setAddressFields (zipCode, fields) {
117
+ if (zipCode === this.localAddress.zip) {
118
+ fields.forEach(([field, value]) => {
119
+ this.$set(this.localAddress, field, value || '')
120
+ this.$set(this.addressFromZip, field, Boolean(value))
121
+ })
122
+ this.$nextTick(() => {
123
+ setTimeout(() => {
124
+ if (this.$refs.inputNumber) {
125
+ this.$refs.inputNumber.select()
126
+ }
127
+ }, 300)
128
+ })
129
+ }
130
+ },
131
+
132
+ fetchAddressInfo (zipCode) {
117
133
  if (zipCode === this.localAddress.zip) {
118
134
  this.zipLoading = zipCode
119
- axios.get(`https://viacep.com.br/ws/${zipCode}/json/`, { timeout: 4000 })
135
+ axios.get(`https://brasilapi.com.br/api/cep/v2/${zipCode}`, { timeout: 4000 })
120
136
  .then(({ data }) => {
121
- if (!data.erro && zipCode === this.localAddress.zip) {
122
- ;[
123
- ['province_code', data.uf],
124
- ['city', data.localidade],
125
- ['borough', data.bairro],
126
- ['street', data.logradouro]
127
- ].forEach(([field, value]) => {
128
- this.$set(this.localAddress, field, value || '')
129
- this.$set(this.addressFromZip, field, Boolean(value))
130
- })
131
- this.$nextTick(() => {
132
- setTimeout(() => {
133
- if (this.$refs.inputNumber) {
134
- this.$refs.inputNumber.select()
135
- }
136
- }, 300)
137
- })
138
- }
137
+ this.setAddressFields(zipCode, [
138
+ ['province_code', data.state],
139
+ ['city', data.city],
140
+ ['borough', data.neighborhood],
141
+ ['street', data.street]
142
+ ])
139
143
  })
140
144
  .catch(err => {
141
145
  console.error(err)
142
- if (!isRetry) {
143
- setTimeout(() => {
144
- this.fetchAddressInfo(zipCode, true)
145
- }, 300)
146
- }
146
+ setTimeout(() => {
147
+ axios.get(`https://viacep.com.br/ws/${zipCode}/json/`, { timeout: 4000 })
148
+ .then(({ data }) => {
149
+ if (!data.erro) {
150
+ this.setAddressFields(zipCode, [
151
+ ['province_code', data.uf],
152
+ ['city', data.localidade],
153
+ ['borough', data.bairro],
154
+ ['street', data.logradouro]
155
+ ])
156
+ }
157
+ })
158
+ .catch(e => console.error(e))
159
+ .finally(() => {
160
+ if (zipCode === this.zipLoading) {
161
+ this.zipLoading = null
162
+ }
163
+ })
164
+ }, 300)
147
165
  })
148
166
  .finally(() => {
149
167
  if (zipCode === this.zipLoading) {