feat: Pulse CRM Frontend v1.0
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
This commit is contained in:
73
src/stores/companies.js
Normal file
73
src/stores/companies.js
Normal file
@@ -0,0 +1,73 @@
|
||||
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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user