ff-admin/src/components/admin/user/role/DeleteRoleModal.vue

73 lines
2.1 KiB
Vue
Raw Normal View History

2024-09-02 15:57:03 +02:00
<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">
2024-09-15 13:52:54 +02:00
<button primary :disabled="status == 'loading' || status?.status == 'success'" @click="triggerDeleteRole">
2024-09-02 15:57:03 +02:00
unwiederuflich löschen
</button>
2024-09-15 13:52:54 +02:00
<Spinner v-if="status == 'loading'" class="my-auto" />
<SuccessCheckmark v-else-if="status?.status == 'success'" />
<FailureXMark v-else-if="status?.status == 'failed'" />
2024-09-02 15:57:03 +02:00
</div>
<div class="flex flex-row justify-end">
<div class="flex flex-row gap-4 py-2">
2024-09-15 13:52:54 +02:00
<button primary-outline @click="closeModal" :disabled="status != null">abbrechen</button>
2024-09-02 15:57:03 +02:00
</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/role";
</script>
<script lang="ts">
export default defineComponent({
2024-09-09 13:13:45 +02:00
data() {
return {
2024-09-15 13:52:54 +02:00
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
2024-09-09 13:13:45 +02:00
timeout: undefined as any,
};
},
beforeUnmount() {
try {
clearTimeout(this.timeout);
} catch (error) {}
},
2024-09-02 15:57:03 +02:00
computed: {
...mapState(useModalStore, ["data"]),
2024-09-15 13:52:54 +02:00
...mapState(useRoleStore, ["roles"]),
2024-09-02 15:57:03 +02:00
role() {
return this.roles.find((r) => r.id == this.data);
},
},
methods: {
...mapActions(useModalStore, ["closeModal"]),
2024-09-15 13:52:54 +02:00
...mapActions(useRoleStore, ["deleteRole"]),
2024-09-02 15:57:03 +02:00
triggerDeleteRole() {
2024-09-15 13:52:54 +02:00
this.deleteRole(this.data)
.then(() => {
this.status = { status: "success" };
this.timeout = setTimeout(() => {
this.closeModal();
}, 1500);
})
.catch(() => {
this.status = { status: "failed" };
});
2024-09-02 15:57:03 +02:00
},
},
});
</script>