Files
InvoiceShelf/resources/scripts/customer/stores/global.js
Darko Gjorgjijoski 691178857f Add HTTP client wrapper and upgrade Axios to v1 (#594)
* refactor: add HTTP client wrapper and upgrade axios to v1

Introduce a thin HTTP wrapper (resources/scripts/http) that centralizes
axios configuration, interceptors, and auth header injection. All 43
files now import from the wrapper instead of axios directly, making
future library swaps a single-file change. Upgrade axios from 0.30.0
to 1.14.0.

* fix: restore window.Ls assignment removed during axios refactor

company.js uses window.Ls.set() to persist selected company,
which broke after the axios plugin (that set window.Ls) was deleted.
2026-04-02 15:08:23 +02:00

69 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({
id: '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)
})
}
})
},
},
})