Private
Public Access
añadida funcionalidad de actualizar marcas
This commit is contained in:
1 parent
4625f75a45
commit
3a9dcdfce7
5 files changed
+165
-6
No files matched your search
@@ -4,6 +4,7 @@
|
||||
import { Add, ArrowUp, Edit, Information, TrashCan } from 'carbon-icons-svelte';
|
||||
import type { Marca } from '../../types';
|
||||
import CrearMarcaForm from './CrearMarcaForm.svelte';
|
||||
import EditarMarcaForm from './EditarMarcaForm.svelte';
|
||||
|
||||
let error = $state("");
|
||||
|
||||
@@ -26,7 +27,9 @@
|
||||
{ key: 'DeletedAt', value: 'Estado' }
|
||||
];
|
||||
|
||||
let openCrear = $state(false)
|
||||
let openCrear = $state(false);
|
||||
let openEdit = $state(false);
|
||||
let marcaSeleccionada: Marca | null = $state(null);
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
@@ -75,8 +78,8 @@
|
||||
{#each headers as header}
|
||||
<TableCell>{String(p[header.key] ?? '-')}</TableCell>
|
||||
{/each}
|
||||
<TableCell>{console.log(p)}
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => {}}>Editar</Button>
|
||||
<TableCell>
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => { marcaSeleccionada = p; openEdit = true; }}>Editar</Button>
|
||||
{#if p.DeletedAt}
|
||||
<Button kind="ghost" size="small" icon={ArrowUp} onclick={() => {}}>Alta</Button>
|
||||
{:else}
|
||||
@@ -91,5 +94,6 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<CrearMarcaForm bind:open={openCrear} onClose={()=> openCrear = false}>
|
||||
</CrearMarcaForm>
|
||||
|
||||
<CrearMarcaForm bind:open={openCrear} onClose={() => openCrear = false} />
|
||||
<EditarMarcaForm bind:open={openEdit} marca={marcaSeleccionada} onClose={() => { openEdit = false; marcaSeleccionada = null; }} />
|
||||
@@ -0,0 +1,75 @@
|
||||
<script lang="ts">
|
||||
import { Modal, TextInput } from 'carbon-components-svelte';
|
||||
import type { Marca } from '../../types';
|
||||
import { actualizarMarca } from '$lib/hooks/marcas/actualizarMarca';
|
||||
import { invalidate } from '$app/navigation';
|
||||
|
||||
// Props to control modal visibility and the marca to edit
|
||||
let { open = $bindable(), onClose, marca } = $props();
|
||||
|
||||
let error = $state('');
|
||||
let enviando = $state(false);
|
||||
let nombre = $state('');
|
||||
|
||||
$effect(()=>{
|
||||
if (marca) {
|
||||
nombre = marca.nombre ?? '';
|
||||
}
|
||||
})
|
||||
|
||||
function handleClose() {
|
||||
reset();
|
||||
onClose?.();
|
||||
}
|
||||
function reset() {
|
||||
nombre = '';
|
||||
error = '';
|
||||
enviando = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
id="editarMarcaForm"
|
||||
onsubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (enviando) return;
|
||||
enviando = true;
|
||||
error = '';
|
||||
if (!nombre.trim()) {
|
||||
error = 'Falta Nombre';
|
||||
}
|
||||
if (error === '' && marca) {
|
||||
const result = await actualizarMarca(marca.ID, nombre);
|
||||
if (result === 'ok') {
|
||||
invalidate('marcas:load');
|
||||
handleClose();
|
||||
} else {
|
||||
error = result ?? 'Error desconocido';
|
||||
}
|
||||
}
|
||||
enviando = false;
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="editarMarcaForm"
|
||||
bind:open
|
||||
size={'lg'}
|
||||
modalHeading="Editar Marca"
|
||||
primaryButtonText="Guardar"
|
||||
primaryButtonDisabled={enviando}
|
||||
secondaryButtonText="Cancelar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
<TextInput
|
||||
name="nombre"
|
||||
type="text"
|
||||
labelText="Nombre:"
|
||||
bind:value={nombre}
|
||||
maxlength={70}
|
||||
/>
|
||||
<div class="text-sm text-gray-500 mt-1">{String(nombre).length}/70</div>
|
||||
</Modal>
|
||||
</form>
|
||||
Reference in new issue
Block a user