Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
93 lines
4.1 KiB
Vue
93 lines
4.1 KiB
Vue
<script setup>
|
||
import { ref } from 'vue';
|
||
import { router } from '@inertiajs/vue3';
|
||
import { Copy, KeyRound, LoaderCircle, Plus, Smartphone, Trash2 } from '@lucide/vue';
|
||
import { toast } from 'vue-sonner';
|
||
import { Button } from '@/components/ui/button';
|
||
import { Input } from '@/components/ui/input';
|
||
import Panel from '@/components/Panel.vue';
|
||
import PushToggle from '@/components/PushToggle.vue';
|
||
import { http } from '@/lib/http';
|
||
import { formatRelative } from '@/lib/format';
|
||
|
||
/**
|
||
* „Benachrichtigungen & Apps“: Push auf diesem Gerät und Zugänge für Apps (REST-API).
|
||
*/
|
||
defineProps({
|
||
tokens: { type: Array, default: () => [] },
|
||
});
|
||
|
||
const adding = ref(false);
|
||
const name = ref('');
|
||
const busy = ref(false);
|
||
const created = ref(null);
|
||
|
||
async function create() {
|
||
busy.value = true;
|
||
|
||
try {
|
||
const data = await http.post('/profil/apps', { name: name.value });
|
||
created.value = data.token;
|
||
name.value = '';
|
||
adding.value = false;
|
||
router.reload({ only: ['tokens'] });
|
||
} catch (error) {
|
||
toast.error(error.data?.errors?.name?.[0] ?? error.message);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
async function copy() {
|
||
try {
|
||
await navigator.clipboard.writeText(created.value);
|
||
toast.success('Zugangsschlüssel kopiert');
|
||
} catch {
|
||
toast.error('Kopieren nicht möglich – bitte markieren und kopieren.');
|
||
}
|
||
}
|
||
|
||
function remove(token) {
|
||
if (window.confirm(`Zugang „${token.name}“ entfernen? Die App wird sofort abgemeldet.`)) {
|
||
router.delete(`/profil/apps/${token.id}`, { preserveScroll: true, only: ['tokens'], onSuccess: () => toast.success('Zugang entfernt') });
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<Panel title="Benachrichtigungen & Apps">
|
||
<PushToggle />
|
||
|
||
<div class="mt-5 border-t pt-4">
|
||
<div class="flex items-center justify-between gap-3">
|
||
<h3 class="text-sm font-medium">Apps & Geräte</h3>
|
||
<Button v-if="!adding" size="sm" variant="ghost" @click="(adding = true), (created = null)"><Plus /> Zugang</Button>
|
||
</div>
|
||
<p class="mt-1 text-[13px] text-muted-foreground">Für Apps, die das Portal über die Schnittstelle nutzen. Jeder Zugang lässt sich einzeln entfernen.</p>
|
||
|
||
<form v-if="adding" class="mt-3 flex gap-2" @submit.prevent="create">
|
||
<Input v-model="name" maxlength="100" placeholder="z. B. Diensthandy" aria-label="Name des Geräts" autofocus />
|
||
<Button type="submit" size="sm" class="h-9" :disabled="busy || !name.trim()"><LoaderCircle v-if="busy" class="animate-spin" /> Anlegen</Button>
|
||
</form>
|
||
|
||
<div v-if="created" class="mt-3 rounded-md border border-amber-300 bg-amber-50 p-3 dark:border-amber-800 dark:bg-amber-950/40">
|
||
<p class="flex items-center gap-1.5 text-[13px] font-medium"><KeyRound class="size-4" /> Zugangsschlüssel – wird nur jetzt angezeigt</p>
|
||
<div class="mt-2 flex items-center gap-2">
|
||
<code class="min-w-0 flex-1 truncate rounded bg-card px-2 py-1 text-xs select-all">{{ created }}</code>
|
||
<Button size="icon" variant="outline" class="size-8" aria-label="Kopieren" @click="copy"><Copy /></Button>
|
||
</div>
|
||
</div>
|
||
|
||
<ul v-if="tokens.length" class="mt-3 divide-y rounded-md border">
|
||
<li v-for="token in tokens" :key="token.id" class="flex items-center gap-3 px-3 py-2">
|
||
<Smartphone class="size-4 shrink-0 text-muted-foreground" />
|
||
<div class="min-w-0 flex-1">
|
||
<p class="truncate text-sm">{{ token.name }}</p>
|
||
<p class="text-xs text-muted-foreground">{{ token.last_used_at ? `zuletzt ${formatRelative(token.last_used_at)}` : 'noch nicht benutzt' }}</p>
|
||
</div>
|
||
<Button size="icon" variant="ghost" class="size-8 text-muted-foreground hover:text-destructive" :aria-label="`${token.name} entfernen`" @click="remove(token)"><Trash2 /></Button>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</Panel>
|
||
</template>
|