Private
Public Access
117 lines
2.8 KiB
Svelte
117 lines
2.8 KiB
Svelte
<script lang="ts">
|
|
import { Button, Modal, NumberInput, TextInput } from 'carbon-components-svelte';
|
|
import type { ActualizarRepuestoDto } from '../../types';
|
|
import { invalidate } from '$app/navigation';
|
|
import { actualizarRepuesto } from '$lib/hooks/repuestos/actualizarRepuesto';
|
|
|
|
let {
|
|
open = $bindable(),
|
|
onClose,
|
|
repuesto = $bindable()
|
|
}: { open: boolean; onClose: Function; repuesto: ActualizarRepuestoDto } = $props();
|
|
|
|
let error = $state('');
|
|
let enviando = $state(false);
|
|
|
|
function handleClose() {
|
|
reset();
|
|
onClose();
|
|
}
|
|
function reset() {
|
|
repuesto = {
|
|
id: 0,
|
|
nombre: '',
|
|
descripcion: '',
|
|
marca: '',
|
|
aliases: [],
|
|
precio: 0,
|
|
stockMinimo: 0
|
|
};
|
|
}
|
|
</script>
|
|
|
|
<form
|
|
id="actualizarRepuestoForm"
|
|
onsubmit={async (e) => {
|
|
e.preventDefault();
|
|
if (enviando) return;
|
|
enviando = true;
|
|
error = '';
|
|
if (repuesto.id == 0) error += 'Falta id';
|
|
if (repuesto.descripcion == '') error += 'Falta Descripcion, ';
|
|
if (repuesto.marca == '') error += 'Falta Marca, ';
|
|
if (repuesto.precio <= 0) error += 'El precio es 0 o menor, ';
|
|
if (repuesto.nombre == '') error += 'Falta Nombre';
|
|
|
|
if (error == '') {
|
|
error = await actualizarRepuesto(repuesto);
|
|
}
|
|
if (error == 'Ok') {
|
|
invalidate('repuestos:load');
|
|
handleClose();
|
|
}
|
|
enviando = false;
|
|
}}
|
|
>
|
|
<Modal
|
|
formId="actualizarRepuestoForm"
|
|
bind:open
|
|
size={'lg'}
|
|
modalHeading={`Editar Repuesto: ${repuesto.id}`}
|
|
primaryButtonText="Editar"
|
|
primaryButtonDisabled={enviando}
|
|
secondaryButtonText="Cerrar"
|
|
on:click:button--secondary={handleClose}
|
|
>
|
|
{#if error}
|
|
<div class="error-msg">{error}</div>
|
|
{/if}
|
|
<TextInput name="nombre" type="text" labelText="Nombre: " bind:value={repuesto.nombre} />
|
|
<TextInput
|
|
name="descripcion"
|
|
type="text"
|
|
labelText="Descripcion: "
|
|
bind:value={repuesto.descripcion}
|
|
/>
|
|
<TextInput
|
|
name="marca"
|
|
type="text"
|
|
labelText="ID Marca: "
|
|
maxlength={3}
|
|
bind:value={repuesto.marca}
|
|
/>
|
|
|
|
<NumberInput name="precio" labelText="Precio: " bind:value={repuesto.precio} />
|
|
<NumberInput
|
|
name="stockMinimo"
|
|
labelText="Stock Minimo (es para los avisos): "
|
|
bind:value={repuesto.stockMinimo}
|
|
/>
|
|
<div class="my-2!">
|
|
<h5>Aliases</h5>
|
|
<table class="w-full">
|
|
<tbody>
|
|
{#each repuesto.aliases as _, index}
|
|
<tr>
|
|
<td>
|
|
<TextInput
|
|
maxlength={70}
|
|
name={`alias-${index}`}
|
|
bind:value={repuesto.aliases[index]}
|
|
on:input={() => {
|
|
if (index === repuesto.aliases.length - 1 && repuesto.aliases[index] !== '') {
|
|
repuesto.aliases.push('');
|
|
} else if (repuesto.aliases[index] == '') {
|
|
repuesto.aliases.pop();
|
|
}
|
|
}}
|
|
/>
|
|
</td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</Modal>
|
|
</form>
|