🎉 Init
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<div class="space-y-5">
|
||||
<p class="text-sm text-text">{{ payload.message }}</p>
|
||||
<p v-if="error" class="text-sm text-red-500">{{ error }}</p>
|
||||
<div class="flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border border-border px-3 py-2 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
|
||||
@click="usePopup().close()"
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 rounded-md bg-red-500 px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
|
||||
:disabled="loading"
|
||||
@click="confirm"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': loading }">
|
||||
{{ loading ? 'progress_activity' : 'delete' }}
|
||||
</span>
|
||||
{{ payload.confirmLabel ?? 'Löschen' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
export interface ConfirmPayload {
|
||||
message: string
|
||||
confirmLabel?: string
|
||||
onConfirm: () => Promise<void> | void
|
||||
}
|
||||
|
||||
const payload = usePopup().require<ConfirmPayload>().payload!
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function confirm() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
await payload.onConfirm()
|
||||
usePopup().callback()
|
||||
usePopup().close()
|
||||
}
|
||||
catch {
|
||||
error.value = 'Das hat nicht geklappt. Versuch es nochmal.'
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user