Skip to content

Commit 7fc8fdf

Browse files
authored
Merge pull request #6987 from FlowFuse/6944-pinia-task-15-teardown
[6944] Pinia Task 15 - teardown
2 parents c9047fd + 5f7b3a7 commit 7fc8fdf

40 files changed

Lines changed: 347 additions & 687 deletions

frontend/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export default {
146146
}
147147
},
148148
mounted () {
149-
this.$store.dispatch('account/checkState')
149+
useAccountAuthStore().checkState()
150150
useProductBrokersStore().checkFlags()
151151
},
152152
methods: {

frontend/src/api/client.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import axios from 'axios'
22

33
import Alerts from '../services/alerts.js'
44

5+
import { useAccountAuthStore } from '@/stores/account-auth.js'
6+
import { useUxLoadingStore } from '@/stores/ux-loading.js'
7+
58
const client = axios.create({
69
headers: {
710
'Content-Type': 'application/json'
@@ -12,24 +15,18 @@ const client = axios.create({
1215
// Common error handler
1316
client.interceptors.response.use(function (response) {
1417
return response
15-
}, function (error) {
18+
}, async function (error) {
1619
if (/^http/.test(error.config.url)) {
1720
// This request is to an external URL. Allow this error to pass back to the caller
1821
return Promise.reject(error)
1922
}
2023

21-
// This is an error response from our own API (or failure to reach it)
22-
// Lazy require to avoid circular dependency:
23-
// api/client.js → stores/account-auth.js → api/user.js → api/client.js
24-
const { useAccountAuthStore } = require('../stores/account-auth.js')
25-
const { useUxLoadingStore } = require('../stores/ux-loading.js')
26-
const store = require('../store/index.js').default
2724
if (error.code === 'ERR_NETWORK') {
2825
// Backend failed to respond
2926
useUxLoadingStore().setOffline(true)
3027
} else if (error.response && error.response.status === 401 && !useUxLoadingStore().appLoader && !useAccountAuthStore().loginInflight) {
3128
// 401 when !pending && !loginInflight means the session has expired
32-
store.dispatch('account/logout')
29+
useAccountAuthStore().logout()
3330
} else if (error.response && error.response.status === 500) {
3431
// show toast notification
3532
Alerts.emit(error.response.data.error + ': ' + error.response.data.message, 'warning', 7500)

frontend/src/components/Offline.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
</div>
1111
</template>
1212
<script>
13+
import { useAccountAuthStore } from '@/stores/account-auth.js'
14+
1315
export default {
1416
name: 'OfflineMessage',
1517
methods: {
1618
reload () {
17-
this.$store.dispatch('account/checkState')
19+
useAccountAuthStore().checkState()
1820
}
1921
}
2022
}

frontend/src/components/auth/UpdateExpiredPassword.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import { mapState } from 'pinia'
4444
4545
import userApi from '../../api/user.js'
46-
import store from '../../store/index.js'
4746
import FormRow from '../FormRow.vue'
4847
4948
import { useAccountAuthStore } from '@/stores/account-auth.js'
@@ -89,7 +88,7 @@ export default {
8988
return false
9089
}
9190
userApi.changePassword(this.input.old_password, this.input.password).then(() => {
92-
this.$store.dispatch('account/checkState')
91+
useAccountAuthStore().checkState()
9392
this.$router.go()
9493
}).catch(e => {
9594
this.errors.password_change = 'Password change failed'
@@ -106,7 +105,7 @@ export default {
106105
this.$refs['row-confirm'].focus()
107106
},
108107
logout () {
109-
store.dispatch('account/logout')
108+
useAccountAuthStore().logout()
110109
}
111110
},
112111
mounted () {

frontend/src/main.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,20 @@ import router from './routes.js'
2020
import Alerts from './services/alerts.js'
2121
import { setupSentry } from './services/error-tracking.js'
2222
import { getServiceFactory } from './services/service.factory.js'
23-
import store from './store/index.js'
2423
import { skipResetPlugin } from './stores/plugins/skip-reset.plugin.js'
2524

2625
import './index.css'
2726
import 'highlight.js/styles/github.css'
2827

2928
import ForgeUIComponents from './ui-components/index.js'
3029

31-
store.commit('initializeStore')
32-
3330
const pinia = createPinia()
3431
pinia.use(piniaPluginPersistedstate)
3532
pinia.use(skipResetPlugin)
3633

3734
const app = createApp(App)
3835
.use(ForgeUIComponents)
3936
.use(pinia)
40-
.use(store)
4137
.use(router)
4238
.use(VueShepherdPlugin)
4339

@@ -47,7 +43,7 @@ const serviceFactory = getServiceFactory()
4743
setupSentry(app, router)
4844

4945
// Boot all services before mounting
50-
serviceFactory.bootAllServices(app, store, router)
46+
serviceFactory.bootAllServices(app, router)
5147
.then((services) => services.bootstrap.init())
5248
.catch((error) => {
5349
console.error('Bootstrap initialization failed:', error)

frontend/src/pages/Login.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ export default {
220220
}
221221
if (valid) {
222222
this.loggingIn = true
223-
this.$store.dispatch('account/login', {
223+
useAccountAuthStore().loginWithCredentials({
224224
username: this.input.username,
225225
password: this.input.password
226226
})
227227
}
228228
},
229229
submitMFAToken () {
230230
this.loggingIn = true
231-
this.$store.dispatch('account/login', {
231+
useAccountAuthStore().loginWithCredentials({
232232
token: this.input.token
233233
})
234234
},

frontend/src/pages/TermsAndConditions.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { mapState } from 'pinia'
2121
2222
import userApi from '../api/user.js'
2323
import FFLayoutBox from '../layouts/Box.vue'
24-
import store from '../store/index.js'
2524
2625
import { useAccountAuthStore } from '@/stores/account-auth.js'
2726
import { useAccountSettingsStore } from '@/stores/account-settings.js'
@@ -43,15 +42,15 @@ export default {
4342
},
4443
methods: {
4544
logout () {
46-
store.dispatch('account/logout')
45+
useAccountAuthStore().logout()
4746
},
4847
async acceptAction () {
4948
const options = {}
5049
try {
5150
options.tcs_accepted = this.accept
5251
this.loading = true
5352
await userApi.updateUser(options)
54-
this.$store.dispatch('account/checkState')
53+
useAccountAuthStore().checkState()
5554
} catch (error) {
5655
console.warn(error)
5756
} finally {

frontend/src/pages/UnverifiedEmail.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { mapActions, mapState } from 'pinia'
3232
3333
import userApi from '../api/user.js'
3434
import FFLayoutBox from '../layouts/Box.vue'
35-
import store from '../store/index.js'
3635
3736
import { useAccountAuthStore } from '@/stores/account-auth.js'
3837
import { useUxToursStore } from '@/stores/ux-tours.js'
@@ -89,7 +88,7 @@ export default {
8988
tick()
9089
},
9190
logout () {
92-
store.dispatch('account/logout')
91+
useAccountAuthStore().logout()
9392
}
9493
}
9594
}

frontend/src/pages/account/Settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default {
277277
if (this.settings['user:offboarding-required']) {
278278
window.location.href = this.settings['user:offboarding-url']
279279
} else {
280-
this.$store.dispatch('account/checkState')
280+
useAccountAuthStore().checkState()
281281
}
282282
})
283283
.catch(error => {

frontend/src/pages/account/VerifyPendingEmailChange.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<form v-if="!pending" class="px-4 sm:px-6 lg:px-8 mt-8 space-y-6">
2+
<form v-if="!appLoader" class="px-4 sm:px-6 lg:px-8 mt-8 space-y-6">
33
<div>
44
<ff-button class="m-auto" @click="verify()">Click here to verify your change of email address</ff-button>
55
</div>
@@ -8,18 +8,20 @@
88

99
<script>
1010
11-
import { mapState } from 'vuex'
11+
import { mapState } from 'pinia'
1212
1313
import userApi from '../../api/user.js'
1414
import alerts from '../../services/alerts.js'
1515
16+
import { useUxLoadingStore } from '@/stores/ux-loading.js'
17+
1618
export default {
1719
name: 'VerifyPendingEmailChange',
1820
props: {
1921
token: { type: String, required: true }
2022
},
2123
computed: {
22-
...mapState(['pending'])
24+
...mapState(useUxLoadingStore, ['appLoader'])
2325
},
2426
methods: {
2527
async verify () {

0 commit comments

Comments
 (0)