81 lines
2.6 KiB
Vue
81 lines
2.6 KiB
Vue
<script setup lang="ts">
|
|
import { Link, router } from '@inertiajs/vue3';
|
|
import { Pencil, Trash2 } from '@lucide/vue';
|
|
import { 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 { PurchaseListItem } from '@/types/purchase';
|
|
|
|
const props = defineProps<{
|
|
purchase: PurchaseListItem;
|
|
}>();
|
|
|
|
const { can } = useCan();
|
|
|
|
const deleteConfirmOpen = ref(false);
|
|
const deleteProcessing = ref(false);
|
|
|
|
function destroyPurchase() {
|
|
deleteProcessing.value = true;
|
|
|
|
router.delete(`/admin/manage/purchases/${props.purchase.id}`, {
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
deleteConfirmOpen.value = false;
|
|
},
|
|
onError: () => {
|
|
toast.error('Gagal menghapus belanja.');
|
|
},
|
|
onFinish: () => {
|
|
deleteProcessing.value = false;
|
|
},
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex items-center justify-end gap-1">
|
|
<Tooltip v-if="can('purchases.update')">
|
|
<TooltipTrigger as-child>
|
|
<Button variant="ghost" size="icon" class="size-8" as-child>
|
|
<Link :href="`/admin/manage/purchases/${purchase.id}/edit`">
|
|
<Pencil class="size-4" />
|
|
<span class="sr-only">Ubah</span>
|
|
</Link>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>Ubah</TooltipContent>
|
|
</Tooltip>
|
|
|
|
<Tooltip v-if="can('purchases.delete')">
|
|
<TooltipTrigger as-child>
|
|
<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>
|
|
</TooltipTrigger>
|
|
<TooltipContent>Hapus</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
|
|
<ConfirmDialog
|
|
v-if="can('purchases.delete')"
|
|
v-model:open="deleteConfirmOpen"
|
|
title="Hapus belanja?"
|
|
:description="`Belanja ${purchase.total_formatted} dari ${purchase.supplier_name} akan dihapus. Stok bahan baku akan dikurangi.`"
|
|
confirm-label="Hapus"
|
|
cancel-label="Batal"
|
|
destructive
|
|
:loading="deleteProcessing"
|
|
@confirm="destroyPurchase"
|
|
/>
|
|
</template>
|