@wikala/spmkt 2.31.1 → 3.0.0-beta.1
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 +310 -0
- package/api/product.js +1 -0
- package/api/request.js +12 -6
- 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/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 +9 -7
- package/components/Cart/Store/state.js +2 -2
- 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 +24 -24
- package/components/Gmaps/GmapsAutocomplete.vue +139 -78
- package/components/Gmaps/GmapsLocations.vue +1 -1
- package/components/Gmaps/GmapsSingleLocation.vue +121 -87
- package/components/MobileMenu/icons/LeftArrowIcon.vue +1 -1
- package/components/MobileMenu/icons/MenuIcon.vue +1 -1
- package/components/MobileMenu/icons/RightArrowIcon.vue +1 -1
- package/components/ModalContainer/ModalContainer.vue +20 -13
- package/components/ModalContainer/index.js +62 -18
- package/components/Product/AddToCart.vue +237 -221
- package/components/Product/BoxAddToCart.vue +114 -86
- package/components/Product/Compare.vue +91 -49
- 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 +336 -342
- 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 +88 -0
- package/locales/en.json +2 -1
- package/locales/sr.json +2 -1
- package/package.json +49 -37
- package/utils/animate.css +50 -0
- package/utils/animate.js +1 -1
- package/utils/buefy.js +62 -0
- package/utils/directives.js +28 -45
- package/utils/event-bus.js +56 -0
- package/utils/filters.js +24 -7
- package/utils/format-date.js +17 -0
- package/utils/{gmaps.js → google/gmaps.js} +43 -10
- package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
- package/utils/random-id.js +10 -0
- 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,310 @@
|
|
|
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` | removed: the host provides `$mq` |
|
|
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
|
+
Of Buefy, `installSpmkt` installs only the components spmkt uses (`buefyPlugins`
|
|
196
|
+
in `utils/buefy.js`), not all of it, so the unused ones stay out of the host's
|
|
197
|
+
bundle. A host whose own templates use another Buefy component installs that
|
|
198
|
+
plugin itself after `installSpmkt`:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
import { Tooltip } from 'buefy'
|
|
202
|
+
|
|
203
|
+
app.use(installSpmkt, { buefy: { defaultIconPack: 'fas' } })
|
|
204
|
+
app.use(Tooltip)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Buefy's `module` entry is one file that bundlers can't tree-shake well, so even
|
|
208
|
+
that subset costs ~82 KB gzipped. Alias `buefy` to its per-component build and it
|
|
209
|
+
drops to ~47 KB. Alias the bare `buefy` import only (CSS imports like
|
|
210
|
+
`buefy/dist/css/buefy.css` stay as they are), and set it in the host's config so the
|
|
211
|
+
host and spmkt share one Buefy, and with it one config:
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
// vite.config.js
|
|
215
|
+
resolve: {
|
|
216
|
+
alias: [{ find: /^buefy$/, replacement: 'buefy/dist/esm/index.js' }]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// webpack.config.js
|
|
220
|
+
resolve: {
|
|
221
|
+
alias: { buefy$: 'buefy/dist/esm/index.js' }
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Bundle size
|
|
226
|
+
|
|
227
|
+
`package.json` marks spmkt's modules side-effect free (`"sideEffects"`), so the
|
|
228
|
+
host's bundler keeps only the components a page imports and their dependencies:
|
|
229
|
+
a page using just `Price` no longer bundles axios, underscore or the Cart. Don't
|
|
230
|
+
rely on spmkt's imports for anything a page doesn't import itself:
|
|
231
|
+
|
|
232
|
+
- `animate.css` is no longer a dependency. spmkt ships only the `pulse` and
|
|
233
|
+
`slideInUp` animations it uses (`utils/animate.css`); a host whose templates
|
|
234
|
+
use other `animate__*` classes installs and imports `animate.css` itself.
|
|
235
|
+
- `window._post` / `window._get` are set by `installSpmkt`, not on import, and
|
|
236
|
+
load the request module on their first call.
|
|
237
|
+
- `window.customEventBus` and `window.GoogleAnalyticsEEC` are still set on
|
|
238
|
+
every page that imports `installSpmkt`.
|
|
239
|
+
- `bulma-divider`, `shortid`, `intl-dateformat` and `scrollmonitor` are no longer
|
|
240
|
+
dependencies. A host theme that `@import`s `bulma-divider` (for Login's
|
|
241
|
+
`.is-divider`) installs it itself.
|
|
242
|
+
- No spmkt component uses Sass, so the host no longer needs `sass` to compile them.
|
|
243
|
+
|
|
244
|
+
## Host Application Requirements
|
|
245
|
+
|
|
246
|
+
spmkt components rely on things the host app provides. In the Vue 2 host these
|
|
247
|
+
came from `Vue.prototype`, a global `Vue.mixin` (`vm.js`) and per-page
|
|
248
|
+
`Vue.directive` calls; in Vue 3 set them on `app.config.globalProperties` and
|
|
249
|
+
register directives with `app.directive`.
|
|
250
|
+
|
|
251
|
+
| Provide | Used by | Notes |
|
|
252
|
+
|---|---|---|
|
|
253
|
+
| `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` |
|
|
254
|
+
| `$t`, `$tc` | all components | e.g. vue-i18n with `globalInjection: true` |
|
|
255
|
+
| `$LC` | prices, addresses | Locale config, falls back to `initialState.lc` |
|
|
256
|
+
| `$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 })` |
|
|
257
|
+
| `getConfig(key)` | CartMode, UserIdentity | Host config lookup (`BASE_URL`, …) |
|
|
258
|
+
| `scrollToElement(selector)` | Delivery, Payment, CartMode | Smooth-scrolls to the element |
|
|
259
|
+
| `logMessage(message)` | Payment, OrderConfirmation | Error reporting (Sentry in the Vue 2 host) |
|
|
260
|
+
| `getRecaptchaToken()` | Payment | Resolves a reCAPTCHA v3 token |
|
|
261
|
+
| `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` |
|
|
262
|
+
| `ageVerificationEnabled()` | DeliveryAddress | `parseInt(initialState.age_verification.enabled)` |
|
|
263
|
+
| `isMobileiOS` | ReservationSlots, ExtendedCreditCard | `true` on iOS Safari |
|
|
264
|
+
| `v-sticky` directive | Delivery | Vue 3 compatible sticky directive, registered as `sticky` |
|
|
265
|
+
| `v-mask` directive | UserIdentity | Vue 3 compatible input mask, registered as `mask` |
|
|
266
|
+
|
|
267
|
+
Host code that listened on its own Vue 2 event bus (e.g. `EventBus.$on('gotoUrl', …)`)
|
|
268
|
+
should use the exported `eventBus` instead, since spmkt components emit there.
|
|
269
|
+
|
|
270
|
+
ReviewImages teleports its image modals to `<body>` inside a
|
|
271
|
+
`.userimg-gallery.userimg-gallery-modals` wrapper. Theme rules that reach the modals
|
|
272
|
+
through a page ancestor (e.g. `.product-page .userimg-gallery .modal`) no longer
|
|
273
|
+
match; scope them to `.userimg-gallery-modals` instead.
|
|
274
|
+
|
|
275
|
+
The address autocomplete (GmapsAutocomplete, used by Address/Edit) uses
|
|
276
|
+
`AutocompleteSuggestion` and `Place`, so the host's Maps key needs the **Places API
|
|
277
|
+
(New)** enabled; with only the legacy Places API it shows an "unavailable" message.
|
|
278
|
+
|
|
279
|
+
`.storybook/preview.js` has minimal stand-ins for all of the above.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Component Migration Checklist
|
|
284
|
+
|
|
285
|
+
For each Vue component, check and update:
|
|
286
|
+
|
|
287
|
+
- [ ] Replace `{{ value | filter }}` with `{{ $filters.filter(value) }}`
|
|
288
|
+
- [ ] Replace `.sync` with `v-model:propName`
|
|
289
|
+
- [ ] Remove `.native` modifier, add `emits` option
|
|
290
|
+
- [ ] Replace `$set`/`$delete` with direct assignment
|
|
291
|
+
- [ ] Replace `beforeDestroy` with `beforeUnmount`
|
|
292
|
+
- [ ] Replace `$scopedSlots` with `$slots`
|
|
293
|
+
- [ ] Update slot syntax from `slot="name"` to `v-slot:name`
|
|
294
|
+
- [ ] Replace `$listeners` with `$attrs` (merged in Vue 3)
|
|
295
|
+
- [ ] Update `$bus.$on`/`$emit` to use imported `eventBus`
|
|
296
|
+
- [ ] Update `value` prop to `modelValue` for v-model components
|
|
297
|
+
- [ ] Update `$emit('input', ...)` to `$emit('update:modelValue', ...)`
|
|
298
|
+
|
|
299
|
+
**Note:** Buefy `<b-*>` components do NOT need to be changed - Buefy 3.x handles Vue 3 compatibility!
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Testing
|
|
304
|
+
|
|
305
|
+
After migration:
|
|
306
|
+
1. Run `npm install` to install new dependencies
|
|
307
|
+
2. Run `npm run build` to build the library
|
|
308
|
+
3. Run `npm run storybook` and click through the stories. The Cart stories
|
|
309
|
+
(Components → Cart) mock every checkout endpoint and use a root `CartStore`
|
|
310
|
+
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,16 +44,17 @@ 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
|
}
|
|
48
53
|
}
|
|
49
54
|
)
|
|
50
55
|
|
|
51
|
-
window._post
|
|
56
|
+
// The host's inline scripts call these as window._post / window._get; installSpmkt sets them
|
|
57
|
+
export const _post = (url, params, callback) => {
|
|
52
58
|
service({
|
|
53
59
|
baseURL: config.BASE_URL,
|
|
54
60
|
url: url,
|
|
@@ -67,7 +73,7 @@ window._post = (url, params, callback) => {
|
|
|
67
73
|
return true
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
|
|
76
|
+
export const _get = (url, params, callback) => {
|
|
71
77
|
let queryString = ''
|
|
72
78
|
if (params) {
|
|
73
79
|
queryString = Object.keys(params)
|
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>
|