This commit is contained in:
fede committed 2026-06-19 23:04:13 -03:00
1 parent 6c0e44cb45
commit 90e76d4963
11 files changed
+112 -38

No files matched your search

@@ -0,0 +1,22 @@
import { API_URL } from '$lib/env';
import { getToken } from '../token';
export async function obtenerRepuestos(fetch2?: Function) {
const fetchfn = fetch2 ? fetch2 : fetch;
try {
const req = await fetchfn(`${API_URL}/repuestos`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${getToken()}`
}
});
const data = await req.json();
if (req.ok) {
return data;
}
return data.error;
} catch {
return 'no se puso alcanzar el servidor';
}
}
+2 -10
View File
@@ -6,17 +6,9 @@ export const load: PageLoad = async ({ fetch }) => {
let grupos: Grupo[] = [];
let permisos: Permiso[] = [];
try {
grupos = await obtenerGrupos(fetch);
} catch {
// token might not be available on server
}
grupos = await obtenerGrupos(fetch);
try {
permisos = await obtenerPermisos(fetch);
} catch {
// token might not be available on server
}
permisos = await obtenerPermisos(fetch);
return { grupos, permisos };
};
+22 -13
View File
@@ -18,8 +18,15 @@
let error = $state('');
let loading = $state('');
let { data } = $props();
let openCrear = $state(false);
$effect(() => {
if (data.error) {
error = data.error;
}
});
const headers = [
{ key: 'id', value: 'ID' },
{ key: 'nombre', value: 'Nombre' },
@@ -54,19 +61,21 @@
</TableRow>
</TableHead>
<TableBody>
{#each [{ id: 1 }] as p (p.id)}
<TableRow>
{#each headers as header}
<TableCell>{String(p[header.key] ?? '-')}</TableCell>
{/each}
<TableCell class="acciones-cell">
<!-- onclick={() => abrirModalEditar(p)} -->
<Button kind="ghost" size="small" icon={Edit}>Editar</Button>
<!-- onclick={() => abrirModalEliminar(p)} -->
<Button kind="ghost" size="small" icon={TrashCan}>Eliminar</Button>
</TableCell>
</TableRow>
{/each}
{#if typeof data.repuestos !== 'string'}
{#each data.repuestos as p}
<TableRow>
{#each headers as header}
<TableCell>{String(p[header.key] ?? '-')}</TableCell>
{/each}
<TableCell class="acciones-cell">
<!-- onclick={() => abrirModalEditar(p)} -->
<Button kind="ghost" size="small" icon={Edit}>Editar</Button>
<!-- onclick={() => abrirModalEliminar(p)} -->
<Button kind="ghost" size="small" icon={TrashCan}>Eliminar</Button>
</TableCell>
</TableRow>
{/each}
{/if}
</TableBody>
</Table>
</TableContainer>
+15
View File
@@ -0,0 +1,15 @@
import { obtenerRepuestos } from '$lib/hooks/repuestos/obtenerRepuestos';
export let ssr = false;
export async function load({ fetch }) {
const repuestos = await obtenerRepuestos(fetch);
let error = '';
if (typeof repuestos === 'string') {
error = repuestos;
}
return {
repuestos: repuestos,
error: error
};
}
@@ -1,6 +1,6 @@
<script>
import { Button, Modal, NumberInput, TextInput } from 'carbon-components-svelte';
import { Add, CPlusPlus } from 'carbon-icons-svelte';
import { Add } from 'carbon-icons-svelte';
let { open = $bindable(), onClose } = $props();