mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 21:44:51 +00:00
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', { ... })
69 lines
1.9 KiB
JavaScript
Vendored
69 lines
1.9 KiB
JavaScript
Vendored
const { defineStore } = window.pinia
|
|
import { handleError } from '@/scripts/helpers/error-handling'
|
|
import { useNotificationStore } from '@/scripts/stores/notification'
|
|
import http from '@/scripts/http'
|
|
|
|
export const usePDFDriverStore = (useWindow = false) => {
|
|
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
|
const { global } = window.i18n
|
|
|
|
return defineStoreFunc('pdf-driver', {
|
|
state: () => ({
|
|
pdfDriverConfig: null,
|
|
pdf_driver: 'dompdf',
|
|
pdf_drivers: [],
|
|
|
|
dompdf: {
|
|
pdf_driver: '',
|
|
},
|
|
gotenberg: {
|
|
pdf_driver: '',
|
|
gotenberg_host: '',
|
|
gotenberg_papersize: ''
|
|
}
|
|
}),
|
|
|
|
actions: {
|
|
async fetchDrivers() {
|
|
try {
|
|
const response = await http.get('/api/v1/pdf/drivers')
|
|
this.pdf_drivers = response.data
|
|
} catch (err) {
|
|
handleError(err)
|
|
throw err
|
|
}
|
|
},
|
|
async fetchConfig() {
|
|
try {
|
|
const response = await http.get('/api/v1/pdf/config')
|
|
this.pdfDriverConfig = response.data
|
|
this.pdf_driver = response.data.pdf_driver
|
|
} catch (err) {
|
|
handleError(err)
|
|
throw err
|
|
}
|
|
},
|
|
async updateConfig(data) {
|
|
try {
|
|
const response = await http.post('/api/v1/pdf/config', data)
|
|
const notificationStore = useNotificationStore()
|
|
if (response.data.success) {
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: global.t('settings.pdf.' + response.data.success),
|
|
})
|
|
} else {
|
|
notificationStore.showNotification({
|
|
type: 'error',
|
|
message: global.t('settings.pdf.' + response.data.error),
|
|
})
|
|
}
|
|
} catch (err) {
|
|
handleError(err)
|
|
throw err
|
|
}
|
|
},
|
|
},
|
|
})()
|
|
}
|