75 lines
2.2 KiB
Vue
75 lines
2.2 KiB
Vue
<template>
|
|
<div class="w-full md:max-w-md">
|
|
<div class="flex flex-col items-center">
|
|
<p class="text-xl font-medium">Rolle {{ role?.role }} löschen?</p>
|
|
</div>
|
|
<br />
|
|
|
|
<div class="flex flex-row gap-2">
|
|
<button primary :disabled="status == 'loading' || status?.status == 'success'" @click="triggerDeleteRole">
|
|
unwiederuflich löschen
|
|
</button>
|
|
<Spinner v-if="status == 'loading'" class="my-auto" />
|
|
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
|
<FailureXMark v-else-if="status?.status == 'failed'" />
|
|
</div>
|
|
|
|
<div class="flex flex-row justify-end">
|
|
<div class="flex flex-row gap-4 py-2">
|
|
<button primary-outline @click="closeModal" :disabled="status == 'loading' || status?.status == 'success'">
|
|
abbrechen
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { defineComponent } from "vue";
|
|
import { mapState, mapActions } from "pinia";
|
|
import { useModalStore } from "@/stores/modal";
|
|
import Spinner from "@/components/Spinner.vue";
|
|
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
|
import FailureXMark from "@/components/FailureXMark.vue";
|
|
import { useRoleStore } from "@/stores/admin/management/role";
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
export default defineComponent({
|
|
data() {
|
|
return {
|
|
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
|
timeout: undefined as any,
|
|
};
|
|
},
|
|
beforeUnmount() {
|
|
try {
|
|
clearTimeout(this.timeout);
|
|
} catch (error) {}
|
|
},
|
|
computed: {
|
|
...mapState(useModalStore, ["data"]),
|
|
...mapState(useRoleStore, ["roles"]),
|
|
role() {
|
|
return this.roles.find((r) => r.id == this.data);
|
|
},
|
|
},
|
|
methods: {
|
|
...mapActions(useModalStore, ["closeModal"]),
|
|
...mapActions(useRoleStore, ["deleteRole"]),
|
|
triggerDeleteRole() {
|
|
this.status = "loading";
|
|
this.deleteRole(this.data)
|
|
.then(() => {
|
|
this.status = { status: "success" };
|
|
this.timeout = setTimeout(() => {
|
|
this.closeModal();
|
|
}, 1500);
|
|
})
|
|
.catch(() => {
|
|
this.status = { status: "failed" };
|
|
});
|
|
},
|
|
},
|
|
});
|
|
</script>
|