feature/nav-tab-general-catalog

This commit is contained in:
hreyes
2026-02-05 16:29:18 -06:00
parent 4cc613d1df
commit d3d42bb0fa
96 changed files with 322 additions and 508 deletions

View File

@@ -22,7 +22,6 @@
} from 'lucide-svelte';
import { fly, scale } from 'svelte/transition';
import { cubicOut } from 'svelte/easing';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioTiposCambio } from '$lib/config/shortcuts/dashboard/general_catalogs/exchange_rate/edit';
let {
@@ -40,13 +39,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Tipos de Cambio',
obtenerAtajosFormularioTiposCambio({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const isMissingRateContext = $derived(!isEdit && initialDate);

View File

@@ -8,28 +8,23 @@
let checked = $state(false);
async function checkExchangeRate() {
console.log('[ExchangeRateGuard] Checking...', companyStore.activeCompany);
if (!companyStore.activeCompany?.id) {
console.log('[ExchangeRateGuard] No active company');
return;
}
// Use local date instead of UTC
const today = new Date().toLocaleDateString('fr-CA'); // YYYY-MM-DD
console.log('[ExchangeRateGuard] Date:', today);
try {
const response = await getExchangeRates(companyStore.activeCompany.id, {
date: today,
page_size: 1
});
console.log('[ExchangeRateGuard] Response (stringified):', JSON.stringify(response, null, 2));
// api.get returns { data: ..., status: ... } and types now reflect that
const items = response.data?.items || [];
if (items.length === 0) {
console.log('[ExchangeRateGuard] No rate found, opening modal');
open = true;
}
} catch (error) {
@@ -46,8 +41,6 @@
});
function handleSuccess() {
console.log('Exchange rate created successfully via guard');
checked = true;
}
</script>

View File

@@ -11,7 +11,6 @@
} from '$lib/api/dashboard/a76/general_catalogs/classification-concepts';
// 👇 2. Importamos el Store para el ID de la empresa
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioClasificacion } from '$lib/config/shortcuts/dashboard/general_catalogs/classification/edit';
let {
@@ -25,13 +24,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Clasificación',
obtenerAtajosFormularioClasificacion({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Clasificación' : 'Nueva Clasificación');

View File

@@ -11,7 +11,6 @@
type Concept
} from '$lib/api/dashboard/a76/general_catalogs/concepts';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioConceptos } from '$lib/config/shortcuts/dashboard/general_catalogs/concepts/edit';
let {
@@ -25,13 +24,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Conceptos',
obtenerAtajosFormularioConceptos({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Concepto' : 'Nuevo Concepto');

View File

@@ -9,7 +9,6 @@
type CustomsBrokerConcept,
type CustomsBrokerConceptCreate
} from '$lib/api/dashboard/a76/general_catalogs/customs-broker-concepts';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioConceptosAA } from '$lib/config/shortcuts/dashboard/general_catalogs/customs_broker_concepts/edit';
let {
@@ -25,13 +24,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Conceptos AA',
obtenerAtajosFormularioConceptosAA({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Concepto AA' : 'Nuevo Concepto AA');

View File

@@ -4,7 +4,7 @@
import { deleteCustomsBrokerConcept, type CustomsBrokerConcept } from "$lib/api/dashboard/a76/general_catalogs/customs-broker-concepts";
import { companyStore } from "$lib/stores/company.svelte";
import { EllipsisVertical, Pencil, LoaderCircle, Trash2 } from 'lucide-svelte';
import CreateEditDialog from "./create-edite-dialoge.svelte";
import CreateEditDialog from "./create-edit-dialog.svelte";
let {
item,

View File

@@ -9,7 +9,6 @@
import { companyStore } from '$lib/stores/company.svelte';
import { createDoda, updateDoda, type Doda } from '$lib/api/dashboard/a76/general_catalogs/doda';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioDoda } from '$lib/config/shortcuts/dashboard/general_catalogs/doda/edit';
let {
@@ -65,13 +64,6 @@
let error = $state<string | null>(null);
// Atajos
useShortcuts(
obtenerAtajosFormularioDoda({
cambiarPestana: (pestana) => (activeTab = pestana),
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
// Cargar datos
$effect(() => {

View File

@@ -4,7 +4,6 @@
import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioAvisosElectrónicos } from '$lib/config/shortcuts/dashboard/general_catalogs/electronic_notices/edit';
let {
@@ -18,13 +17,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Avisos Electrónicos',
obtenerAtajosFormularioAvisosElectrónicos({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(

View File

@@ -9,7 +9,6 @@
updateEquivalency,
type Equivalency
} from '$lib/api/dashboard/a76/general_catalogs/equivalencies';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioEquivalencias } from '$lib/config/shortcuts/dashboard/general_catalogs/equivalencies/edit';
let {
@@ -23,13 +22,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Equivalencias',
obtenerAtajosFormularioEquivalencias({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(

View File

@@ -12,7 +12,6 @@
type ErrorClassification
} from '$lib/api/dashboard/a76/general_catalogs/error-catalogs';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioErrores } from '$lib/config/shortcuts/dashboard/general_catalogs/error_catalogs/edit';
let {
@@ -26,13 +25,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Errores',
obtenerAtajosFormularioErrores({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Error' : 'Nuevo Error');

View File

@@ -4,7 +4,6 @@
import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioIdentificadores } from '$lib/config/shortcuts/dashboard/general_catalogs/identifiers/edit';
let {
@@ -18,13 +17,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Identificadores',
obtenerAtajosFormularioIdentificadores({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(

View File

@@ -5,7 +5,6 @@
import { Label } from '$lib/components/ui/label';
import { companyStore } from '$lib/stores/company.svelte';
import { createINPC, updateINPC, type INPC } from '$lib/api/dashboard/a76/general_catalogs/inpc';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioInpc } from '$lib/config/shortcuts/dashboard/general_catalogs/inpc/edit';
let {

View File

@@ -1,165 +0,0 @@
<script lang="ts">
import { Button } from "$lib/components/ui/button";
import * as Dialog from "$lib/components/ui/dialog";
import { Input } from "$lib/components/ui/input";
import { Label } from "$lib/components/ui/label";
import {
createINPC,
updateINPC,
type INPC
} from "$lib/api/dashboard/a76/general_catalogs/inpc";
import { companyStore } from "$lib/stores/company.svelte";
let {
open = $bindable(false),
item = null,
onSuccess
}: {
open: boolean;
item?: INPC | null;
onSuccess?: () => void;
} = $props();
const isEdit = $derived(!!item);
const title = $derived(isEdit ? "Editar INPC" : "Nuevo INPC");
let formData = $state({
year: '',
month: '',
value: null as number | null
});
let loading = $state(false);
let error = $state<string | null>(null);
// Cargar datos al abrir
$effect(() => {
if (open) {
if (item) {
formData = {
year: item.year,
month: item.month,
value: item.value || null
};
} else {
formData = {
year: '',
month: '',
value: null
};
}
error = null;
}
});
async function handleSubmit() {
loading = true;
error = null;
try {
const companyId = companyStore.activeCompany?.id;
if (!companyId) throw new Error('No hay una compañía seleccionada');
// Validaciones
if (!formData.year.trim()) throw new Error('El año es requerido');
if (formData.year.length !== 4) throw new Error('El año debe tener 4 dígitos');
if (!formData.month.trim()) throw new Error('El mes es requerido');
// Preparar datos (limpios)
const dataToSend = {
year: formData.year.trim(),
month: formData.month.trim(),
value: formData.value // Ya es número o null
};
let response;
if (isEdit && item) {
response = await updateINPC(item.id, dataToSend, companyId);
} else {
response = await createINPC(dataToSend, companyId);
}
open = false;
if (onSuccess) onSuccess();
} catch (e) {
error = e instanceof Error ? e.message : 'Error al guardar el INPC';
} finally {
loading = false;
}
}
</script>
<Dialog.Root bind:open>
<Dialog.Content class="sm:max-w-[400px]">
<Dialog.Header>
<Dialog.Title>{title}</Dialog.Title>
</Dialog.Header>
<form onsubmit={(e) => { e.preventDefault(); handleSubmit(); }} class="space-y-4 py-4">
{#if error}
<div class="rounded-md bg-destructive/15 p-3 text-sm text-destructive">
{error}
</div>
{/if}
<div class="grid gap-4">
<div class="grid grid-cols-4 items-center gap-4">
<Label for="year" class="text-right">Año <span class="text-destructive">*</span></Label>
<div class="col-span-3">
<Input
id="year"
bind:value={formData.year}
placeholder="Ej: 2025"
maxlength={4}
disabled={loading}
required
/>
</div>
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label for="month" class="text-right">Mes <span class="text-destructive">*</span></Label>
<div class="col-span-3">
<Input
id="month"
bind:value={formData.month}
placeholder="Ej: 01"
maxlength={2}
disabled={loading}
required
/>
<p class="text-[10px] text-muted-foreground mt-1">Formato MM (Ej: 01, 12)</p>
</div>
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label for="value" class="text-right">Valor</Label>
<div class="col-span-3">
<Input
id="value"
type="number"
step="0.00000001"
bind:value={formData.value}
placeholder="0.0000"
disabled={loading}
/>
<p class="text-[10px] text-muted-foreground mt-1">Hasta 8 decimales</p>
</div>
</div>
</div>
<Dialog.Footer>
<Button type="button" variant="outline" onclick={() => open = false} disabled={loading}>
Cancelar
</Button>
<Button type="submit" disabled={loading}>
{loading ? 'Guardando...' : isEdit ? 'Actualizar' : 'Crear'}
</Button>
</Dialog.Footer>
</form>
</Dialog.Content>
</Dialog.Root>

View File

@@ -10,7 +10,6 @@
type Legend
} from '$lib/api/dashboard/a76/general_catalogs/legends';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioLeyendas } from '$lib/config/shortcuts/dashboard/general_catalogs/legends/edit';
let {
@@ -24,13 +23,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Leyendas',
obtenerAtajosFormularioLeyendas({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Leyenda' : 'Nueva Leyenda');

View File

@@ -4,7 +4,7 @@
import { deleteLegend, type Legend } from "$lib/api/dashboard/a76/general_catalogs/legends";
import { companyStore } from "$lib/stores/company.svelte";
import { EllipsisVertical, Pencil, LoaderCircle, Trash2 } from 'lucide-svelte';
import CreateDialog from '$lib/components/dashboard/general_catalogs/legend/create-edite-dialoge.svelte';
import CreateDialog from './create-edit-dialog.svelte';
let {

View File

@@ -9,7 +9,6 @@
type Location
} from '$lib/api/dashboard/a76/general_catalogs/locations';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioLocalidades } from '$lib/config/shortcuts/dashboard/general_catalogs/locations/edit';
let {
@@ -23,13 +22,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Localidades',
obtenerAtajosFormularioLocalidades({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Ubicación' : 'Nueva Ubicación');

View File

@@ -10,7 +10,6 @@
type MultiCurrencyType
} from '$lib/api/dashboard/a76/general_catalogs/multi-currency-types';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioMonedas } from '$lib/config/shortcuts/dashboard/general_catalogs/multi_currency_types/edit';
let {
@@ -24,13 +23,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Monedas',
obtenerAtajosFormularioMonedas({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(

View File

@@ -9,7 +9,6 @@
updatePrevalidator,
type Prevalidator
} from '$lib/api/dashboard/a76/general_catalogs/prevalidators';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioPrevalidadores } from '$lib/config/shortcuts/dashboard/general_catalogs/prevalidators/edit';
let {
@@ -26,13 +25,6 @@
const title = $derived(isEdit ? `Editar Prevalidador ${item?.code || ''}` : 'Nuevo Prevalidador');
// Atajos
useShortcuts(
'Formulario Prevalidadores',
obtenerAtajosFormularioPrevalidadores({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
// Estado del formulario
let formData = $state({

View File

@@ -11,7 +11,6 @@
type Signature
} from '$lib/api/dashboard/a76/general_catalogs/signatures';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioFirmas } from '$lib/config/shortcuts/dashboard/general_catalogs/signatures/edit';
let {
@@ -25,13 +24,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Firmas',
obtenerAtajosFormularioFirmas({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Firma' : 'Nueva Firma');

View File

@@ -9,7 +9,6 @@
type UnitConversion
} from '$lib/api/dashboard/a76/general_catalogs/unit-conversions';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioConversiones } from '$lib/config/shortcuts/dashboard/general_catalogs/unit_conversions/edit';
let {
@@ -25,13 +24,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Conversiones',
obtenerAtajosFormularioConversiones({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(mode === 'edit');
const title = $derived(isEdit ? 'Editar Conversión' : 'Nueva Conversión');

View File

@@ -9,7 +9,6 @@
type UnitOfMeasureACE
} from '$lib/api/dashboard/a76/general_catalogs/units-of-measure';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioUnidadesACE } from '$lib/config/shortcuts/dashboard/general_catalogs/units_of_measure/ace/edit';
let {
@@ -23,13 +22,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Unidades ACE',
obtenerAtajosFormularioUnidadesACE({
manejarGuardar: () => handleSubmit(),
manejarCerrar: () => (open = false)
})
);
const isEdit = $derived(!!item);
const title = $derived(isEdit ? 'Editar Unidad ACE' : 'Nueva Unidad ACE');

View File

@@ -13,7 +13,6 @@
updateUnitOfMeasureAmerican
} from '$lib/api/dashboard/a76/general_catalogs/units-of-measure';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioUnidadesAmericanas } from '$lib/config/shortcuts/dashboard/general_catalogs/units_of_measure/american/edit';
interface Props {
@@ -25,13 +24,6 @@
let { open = $bindable(), unit, onSuccess }: Props = $props();
// Atajos
useShortcuts(
'Formulario Unidades Americanas',
obtenerAtajosFormularioUnidadesAmericanas({
manejarGuardar: (e: any) => handleSubmit(e),
manejarCerrar: () => (open = false)
})
);
let formData = $state({
code: '',

View File

@@ -13,7 +13,6 @@
updateUnitOfMeasureCustoms
} from '$lib/api/dashboard/a76/general_catalogs/units-of-measure';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioUnidadesAduanas } from '$lib/config/shortcuts/dashboard/general_catalogs/units_of_measure/customs/edit';
interface Props {
@@ -25,13 +24,6 @@
let { open = $bindable(), unit, onSuccess }: Props = $props();
// Atajos
useShortcuts(
'Formulario Unidades Aduanas',
obtenerAtajosFormularioUnidadesAduanas({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
let formData = $state({
code: '',

View File

@@ -13,7 +13,6 @@
updateUnitOfMeasureGeneral
} from '$lib/api/dashboard/a76/general_catalogs/units-of-measure';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioUnidadesGeneral } from '$lib/config/shortcuts/dashboard/general_catalogs/units_of_measure/general/edit';
interface Props {
@@ -25,13 +24,6 @@
let { open = $bindable(), unit, onSuccess }: Props = $props();
// Atajos
useShortcuts(
'Formulario Unidades de Medida',
obtenerAtajosFormularioUnidadesGeneral({
manejarGuardar: (e: any) => handleSubmit(e),
manejarCerrar: () => (open = false)
})
);
let formData = $state({
code: '',

View File

@@ -13,7 +13,6 @@
updateUnitOfMeasureOMA
} from '$lib/api/dashboard/a76/general_catalogs/units-of-measure';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioUnidadesOMA } from '$lib/config/shortcuts/dashboard/general_catalogs/units_of_measure/oma/edit';
interface Props {
@@ -25,13 +24,6 @@
let { open = $bindable(), unit, onSuccess }: Props = $props();
// Atajos
useShortcuts(
'Formulario Unidades OMA',
obtenerAtajosFormularioUnidadesOMA({
manejarGuardar: (e: any) => handleSubmit(e),
manejarCerrar: () => (open = false)
})
);
let formData = $state({
code: '',

View File

@@ -9,7 +9,6 @@
type Package
} from '$lib/api/dashboard/a76/general_catalogs/packages';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioBultos } from '$lib/config/shortcuts/dashboard/general_catalogs/packages/edit';
let {
@@ -27,13 +26,6 @@
const title = $derived(isEdit ? 'Editar Bulto' : 'Nuevo Bulto');
// Atajos
useShortcuts(
'Formulario Bultos',
obtenerAtajosFormularioBultos({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
// Estado del formulario
let formData = $state({

View File

@@ -11,7 +11,6 @@
PortType
} from '$lib/api/dashboard/a76/general_catalogs/ports';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioPuertos } from '$lib/config/shortcuts/dashboard/general_catalogs/ports/edit';
let {
@@ -30,13 +29,6 @@
const title = $derived(isEdit ? 'Editar Puerto' : 'Nuevo Puerto');
// Atajos
useShortcuts(
'Formulario Puertos',
obtenerAtajosFormularioPuertos({
manejarGuardar: handleSubmit,
manejarCerrar: () => (open = false)
})
);
let formData = $state({
port_code: '',

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -62,5 +62,5 @@
<!-- Dialogs -->
<DetailsDialog bind:open={showDetailsDialog} {item} />
<CreateEditDialog bind:open={showEditDialog} bind:item {onSuccess} />
<CreateEditDialog bind:open={showEditDialog} item={item} {onSuccess} />
<DeleteDialog bind:open={showDeleteDialog} {item} {onSuccess} />

View File

@@ -7,7 +7,6 @@
import type { Seal } from '$lib/api/dashboard/a76/general_catalogs/seal';
import { createSeal, updateSeal } from '$lib/api/dashboard/a76/general_catalogs/seal';
import { companyStore } from '$lib/stores/company.svelte';
import { useShortcuts } from '$lib/hooks/use-shortcuts';
import { obtenerAtajosFormularioSellos } from '$lib/config/shortcuts/dashboard/general_catalogs/seal/edit';
let {
@@ -21,13 +20,6 @@
} = $props();
// Atajos
useShortcuts(
'Formulario Sellos',
obtenerAtajosFormularioSellos({
manejarGuardar: (e: any) => handleSubmit(e),
manejarCerrar: () => (open = false)
})
);
let loading = $state(false);
let error = $state<string | null>(null);

View File

@@ -1,5 +1,7 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { browser } from '$app/environment';
import { GLOBAL_NAV } from '$lib/config/shortcuts';
import { shortcutStore, activeShortcutsList } from '$lib/stores/shortcut-store';
import { focusStore } from '$lib/stores/focus-store';
@@ -8,6 +10,16 @@
let showHelp = $state(false);
let lastShortcutTime = 0;
// Verificar si el usuario está autenticado
function isAuthenticated(): boolean {
if (!browser) return false;
const currentPath = $page?.url?.pathname || '';
const isAuthenticatedRoute = currentPath.startsWith('/dashboard');
const hasAccessToken = document.cookie.includes('access_token=') ||
localStorage.getItem('access_token');
return isAuthenticatedRoute && !!hasAccessToken;
}
function autoFocusFirstInput() {
// Small delay to allow Svelte to render the new view
setTimeout(() => {
@@ -101,6 +113,9 @@
});
function handleKeydown(event: KeyboardEvent) {
// Verificar autenticación al inicio
const authenticated = isAuthenticated();
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
const lowerKey = key.toLowerCase();
@@ -138,6 +153,10 @@
// 1. HELP: F1
if (key === 'F1') {
// Solo permitir F1 si está autenticado
if (!isAuthenticated()) {
return;
}
event.preventDefault();
showHelp = !showHelp;
return;
@@ -160,28 +179,30 @@
}
// 3. PRIORITY: LOCAL SHORTCUTS
// Match exact combo string against registered shortcuts
// Search in REVERSE order (LIFO) so recent contexts (modals) override earlier ones (pages)
const reversedShortcuts = [...$activeShortcutsList].reverse();
let match = reversedShortcuts.find((s) => s.key === combo);
// Solo permitir atajos locales si está autenticado
if (authenticated) {
// Match exact combo string against registered shortcuts
// Search in REVERSE order (LIFO) so recent contexts (modals) override earlier ones (pages)
const reversedShortcuts = [...$activeShortcutsList].reverse();
let match = reversedShortcuts.find((s) => s.key === combo);
// Fallback: If no match found by 'key' (e.g. Shift+1 produces 'Alt+Shift+!'),
// try matching by 'code' (e.g. 'Alt+Shift+Digit1')
if (!match) {
const codeCombo = [...modifiers, event.code].join('+');
match = reversedShortcuts.find((s) => s.key === codeCombo);
}
if (match) {
// Guard: If it's a single key (no modifiers) and we are in input, ignore it
// Unless the shortcut explicitly says "allowInInput" (not implemented yet, assuming strictly no inputs for single keys)
if (modifiers.length === 0 && isInput) {
// allow native typing
return;
// Fallback: If no match found by 'key' (e.g. Shift+1 produces 'Alt+Shift+!'),
// try matching by 'code' (e.g. 'Alt+Shift+Digit1')
if (!match) {
const codeCombo = [...modifiers, event.code].join('+');
match = reversedShortcuts.find((s) => s.key === codeCombo);
}
event.preventDefault();
event.stopPropagation(); // Stop bubbling
if (match) {
// Guard: If it's a single key (no modifiers) and we are in input, ignore it
// Unless the shortcut explicitly says "allowInInput" (not implemented yet, assuming strictly no inputs for single keys)
if (modifiers.length === 0 && isInput) {
// allow native typing
return;
}
event.preventDefault();
event.stopPropagation(); // Stop bubbling
lastShortcutTime = Date.now();
match.action();
@@ -200,12 +221,11 @@
}
return;
}
} // Fin del bloque authenticated
// 4. GLOBAL NAV: Alt + Key (Legacy/Default behavior for global nav)
// We keep this simple logic for now, or we could move GLOBAL_NAV to be registered in the store too?
// Let's keep the hardcoded Alt+Key check for GLOBAL_NAV for simplicity/performance
// essentially satisfying the "Central Config" requirement.
if (altKey && modifiers.length === 1) {
// Solo permitir si está autenticado
if (authenticated && altKey && modifiers.length === 1) {
// Exactly Alt + Key (no shift/ctrl)
// Special: Alt+B -> Focus Search
if (lowerKey === 'b') {