- Updated the "Nueva Sección" button in customs_sections, customs_warehouses, incoterms, invoice_types, material_types, payment_methods, pedimento_codes, pedimento_regimens, sectors, states, transport_modes, and transport_types pages to use the Plus icon from Lucide. - Updated the "Actualizar" button in the same pages to use the RefreshCw icon from Lucide. - Added a new edit dialog component for customs brokers with a comprehensive form for editing broker details, including validation and loading states.
104 lines
3.1 KiB
Svelte
104 lines
3.1 KiB
Svelte
<script lang="ts">
|
|
import EllipsisIcon from "@lucide/svelte/icons/ellipsis";
|
|
import { Button } from "$lib/components/ui/button/index.js";
|
|
import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js";
|
|
import type { ClientProvider } from "./columns.js";
|
|
import CreateEditDialog from "./create-edit-dialog.svelte";
|
|
import DetailsDialog from "./details-dialog.svelte";
|
|
import DeleteDialog from "./delete-dialog.svelte";
|
|
import { clientsProvidersApi } from "$lib/api/dashboard/a76/clients-providers";
|
|
import { companyStore } from "$lib/stores/company.svelte";
|
|
|
|
let {
|
|
item,
|
|
onSuccess
|
|
}: {
|
|
item: ClientProvider;
|
|
onSuccess?: () => void;
|
|
} = $props();
|
|
|
|
let showDetailsDialog = $state(false);
|
|
let showEditDialog = $state(false);
|
|
let showDeleteDialog = $state(false);
|
|
let isToggling = $state(false);
|
|
|
|
function handleCopyId() {
|
|
navigator.clipboard.writeText(item.id.toString());
|
|
}
|
|
|
|
function handleCopyRfc() {
|
|
navigator.clipboard.writeText(item.rfc);
|
|
}
|
|
|
|
function handleViewDetails() {
|
|
showDetailsDialog = true;
|
|
}
|
|
|
|
function handleEdit() {
|
|
showEditDialog = true;
|
|
}
|
|
|
|
function handleDelete() {
|
|
showDeleteDialog = true;
|
|
}
|
|
|
|
async function handleToggleStatus() {
|
|
if (isToggling || !companyStore.activeCompany) return;
|
|
|
|
isToggling = true;
|
|
try {
|
|
const response = await clientsProvidersApi.toggleStatus(item.id, companyStore.activeCompany.id);
|
|
|
|
if (response.error) {
|
|
console.error('Error toggling status:', response.error);
|
|
alert(`Error: ${response.error}`);
|
|
} else {
|
|
// Llamar al callback de éxito para recargar datos
|
|
if (onSuccess) {
|
|
onSuccess();
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('Error toggling status:', error);
|
|
alert('Error cambiando el estado');
|
|
} finally {
|
|
isToggling = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<DropdownMenu.Root>
|
|
<DropdownMenu.Trigger>
|
|
{#snippet child({ props })}
|
|
<Button {...props} variant="ghost" size="icon" class="relative size-8 p-0">
|
|
<span class="sr-only">Abrir menú</span>
|
|
<EllipsisIcon class="size-4" />
|
|
</Button>
|
|
{/snippet}
|
|
</DropdownMenu.Trigger>
|
|
<DropdownMenu.Content align="end">
|
|
<DropdownMenu.Group>
|
|
<DropdownMenu.Label>Acciones</DropdownMenu.Label>
|
|
<DropdownMenu.Item onclick={handleCopyId}>
|
|
Copiar ID
|
|
</DropdownMenu.Item>
|
|
<DropdownMenu.Item onclick={handleCopyRfc}>
|
|
Copiar RFC
|
|
</DropdownMenu.Item>
|
|
</DropdownMenu.Group>
|
|
<DropdownMenu.Separator />
|
|
<DropdownMenu.Item onclick={handleViewDetails}>Ver detalles</DropdownMenu.Item>
|
|
<DropdownMenu.Item onclick={handleEdit}>Editar</DropdownMenu.Item>
|
|
<DropdownMenu.Item onclick={handleToggleStatus} disabled={isToggling}>
|
|
{isToggling ? 'Cambiando...' : item.is_active === true ? 'Desactivar' : 'Activar'}
|
|
</DropdownMenu.Item>
|
|
<DropdownMenu.Separator />
|
|
<DropdownMenu.Item class="text-destructive" onclick={handleDelete}>Eliminar</DropdownMenu.Item>
|
|
</DropdownMenu.Content>
|
|
</DropdownMenu.Root>
|
|
|
|
<!-- Dialogs -->
|
|
<DetailsDialog bind:open={showDetailsDialog} {item} />
|
|
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
|
|
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />
|