mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 20:21:10 -04:00
v6 update
This commit is contained in:
62
resources/scripts/customer/stores/global.js
Normal file
62
resources/scripts/customer/stores/global.js
Normal file
@ -0,0 +1,62 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
import { useUserStore } from './user'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
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) => {
|
||||
axios
|
||||
.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)
|
||||
window.i18n.locale = response.data.default_language
|
||||
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 {
|
||||
axios
|
||||
.get(`/api/v1/${this.companySlug}/customer/countries`)
|
||||
.then((response) => {
|
||||
this.countries = response.data.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user