Files
InvoiceShelf/resources/scripts/customer/stores/global.js
agencetwogether 3b61440e1f Complete dashboard translations & small UI improvements (#69)
* fix dropdown action Estimate Dashboard and fix translating full Dasboard page

* Update app.php

* fix locale in app.php config

* Wizard install with translation, customer portal with translation, and fixing hardcoding strings to get translation

* fixes asked to review

* fixes pint

---------

Co-authored-by: Max <contact@agencetwogether.fr>
Co-authored-by: Darko Gjorgjijoski <5760249+gdarko@users.noreply.github.com>
2024-06-05 12:07:46 +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 axios from 'axios'
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) => {
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)
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 {
axios
.get(`/api/v1/${this.companySlug}/customer/countries`)
.then((response) => {
this.countries = response.data.data
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
}
})
},
},
})