- Introduced typography styles in _typography.scss for headings, paragraphs, blockquotes, and horizontal rules. - Added utility classes in _utils.scss for card styling and clearfix. - Updated layout.scss to include new typography and utility styles. - Defined common CSS variables in _common.scss for consistent theming. - Created dark and light theme variables in _dark.scss and _light.scss respectively. - Integrated Tailwind CSS with custom configurations in tailwind.config.js and postcss.config.js. - Implemented database migrations for contact and contact_persons tables. - Added data fixtures for generating sample contact data. - Developed Contact and ContactPerson entities with appropriate validation and serialization. - Enhanced ContactRepository with search and type filtering methods.
790 lines
25 KiB
Vue
790 lines
25 KiB
Vue
<template>
|
|
<div class="contact-management">
|
|
<div class="flex justify-content-between align-items-center mb-4">
|
|
<h1 class="text-3xl font-bold">Kontakte</h1>
|
|
<Button label="Neuer Kontakt" icon="pi pi-plus" @click="openNewContactDialog" />
|
|
</div>
|
|
|
|
<Card>
|
|
<template #content>
|
|
<DataTable
|
|
v-model:filters="globalFilter"
|
|
:value="contacts"
|
|
:loading="loading"
|
|
paginator
|
|
:rows="10"
|
|
:rowsPerPageOptions="[10, 25, 50]"
|
|
:globalFilterFields="['companyName', 'city', 'email']"
|
|
sortField="companyName"
|
|
:sortOrder="1"
|
|
>
|
|
<template #header>
|
|
<div class="flex justify-content-between">
|
|
<IconField iconPosition="left">
|
|
<InputIcon>
|
|
<i class="pi pi-search" />
|
|
</InputIcon>
|
|
<InputText
|
|
v-model="globalFilter"
|
|
placeholder="Suchen..."
|
|
style="width: 300px"
|
|
/>
|
|
</IconField>
|
|
<div class="flex gap-2">
|
|
<Button
|
|
label="Alle"
|
|
:outlined="typeFilter !== 'all'"
|
|
@click="filterByType('all')"
|
|
size="small"
|
|
/>
|
|
<Button
|
|
label="Debitoren"
|
|
:outlined="typeFilter !== 'debtor'"
|
|
@click="filterByType('debtor')"
|
|
size="small"
|
|
/>
|
|
<Button
|
|
label="Kreditoren"
|
|
:outlined="typeFilter !== 'creditor'"
|
|
@click="filterByType('creditor')"
|
|
size="small"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<Column field="companyName" header="Firma" sortable style="min-width: 200px">
|
|
<template #body="{ data }">
|
|
<div class="font-semibold">{{ data.companyName }}</div>
|
|
<div class="text-sm text-500" v-if="data.companyNumber">
|
|
Nr: {{ data.companyNumber }}
|
|
</div>
|
|
</template>
|
|
</Column>
|
|
|
|
<Column field="city" header="Ort" sortable style="min-width: 150px">
|
|
<template #body="{ data }">
|
|
<div v-if="data.zipCode || data.city">
|
|
{{ data.zipCode }} {{ data.city }}
|
|
</div>
|
|
<div class="text-sm text-500" v-if="data.country">
|
|
{{ data.country }}
|
|
</div>
|
|
</template>
|
|
</Column>
|
|
|
|
<Column header="Ansprechpartner" style="min-width: 200px">
|
|
<template #body="{ data }">
|
|
<div v-if="data.contactPersons && data.contactPersons.length > 0">
|
|
<div
|
|
v-for="person in data.contactPersons.slice(0, 2)"
|
|
:key="person.id"
|
|
class="mb-1"
|
|
>
|
|
<div class="font-medium">
|
|
{{ person.firstName }} {{ person.lastName }}
|
|
<Tag v-if="person.isPrimary" value="Primär" severity="info" class="ml-1" />
|
|
</div>
|
|
<div class="text-sm text-500" v-if="person.email">
|
|
{{ person.email }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<span v-else class="text-500">Keine Ansprechpartner</span>
|
|
</template>
|
|
</Column>
|
|
|
|
<Column header="Typ" style="min-width: 130px">
|
|
<template #body="{ data }">
|
|
<div class="flex gap-1">
|
|
<Tag v-if="data.isDebtor" value="Debitor" severity="success" />
|
|
<Tag v-if="data.isCreditor" value="Kreditor" severity="warning" />
|
|
</div>
|
|
</template>
|
|
</Column>
|
|
|
|
<Column header="Status" style="min-width: 100px">
|
|
<template #body="{ data }">
|
|
<Tag
|
|
:value="data.isActive ? 'Aktiv' : 'Inaktiv'"
|
|
:severity="data.isActive ? 'success' : 'danger'"
|
|
/>
|
|
</template>
|
|
</Column>
|
|
|
|
<Column header="Kontakt" style="min-width: 200px">
|
|
<template #body="{ data }">
|
|
<div class="flex flex-column gap-1">
|
|
<div v-if="data.phone" class="text-sm">
|
|
<i class="pi pi-phone mr-1"></i> {{ data.phone }}
|
|
</div>
|
|
<div v-if="data.email" class="text-sm">
|
|
<i class="pi pi-envelope mr-1"></i> {{ data.email }}
|
|
</div>
|
|
<div v-if="data.website" class="text-sm">
|
|
<i class="pi pi-globe mr-1"></i>
|
|
<a :href="data.website" target="_blank">{{ data.website }}</a>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</Column>
|
|
|
|
<Column :exportable="false" style="min-width: 120px">
|
|
<template #body="{ data }">
|
|
<div class="flex gap-2">
|
|
<Button
|
|
icon="pi pi-pencil"
|
|
outlined
|
|
rounded
|
|
@click="editContact(data)"
|
|
size="small"
|
|
/>
|
|
<Button
|
|
icon="pi pi-trash"
|
|
outlined
|
|
rounded
|
|
severity="danger"
|
|
@click="confirmDelete(data)"
|
|
size="small"
|
|
/>
|
|
</div>
|
|
</template>
|
|
</Column>
|
|
|
|
<template #empty>Keine Kontakte gefunden.</template>
|
|
</DataTable>
|
|
</template>
|
|
</Card>
|
|
|
|
<!-- Contact Dialog -->
|
|
<Dialog
|
|
v-model:visible="contactDialog"
|
|
:header="editingContact?.id ? 'Kontakt bearbeiten' : 'Neuer Kontakt'"
|
|
:modal="true"
|
|
:style="{ width: '1000px' }"
|
|
:closable="true"
|
|
class="contact-dialog"
|
|
>
|
|
<div v-if="editingContact">
|
|
<!-- Basisdaten -->
|
|
<Card class="mb-3">
|
|
<template #title>
|
|
<div class="flex align-items-center gap-2">
|
|
<i class="pi pi-building text-primary"></i>
|
|
<span>Basisdaten</span>
|
|
</div>
|
|
</template>
|
|
<template #content>
|
|
<div class="formgrid grid">
|
|
<div class="field col-12 md:col-8">
|
|
<label for="companyName" class="block mb-2 font-medium">
|
|
Firmenname <span class="text-red-500">*</span>
|
|
</label>
|
|
<InputText
|
|
id="companyName"
|
|
v-model="editingContact.companyName"
|
|
class="w-full"
|
|
:class="{ 'p-invalid': submitted && !editingContact.companyName }"
|
|
/>
|
|
<small v-if="submitted && !editingContact.companyName" class="p-error">
|
|
Firmenname ist erforderlich
|
|
</small>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-4">
|
|
<label for="companyNumber" class="block mb-2 font-medium">Kundennummer</label>
|
|
<InputText id="companyNumber" v-model="editingContact.companyNumber" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12">
|
|
<div class="flex gap-4">
|
|
<div class="field-checkbox mb-0">
|
|
<Checkbox
|
|
inputId="isDebtor"
|
|
v-model="editingContact.isDebtor"
|
|
:binary="true"
|
|
/>
|
|
<label for="isDebtor" class="ml-2">Debitor</label>
|
|
</div>
|
|
<div class="field-checkbox mb-0">
|
|
<Checkbox
|
|
inputId="isCreditor"
|
|
v-model="editingContact.isCreditor"
|
|
:binary="true"
|
|
/>
|
|
<label for="isCreditor" class="ml-2">Kreditor</label>
|
|
</div>
|
|
<div class="field-checkbox mb-0">
|
|
<Checkbox
|
|
inputId="isActive"
|
|
v-model="editingContact.isActive"
|
|
:binary="true"
|
|
/>
|
|
<label for="isActive" class="ml-2">Aktiv</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</Card>
|
|
|
|
<!-- Adresse -->
|
|
<Card class="mb-3">
|
|
<template #title>
|
|
<div class="flex align-items-center gap-2">
|
|
<i class="pi pi-map-marker text-primary"></i>
|
|
<span>Adresse</span>
|
|
</div>
|
|
</template>
|
|
<template #content>
|
|
<div class="formgrid grid">
|
|
<div class="field col-12">
|
|
<label for="street" class="block mb-2 font-medium">Straße</label>
|
|
<InputText id="street" v-model="editingContact.street" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-3">
|
|
<label for="zipCode" class="block mb-2 font-medium">PLZ</label>
|
|
<InputText id="zipCode" v-model="editingContact.zipCode" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-5">
|
|
<label for="city" class="block mb-2 font-medium">Ort</label>
|
|
<InputText id="city" v-model="editingContact.city" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-4">
|
|
<label for="country" class="block mb-2 font-medium">Land</label>
|
|
<InputText id="country" v-model="editingContact.country" class="w-full" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</Card>
|
|
|
|
<!-- Kontaktdaten -->
|
|
<Card class="mb-3">
|
|
<template #title>
|
|
<div class="flex align-items-center gap-2">
|
|
<i class="pi pi-phone text-primary"></i>
|
|
<span>Kontaktdaten</span>
|
|
</div>
|
|
</template>
|
|
<template #content>
|
|
<div class="formgrid grid">
|
|
<div class="field col-12 md:col-6">
|
|
<label for="phone" class="block mb-2 font-medium">Telefon</label>
|
|
<InputText id="phone" v-model="editingContact.phone" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-6">
|
|
<label for="fax" class="block mb-2 font-medium">Fax</label>
|
|
<InputText id="fax" v-model="editingContact.fax" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-6">
|
|
<label for="email" class="block mb-2 font-medium">E-Mail</label>
|
|
<InputText id="email" v-model="editingContact.email" type="email" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-6">
|
|
<label for="website" class="block mb-2 font-medium">Website</label>
|
|
<InputText id="website" v-model="editingContact.website" class="w-full" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</Card>
|
|
|
|
<!-- Steuerdaten -->
|
|
<Card class="mb-3">
|
|
<template #title>
|
|
<div class="flex align-items-center gap-2">
|
|
<i class="pi pi-calculator text-primary"></i>
|
|
<span>Steuerdaten</span>
|
|
</div>
|
|
</template>
|
|
<template #content>
|
|
<div class="formgrid grid">
|
|
<div class="field col-12 md:col-6">
|
|
<label for="taxNumber" class="block mb-2 font-medium">Steuernummer</label>
|
|
<InputText id="taxNumber" v-model="editingContact.taxNumber" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-6">
|
|
<label for="vatNumber" class="block mb-2 font-medium">USt-IdNr.</label>
|
|
<InputText id="vatNumber" v-model="editingContact.vatNumber" class="w-full" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</Card>
|
|
|
|
<!-- Ansprechpartner -->
|
|
<Card class="mb-3">
|
|
<template #title>
|
|
<div class="flex align-items-center justify-content-between">
|
|
<div class="flex align-items-center gap-2">
|
|
<i class="pi pi-users text-primary"></i>
|
|
<span>Ansprechpartner</span>
|
|
</div>
|
|
<Button
|
|
label="Hinzufügen"
|
|
icon="pi pi-plus"
|
|
size="small"
|
|
outlined
|
|
@click="addContactPerson"
|
|
:disabled="editingContact.contactPersons.length >= 2"
|
|
/>
|
|
</div>
|
|
</template>
|
|
<template #content>
|
|
<div v-if="editingContact.contactPersons.length === 0" class="text-center py-4 text-500">
|
|
<i class="pi pi-user-plus text-4xl mb-3"></i>
|
|
<p>Noch keine Ansprechpartner hinzugefügt</p>
|
|
</div>
|
|
|
|
<div
|
|
v-for="(person, index) in editingContact.contactPersons"
|
|
:key="index"
|
|
class="mb-4"
|
|
>
|
|
<Divider v-if="index > 0" />
|
|
<div class="formgrid grid">
|
|
<div class="field col-12 flex justify-content-between align-items-center mb-3">
|
|
<h4 class="m-0 font-semibold">
|
|
<i class="pi pi-user mr-2"></i>
|
|
Ansprechpartner {{ index + 1 }}
|
|
<Tag v-if="person.isPrimary" value="Primär" severity="info" class="ml-2" />
|
|
</h4>
|
|
<Button
|
|
icon="pi pi-trash"
|
|
text
|
|
rounded
|
|
severity="danger"
|
|
@click="removeContactPerson(index)"
|
|
size="small"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-3">
|
|
<label :for="'salutation-' + index" class="block mb-2 font-medium">
|
|
Anrede
|
|
</label>
|
|
<Dropdown
|
|
:id="'salutation-' + index"
|
|
v-model="person.salutation"
|
|
:options="salutations"
|
|
placeholder="Wählen..."
|
|
class="w-full"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-3">
|
|
<label :for="'title-' + index" class="block mb-2 font-medium">Titel</label>
|
|
<InputText :id="'title-' + index" v-model="person.title" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-3">
|
|
<label :for="'firstName-' + index" class="block mb-2 font-medium">
|
|
Vorname <span class="text-red-500">*</span>
|
|
</label>
|
|
<InputText
|
|
:id="'firstName-' + index"
|
|
v-model="person.firstName"
|
|
class="w-full"
|
|
:class="{ 'p-invalid': submitted && !person.firstName }"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-3">
|
|
<label :for="'lastName-' + index" class="block mb-2 font-medium">
|
|
Nachname <span class="text-red-500">*</span>
|
|
</label>
|
|
<InputText
|
|
:id="'lastName-' + index"
|
|
v-model="person.lastName"
|
|
class="w-full"
|
|
:class="{ 'p-invalid': submitted && !person.lastName }"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-6">
|
|
<label :for="'position-' + index" class="block mb-2 font-medium">
|
|
Position
|
|
</label>
|
|
<InputText :id="'position-' + index" v-model="person.position" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-6">
|
|
<label :for="'department-' + index" class="block mb-2 font-medium">
|
|
Abteilung
|
|
</label>
|
|
<InputText
|
|
:id="'department-' + index"
|
|
v-model="person.department"
|
|
class="w-full"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-4">
|
|
<label :for="'personPhone-' + index" class="block mb-2 font-medium">
|
|
Telefon
|
|
</label>
|
|
<InputText
|
|
:id="'personPhone-' + index"
|
|
v-model="person.phone"
|
|
class="w-full"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-4">
|
|
<label :for="'mobile-' + index" class="block mb-2 font-medium">Mobil</label>
|
|
<InputText :id="'mobile-' + index" v-model="person.mobile" class="w-full" />
|
|
</div>
|
|
|
|
<div class="field col-12 md:col-4">
|
|
<label :for="'personEmail-' + index" class="block mb-2 font-medium">
|
|
E-Mail
|
|
</label>
|
|
<InputText
|
|
:id="'personEmail-' + index"
|
|
v-model="person.email"
|
|
type="email"
|
|
class="w-full"
|
|
/>
|
|
</div>
|
|
|
|
<div class="field col-12">
|
|
<div class="field-checkbox mb-0">
|
|
<Checkbox
|
|
:inputId="'isPrimary-' + index"
|
|
v-model="person.isPrimary"
|
|
:binary="true"
|
|
/>
|
|
<label :for="'isPrimary-' + index" class="ml-2">
|
|
Hauptansprechpartner
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</Card>
|
|
|
|
<!-- Notizen -->
|
|
<Card>
|
|
<template #title>
|
|
<div class="flex align-items-center gap-2">
|
|
<i class="pi pi-comment text-primary"></i>
|
|
<span>Notizen</span>
|
|
</div>
|
|
</template>
|
|
<template #content>
|
|
<Textarea
|
|
id="notes"
|
|
v-model="editingContact.notes"
|
|
class="w-full"
|
|
:rows="4"
|
|
placeholder="Interne Notizen zu diesem Kontakt..."
|
|
/>
|
|
</template>
|
|
</Card>
|
|
</div>
|
|
|
|
<template #footer>
|
|
<Button label="Abbrechen" outlined @click="hideDialog" />
|
|
<Button label="Speichern" @click="saveContact" :loading="saving" />
|
|
</template>
|
|
</Dialog>
|
|
|
|
<!-- Delete Confirmation -->
|
|
<Dialog
|
|
v-model:visible="deleteDialog"
|
|
header="Bestätigung"
|
|
:modal="true"
|
|
:style="{ width: '450px' }"
|
|
>
|
|
<div class="flex align-items-center">
|
|
<i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem; color: var(--red-500)"></i>
|
|
<span v-if="editingContact">
|
|
Möchten Sie den Kontakt <b>{{ editingContact.companyName }}</b> wirklich löschen?
|
|
</span>
|
|
</div>
|
|
<template #footer>
|
|
<Button label="Nein" outlined @click="deleteDialog = false" />
|
|
<Button label="Ja" severity="danger" @click="deleteContact" :loading="deleting" />
|
|
</template>
|
|
</Dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, onMounted } from 'vue'
|
|
import { useToast } from 'primevue/usetoast'
|
|
import DataTable from 'primevue/datatable'
|
|
import Column from 'primevue/column'
|
|
import Button from 'primevue/button'
|
|
import InputText from 'primevue/inputtext'
|
|
import Textarea from 'primevue/textarea'
|
|
import Dialog from 'primevue/dialog'
|
|
import Card from 'primevue/card'
|
|
import Tag from 'primevue/tag'
|
|
import Checkbox from 'primevue/checkbox'
|
|
import Dropdown from 'primevue/dropdown'
|
|
import Divider from 'primevue/divider'
|
|
import IconField from 'primevue/iconfield'
|
|
import InputIcon from 'primevue/inputicon'
|
|
|
|
const toast = useToast()
|
|
|
|
const contacts = ref([])
|
|
const loading = ref(false)
|
|
const contactDialog = ref(false)
|
|
const deleteDialog = ref(false)
|
|
const editingContact = ref(null)
|
|
const submitted = ref(false)
|
|
const saving = ref(false)
|
|
const deleting = ref(false)
|
|
const typeFilter = ref('all')
|
|
const globalFilter = ref('')
|
|
|
|
const salutations = ref(['Herr', 'Frau', 'Divers'])
|
|
|
|
const emptyContact = () => ({
|
|
companyName: '',
|
|
companyNumber: '',
|
|
street: '',
|
|
zipCode: '',
|
|
city: '',
|
|
country: 'Deutschland',
|
|
phone: '',
|
|
fax: '',
|
|
email: '',
|
|
website: '',
|
|
taxNumber: '',
|
|
vatNumber: '',
|
|
isDebtor: false,
|
|
isCreditor: false,
|
|
isActive: true,
|
|
notes: '',
|
|
contactPersons: []
|
|
})
|
|
|
|
const emptyContactPerson = () => ({
|
|
salutation: null,
|
|
title: '',
|
|
firstName: '',
|
|
lastName: '',
|
|
position: '',
|
|
department: '',
|
|
phone: '',
|
|
mobile: '',
|
|
email: '',
|
|
isPrimary: false
|
|
})
|
|
|
|
onMounted(() => {
|
|
loadContacts()
|
|
})
|
|
|
|
const loadContacts = async () => {
|
|
loading.value = true
|
|
try {
|
|
// API-Filter Parameter aufbauen
|
|
let url = '/api/contacts'
|
|
const params = new URLSearchParams()
|
|
|
|
if (typeFilter.value === 'debtor') {
|
|
params.append('isDebtor', 'true')
|
|
} else if (typeFilter.value === 'creditor') {
|
|
params.append('isCreditor', 'true')
|
|
}
|
|
|
|
if (params.toString()) {
|
|
url += '?' + params.toString()
|
|
}
|
|
|
|
const response = await fetch(url, {
|
|
credentials: 'include'
|
|
})
|
|
if (!response.ok) throw new Error('Fehler beim Laden der Kontakte')
|
|
const data = await response.json()
|
|
|
|
// API Platform gibt member zurück
|
|
contacts.value = data.member || []
|
|
|
|
console.log('Loaded contacts:', contacts.value.length, 'with filter:', typeFilter.value)
|
|
} catch (error) {
|
|
console.error('Error loading contacts:', error)
|
|
toast.add({
|
|
severity: 'error',
|
|
summary: 'Fehler',
|
|
detail: 'Kontakte konnten nicht geladen werden',
|
|
life: 3000
|
|
})
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const filterByType = (type) => {
|
|
typeFilter.value = type
|
|
loadContacts()
|
|
}
|
|
|
|
const openNewContactDialog = () => {
|
|
editingContact.value = emptyContact()
|
|
submitted.value = false
|
|
contactDialog.value = true
|
|
}
|
|
|
|
const editContact = (contact) => {
|
|
editingContact.value = { ...contact }
|
|
// Ensure contactPersons is initialized
|
|
if (!editingContact.value.contactPersons) {
|
|
editingContact.value.contactPersons = []
|
|
}
|
|
submitted.value = false
|
|
contactDialog.value = true
|
|
}
|
|
|
|
const hideDialog = () => {
|
|
contactDialog.value = false
|
|
submitted.value = false
|
|
editingContact.value = null
|
|
}
|
|
|
|
const addContactPerson = () => {
|
|
if (editingContact.value.contactPersons.length < 2) {
|
|
editingContact.value.contactPersons.push(emptyContactPerson())
|
|
}
|
|
}
|
|
|
|
const removeContactPerson = (index) => {
|
|
editingContact.value.contactPersons.splice(index, 1)
|
|
}
|
|
|
|
const validateContact = () => {
|
|
if (!editingContact.value.companyName) {
|
|
return false
|
|
}
|
|
|
|
// Validate contact persons
|
|
for (const person of editingContact.value.contactPersons) {
|
|
if (!person.firstName || !person.lastName) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
const saveContact = async () => {
|
|
submitted.value = true
|
|
|
|
if (!validateContact()) {
|
|
toast.add({
|
|
severity: 'warn',
|
|
summary: 'Validierung fehlgeschlagen',
|
|
detail: 'Bitte füllen Sie alle Pflichtfelder aus',
|
|
life: 3000
|
|
})
|
|
return
|
|
}
|
|
|
|
saving.value = true
|
|
try {
|
|
const url = editingContact.value.id
|
|
? `/api/contacts/${editingContact.value.id}`
|
|
: '/api/contacts'
|
|
|
|
const method = editingContact.value.id ? 'PUT' : 'POST'
|
|
|
|
const response = await fetch(url, {
|
|
method,
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
credentials: 'include',
|
|
body: JSON.stringify(editingContact.value)
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json()
|
|
throw new Error(error.message || 'Fehler beim Speichern')
|
|
}
|
|
|
|
toast.add({
|
|
severity: 'success',
|
|
summary: 'Erfolg',
|
|
detail: 'Kontakt wurde gespeichert',
|
|
life: 3000
|
|
})
|
|
|
|
hideDialog()
|
|
loadContacts()
|
|
} catch (error) {
|
|
console.error('Error saving contact:', error)
|
|
toast.add({
|
|
severity: 'error',
|
|
summary: 'Fehler',
|
|
detail: error.message || 'Kontakt konnte nicht gespeichert werden',
|
|
life: 3000
|
|
})
|
|
} finally {
|
|
saving.value = false
|
|
}
|
|
}
|
|
|
|
const confirmDelete = (contact) => {
|
|
editingContact.value = contact
|
|
deleteDialog.value = true
|
|
}
|
|
|
|
const deleteContact = async () => {
|
|
deleting.value = true
|
|
try {
|
|
const response = await fetch(`/api/contacts/${editingContact.value.id}`, {
|
|
method: 'DELETE',
|
|
credentials: 'include'
|
|
})
|
|
|
|
if (!response.ok) throw new Error('Fehler beim Löschen')
|
|
|
|
toast.add({
|
|
severity: 'success',
|
|
summary: 'Erfolg',
|
|
detail: 'Kontakt wurde gelöscht',
|
|
life: 3000
|
|
})
|
|
|
|
deleteDialog.value = false
|
|
editingContact.value = null
|
|
loadContacts()
|
|
} catch (error) {
|
|
console.error('Error deleting contact:', error)
|
|
toast.add({
|
|
severity: 'error',
|
|
summary: 'Fehler',
|
|
detail: 'Kontakt konnte nicht gelöscht werden',
|
|
life: 3000
|
|
})
|
|
} finally {
|
|
deleting.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.contact-management {
|
|
padding: 1rem;
|
|
}
|
|
|
|
.p-invalid {
|
|
border-color: var(--red-500);
|
|
}
|
|
|
|
.p-error {
|
|
color: var(--red-500);
|
|
font-size: 0.875rem;
|
|
}
|
|
</style>
|