@wikala/spmkt 2.31.0 → 3.0.0-beta.0
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/MIGRATION_GUIDE.md +261 -0
- package/api/product.js +1 -0
- package/api/request.js +9 -4
- package/api/user.js +1 -1
- package/components/Account/AccountDashboard.vue +101 -101
- package/components/Account/AccountStore.js +57 -31
- package/components/Account/AffiliateReport.vue +56 -60
- package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
- package/components/Account/Orders/Orders.vue +124 -0
- package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
- package/components/Account/Settings/ChangeEmail.vue +136 -0
- package/components/Account/Settings/ChangeName.vue +82 -0
- package/components/Account/Settings/ChangePassword.vue +91 -0
- package/components/Address/Address.vue +38 -57
- package/components/Address/AddressBook.vue +77 -57
- package/components/Address/AddressSelect.vue +94 -87
- package/components/Address/Edit.vue +253 -265
- package/components/Address/PostalCode.vue +22 -21
- package/components/AgeGate.vue +11 -5
- package/components/Auth/Login.vue +62 -44
- package/components/Auth/Register.vue +82 -60
- package/components/Auth/ResetPassword.vue +45 -30
- package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
- package/components/Cart/CartBadge.vue +15 -4
- package/components/Cart/CartBox.vue +19 -11
- package/components/Cart/CartItem.vue +3 -3
- package/components/Cart/CartMode.vue +6 -5
- package/components/Cart/CartPreview.vue +24 -18
- package/components/Cart/Coupon.vue +4 -5
- package/components/Cart/CreditCard/Everyware.vue +10 -10
- package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
- package/components/Cart/CreditCard/SquarePay.vue +18 -16
- package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
- package/components/Cart/Delivery/Delivery.vue +16 -12
- package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
- package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
- package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
- package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
- package/components/Cart/Delivery/ReservationSlots.vue +14 -8
- package/components/Cart/Disclaimer.vue +1 -1
- package/components/Cart/OrderConfirmation.vue +1 -1
- package/components/Cart/Payment/Payment.vue +37 -33
- package/components/Cart/Payment/PaymentMethods.vue +6 -4
- package/components/Cart/ReviewAndSubmit.vue +9 -7
- package/components/Cart/ShoppingCart.vue +42 -31
- package/components/Cart/Store/actions.js +1 -1
- package/components/Cart/Store/getters.js +2 -1
- package/components/Cart/Store/index.js +1 -1
- package/components/Cart/Store/mutations.js +7 -5
- package/components/Cart/UserIdentity.vue +1 -1
- package/components/Category/CategoryFilter.vue +128 -114
- package/components/Category/CategorySort.vue +44 -32
- package/components/Category/LoadMore.vue +39 -23
- package/components/DeliverTo.vue +10 -15
- package/components/DeliveryNotice.vue +72 -68
- package/components/DobInput.vue +23 -23
- package/components/Gmaps/GmapsAutocomplete.vue +139 -78
- package/components/Gmaps/GmapsLocations.vue +1 -1
- package/components/Gmaps/GmapsSingleLocation.vue +121 -87
- package/components/ModalContainer/ModalContainer.vue +12 -9
- package/components/ModalContainer/index.js +61 -18
- package/components/Product/AddToCart.vue +237 -221
- package/components/Product/BoxAddToCart.vue +114 -86
- package/components/Product/Compare.vue +68 -48
- package/components/Product/CompareBox.vue +128 -123
- package/components/Product/Lookup.vue +92 -65
- package/components/Product/Photo.vue +105 -66
- package/components/Product/Price.vue +64 -43
- package/components/Product/ProductAutocomplete.vue +52 -57
- package/components/Product/ProductBox.vue +61 -38
- package/components/Product/ProductImages.vue +83 -86
- package/components/Product/Quantity.vue +115 -53
- package/components/Product/QuickView.vue +52 -45
- package/components/Product/RelatedProducts.vue +88 -23
- package/components/Product/SKU.vue +27 -8
- package/components/Product/Variants.vue +335 -341
- package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
- package/components/Product/reviews-questions/ProductReviews.vue +122 -107
- package/components/Product/reviews-questions/Review.vue +54 -59
- package/components/Product/reviews-questions/ReviewForm.vue +222 -170
- package/components/Product/reviews-questions/ReviewImages.vue +197 -216
- package/components/Product/reviews-questions/Vote.vue +83 -57
- package/components/QuantityInput.vue +18 -8
- package/components/RangeInput.vue +15 -8
- package/components/Recaptcha.vue +8 -1
- package/components/SelectShippingCountry.vue +81 -62
- package/components/TimedOffer.vue +59 -74
- package/composables/globals.js +53 -0
- package/config.js +5 -2
- package/index.js +41 -10
- package/install.js +75 -0
- package/locales/en.json +2 -1
- package/locales/sr.json +2 -1
- package/package.json +43 -30
- package/utils/directives.js +28 -45
- package/utils/event-bus.js +56 -0
- package/utils/filters.js +24 -7
- package/utils/{gmaps.js → google/gmaps.js} +43 -10
- package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
- package/babel.config.js +0 -5
- package/components/Account/ChangeEmail.vue +0 -133
- package/components/Account/ChangeName.vue +0 -92
- package/components/Account/ChangePassword.vue +0 -94
- package/components/Account/CreditCards.vue +0 -18
- package/components/Account/Orders.vue +0 -110
- package/components/Account/Settings.vue +0 -18
- package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
- package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
- package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
- package/components/Instagram.vue +0 -49
- package/components/ProductImageModal.vue +0 -41
- package/jest.config.js +0 -16
- package/test/e2e/.babelrc.js +0 -8
- package/test/e2e/.eslintrc.js +0 -11
- package/test/e2e/accAuth.spec.js +0 -64
- package/test/e2e/ageGate.spec.js +0 -26
- package/test/e2e/checkout.spec.js +0 -106
- package/test/e2e/compare.spec.js +0 -52
- package/test/e2e/config/data.js +0 -21
- package/test/e2e/config/routes.js +0 -11
- package/test/e2e/region.spec.js +0 -46
- package/test/e2e/search.spec.js +0 -32
- package/tests/vueBuefy.js +0 -4
- package/tsconfig.json +0 -8
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Vue 2 to Vue 3 Migration Guide
|
|
2
|
+
|
|
3
|
+
This document outlines the changes made and remaining work needed to complete the Vue 3 migration for @wikala/spmkt.
|
|
4
|
+
|
|
5
|
+
## Completed Infrastructure Changes
|
|
6
|
+
|
|
7
|
+
### 1. Package Dependencies Updated (`package.json`)
|
|
8
|
+
|
|
9
|
+
| Old (Vue 2) | New (Vue 3) |
|
|
10
|
+
|-------------|-------------|
|
|
11
|
+
| `vue@^2.6.14` | `vue@^3.4.0` |
|
|
12
|
+
| `vuex@^3.6.2` | `vuex@^4.1.0` |
|
|
13
|
+
| `buefy@^0.9.10` | `buefy@^3.0.3` (Vue 3 compatible) |
|
|
14
|
+
| `vue-mq@^1.0.1` | `vue3-mq@^3.1.3` |
|
|
15
|
+
| `vue-template-compiler` | `@vue/compiler-sfc` |
|
|
16
|
+
| `@vue/test-utils@^1.3.6` | `@vue/test-utils@^2.4.3` |
|
|
17
|
+
|
|
18
|
+
**Note:** Buefy 3.x is the official Vue 3 compatible version. All `<b-*>` components remain unchanged!
|
|
19
|
+
|
|
20
|
+
### 2. Event Bus (`utils/event-bus.js`)
|
|
21
|
+
|
|
22
|
+
Vue 2 pattern:
|
|
23
|
+
```javascript
|
|
24
|
+
// main.js
|
|
25
|
+
Vue.prototype.$bus = new Vue()
|
|
26
|
+
|
|
27
|
+
// Component
|
|
28
|
+
this.$bus.$emit('event', data)
|
|
29
|
+
this.$bus.$on('event', handler)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Vue 3 pattern:
|
|
33
|
+
```javascript
|
|
34
|
+
// Using mitt library
|
|
35
|
+
import { eventBus } from '@wikala/spmkt'
|
|
36
|
+
|
|
37
|
+
eventBus.emit('event', data)
|
|
38
|
+
eventBus.on('event', handler)
|
|
39
|
+
|
|
40
|
+
// Or via injected $bus in components
|
|
41
|
+
this.$bus.emit('event', data)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Filters (`utils/filters.js`)
|
|
45
|
+
|
|
46
|
+
Vue 2 pattern:
|
|
47
|
+
```html
|
|
48
|
+
<template>
|
|
49
|
+
{{ price | formatMoney }}
|
|
50
|
+
</template>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Vue 3 pattern:
|
|
54
|
+
```html
|
|
55
|
+
<template>
|
|
56
|
+
{{ $filters.formatMoney(price) }}
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
<!-- Or import directly -->
|
|
60
|
+
<script>
|
|
61
|
+
import { formatMoney } from '@wikala/spmkt'
|
|
62
|
+
</script>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 4. Custom Directives (`utils/directives.js`)
|
|
66
|
+
|
|
67
|
+
Lifecycle hooks renamed:
|
|
68
|
+
- `bind` → `beforeMount`
|
|
69
|
+
- `inserted` → `mounted`
|
|
70
|
+
- `componentUpdated` → `updated`
|
|
71
|
+
- `unbind` → `unmounted`
|
|
72
|
+
|
|
73
|
+
### 5. v-model on spmkt Components
|
|
74
|
+
|
|
75
|
+
Components that took a `value` prop and emitted `input` now follow the Vue 3
|
|
76
|
+
`v-model` contract (`modelValue` / `update:modelValue`): `QuantityInput`,
|
|
77
|
+
`RangeInput`, `DobInput`, `PostalCode`, `Recaptcha`, and the Cart's
|
|
78
|
+
`PaymentMethods`, `ReservationSlots` and `DeliveryTypes`. `v-model` keeps
|
|
79
|
+
working; host code using `:value` + `@input` (e.g. `<Recaptcha @input="…">`)
|
|
80
|
+
must switch to `:modelValue` + `@update:modelValue`.
|
|
81
|
+
|
|
82
|
+
### 6. Plugin Installation Pattern
|
|
83
|
+
|
|
84
|
+
Vue 2:
|
|
85
|
+
```javascript
|
|
86
|
+
Vue.prototype.$myPlugin = plugin
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Vue 3:
|
|
90
|
+
```javascript
|
|
91
|
+
app.config.globalProperties.$myPlugin = plugin
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Remaining Component Migration Work
|
|
97
|
+
|
|
98
|
+
### ✅ Buefy Components - No Changes Required!
|
|
99
|
+
|
|
100
|
+
Since we're using Buefy 3.x (Vue 3 compatible), all `<b-*>` components work as-is:
|
|
101
|
+
- `<b-field>`, `<b-input>`, `<b-button>`, `<b-select>`
|
|
102
|
+
- `<b-modal>`, `<b-table>`, `<b-tabs>`, `<b-tab-item>`
|
|
103
|
+
- `<b-loading>`, `<b-checkbox>`, `<b-radio>`
|
|
104
|
+
- `<b-autocomplete>`, `<b-datepicker>`, `<b-pagination>`
|
|
105
|
+
- `<b-collapse>`, `<b-dropdown>`, `<b-tooltip>`, `<b-slider>`
|
|
106
|
+
|
|
107
|
+
### Medium Priority: Vue 2 Syntax Updates
|
|
108
|
+
|
|
109
|
+
#### `.sync` Modifier → `v-model:propName`
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<!-- Vue 2 -->
|
|
113
|
+
<child :selected.sync="value" />
|
|
114
|
+
|
|
115
|
+
<!-- Vue 3 -->
|
|
116
|
+
<child v-model:selected="value" />
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Files to update:
|
|
120
|
+
- `components/Address/AddressSelect.vue`
|
|
121
|
+
- `components/Cart/ShoppingCart.vue`
|
|
122
|
+
- `components/Account/*.vue`
|
|
123
|
+
|
|
124
|
+
#### `.native` Modifier Removal
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<!-- Vue 2 -->
|
|
128
|
+
<b-input @paste.native="handler" />
|
|
129
|
+
|
|
130
|
+
<!-- Vue 3 - .native removed, add emits option -->
|
|
131
|
+
<o-input @paste="handler" />
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Files to update:
|
|
135
|
+
- `components/Address/*.vue`
|
|
136
|
+
- `components/Cart/CreditCard/*.vue`
|
|
137
|
+
|
|
138
|
+
#### `$set` / `$delete` Removal
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
// Vue 2
|
|
142
|
+
this.$set(this.object, 'key', value)
|
|
143
|
+
|
|
144
|
+
// Vue 3 - reactive by default
|
|
145
|
+
this.object.key = value
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Low Priority: Lifecycle Hook Renames
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// Vue 2
|
|
152
|
+
beforeDestroy() { }
|
|
153
|
+
|
|
154
|
+
// Vue 3
|
|
155
|
+
beforeUnmount() { }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Installation in Consuming Application
|
|
161
|
+
|
|
162
|
+
Each page creates its own app and, where needed, its own root store from a
|
|
163
|
+
single spmkt store, as the Vue 2 host did with `new Vuex.Store(CartStore)`:
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
// cart page
|
|
167
|
+
import { createApp } from 'vue'
|
|
168
|
+
import { createStore } from 'vuex'
|
|
169
|
+
import { installSpmkt, ShoppingCart, CartStore } from '@wikala/spmkt'
|
|
170
|
+
|
|
171
|
+
const app = createApp({
|
|
172
|
+
components: { ShoppingCart },
|
|
173
|
+
data: () => ({ cartCouponEnabled: true }) // read by CartSummary as $root.cartCouponEnabled
|
|
174
|
+
})
|
|
175
|
+
app.use(createStore(CartStore))
|
|
176
|
+
app.use(installSpmkt, {
|
|
177
|
+
buefy: { defaultIconPack: 'fas' },
|
|
178
|
+
modalContainer: { className: 'wkl-modal-container' }
|
|
179
|
+
})
|
|
180
|
+
app.mount('#app')
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The account page does the same with `createStore(AccountStore)`.
|
|
184
|
+
|
|
185
|
+
**Don't combine the stores** as `modules: { cart: CartStore, account: AccountStore }`.
|
|
186
|
+
The Cart components read state at the root (`mapState(['cart', 'steps', ...])`),
|
|
187
|
+
so inside a module every read comes back undefined. The two stores also define
|
|
188
|
+
the same `setAddressList` / `setCountryList` mutations, which would collide.
|
|
189
|
+
|
|
190
|
+
`installSpmkt` installs Buefy, the event bus (`$bus`), `$modalContainer`, the
|
|
191
|
+
`$filters` and the `v-digitsonly` / `v-click-outside` directives. The host no
|
|
192
|
+
longer calls `Vue.use(Buefy)`, `registerFilters(Vue)` or `registerDirectives(Vue)`
|
|
193
|
+
itself; pass Buefy and modal container options through `installSpmkt` instead.
|
|
194
|
+
|
|
195
|
+
## Host Application Requirements
|
|
196
|
+
|
|
197
|
+
spmkt components rely on things the host app provides. In the Vue 2 host these
|
|
198
|
+
came from `Vue.prototype`, a global `Vue.mixin` (`vm.js`) and per-page
|
|
199
|
+
`Vue.directive` calls; in Vue 3 set them on `app.config.globalProperties` and
|
|
200
|
+
register directives with `app.directive`.
|
|
201
|
+
|
|
202
|
+
| Provide | Used by | Notes |
|
|
203
|
+
|---|---|---|
|
|
204
|
+
| `initialState` | most components | `window.wkl_initial_state`. Set it as a global property, not mixin `data`: Composition API components read it through `composables/globals.js` |
|
|
205
|
+
| `$t`, `$tc` | all components | e.g. vue-i18n with `globalInjection: true` |
|
|
206
|
+
| `$LC` | prices, addresses | Locale config, falls back to `initialState.lc` |
|
|
207
|
+
| `$mq` | Cart, Gmaps, Product | Current breakpoint as a string. Options API components compare `this.$mq === 'mobile'` and global properties aren't unwrapped, so expose a ref through a getter: `Object.defineProperty(app.config.globalProperties, '$mq', { get: () => mq.value })` |
|
|
208
|
+
| `getConfig(key)` | CartMode, UserIdentity | Host config lookup (`BASE_URL`, …) |
|
|
209
|
+
| `scrollToElement(selector)` | Delivery, Payment, CartMode | Smooth-scrolls to the element |
|
|
210
|
+
| `logMessage(message)` | Payment, OrderConfirmation | Error reporting (Sentry in the Vue 2 host) |
|
|
211
|
+
| `getRecaptchaToken()` | Payment | Resolves a reCAPTCHA v3 token |
|
|
212
|
+
| `openModal(name, props)`, `closeModal()` | CartPreview, ProductQuestions, ReviewForm | Opens a component in `$modalContainer`. Globally registered components are no longer in `this.$options.components`; resolve names with `app.component(name)`. ReviewForm emits `close` after posting, which `$modalContainer` handles; it calls `closeModal()` only when its parent doesn't listen for `close` |
|
|
213
|
+
| `ageVerificationEnabled()` | DeliveryAddress | `parseInt(initialState.age_verification.enabled)` |
|
|
214
|
+
| `isMobileiOS` | ReservationSlots, ExtendedCreditCard | `true` on iOS Safari |
|
|
215
|
+
| `v-sticky` directive | Delivery | Vue 3 compatible sticky directive, registered as `sticky` |
|
|
216
|
+
| `v-mask` directive | UserIdentity | Vue 3 compatible input mask, registered as `mask` |
|
|
217
|
+
|
|
218
|
+
Host code that listened on its own Vue 2 event bus (e.g. `EventBus.$on('gotoUrl', …)`)
|
|
219
|
+
should use the exported `eventBus` instead, since spmkt components emit there.
|
|
220
|
+
|
|
221
|
+
ReviewImages teleports its image modals to `<body>` inside a
|
|
222
|
+
`.userimg-gallery.userimg-gallery-modals` wrapper. Theme rules that reach the modals
|
|
223
|
+
through a page ancestor (e.g. `.product-page .userimg-gallery .modal`) no longer
|
|
224
|
+
match; scope them to `.userimg-gallery-modals` instead.
|
|
225
|
+
|
|
226
|
+
The address autocomplete (GmapsAutocomplete, used by Address/Edit) uses
|
|
227
|
+
`AutocompleteSuggestion` and `Place`, so the host's Maps key needs the **Places API
|
|
228
|
+
(New)** enabled; with only the legacy Places API it shows an "unavailable" message.
|
|
229
|
+
|
|
230
|
+
`.storybook/preview.js` has minimal stand-ins for all of the above.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Component Migration Checklist
|
|
235
|
+
|
|
236
|
+
For each Vue component, check and update:
|
|
237
|
+
|
|
238
|
+
- [ ] Replace `{{ value | filter }}` with `{{ $filters.filter(value) }}`
|
|
239
|
+
- [ ] Replace `.sync` with `v-model:propName`
|
|
240
|
+
- [ ] Remove `.native` modifier, add `emits` option
|
|
241
|
+
- [ ] Replace `$set`/`$delete` with direct assignment
|
|
242
|
+
- [ ] Replace `beforeDestroy` with `beforeUnmount`
|
|
243
|
+
- [ ] Replace `$scopedSlots` with `$slots`
|
|
244
|
+
- [ ] Update slot syntax from `slot="name"` to `v-slot:name`
|
|
245
|
+
- [ ] Replace `$listeners` with `$attrs` (merged in Vue 3)
|
|
246
|
+
- [ ] Update `$bus.$on`/`$emit` to use imported `eventBus`
|
|
247
|
+
- [ ] Update `value` prop to `modelValue` for v-model components
|
|
248
|
+
- [ ] Update `$emit('input', ...)` to `$emit('update:modelValue', ...)`
|
|
249
|
+
|
|
250
|
+
**Note:** Buefy `<b-*>` components do NOT need to be changed - Buefy 3.x handles Vue 3 compatibility!
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Testing
|
|
255
|
+
|
|
256
|
+
After migration:
|
|
257
|
+
1. Run `npm install` to install new dependencies
|
|
258
|
+
2. Run `npm run build` to build the library
|
|
259
|
+
3. Run `npm run storybook` and click through the stories. The Cart stories
|
|
260
|
+
(Components → Cart) mock every checkout endpoint and use a root `CartStore`
|
|
261
|
+
via `parameters.host.store`
|
package/api/product.js
CHANGED
package/api/request.js
CHANGED
|
@@ -10,7 +10,10 @@ const service = axios.create({
|
|
|
10
10
|
service.interceptors.request.use(
|
|
11
11
|
(config) => {
|
|
12
12
|
config.headers['X-Requested-With'] = 'XMLHttpRequest'
|
|
13
|
-
|
|
13
|
+
const csrfElement = document.querySelector('meta[name="csrf-token"]')
|
|
14
|
+
if (csrfElement) {
|
|
15
|
+
config.headers['X-CSRF-TOKEN'] = csrfElement.getAttribute('content')
|
|
16
|
+
}
|
|
14
17
|
return config
|
|
15
18
|
},
|
|
16
19
|
(error) => {
|
|
@@ -30,6 +33,8 @@ service.interceptors.response.use(
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
if (error.response) {
|
|
36
|
+
// Some backends return plain strings on errors; normalize to an object
|
|
37
|
+
const data = typeof error.response.data === 'object' ? error.response.data : { message: error.response.data }
|
|
33
38
|
if (error.response.status == 419) {
|
|
34
39
|
throw new Error('Something went wrong. Try refreshing the page.')
|
|
35
40
|
return false
|
|
@@ -39,9 +44,9 @@ service.interceptors.response.use(
|
|
|
39
44
|
window.location.reload()
|
|
40
45
|
return false
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return Promise.reject(
|
|
47
|
+
data.status = error.response.status
|
|
48
|
+
data.statusText = error.response.statusText
|
|
49
|
+
return Promise.reject(data)
|
|
45
50
|
} else {
|
|
46
51
|
return Promise.reject(error)
|
|
47
52
|
}
|
package/api/user.js
CHANGED
|
@@ -2,28 +2,27 @@
|
|
|
2
2
|
<div class="account-dashboard-container">
|
|
3
3
|
<div class="your-account-title">
|
|
4
4
|
<div class="container">
|
|
5
|
-
<h1 class="subtitle">{{
|
|
5
|
+
<h1 class="subtitle">{{ titleText }}</h1>
|
|
6
6
|
</div>
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
9
|
<div class="container">
|
|
10
10
|
<b-tabs
|
|
11
|
-
:size="
|
|
11
|
+
:size="tabSize"
|
|
12
12
|
class="block"
|
|
13
13
|
:animated="false"
|
|
14
14
|
v-model="activeTab"
|
|
15
|
-
@
|
|
16
|
-
@
|
|
17
|
-
@click.native="ordersTabClick(activeTab, $event)"
|
|
15
|
+
@update:modelValue="handleTabUpdate"
|
|
16
|
+
@click="ordersTabClick(activeTab, $event)"
|
|
18
17
|
>
|
|
19
|
-
<b-tab-item :label="
|
|
20
|
-
<Orders :no-orders-notification="
|
|
18
|
+
<b-tab-item :label="ordersTabLabelText">
|
|
19
|
+
<Orders :no-orders-notification="noOrdersNotificationText" />
|
|
21
20
|
</b-tab-item>
|
|
22
21
|
|
|
23
22
|
<b-tab-item :label="$t('account.addresses')">
|
|
24
|
-
<AddressBook
|
|
25
|
-
:countries="
|
|
26
|
-
:orderAsBussinessEnabled="
|
|
23
|
+
<AddressBook
|
|
24
|
+
:countries="countryList"
|
|
25
|
+
:orderAsBussinessEnabled="orderAsBusinessEnabled"
|
|
27
26
|
/>
|
|
28
27
|
</b-tab-item>
|
|
29
28
|
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
<AccountSettings />
|
|
32
31
|
</b-tab-item>
|
|
33
32
|
|
|
34
|
-
<b-tab-item v-if="
|
|
33
|
+
<b-tab-item v-if="hasAffiliateReport" label="Affiliate Report">
|
|
35
34
|
<AffiliateReport />
|
|
36
35
|
</b-tab-item>
|
|
37
36
|
</b-tabs>
|
|
@@ -39,98 +38,99 @@
|
|
|
39
38
|
</div>
|
|
40
39
|
</template>
|
|
41
40
|
|
|
42
|
-
<script>
|
|
43
|
-
import {
|
|
44
|
-
|
|
41
|
+
<script setup>
|
|
42
|
+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
43
|
+
import { useStore } from 'vuex'
|
|
45
44
|
import Cookie from 'js-cookie'
|
|
46
45
|
|
|
47
|
-
import
|
|
48
|
-
|
|
49
|
-
import Orders from './Orders'
|
|
50
|
-
import
|
|
51
|
-
import
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
computed: {
|
|
96
|
-
...mapState(['countryList', 'user'])
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
methods: {
|
|
100
|
-
...mapActions(['getCountries', 'getUser', 'getAffiliateReport']),
|
|
101
|
-
|
|
102
|
-
ordersTabClick(index, e) {
|
|
103
|
-
if (e.target.parentElement.getAttribute('role') === 'tab' && index === 0) {
|
|
104
|
-
this.$bus.$emit('orderDetailClose')
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
tabChange(index) {
|
|
109
|
-
Cookie.set('lastActiveTab', index, { expires: 7 })
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
tabClick(index) {
|
|
113
|
-
if (index === 0) {
|
|
114
|
-
this.$bus.$emit('orderDetailClose')
|
|
115
|
-
}
|
|
116
|
-
history.pushState(null, this.initialState.site_name + ' Account', '?tab=' + this.tabs[index])
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
switchTabBasedOnUrl() {
|
|
120
|
-
let urlTab = new URL(document.location).searchParams.get('tab')
|
|
121
|
-
this.activeTab = this.tabs.indexOf(urlTab) !== -1 ? this.tabs.indexOf(urlTab) : 0
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
async mounted() {
|
|
126
|
-
this.switchTabBasedOnUrl()
|
|
127
|
-
await this.getCountries()
|
|
128
|
-
await this.getUser()
|
|
129
|
-
|
|
130
|
-
window.addEventListener('popstate', () => {
|
|
131
|
-
console.log('popstate ', this.activeTab, window.location.href)
|
|
132
|
-
this.switchTabBasedOnUrl()
|
|
133
|
-
})
|
|
46
|
+
import { useBus, useInitialState, useMq, useT } from '../../composables/globals'
|
|
47
|
+
import AddressBook from '../Address/AddressBook.vue'
|
|
48
|
+
import Orders from './Orders/Orders.vue'
|
|
49
|
+
import AccountSettings from './Settings/AccountSettings.vue'
|
|
50
|
+
import AffiliateReport from './AffiliateReport.vue'
|
|
51
|
+
|
|
52
|
+
const tabs = ['orders', 'addresses', 'settings', 'affiliate-report']
|
|
53
|
+
|
|
54
|
+
const { t: $t } = useT()
|
|
55
|
+
const initialState = useInitialState()
|
|
56
|
+
const eventBus = useBus()
|
|
57
|
+
const mqValue = useMq()
|
|
58
|
+
|
|
59
|
+
const props = defineProps({
|
|
60
|
+
title: String,
|
|
61
|
+
ordersTabLabel: String,
|
|
62
|
+
noOrdersNotification: String,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const store = useStore()
|
|
66
|
+
|
|
67
|
+
const activeTab = ref(0)
|
|
68
|
+
|
|
69
|
+
const countryList = computed(() => store.state?.account?.countryList ?? store.state?.countryList ?? [])
|
|
70
|
+
const user = computed(() => store.state?.account?.user ?? store.state?.user ?? {})
|
|
71
|
+
|
|
72
|
+
const titleText = computed(() => props.title || $t('account.yourAccount'))
|
|
73
|
+
const ordersTabLabelText = computed(() => props.ordersTabLabel || $t('account.orders'))
|
|
74
|
+
const noOrdersNotificationText = computed(() => props.noOrdersNotification || $t('account.ordersEmpty'))
|
|
75
|
+
const hasAffiliateReport = computed(() => Boolean(user.value?.affiliate?.id))
|
|
76
|
+
const tabSize = computed(() => (mqValue.value === 'mobile' ? '' : 'is-large'))
|
|
77
|
+
const orderAsBusinessEnabled = computed(() => Boolean(parseInt(initialState.orderAsBusiness || 0, 10)))
|
|
78
|
+
|
|
79
|
+
const tabChange = (index) => {
|
|
80
|
+
Cookie.set('lastActiveTab', index, { expires: 7 })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const tabClick = (index) => {
|
|
84
|
+
if (index === 0) {
|
|
85
|
+
eventBus.emit('orderDetailClose')
|
|
86
|
+
}
|
|
87
|
+
const siteName = initialState.site_name || 'Account'
|
|
88
|
+
history.pushState(null, `${siteName} Account`, `?tab=${tabs[index]}`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const ordersTabClick = (index, event) => {
|
|
92
|
+
if (index === 0 && event?.target?.closest('[role="tab"]')) {
|
|
93
|
+
eventBus.emit('orderDetailClose')
|
|
134
94
|
}
|
|
135
95
|
}
|
|
96
|
+
|
|
97
|
+
const handleTabUpdate = (index) => {
|
|
98
|
+
activeTab.value = index
|
|
99
|
+
tabClick(index)
|
|
100
|
+
tabChange(index)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const switchTabBasedOnUrl = () => {
|
|
104
|
+
const urlTab = new URL(document.location).searchParams.get('tab')
|
|
105
|
+
const cookieTab = parseInt(Cookie.get('lastActiveTab'), 10)
|
|
106
|
+
const urlIndex = tabs.indexOf(urlTab)
|
|
107
|
+
|
|
108
|
+
if (urlIndex !== -1) {
|
|
109
|
+
activeTab.value = urlIndex
|
|
110
|
+
} else if (!Number.isNaN(cookieTab) && cookieTab >= 0 && cookieTab < tabs.length) {
|
|
111
|
+
activeTab.value = cookieTab
|
|
112
|
+
} else {
|
|
113
|
+
activeTab.value = 0
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const handlePopstate = () => {
|
|
118
|
+
switchTabBasedOnUrl()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
onMounted(async () => {
|
|
122
|
+
switchTabBasedOnUrl()
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
await Promise.all([store.dispatch('getCountries'), store.dispatch('getUser')])
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error('Failed to load account dashboard data', error)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
window.addEventListener('popstate', handlePopstate)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
onBeforeUnmount(() => {
|
|
134
|
+
window.removeEventListener('popstate', handlePopstate)
|
|
135
|
+
})
|
|
136
136
|
</script>
|
|
@@ -1,71 +1,97 @@
|
|
|
1
1
|
|
|
2
2
|
import { Address, Countries, User, Affiliate } from '../../api'
|
|
3
3
|
|
|
4
|
+
const createEmptyAffiliateReport = () => ({
|
|
5
|
+
items: [],
|
|
6
|
+
total: {
|
|
7
|
+
item: 0,
|
|
8
|
+
commission: 0,
|
|
9
|
+
count: 0,
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
|
|
4
13
|
const AccountStore = {
|
|
5
|
-
state: {
|
|
14
|
+
state: () => ({
|
|
6
15
|
user: {},
|
|
7
16
|
addressList: [],
|
|
8
17
|
countryList: [],
|
|
9
|
-
affiliateReport:
|
|
10
|
-
},
|
|
18
|
+
affiliateReport: createEmptyAffiliateReport(),
|
|
19
|
+
}),
|
|
11
20
|
|
|
12
21
|
mutations: {
|
|
13
22
|
setUser(state, user) {
|
|
14
|
-
state.user = user
|
|
23
|
+
state.user = user || {}
|
|
15
24
|
},
|
|
16
25
|
setAddressList(state, addressList) {
|
|
17
|
-
state.addressList = addressList
|
|
26
|
+
state.addressList = addressList || []
|
|
18
27
|
},
|
|
19
28
|
setCountryList(state, countryList) {
|
|
20
|
-
state.countryList = countryList
|
|
29
|
+
state.countryList = countryList || []
|
|
21
30
|
},
|
|
22
31
|
setAffiliateReport(state, affiliateReport) {
|
|
23
|
-
state.affiliateReport = affiliateReport
|
|
32
|
+
state.affiliateReport = affiliateReport || createEmptyAffiliateReport()
|
|
24
33
|
}
|
|
25
34
|
},
|
|
26
35
|
|
|
27
36
|
actions: {
|
|
28
|
-
async getUser({commit}) {
|
|
37
|
+
async getUser({ commit }) {
|
|
29
38
|
try {
|
|
30
|
-
|
|
39
|
+
const res = await User.get()
|
|
31
40
|
commit('setUser', res.data.data)
|
|
32
|
-
|
|
41
|
+
return res.data.data
|
|
42
|
+
} catch (e) {
|
|
33
43
|
console.log('Cannot get user', e)
|
|
44
|
+
return null
|
|
34
45
|
}
|
|
35
46
|
},
|
|
36
47
|
|
|
37
|
-
getAddresses({ commit
|
|
48
|
+
async getAddresses({ commit }) {
|
|
38
49
|
if (!User.isLogged()) {
|
|
39
50
|
return true
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
try {
|
|
54
|
+
const response = await Address.getList()
|
|
55
|
+
const addresses = response.data.data
|
|
56
|
+
commit('setAddressList', addresses.reverse())
|
|
57
|
+
return addresses
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.log('getAddresses error: ', error)
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
50
62
|
},
|
|
51
63
|
|
|
52
64
|
async getAffiliateReport({ commit, state }) {
|
|
53
65
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
const affiliateId = state.user?.affiliate?.id
|
|
67
|
+
|
|
68
|
+
if (!affiliateId) {
|
|
69
|
+
commit('setAffiliateReport', createEmptyAffiliateReport())
|
|
70
|
+
return createEmptyAffiliateReport()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const res = await Affiliate.getReport(affiliateId)
|
|
74
|
+
const report = res.data.data || createEmptyAffiliateReport()
|
|
75
|
+
commit('setAffiliateReport', report)
|
|
76
|
+
return report
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.log('getAffiliateReport error', e)
|
|
79
|
+
commit('setAffiliateReport', createEmptyAffiliateReport())
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
57
82
|
},
|
|
58
83
|
|
|
59
|
-
getCountries({ commit
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
async getCountries({ commit }) {
|
|
85
|
+
try {
|
|
86
|
+
const response = await Countries.get()
|
|
87
|
+
commit('setCountryList', response.data)
|
|
88
|
+
return response.data
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.log('getCountries error', error)
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
67
93
|
}
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
|
|
71
|
-
export default AccountStore
|
|
97
|
+
export default AccountStore
|