Private
Public Access
wip: skeleton de la funcionalidad falta arreglar un bug
This commit is contained in:
1 parent
266365ae0f
commit
f9cf001fca
9 files changed
+270
-1
No files matched your search
@@ -0,0 +1,105 @@
|
||||
<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
|
||||
}: { open: boolean; onClose: Function; repuesto: ActualizarRepuestoDto } = $props();
|
||||
|
||||
let error = $state('');
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="actualizarRepuestoForm"
|
||||
bind:open
|
||||
size={'lg'}
|
||||
modalHeading={`Editar Repuesto: ${repuesto.id}`}
|
||||
primaryButtonText="Editar"
|
||||
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="Marca: " 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>
|
||||
Reference in new issue
Block a user