Restructured Create Process Into Store
This commit is contained in:
36
spaces/pages/vendors/[mode]/[[id]].vue
vendored
36
spaces/pages/vendors/[mode]/[[id]].vue
vendored
@@ -13,7 +13,7 @@ const toast = useToast()
|
||||
const id = ref(route.params.id ? route.params.id : null )
|
||||
const numberRange = useNumberRange("vendors")
|
||||
|
||||
let currentItem = null
|
||||
let currentItem = ref(null)
|
||||
|
||||
|
||||
|
||||
@@ -25,35 +25,11 @@ const itemInfo = ref({
|
||||
|
||||
//Functions
|
||||
const setupPage = () => {
|
||||
if(mode.value === "show" || mode.value === "edit"){
|
||||
currentItem = dataStore.getVendorById(Number(useRoute().params.id))
|
||||
if (mode.value === "show" || mode.value === "edit") {
|
||||
currentItem.value = dataStore.getVendorById(Number(useRoute().params.id))
|
||||
}
|
||||
|
||||
if(mode.value === "edit") itemInfo.value = currentItem
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
|
||||
if(!itemInfo.value.vendorNumber) itemInfo.value.vendorNumber = await numberRange.useNextNumber()
|
||||
|
||||
const {data,error} = await supabase
|
||||
.from("vendors")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {}
|
||||
toast.add({title: "Lieferant erfolgreich erstellt"})
|
||||
await dataStore.fetchVendors()
|
||||
router.push(`/vendors/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
if (mode.value === "edit") itemInfo.value = currentItem.value
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
@@ -75,7 +51,7 @@ const updateItem = async () => {
|
||||
console.log(error)
|
||||
} else {
|
||||
toast.add({title: "Lieferant erfolgreich gespeichert"})
|
||||
router.push(`/vendors/show/${currentItem.id}`)
|
||||
router.push(`/vendors/show/${currentItem.value.id}`)
|
||||
dataStore.fetchVendors()
|
||||
}
|
||||
|
||||
@@ -226,7 +202,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('vendors',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
Reference in New Issue
Block a user