78 lines
2.7 KiB
Vue
78 lines
2.7 KiB
Vue
<script setup lang="ts">
|
|
import { Link, router } from '@inertiajs/vue3';
|
|
import { Pencil, Trash2 } from '@lucide/vue';
|
|
import { computed, ref } from 'vue';
|
|
import { toast } from 'vue-sonner';
|
|
import ConfirmDialog from '@/components/ConfirmDialog.vue';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
|
import { useCan } from '@/composables/useCan';
|
|
import type { RoleListItem } from './columns';
|
|
import { edit, destroy } from '@/routes/admin/system/roles';
|
|
|
|
const props = defineProps<{
|
|
role: RoleListItem;
|
|
}>();
|
|
|
|
const { can } = useCan();
|
|
|
|
const deleteConfirmOpen = ref(false);
|
|
const deleteProcessing = ref(false);
|
|
|
|
const isSystemRole = computed(() => {
|
|
return ['developer', 'owner', 'admin-toko', 'admin-bahan-baku', 'direktur', 'marketing', 'cashier', 'non-operator'].includes(props.role.name);
|
|
});
|
|
|
|
function destroyRole() {
|
|
deleteProcessing.value = true;
|
|
|
|
router.delete(destroy.url(props.role.id), {
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
deleteConfirmOpen.value = false;
|
|
},
|
|
onError: () => {
|
|
toast.error('Gagal menghapus role.');
|
|
},
|
|
onFinish: () => {
|
|
deleteProcessing.value = false;
|
|
},
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex items-center justify-end gap-1">
|
|
<Tooltip v-if="can('roles.update')">
|
|
<TooltipTrigger as-child>
|
|
<Button variant="ghost" size="icon" class="size-8" as-child>
|
|
<Link :href="edit.url(props.role.id)">
|
|
<Pencil class="size-4" />
|
|
<span class="sr-only">Ubah</span>
|
|
</Link>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>Ubah</TooltipContent>
|
|
</Tooltip>
|
|
|
|
<Tooltip v-if="can('roles.delete')">
|
|
<TooltipTrigger as-child>
|
|
<span>
|
|
<Button variant="ghost" size="icon" class="text-destructive hover:text-destructive size-8"
|
|
@click="deleteConfirmOpen = true">
|
|
<Trash2 class="size-4" />
|
|
<span class="sr-only">Hapus</span>
|
|
</Button>
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
Hapus
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
|
|
<ConfirmDialog v-if="can('roles.delete') && !isSystemRole" v-model:open="deleteConfirmOpen" title="Hapus role?"
|
|
:description="`Role ${role.name} akan dihapus secara permanen. Tindakan ini tidak dapat dibatalkan.`"
|
|
confirm-label="Hapus" cancel-label="Batal" destructive :loading="deleteProcessing" @confirm="destroyRole" />
|
|
</template>
|