Vue 3 + Vite + Tailwind CSS Views: - Dashboard mit Stats & Aktivitäten - Kontakte mit Suche & CRUD - Firmen mit Cards & CRUD - Pipeline Kanban Board (Drag & Drop) - Aktivitäten mit Filter & Timeline - Settings mit DSGVO-Info Features: - Dark Theme (Pulse Design) - Responsive Layout - Pinia State Management - Vue Router mit Guards - Axios API Client Task: #13 Frontend UI
74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import api from '@/lib/api'
|
|
|
|
export const useCompaniesStore = defineStore('companies', () => {
|
|
const companies = ref([])
|
|
const currentCompany = ref(null)
|
|
const loading = ref(false)
|
|
const error = ref(null)
|
|
const meta = ref({ page: 1, limit: 25, total: 0 })
|
|
|
|
async function fetchCompanies(params = {}) {
|
|
loading.value = true
|
|
error.value = null
|
|
|
|
try {
|
|
const response = await api.get('/api/v1/companies', { params })
|
|
companies.value = response.data.data
|
|
meta.value = response.data.meta
|
|
} catch (e) {
|
|
error.value = e.response?.data?.error?.message || 'Fehler beim Laden'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function fetchCompany(id) {
|
|
loading.value = true
|
|
try {
|
|
const response = await api.get(`/api/v1/companies/${id}`)
|
|
currentCompany.value = response.data.data
|
|
return currentCompany.value
|
|
} catch (e) {
|
|
error.value = e.response?.data?.error?.message || 'Firma nicht gefunden'
|
|
return null
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function createCompany(data) {
|
|
try {
|
|
const response = await api.post('/api/v1/companies', data)
|
|
companies.value.unshift(response.data.data)
|
|
return response.data.data
|
|
} catch (e) {
|
|
error.value = e.response?.data?.error?.message || 'Fehler beim Erstellen'
|
|
throw e
|
|
}
|
|
}
|
|
|
|
async function deleteCompany(id) {
|
|
try {
|
|
await api.delete(`/api/v1/companies/${id}`)
|
|
companies.value = companies.value.filter(c => c.id !== id)
|
|
} catch (e) {
|
|
error.value = e.response?.data?.error?.message || 'Fehler beim Löschen'
|
|
throw e
|
|
}
|
|
}
|
|
|
|
return {
|
|
companies,
|
|
currentCompany,
|
|
loading,
|
|
error,
|
|
meta,
|
|
fetchCompanies,
|
|
fetchCompany,
|
|
createCompany,
|
|
deleteCompany
|
|
}
|
|
})
|