Files
InvoiceShelf/resources/scripts/customer/stores/dashboard.js
Darko Gjorgjijoski 3ceb08bc31 Upgrade Pinia from v2 to v3 (#596)
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', { ... })
2026-04-02 16:12:11 +02:00

43 lines
1.3 KiB
JavaScript
Vendored

const { defineStore } = window.pinia
import { useGlobalStore } from '@/scripts/customer/stores/global'
import http from '@/scripts/http'
import { handleError } from '@/scripts/customer/helpers/error-handling'
export const useDashboardStore = defineStore('dashboard', {
state: () => ({
recentInvoices: [],
recentEstimates: [],
invoiceCount: 0,
estimateCount: 0,
paymentCount: 0,
totalDueAmount: [],
isDashboardDataLoaded: false,
}),
actions: {
loadData(data) {
const globalStore = useGlobalStore()
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${globalStore.companySlug}/customer/dashboard`, {
data,
})
.then((response) => {
this.totalDueAmount = response.data.due_amount
this.estimateCount = response.data.estimate_count
this.invoiceCount = response.data.invoice_count
this.paymentCount = response.data.payment_count
this.recentInvoices = response.data.recentInvoices
this.recentEstimates = response.data.recentEstimates
globalStore.getDashboardDataLoaded = true
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
},
})