Restructured Update Process Into Store

This commit is contained in:
2024-01-15 21:54:12 +01:00
parent 9f5a142680
commit 497d768d4e
20 changed files with 176 additions and 918 deletions

View File

@@ -13,7 +13,7 @@ const id = ref(route.params.id ? route.params.id : null )
const numberRange = useNumberRange("customers")
const dataStore = useDataStore()
let currentCustomer = ref(null)
let currentItem = ref(null)
@@ -28,16 +28,16 @@ const itemInfo = ref({
//Functions
const setupPage = async () => {
if(mode.value === "show" || mode.value === "edit"){
currentCustomer.value = await dataStore.getCustomerById(Number(useRoute().params.id))
currentItem.value = await dataStore.getCustomerById(Number(useRoute().params.id))
}
if(mode.value === "edit") itemInfo.value = currentCustomer.value
if(mode.value === "edit") itemInfo.value = currentItem.value
}
const editCustomer = async () => {
router.push(`/customers/edit/${currentCustomer.value.id}`)
router.push(`/customers/edit/${currentItem.value.id}`)
setupPage()
}
@@ -50,19 +50,7 @@ const cancelEditorCreate = () => {
}
}
const updateCustomer = async () => {
const {error} = await supabase
.from("customers")
.update(itemInfo.value)
.eq('id',itemInfo.value.id)
if(error) {
console.log(error)
}
toast.add({title: "Kunde erfolgreich gespeichert"})
router.push(`/customers/show/${currentCustomer.id}`)
dataStore.fetchCustomers()
}
@@ -70,10 +58,10 @@ setupPage()
</script>
<template>
<UCard v-if="currentCustomer && mode == 'show'" >
<UCard v-if="currentItem && mode == 'show'" >
<template #header>
<UBadge
v-if="currentCustomer.active"
v-if="currentItem.active"
>
Kunde aktiv
</UBadge>
@@ -83,37 +71,37 @@ setupPage()
>
Kunde gesperrt
</UBadge>
{{currentCustomer.name}}
{{currentItem.name}}
</template>
<InputGroup>
<UButton
@click="router.push(`/projects/create?customer=${currentCustomer.id}`)"
@click="router.push(`/projects/create?customer=${currentItem.id}`)"
>
+ Projekt
</UButton>
<UButton
@click="router.push(`/contacts/create?customer=${currentCustomer.id}`)"
@click="router.push(`/contacts/create?customer=${currentItem.id}`)"
>
+ Ansprechpartner
</UButton>
</InputGroup>
Kundennummer: {{currentCustomer.customerNumber}} <br>
Kundennummer: {{currentItem.customerNumber}} <br>
<UDivider
class="my-2"
/>
Informationen:<br>
<div v-if="currentCustomer.infoData">
<span v-if="currentCustomer.infoData.street">Straße + Hausnummer: {{currentCustomer.infoData.street}}<br></span>
<span v-if="currentCustomer.infoData.zip && currentCustomer.infoData.city">PLZ + Ort: {{currentCustomer.infoData.zip}} {{currentCustomer.infoData.city}}<br></span>
<span v-if="currentCustomer.infoData.tel">Telefon: {{currentCustomer.infoData.tel}}<br></span>
<span v-if="currentCustomer.infoData.email">E-Mail: {{currentCustomer.infoData.email}}<br></span>
<span v-if="currentCustomer.infoData.web">Web: {{currentCustomer.infoData.web}}<br></span>
<span v-if="currentCustomer.infoData.ustid">USt-Id: {{currentCustomer.infoData.ustid}}<br></span>
<div v-if="currentItem.infoData">
<span v-if="currentItem.infoData.street">Straße + Hausnummer: {{currentItem.infoData.street}}<br></span>
<span v-if="currentItem.infoData.zip && currentItem.infoData.city">PLZ + Ort: {{currentItem.infoData.zip}} {{currentItem.infoData.city}}<br></span>
<span v-if="currentItem.infoData.tel">Telefon: {{currentItem.infoData.tel}}<br></span>
<span v-if="currentItem.infoData.email">E-Mail: {{currentItem.infoData.email}}<br></span>
<span v-if="currentItem.infoData.web">Web: {{currentItem.infoData.web}}<br></span>
<span v-if="currentItem.infoData.ustid">USt-Id: {{currentItem.infoData.ustid}}<br></span>
</div>
<UDivider
@@ -121,7 +109,7 @@ setupPage()
/>
Notizen:<br>
{{currentCustomer.notes}}<br>
{{currentItem.notes}}<br>
<UDivider
class="my-2"
@@ -131,7 +119,7 @@ setupPage()
<ul>
<li
v-for="contact in dataStore.getContactsByCustomerId(currentCustomer.id)"
v-for="contact in dataStore.getContactsByCustomerId(currentItem.id)"
>
<router-link :to="'/contacts/show/' + contact.id">{{contact.salutation}} {{contact.fullName}} - {{contact.role}}</router-link>
</li>
@@ -142,7 +130,7 @@ setupPage()
<template #footer>
<UButton
v-if="mode == 'show' && currentCustomer.id"
v-if="mode == 'show' && currentItem.id"
@click="editCustomer"
>
Bearbeiten
@@ -253,7 +241,7 @@ setupPage()
<template #footer>
<UButton
v-if="mode == 'edit'"
@click="updateCustomer"
@click="dataStore.updateItem('customers', itemInfo)"
>
Speichern
</UButton>
@@ -276,8 +264,8 @@ setupPage()
<HistoryDisplay
type="customer"
v-if="currentCustomer"
:element-id="currentCustomer.id"
v-if="currentItem"
:element-id="currentItem.id"
/>
</template>