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

77 lines
2.0 KiB
JavaScript
Vendored

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 http from '@/scripts/http'
import { useGlobalStore } from '@/scripts/customer/stores/global'
export const useUserStore = defineStore('customerUserStore', {
state: () => ({
customers: [],
userForm: {
avatar: null,
name: '',
email: '',
password: '',
company: '',
confirm_password: '',
billing: {
...stubs,
},
shipping: {
...stubs,
},
},
}),
actions: {
copyAddress() {
this.userForm.shipping = {
...this.userForm.billing,
type: 'shipping',
}
},
fetchCurrentUser() {
const globalStore = useGlobalStore()
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${globalStore.companySlug}/customer/me`)
.then((response) => {
Object.assign(this.userForm, response.data.data)
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
updateCurrentUser({ data, message }) {
const globalStore = useGlobalStore()
return new Promise((resolve, reject) => {
http
.post(`/api/v1/${globalStore.companySlug}/customer/profile`, data)
.then((response) => {
this.userForm = response.data.data
globalStore.currentUser = response.data.data
resolve(response)
if (message) {
const notificationStore = useNotificationStore(true)
notificationStore.showNotification({
type: 'success',
message: message,
})
}
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
},
})