mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
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.
This commit is contained in:
committed by
GitHub
parent
a38f09cf7b
commit
691178857f
12
resources/scripts/customer/stores/auth.js
vendored
12
resources/scripts/customer/stores/auth.js
vendored
@@ -1,5 +1,5 @@
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import router from '@/scripts/customer/customer-router'
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
@@ -20,9 +20,9 @@ export const useAuthStore = defineStore({
|
||||
login(data) {
|
||||
const notificationStore = useNotificationStore(true)
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get('/sanctum/csrf-cookie').then((response) => {
|
||||
http.get('/sanctum/csrf-cookie').then((response) => {
|
||||
if (response) {
|
||||
axios
|
||||
http
|
||||
.post(`/${data.company}/customer/login`, data)
|
||||
.then((response) => {
|
||||
notificationStore.showNotification({
|
||||
@@ -47,7 +47,7 @@ export const useAuthStore = defineStore({
|
||||
forgotPassword(data) {
|
||||
const notificationStore = useNotificationStore(true)
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.post(`/api/v1/${data.company}/customer/auth/password/email`, data)
|
||||
|
||||
.then((response) => {
|
||||
@@ -75,7 +75,7 @@ export const useAuthStore = defineStore({
|
||||
|
||||
resetPassword(data, company) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.post(`/api/v1/${company}/customer/auth/reset/password`, data)
|
||||
|
||||
.then((response) => {
|
||||
@@ -102,7 +102,7 @@ export const useAuthStore = defineStore({
|
||||
|
||||
logout(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.post(`/${data}/customer/logout`)
|
||||
.then((response) => {
|
||||
const notificationStore = useNotificationStore()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { defineStore } = window.pinia
|
||||
import { useGlobalStore } from '@/scripts/customer/stores/global'
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
|
||||
export const useDashboardStore = defineStore({
|
||||
@@ -19,7 +19,7 @@ export const useDashboardStore = defineStore({
|
||||
loadData(data) {
|
||||
const globalStore = useGlobalStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${globalStore.companySlug}/customer/dashboard`, {
|
||||
data,
|
||||
})
|
||||
|
||||
12
resources/scripts/customer/stores/estimate.js
vendored
12
resources/scripts/customer/stores/estimate.js
vendored
@@ -1,6 +1,6 @@
|
||||
const { defineStore } = window.pinia
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
|
||||
export const useEstimateStore = defineStore({
|
||||
@@ -13,7 +13,7 @@ export const useEstimateStore = defineStore({
|
||||
actions: {
|
||||
fetchEstimate(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/estimates`, { params })
|
||||
.then((response) => {
|
||||
this.estimates = response.data.data
|
||||
@@ -29,7 +29,7 @@ export const useEstimateStore = defineStore({
|
||||
|
||||
fetchViewEstimate(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/estimates/${params.id}`, {
|
||||
params,
|
||||
})
|
||||
@@ -47,7 +47,7 @@ export const useEstimateStore = defineStore({
|
||||
|
||||
searchEstimate(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/estimates`, { params })
|
||||
.then((response) => {
|
||||
this.estimates = response.data
|
||||
@@ -62,7 +62,7 @@ export const useEstimateStore = defineStore({
|
||||
acceptEstimate({ slug, id, status }) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.post(`/api/v1/${slug}/customer/estimate/${id}/status`, { status })
|
||||
.then((response) => {
|
||||
let pos = this.estimates.findIndex(
|
||||
@@ -89,7 +89,7 @@ export const useEstimateStore = defineStore({
|
||||
rejectEstimate({ slug, id, status }) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.post(`/api/v1/${slug}/customer/estimate/${id}/status`, { status })
|
||||
.then((response) => {
|
||||
let pos = this.estimates.findIndex(
|
||||
|
||||
6
resources/scripts/customer/stores/global.js
vendored
6
resources/scripts/customer/stores/global.js
vendored
@@ -1,7 +1,7 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
import { useUserStore } from './user'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
const { global } = window.i18n
|
||||
export const useGlobalStore = defineStore({
|
||||
id: 'CustomerPortalGlobalStore',
|
||||
@@ -22,7 +22,7 @@ export const useGlobalStore = defineStore({
|
||||
this.companySlug = data
|
||||
const userStore = useUserStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${data}/customer/bootstrap`)
|
||||
.then((response) => {
|
||||
this.currentUser = response.data.data
|
||||
@@ -51,7 +51,7 @@ export const useGlobalStore = defineStore({
|
||||
if (this.countries.length) {
|
||||
resolve(this.countries)
|
||||
} else {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${this.companySlug}/customer/countries`)
|
||||
.then((response) => {
|
||||
this.countries = response.data.data
|
||||
|
||||
8
resources/scripts/customer/stores/invoice.js
vendored
8
resources/scripts/customer/stores/invoice.js
vendored
@@ -1,6 +1,6 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
export const useInvoiceStore = defineStore({
|
||||
id: 'customerInvoiceStore',
|
||||
state: () => ({
|
||||
@@ -12,7 +12,7 @@ export const useInvoiceStore = defineStore({
|
||||
actions: {
|
||||
fetchInvoices(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/invoices`, { params })
|
||||
.then((response) => {
|
||||
this.invoices = response.data.data
|
||||
@@ -28,7 +28,7 @@ export const useInvoiceStore = defineStore({
|
||||
|
||||
fetchViewInvoice(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/invoices/${params.id}`, {
|
||||
params,
|
||||
})
|
||||
@@ -46,7 +46,7 @@ export const useInvoiceStore = defineStore({
|
||||
|
||||
searchInvoice(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/invoices`, { params })
|
||||
.then((response) => {
|
||||
this.invoices = response.data
|
||||
|
||||
10
resources/scripts/customer/stores/payment.js
vendored
10
resources/scripts/customer/stores/payment.js
vendored
@@ -1,6 +1,6 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
|
||||
export const usePaymentStore = defineStore({
|
||||
id: 'customerPaymentStore',
|
||||
@@ -13,7 +13,7 @@ export const usePaymentStore = defineStore({
|
||||
actions: {
|
||||
fetchPayments(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/payments`, { params })
|
||||
.then((response) => {
|
||||
this.payments = response.data.data
|
||||
@@ -29,7 +29,7 @@ export const usePaymentStore = defineStore({
|
||||
|
||||
fetchViewPayment(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/payments/${params.id}`)
|
||||
|
||||
.then((response) => {
|
||||
@@ -45,7 +45,7 @@ export const usePaymentStore = defineStore({
|
||||
|
||||
searchPayment(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/payments`, { params })
|
||||
.then((response) => {
|
||||
this.payments = response.data
|
||||
@@ -60,7 +60,7 @@ export const usePaymentStore = defineStore({
|
||||
|
||||
fetchPaymentModes(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${slug}/customer/payment-method`, { params })
|
||||
.then((response) => {
|
||||
resolve(response)
|
||||
|
||||
6
resources/scripts/customer/stores/user.js
vendored
6
resources/scripts/customer/stores/user.js
vendored
@@ -2,7 +2,7 @@ import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import stubs from '@/scripts/customer/stubs/address'
|
||||
import axios from 'axios'
|
||||
import http from '@/scripts/http'
|
||||
import { useGlobalStore } from '@/scripts/customer/stores/global'
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
@@ -37,7 +37,7 @@ export const useUserStore = defineStore({
|
||||
fetchCurrentUser() {
|
||||
const globalStore = useGlobalStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.get(`/api/v1/${globalStore.companySlug}/customer/me`)
|
||||
.then((response) => {
|
||||
Object.assign(this.userForm, response.data.data)
|
||||
@@ -53,7 +53,7 @@ export const useUserStore = defineStore({
|
||||
updateCurrentUser({ data, message }) {
|
||||
const globalStore = useGlobalStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
http
|
||||
.post(`/api/v1/${globalStore.companySlug}/customer/profile`, data)
|
||||
.then((response) => {
|
||||
this.userForm = response.data.data
|
||||
|
||||
Reference in New Issue
Block a user