mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
Migrate all 37 store definitions from the deprecated object-with-id
signature to the string-id-first signature required by Pinia 3:
defineStore({ id: 'name', ... }) → defineStore('name', { ... })
68 lines
1.9 KiB
JavaScript
Vendored
68 lines
1.9 KiB
JavaScript
Vendored
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
|
import { useUserStore } from './user'
|
|
const { defineStore } = window.pinia
|
|
import http from '@/scripts/http'
|
|
const { global } = window.i18n
|
|
export const useGlobalStore = defineStore('CustomerPortalGlobalStore', {
|
|
state: () => ({
|
|
languages: [],
|
|
currency: null,
|
|
isAppLoaded: false,
|
|
countries: [],
|
|
getDashboardDataLoaded: false,
|
|
currentUser: null,
|
|
companySlug: '',
|
|
mainMenu: null,
|
|
enabledModules: []
|
|
}),
|
|
|
|
actions: {
|
|
bootstrap(data) {
|
|
this.companySlug = data
|
|
const userStore = useUserStore()
|
|
return new Promise((resolve, reject) => {
|
|
http
|
|
.get(`/api/v1/${data}/customer/bootstrap`)
|
|
.then((response) => {
|
|
this.currentUser = response.data.data
|
|
this.mainMenu = response.data.meta.menu
|
|
this.currency = response.data.data.currency
|
|
this.enabledModules = response.data.meta.modules
|
|
Object.assign(userStore.userForm, response.data.data)
|
|
|
|
if(typeof global.locale !== 'string') {
|
|
global.locale.value =
|
|
response.data.meta.current_company_language || 'en'
|
|
}
|
|
|
|
this.isAppLoaded = true
|
|
resolve(response)
|
|
})
|
|
.catch((err) => {
|
|
handleError(err)
|
|
reject(err)
|
|
})
|
|
})
|
|
},
|
|
|
|
fetchCountries() {
|
|
return new Promise((resolve, reject) => {
|
|
if (this.countries.length) {
|
|
resolve(this.countries)
|
|
} else {
|
|
http
|
|
.get(`/api/v1/${this.companySlug}/customer/countries`)
|
|
.then((response) => {
|
|
this.countries = response.data.data
|
|
resolve(response)
|
|
})
|
|
.catch((err) => {
|
|
handleError(err)
|
|
reject(err)
|
|
})
|
|
}
|
|
})
|
|
},
|
|
},
|
|
})
|