Private
Public Access
funcionalidad de alta repuesto terminada
This commit is contained in:
1 parent
d0500dc764
commit
352973d2f5
15 files changed
+218
-38
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { obtenerRepuestos } from '$lib/hooks/repuestos/obtenerRepuestos';
|
||||
|
||||
export let ssr = false;
|
||||
export async function load({ fetch }) {
|
||||
export async function load({ fetch, depends }) {
|
||||
depends('repuestos:load');
|
||||
const repuestos = await obtenerRepuestos(fetch);
|
||||
|
||||
let error = '';
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { Button, Modal, NumberInput, TextInput } from 'carbon-components-svelte';
|
||||
import { Add } from 'carbon-icons-svelte';
|
||||
import type { CrearRepuestoDto } from '../../types';
|
||||
import { crearRepuesto } from '$lib/hooks/repuestos/crearRepuesto';
|
||||
import { invalidate } from '$app/navigation';
|
||||
|
||||
let { open = $bindable(), onClose } = $props();
|
||||
|
||||
let error = $state('');
|
||||
let repuesto = $state({
|
||||
let repuesto: CrearRepuestoDto = $state({
|
||||
nombre: '',
|
||||
descripcion: '',
|
||||
marca: '',
|
||||
aliases: [],
|
||||
aliases: [''],
|
||||
precio: 0,
|
||||
stockMinimo: 0
|
||||
});
|
||||
@@ -31,8 +33,21 @@
|
||||
|
||||
<form
|
||||
id="crearRepuestoForm"
|
||||
onsubmit={(e) => {
|
||||
onsubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
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 crearRepuesto(repuesto);
|
||||
}
|
||||
if (error == 'Ok') {
|
||||
invalidate('repuestos:load');
|
||||
handleClose();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
@@ -62,20 +77,30 @@
|
||||
labelText="Stock Minimo (es para los avisos): "
|
||||
bind:value={repuesto.stockMinimo}
|
||||
/>
|
||||
<div class="my-2! flex justify-between">
|
||||
<div class="my-2!">
|
||||
<h5>Aliases</h5>
|
||||
<Button
|
||||
size="small"
|
||||
icon={Add}
|
||||
onclick={() => {
|
||||
repuesto.aliases.push('');
|
||||
}}>Añadir Alias</Button
|
||||
>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
{#each repuesto.aliases as _, index}
|
||||
<TextInput name={`alias-${index}`} bind:value={repuesto.aliases[index]} />
|
||||
{/each}
|
||||
<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