97 lines
2.1 KiB
Vue
97 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted } from "vue"
|
|
|
|
const { loadToken } = useAuth()
|
|
const { apiFetch } = useApi()
|
|
|
|
const owners = ref([])
|
|
const newOwnerName = ref("")
|
|
const loading = ref(false)
|
|
const error = ref("")
|
|
|
|
async function loadOwners() {
|
|
loading.value = true
|
|
try {
|
|
owners.value = await apiFetch("/owners")
|
|
} catch (e: any) {
|
|
error.value = e.message
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function createOwner() {
|
|
if (!newOwnerName.value.trim()) return
|
|
|
|
try {
|
|
const owner = await apiFetch("/owners", {
|
|
method: "POST",
|
|
body: {
|
|
name: newOwnerName.value
|
|
}
|
|
})
|
|
|
|
owners.value.push(owner)
|
|
newOwnerName.value = ""
|
|
} catch (e: any) {
|
|
error.value = e.message
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadToken()
|
|
loadOwners()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="space-y-6">
|
|
<h1 class="text-3xl font-bold">Owner Verwaltung</h1>
|
|
|
|
<div class="p-4 bg-white shadow rounded space-y-4">
|
|
<h2 class="text-xl font-semibold">Neuen Owner anlegen</h2>
|
|
|
|
<div class="flex gap-4">
|
|
<input
|
|
v-model="newOwnerName"
|
|
type="text"
|
|
placeholder="Owner Name"
|
|
class="border p-2 rounded flex-1"
|
|
/>
|
|
|
|
<button
|
|
@click="createOwner"
|
|
class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
|
|
>
|
|
Speichern
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="p-4 bg-white shadow rounded">
|
|
<h2 class="text-xl font-semibold mb-4">Owner Liste</h2>
|
|
|
|
<div v-if="loading">Lade Owner…</div>
|
|
<div v-if="error" class="text-red-600">{{ error }}</div>
|
|
|
|
<table class="w-full border-collapse">
|
|
<thead>
|
|
<tr class="border-b">
|
|
<th class="text-left p-2">ID</th>
|
|
<th class="text-left p-2">Name</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr
|
|
v-for="owner in owners"
|
|
:key="owner.id"
|
|
class="border-b hover:bg-gray-50"
|
|
>
|
|
<td class="p-2">{{ owner.id }}</td>
|
|
<td class="p-2">{{ owner.name }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</template>
|