feat: logs para cuando le volves a dar el alta a un repuesto

This commit is contained in:
fede committed 2026-07-20 18:20:21 -03:00
1 parent c906dd4511
commit 6d123ea01d
13 files changed
+215 -7

No files matched your search

@@ -0,0 +1,20 @@
import { API_URL } from '$lib/env';
import { getToken } from '../token';
export async function altaRepuesto(id: number) {
try {
const req = await fetch(`${API_URL}/repuestos/${id}/alta`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${getToken()}`
}
});
if (req.ok) {
return 'Ok';
}
const data = await req.json();
return data.error;
} catch {
return 'no se puso alcanzar el servidor';
}
}
@@ -0,0 +1,50 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { altaRepuesto } from '$lib/hooks/repuestos/altaRepuesto';
import { Modal } from 'carbon-components-svelte';
let {
show = $bindable(),
onclose,
repuesto
}: { show?: boolean; onclose: () => void; repuesto: { id: number } } = $props();
let error = $state('');
async function handleSubmit(e: Event) {
e.preventDefault();
error = '';
if (!repuesto.id) {
error = 'No se pudo obtener la id del Repuesto? recarga la pagina.';
return;
}
const result = await altaRepuesto(repuesto.id);
if (result !== 'Ok') {
error = result;
return;
}
handleClose();
}
function handleClose() {
error = '';
invalidate('repuestos:load');
onclose();
}
</script>
<form id="altaRepuestoForm" onsubmit={handleSubmit}>
<Modal
formId="altaRepuestoForm"
bind:open={show}
modalHeading="Alta Repuesto"
primaryButtonText="Alta"
secondaryButtonText="Cerrar"
on:click:button--secondary={handleClose}
>
{#if error}
<div>{error}</div>
{/if}
Esta seguro que quiere volver a dar de alta a este Repuesto?
</Modal>
</form>