Skip to content

Commit dba8f2c

Browse files
committed
Fix deconstructed getters/state
1 parent 5b9f566 commit dba8f2c

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

frontend/src/composables/Components/multi-step-forms/instance/InstanceFormHelper.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { storeToRefs } from 'pinia'
2+
13
import store from '../../../../store/index.js'
24
import { getTeamProperty } from '../../../TeamProperties.js'
35

@@ -7,7 +9,8 @@ export function useInstanceFormHelper () {
79
const _store = store
810

911
const teamRuntimeLimitReached = () => {
10-
const { team } = useContextStore()
12+
const { team: teamRef } = storeToRefs(useContextStore())
13+
const team = teamRef.value
1114
let teamTypeRuntimeLimit = getTeamProperty(team, 'runtimes.limit')
1215
const currentRuntimeCount = (team?.deviceCount ?? 0) + (team?.instanceCount ?? 0)
1316
if (team?.billing?.trial && !team?.billing?.active && getTeamProperty(team, 'trial.runtimesLimit')) {
@@ -17,7 +20,8 @@ export function useInstanceFormHelper () {
1720
}
1821

1922
const decorateInstanceTypes = (instanceTypes) => {
20-
const { team } = useContextStore()
23+
const { team: teamRef } = storeToRefs(useContextStore())
24+
const team = teamRef.value
2125
// Do a first pass of the instance types to disable any not allowed for this team
2226
instanceTypes = instanceTypes.map(instanceType => {
2327
// Need to combine the projectType billing info with any overrides

frontend/src/pages/account/Settings.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</template>
5252

5353
<script>
54-
import { mapState } from 'pinia'
54+
import { mapState, storeToRefs } from 'pinia'
5555
import { mapState as mapVuexState } from 'vuex'
5656
5757
import teamApi from '../../api/team.js'
@@ -65,6 +65,7 @@ import { RoleNames, Roles } from '../../utils/roles.js'
6565
6666
import { useAccountAuthStore } from '@/stores/account-auth.js'
6767
import { useAccountTeamStore } from '@/stores/account-team.js'
68+
import { useContextStore } from '@/stores/context.js'
6869
6970
export default {
7071
name: 'AccountSettings',
@@ -298,12 +299,13 @@ export default {
298299
// refresh teams
299300
return useAccountTeamStore().refreshTeams()
300301
}).then(() => {
301-
const { team, teams } = useAccountTeamStore()
302+
const { teams } = storeToRefs(useAccountTeamStore())
303+
const team = useContextStore().team
302304
// check if the active team is one deleted
303305
if (team?.id === teamId) {
304-
if (teams.length > 0) {
306+
if (teams.value.length > 0) {
305307
// get another team
306-
useAccountTeamStore().setTeam(teams[0].slug)
308+
useAccountTeamStore().setTeam(teams.value[0].slug)
307309
}
308310
}
309311
}).catch(err => {

frontend/src/store/modules/account/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getActivePinia } from 'pinia'
1+
import { getActivePinia, storeToRefs } from 'pinia'
22
import { nextTick } from 'vue'
33

44
import settingsApi from '../../../api/settings.js'
@@ -53,8 +53,11 @@ const getters = {
5353
return state.settings
5454
},
5555
requiresBilling (state, getters) {
56-
const { user } = useAccountAuthStore()
57-
const { team, isTrialAccount } = useContextStore()
56+
const { user: userRef } = storeToRefs(useAccountAuthStore())
57+
const { team: teamRef, isTrialAccount: isTrialAccountRef } = storeToRefs(useContextStore())
58+
const user = userRef.value
59+
const team = teamRef.value
60+
const isTrialAccount = isTrialAccountRef.value
5861
const isNotAdmin = (user && !user.admin)
5962

6063
return isNotAdmin &&
@@ -76,7 +79,9 @@ const getters = {
7679
getters.settings['team:create']
7780
},
7881
featuresCheck: (state) => {
79-
const { teamMembership, team } = useContextStore()
82+
const { teamMembership: teamMembershipRef, team: teamRef } = storeToRefs(useContextStore())
83+
const teamMembership = teamMembershipRef.value
84+
const team = teamRef.value
8085

8186
const preCheck = {
8287
// Instances
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Temporary bridge — reads account data from Vuex/Pinia during migration.
22
// Delete this file after the account stores are migrated to Pinia.
33

4+
import { storeToRefs } from 'pinia'
5+
46
import { useAccountAuthStore } from '@/stores/account-auth.js'
57

68
export function useAccountBridge () {
@@ -10,19 +12,19 @@ export function useAccountBridge () {
1012
// context.js imports _account_bridge.js statically; requiring context.js lazily here avoids a cycle.
1113
const store = require('../store/index.js').default
1214
const { useContextStore } = require('@/stores/context.js')
13-
const { user } = useAccountAuthStore()
14-
const { team, teamMembership, isTrialAccount, isTrialAccountExpired } = useContextStore()
15+
const { user } = storeToRefs(useAccountAuthStore())
16+
const { team, teamMembership, isTrialAccount, isTrialAccountExpired } = storeToRefs(useContextStore())
1517
return {
16-
user,
17-
userId: user?.id || null,
18-
team,
19-
teamId: team?.id || null,
20-
teamSlug: team?.slug || null,
18+
user: user.value,
19+
userId: user.value?.id || null,
20+
team: team.value,
21+
teamId: team.value?.id || null,
22+
teamSlug: team.value?.slug || null,
2123
features: store.state.account.features,
22-
teamMembership: teamMembership ?? { role: 0 },
24+
teamMembership: teamMembership.value ?? { role: 0 },
2325
featuresCheck: store.getters['account/featuresCheck'],
2426
requiresBilling: store.getters['account/requiresBilling'],
25-
isTrialAccount,
26-
isTrialAccountExpired
27+
isTrialAccount: isTrialAccount.value,
28+
isTrialAccountExpired: isTrialAccountExpired.value
2729
}
2830
}

frontend/src/stores/account-team.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export const useAccountTeamStore = defineStore('account-team', {
2323
},
2424
defaultBlueprint () { return this.blueprints?.find(blueprint => blueprint.default) },
2525
defaultUserTeam: (state) => {
26-
const { user } = useAccountAuthStore()
27-
const defaultTeamId = user?.defaultTeam || state.teams[0]?.id
26+
const defaultTeamId = useAccountAuthStore().user?.defaultTeam || state.teams[0]?.id
2827
return state.teams.find(team => team.id === defaultTeamId)
2928
},
3029
notificationsCount: state => state.notifications?.length || 0,

0 commit comments

Comments
 (0)