feature/mercancias-permisos
This commit is contained in:
@@ -18,7 +18,16 @@ function formatCurrency(amount: number | null, currency: string | null): string
|
||||
}).format(amount);
|
||||
}
|
||||
|
||||
export function createColumns(onSuccess?: () => void): ColumnDef<Part>[] {
|
||||
export type GoodsPartsColumnOptions = {
|
||||
canEdit?: boolean;
|
||||
canDelete?: boolean;
|
||||
};
|
||||
|
||||
export function createColumns(
|
||||
onSuccess?: () => void,
|
||||
options: GoodsPartsColumnOptions = {}
|
||||
): ColumnDef<Part>[] {
|
||||
const { canEdit = false, canDelete = false } = options;
|
||||
return [
|
||||
{
|
||||
id: "select",
|
||||
@@ -301,10 +310,13 @@ export function createColumns(onSuccess?: () => void): ColumnDef<Part>[] {
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => {
|
||||
return renderComponent(DataTableActions, { item: row.original, onSuccess });
|
||||
return renderComponent(DataTableActions, {
|
||||
item: row.original,
|
||||
onSuccess,
|
||||
canEdit,
|
||||
canDelete
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
export const columns = createColumns();
|
||||
}
|
||||
@@ -9,16 +9,21 @@
|
||||
|
||||
let {
|
||||
item,
|
||||
onSuccess
|
||||
onSuccess,
|
||||
canEdit = false,
|
||||
canDelete = false
|
||||
}: {
|
||||
item: Part; // Cambiado a Part
|
||||
onSuccess?: () => void;
|
||||
canEdit?: boolean;
|
||||
canDelete?: boolean;
|
||||
} = $props();
|
||||
|
||||
let loading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
async function handleDelete() {
|
||||
if (!canDelete) return;
|
||||
// 2. Ajustamos el mensaje de confirmación para que muestre el No. Parte
|
||||
if (!confirm(`¿Estás seguro de eliminar la parte "${item.part_number}"?`)) {
|
||||
return;
|
||||
@@ -64,11 +69,13 @@
|
||||
}
|
||||
|
||||
function handleEdit() {
|
||||
if (!canEdit) return;
|
||||
// Redirigimos a la página de edición usando el ID
|
||||
goto(`/dashboard/goods/parts/edit/${item.id}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if canEdit || canDelete}
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger>
|
||||
{#snippet child({ props })}
|
||||
@@ -81,14 +88,14 @@
|
||||
<DropdownMenu.Content align="end" class="w-[160px]">
|
||||
<DropdownMenu.Label>Acciones</DropdownMenu.Label>
|
||||
<DropdownMenu.Separator />
|
||||
|
||||
{#if canEdit}
|
||||
<DropdownMenu.Item onSelect={handleEdit}>
|
||||
<Pencil size={16} class="mr-2" />
|
||||
<span>Editar</span>
|
||||
</DropdownMenu.Item>
|
||||
|
||||
<DropdownMenu.Separator />
|
||||
|
||||
{/if}
|
||||
{#if canDelete}
|
||||
{#if canEdit}<DropdownMenu.Separator />{/if}
|
||||
<DropdownMenu.Item onclick={handleDelete} class="text-destructive" disabled={loading}>
|
||||
{#if loading}
|
||||
<LoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
||||
@@ -97,5 +104,7 @@
|
||||
{/if}
|
||||
Eliminar
|
||||
</DropdownMenu.Item>
|
||||
{/if}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Root>
|
||||
</DropdownMenu.Root>
|
||||
{/if}
|
||||
@@ -367,10 +367,12 @@ export function getSidebarData(): SidebarData {
|
||||
{
|
||||
title: m["sidebar.goods.classes"](),
|
||||
url: "/dashboard/goods/fixed-asset-classes",
|
||||
permission: 'goods_classes.view',
|
||||
},
|
||||
{
|
||||
title: m["sidebar.goods.parts"](),
|
||||
url: "/dashboard/goods/parts",
|
||||
permission: 'goods_parts.view',
|
||||
},
|
||||
{
|
||||
title: m["sidebar.goods.fda_codes"](),
|
||||
|
||||
Reference in New Issue
Block a user