Private
Public Access
feat: añadido eliminar repuestos y un modal para ver el objeto entero
This commit is contained in:
1 parent
72790ac9a3
commit
2549b7d6ba
7 files changed
+168
-12
No files matched your search
@@ -12,14 +12,21 @@
|
||||
TableHeader,
|
||||
TableRow
|
||||
} from 'carbon-components-svelte';
|
||||
import { Add, Edit, TrashCan } from 'carbon-icons-svelte';
|
||||
import { Add, Edit, Information, TrashCan } from 'carbon-icons-svelte';
|
||||
import CrearRepuestoForm from './CrearRepuestoForm.svelte';
|
||||
import EliminarRepuestoForm from './EliminarRepuestoForm.svelte';
|
||||
import ModalStructured from '$lib/components/ModalStructured.svelte';
|
||||
|
||||
let error = $state('');
|
||||
let loading = $state('');
|
||||
|
||||
let { data } = $props();
|
||||
let openCrear = $state(false);
|
||||
let openEliminar = $state(false);
|
||||
let openInfo = $state(false);
|
||||
|
||||
let repuestoEliminar = $state({ id: 0 });
|
||||
let repuestoInfo = $state();
|
||||
|
||||
$effect(() => {
|
||||
if (data.error) {
|
||||
@@ -72,8 +79,24 @@
|
||||
<!-- onclick={() => abrirModalEditar(p)} -->
|
||||
<Button kind="ghost" size="small" icon={Edit}>Editar</Button>
|
||||
<Button kind="ghost" size="small">Ver Existencias</Button>
|
||||
<!-- onclick={() => abrirModalEliminar(p)} -->
|
||||
<Button kind="ghost" size="small" icon={TrashCan}>Eliminar</Button>
|
||||
<Button
|
||||
onclick={() => {
|
||||
repuestoInfo = p;
|
||||
openInfo = true;
|
||||
}}
|
||||
kind="ghost"
|
||||
size="small"
|
||||
icon={Information}>Ver registro</Button
|
||||
>
|
||||
<Button
|
||||
onclick={() => {
|
||||
repuestoEliminar = p;
|
||||
openEliminar = true;
|
||||
}}
|
||||
kind="ghost"
|
||||
size="small"
|
||||
icon={TrashCan}>Eliminar</Button
|
||||
>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
@@ -90,3 +113,14 @@
|
||||
openCrear = false;
|
||||
}}
|
||||
></CrearRepuestoForm>
|
||||
|
||||
<EliminarRepuestoForm
|
||||
bind:show={openEliminar}
|
||||
onclose={() => {
|
||||
openEliminar = false;
|
||||
repuestoEliminar = { id: 0 };
|
||||
}}
|
||||
repuesto={repuestoEliminar}
|
||||
></EliminarRepuestoForm>
|
||||
|
||||
<ModalStructured objeto={repuestoInfo} bind:open={openInfo} />
|
||||
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { eliminarRepuesto } from '$lib/hooks/repuestos/eliminarRepuesto';
|
||||
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 eliminarRepuesto(repuesto.id);
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
handleClose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
error = '';
|
||||
invalidate('repuestos:load');
|
||||
onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="eliminarRepuestoForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="eliminarRepuestoForm"
|
||||
bind:open={show}
|
||||
modalHeading="Eliminar Repuesto"
|
||||
primaryButtonText="Eliminar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div>{error}</div>
|
||||
{/if}
|
||||
Esta seguro que quiere borrar este Repuesto?
|
||||
</Modal>
|
||||
</form>
|
||||
@@ -41,16 +41,8 @@
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
<div>{error}</div>
|
||||
{/if}
|
||||
Esta seguro que quiere borrar este usuario?
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.error-msg {
|
||||
color: #da1e28;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user