frontend: Workload pages
This commit is contained in:
parent
c24a5ce480
commit
9eb9be7318
8 changed files with 372 additions and 21 deletions
|
|
@ -4,6 +4,7 @@ definePageMeta({
|
|||
requiresAuth: true
|
||||
})
|
||||
|
||||
import { isUnauthorized } from "~/utils/auth"
|
||||
import { ref, onMounted } from "vue"
|
||||
|
||||
const { loadToken } = useAuth()
|
||||
|
|
@ -17,7 +18,12 @@ const error = ref("")
|
|||
async function loadOwners() {
|
||||
loading.value = true
|
||||
try {
|
||||
owners.value = await apiFetch("/owners")
|
||||
const result = await apiFetch("/owners")
|
||||
if (isUnauthorized(result)) {
|
||||
return result
|
||||
}
|
||||
owners.value = result
|
||||
return result
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
|
|
@ -29,23 +35,27 @@ async function createOwner() {
|
|||
if (!newOwnerName.value.trim()) return
|
||||
|
||||
try {
|
||||
const owner = await apiFetch("/owners", {
|
||||
const result = await apiFetch("/owners", {
|
||||
method: "POST",
|
||||
body: {
|
||||
name: newOwnerName.value
|
||||
}
|
||||
})
|
||||
if (isUnauthorized(result)) {
|
||||
return result
|
||||
}
|
||||
|
||||
owners.value.push(owner)
|
||||
owners.value.push(result)
|
||||
newOwnerName.value = ""
|
||||
return result
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted( async () => {
|
||||
loadToken()
|
||||
loadOwners()
|
||||
if (isUnauthorized(await loadOwners())) return
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue