Files
InvoiceShelf/resources/scripts/customer/stores/estimate.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

117 lines
3.3 KiB
JavaScript
Vendored

const { defineStore } = window.pinia
import { useNotificationStore } from '@/scripts/stores/notification'
import http from '@/scripts/http'
import { handleError } from '@/scripts/customer/helpers/error-handling'
export const useEstimateStore = defineStore({
id: 'customerEstimateStore',
state: () => ({
estimates: [],
totalEstimates: 0,
selectedViewEstimate: [],
}),
actions: {
fetchEstimate(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/estimates`, { params })
.then((response) => {
this.estimates = response.data.data
this.totalEstimates = response.data.meta.estimateTotalCount
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
fetchViewEstimate(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/estimates/${params.id}`, {
params,
})
.then((response) => {
this.selectedViewEstimate = response.data.data
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
searchEstimate(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/estimates`, { params })
.then((response) => {
this.estimates = response.data
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
acceptEstimate({ slug, id, status }) {
return new Promise((resolve, reject) => {
http
.post(`/api/v1/${slug}/customer/estimate/${id}/status`, { status })
.then((response) => {
let pos = this.estimates.findIndex(
(estimate) => estimate.id === id
)
if (this.estimates[pos]) {
this.estimates[pos].status = 'ACCEPTED'
const notificationStore = useNotificationStore(true)
notificationStore.showNotification({
type: 'success',
message: global.t('estimates.marked_as_accepted_message'),
})
}
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
rejectEstimate({ slug, id, status }) {
return new Promise((resolve, reject) => {
http
.post(`/api/v1/${slug}/customer/estimate/${id}/status`, { status })
.then((response) => {
let pos = this.estimates.findIndex(
(estimate) => estimate.id === id
)
if (this.estimates[pos]) {
this.estimates[pos].status = 'REJECTED'
const notificationStore = useNotificationStore(true)
notificationStore.showNotification({
type: 'success',
message: global.t('estimates.marked_as_rejected_message'),
})
}
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
},
})