Restructured Create Process Into Store

This commit is contained in:
2024-01-15 19:50:26 +01:00
parent f6c1f4219b
commit 9f5a142680
12 changed files with 126 additions and 233 deletions

View File

@@ -19,7 +19,7 @@ let currentCustomer = ref(null)
//Working
const mode = ref(route.params.mode || "show")
const customerInfo = ref({
const itemInfo = ref({
name: "",
infoData: {},
active: true
@@ -31,37 +31,11 @@ const setupPage = async () => {
currentCustomer.value = await dataStore.getCustomerById(Number(useRoute().params.id))
}
if(mode.value === "edit") customerInfo.value = currentCustomer.value
if(mode.value === "edit") itemInfo.value = currentCustomer.value
}
const createCustomer = async () => {
if(!customerInfo.value.customerNumber) customerInfo.value.customerNumber = await numberRange.useNextNumber()
const {data,error} = await supabase
.from("customers")
.insert([customerInfo.value])
.select()
if(error) {
console.log(error)
} else {
mode.value = "show"
customerInfo.value = {
id: 0,
name: "",
infoData: {}
}
toast.add({title: "Kunde erfolgreich erstellt"})
await dataStore.fetchCustomers()
router.push(`/customers/show/${data[0].id}`)
setupPage()
}
}
const editCustomer = async () => {
router.push(`/customers/edit/${currentCustomer.value.id}`)
setupPage()
@@ -69,7 +43,7 @@ const editCustomer = async () => {
const cancelEditorCreate = () => {
mode.value = "show"
customerInfo.value = {
itemInfo.value = {
id: 0,
name: "",
infoData: {}
@@ -79,8 +53,8 @@ const cancelEditorCreate = () => {
const updateCustomer = async () => {
const {error} = await supabase
.from("customers")
.update(customerInfo.value)
.eq('id',customerInfo.value.id)
.update(itemInfo.value)
.eq('id',itemInfo.value.id)
if(error) {
console.log(error)
@@ -188,14 +162,14 @@ setupPage()
</UCard>
<UCard v-else-if="mode == 'edit' || mode == 'create'" >
<template #header v-if="mode === 'edit'">
<UBadge>{{customerInfo.customerNumber}}</UBadge>{{customerInfo.name}}
<UBadge>{{itemInfo.customerNumber}}</UBadge>{{itemInfo.name}}
</template>
<UFormGroup
label="Name:"
>
<UInput
v-model="customerInfo.name"
v-model="itemInfo.name"
/>
</UFormGroup>
@@ -203,7 +177,7 @@ setupPage()
label="Kundennummer:"
>
<UInput
v-model="customerInfo.customerNumber"
v-model="itemInfo.customerNumber"
placeholder="Leer lassen für automatisch generierte Nummer"
/>
</UFormGroup>
@@ -213,7 +187,7 @@ setupPage()
label="Kunde aktiv:"
>
<UCheckbox
v-model="customerInfo.active"
v-model="itemInfo.active"
/>
</UFormGroup>
</UTooltip>
@@ -221,7 +195,7 @@ setupPage()
label="Notizen:"
>
<UTextarea
v-model="customerInfo.notes"
v-model="itemInfo.notes"
/>
</UFormGroup>
@@ -229,21 +203,21 @@ setupPage()
label="Straße + Hausnummer"
>
<UInput
v-model="customerInfo.infoData.street"
v-model="itemInfo.infoData.street"
/>
</UFormGroup>
<UFormGroup
label="Postleitzahl"
>
<UInput
v-model="customerInfo.infoData.zip"
v-model="itemInfo.infoData.zip"
/>
</UFormGroup>
<UFormGroup
label="Ort"
>
<UInput
v-model="customerInfo.infoData.city"
v-model="itemInfo.infoData.city"
/>
</UFormGroup>
@@ -251,28 +225,28 @@ setupPage()
label="Telefon:"
>
<UInput
v-model="customerInfo.infoData.tel"
v-model="itemInfo.infoData.tel"
/>
</UFormGroup>
<UFormGroup
label="E-Mail:"
>
<UInput
v-model="customerInfo.infoData.email"
v-model="itemInfo.infoData.email"
/>
</UFormGroup>
<UFormGroup
label="Webseite:"
>
<UInput
v-model="customerInfo.infoData.web"
v-model="itemInfo.infoData.web"
/>
</UFormGroup>
<UFormGroup
label="USt-Id:"
>
<UInput
v-model="customerInfo.infoData.ustid"
v-model="itemInfo.infoData.ustid"
/>
</UFormGroup>
@@ -285,7 +259,7 @@ setupPage()
</UButton>
<UButton
v-else-if="mode == 'create'"
@click="createCustomer"
@click="dataStore.createNewItem('customers',itemInfo)"
>
Erstellen
</UButton>